MichaelRKessler Claude Fable 5 commited on
Commit
975a31d
·
1 Parent(s): 3ca546a

Add Shape 2 and Shape 3 G-code sources to visualization tab

Browse files

The G-Code source selector now offers "Use Shape 2 G-Code" and
"Use Shape 3 G-Code" alongside Shape 1 and file upload, each pulling
the corresponding generated file from the TIFF Slices to GCode tab.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +33 -11
app.py CHANGED
@@ -983,6 +983,8 @@ def run_all_tiff_to_gcode(
983
 
984
 
985
  GCODE_SOURCE_SHAPE1 = "Use Shape 1 G-Code"
 
 
986
  GCODE_SOURCE_UPLOAD = "Upload G-Code file"
987
 
988
 
@@ -994,6 +996,8 @@ def render_toolpath(
994
  source: str,
995
  uploaded_path: str | None,
996
  shape1_path: str | None,
 
 
997
  travel_opacity: float = 0.25,
998
  print_opacity: float = 1.0,
999
  travel_color: str = "#969696",
@@ -1007,9 +1011,14 @@ def render_toolpath(
1007
  if not path:
1008
  return None, "No G-code file uploaded yet.", {}
1009
  else:
1010
- path = shape1_path
 
 
 
 
 
1011
  if not path:
1012
- return None, "No Shape 1 G-code available yet. Generate it on the TIFF Slices to GCode tab first.", {}
1013
 
1014
  try:
1015
  text = Path(path).read_text()
@@ -1037,6 +1046,8 @@ def render_toolpath_lines(
1037
  source: str,
1038
  uploaded_path: str | None,
1039
  shape1_path: str | None,
 
 
1040
  travel_opacity: float,
1041
  print_opacity: float,
1042
  travel_color: str,
@@ -1045,8 +1056,9 @@ def render_toolpath_lines(
1045
  travel_width: float,
1046
  ) -> tuple[Any, str, dict, str, dict[str, Any], dict[str, Any]]:
1047
  figure, status, parsed = render_toolpath(
1048
- source, uploaded_path, shape1_path, travel_opacity, print_opacity,
1049
- travel_color, print_color, print_width, travel_width, tube=False,
 
1050
  )
1051
  return figure, status, parsed, "line", gr.update(visible=False), gr.update(visible=False)
1052
 
@@ -1055,6 +1067,8 @@ def render_toolpath_tubes(
1055
  source: str,
1056
  uploaded_path: str | None,
1057
  shape1_path: str | None,
 
 
1058
  travel_opacity: float,
1059
  print_opacity: float,
1060
  travel_color: str,
@@ -1063,8 +1077,9 @@ def render_toolpath_tubes(
1063
  travel_width: float,
1064
  ) -> tuple[Any, str, dict, str, dict[str, Any], dict[str, Any]]:
1065
  figure, status, parsed = render_toolpath(
1066
- source, uploaded_path, shape1_path, travel_opacity, print_opacity,
1067
- travel_color, print_color, print_width, travel_width, tube=True,
 
1068
  )
1069
  # Playback controls and mm width sliders only apply to the tube figure.
1070
  has_animation = bool(parsed.get("point_count"))
@@ -1076,6 +1091,8 @@ def rerender_toolpath_current_mode(
1076
  source: str,
1077
  uploaded_path: str | None,
1078
  shape1_path: str | None,
 
 
1079
  travel_opacity: float,
1080
  print_opacity: float,
1081
  travel_color: str,
@@ -1084,9 +1101,9 @@ def rerender_toolpath_current_mode(
1084
  travel_width: float,
1085
  ) -> tuple[Any, str, dict]:
1086
  return render_toolpath(
1087
- source, uploaded_path, shape1_path, travel_opacity, print_opacity,
1088
- travel_color, print_color, print_width, travel_width,
1089
- tube=(mode != "line"),
1090
  )
1091
 
1092
 
@@ -1586,7 +1603,12 @@ def build_demo() -> gr.Blocks:
1586
  # --- G-code source selection, above the controls/chart area ---
1587
  with gr.Row():
1588
  gcode_source = gr.Radio(
1589
- choices=[GCODE_SOURCE_SHAPE1, GCODE_SOURCE_UPLOAD],
 
 
 
 
 
1590
  value=GCODE_SOURCE_SHAPE1,
1591
  label="G-Code source",
1592
  )
@@ -1680,7 +1702,7 @@ def build_demo() -> gr.Blocks:
1680
  outputs=[upload_col],
1681
  queue=False,
1682
  )
1683
- render_inputs = [gcode_source, gcode_upload, gcode_file_1, travel_opacity_slider, print_opacity_slider, travel_color_picker, print_color_picker, print_width_slider, travel_width_slider]
1684
  render_line_button.click(
1685
  fn=render_toolpath_lines,
1686
  inputs=render_inputs,
 
983
 
984
 
985
  GCODE_SOURCE_SHAPE1 = "Use Shape 1 G-Code"
986
+ GCODE_SOURCE_SHAPE2 = "Use Shape 2 G-Code"
987
+ GCODE_SOURCE_SHAPE3 = "Use Shape 3 G-Code"
988
  GCODE_SOURCE_UPLOAD = "Upload G-Code file"
989
 
990
 
 
996
  source: str,
997
  uploaded_path: str | None,
998
  shape1_path: str | None,
999
+ shape2_path: str | None,
1000
+ shape3_path: str | None,
1001
  travel_opacity: float = 0.25,
1002
  print_opacity: float = 1.0,
1003
  travel_color: str = "#969696",
 
1011
  if not path:
1012
  return None, "No G-code file uploaded yet.", {}
1013
  else:
1014
+ shape_paths = {
1015
+ GCODE_SOURCE_SHAPE1: (shape1_path, 1),
1016
+ GCODE_SOURCE_SHAPE2: (shape2_path, 2),
1017
+ GCODE_SOURCE_SHAPE3: (shape3_path, 3),
1018
+ }
1019
+ path, shape_num = shape_paths.get(source, (shape1_path, 1))
1020
  if not path:
1021
+ return None, f"No Shape {shape_num} G-code available yet. Generate it on the TIFF Slices to GCode tab first.", {}
1022
 
1023
  try:
1024
  text = Path(path).read_text()
 
1046
  source: str,
1047
  uploaded_path: str | None,
1048
  shape1_path: str | None,
1049
+ shape2_path: str | None,
1050
+ shape3_path: str | None,
1051
  travel_opacity: float,
1052
  print_opacity: float,
1053
  travel_color: str,
 
1056
  travel_width: float,
1057
  ) -> tuple[Any, str, dict, str, dict[str, Any], dict[str, Any]]:
1058
  figure, status, parsed = render_toolpath(
1059
+ source, uploaded_path, shape1_path, shape2_path, shape3_path,
1060
+ travel_opacity, print_opacity, travel_color, print_color,
1061
+ print_width, travel_width, tube=False,
1062
  )
1063
  return figure, status, parsed, "line", gr.update(visible=False), gr.update(visible=False)
1064
 
 
1067
  source: str,
1068
  uploaded_path: str | None,
1069
  shape1_path: str | None,
1070
+ shape2_path: str | None,
1071
+ shape3_path: str | None,
1072
  travel_opacity: float,
1073
  print_opacity: float,
1074
  travel_color: str,
 
1077
  travel_width: float,
1078
  ) -> tuple[Any, str, dict, str, dict[str, Any], dict[str, Any]]:
1079
  figure, status, parsed = render_toolpath(
1080
+ source, uploaded_path, shape1_path, shape2_path, shape3_path,
1081
+ travel_opacity, print_opacity, travel_color, print_color,
1082
+ print_width, travel_width, tube=True,
1083
  )
1084
  # Playback controls and mm width sliders only apply to the tube figure.
1085
  has_animation = bool(parsed.get("point_count"))
 
1091
  source: str,
1092
  uploaded_path: str | None,
1093
  shape1_path: str | None,
1094
+ shape2_path: str | None,
1095
+ shape3_path: str | None,
1096
  travel_opacity: float,
1097
  print_opacity: float,
1098
  travel_color: str,
 
1101
  travel_width: float,
1102
  ) -> tuple[Any, str, dict]:
1103
  return render_toolpath(
1104
+ source, uploaded_path, shape1_path, shape2_path, shape3_path,
1105
+ travel_opacity, print_opacity, travel_color, print_color,
1106
+ print_width, travel_width, tube=(mode != "line"),
1107
  )
1108
 
1109
 
 
1603
  # --- G-code source selection, above the controls/chart area ---
1604
  with gr.Row():
1605
  gcode_source = gr.Radio(
1606
+ choices=[
1607
+ GCODE_SOURCE_SHAPE1,
1608
+ GCODE_SOURCE_SHAPE2,
1609
+ GCODE_SOURCE_SHAPE3,
1610
+ GCODE_SOURCE_UPLOAD,
1611
+ ],
1612
  value=GCODE_SOURCE_SHAPE1,
1613
  label="G-Code source",
1614
  )
 
1702
  outputs=[upload_col],
1703
  queue=False,
1704
  )
1705
+ render_inputs = [gcode_source, gcode_upload, gcode_file_1, gcode_file_2, gcode_file_3, travel_opacity_slider, print_opacity_slider, travel_color_picker, print_color_picker, print_width_slider, travel_width_slider]
1706
  render_line_button.click(
1707
  fn=render_toolpath_lines,
1708
  inputs=render_inputs,