From 26c8aacc54eb8bc80dec1bc562ee3f5de095e8b6 Mon Sep 17 00:00:00 2001 From: jalapenopuzzle <8386278+jalapenopuzzle@users.noreply.github.com> Date: Tue, 8 Apr 2025 10:29:44 +1000 Subject: [PATCH] CAM: snapmaker --machine is a required option --- src/Mod/CAM/CAMTests/TestSnapmakerPost.py | 14 +++++++++++++- src/Mod/CAM/Path/Post/scripts/snapmaker_post.py | 15 ++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/Mod/CAM/CAMTests/TestSnapmakerPost.py b/src/Mod/CAM/CAMTests/TestSnapmakerPost.py index eb28b107eb..117b509ee3 100644 --- a/src/Mod/CAM/CAMTests/TestSnapmakerPost.py +++ b/src/Mod/CAM/CAMTests/TestSnapmakerPost.py @@ -238,10 +238,22 @@ M5 ) # no TLO on Snapmaker (G43 inserted after tool change) def test_models(self): - """Test the various models.""" + """Test the various models, and also test models that don't exist cause an error.""" command = Path.Command("G0 X10 Y20 Z30") expected = "G0 X10.000 Y20.000 Z30.000" + with self.assertRaises(SystemExit): + self.get_gcode( + [command], + "--no-header", + ) + + with self.assertRaises(SystemExit): + gcode = self.get_gcode( + [command], + "--machine=robot --no-header", + ) + gcode = self.get_gcode( [command], "--machine=Original --toolhead=50W --spindle-percent --no-header", diff --git a/src/Mod/CAM/Path/Post/scripts/snapmaker_post.py b/src/Mod/CAM/Path/Post/scripts/snapmaker_post.py index d724861df1..31ad9c01ec 100644 --- a/src/Mod/CAM/Path/Post/scripts/snapmaker_post.py +++ b/src/Mod/CAM/Path/Post/scripts/snapmaker_post.py @@ -179,7 +179,7 @@ class Snapmaker(Path.Post.Processor.PostProcessor): self.values["END_OF_LINE_CHARACTERS"] = "\n" self.values["FINISH_LABEL"] = "End" self.values["LINE_INCREMENT"] = 1 - self.values["MACHINE_NAME"] = "Generic Snapmaker" + self.values["MACHINE_NAME"] = None self.values["MODAL"] = False self.values["OUTPUT_PATH_LABELS"] = True self.values["OUTPUT_HEADER"] = ( @@ -327,6 +327,7 @@ class Snapmaker(Path.Post.Processor.PostProcessor): group.add_argument( "--machine", default=None, + required=True, choices=self.values["MACHINES"].keys(), help=f"Snapmaker machine. Choose from [{self.values['MACHINES'].keys()}].", ) @@ -382,12 +383,12 @@ class Snapmaker(Path.Post.Processor.PostProcessor): if flag: # process extra arguments only if flag is True self._units = self.values["UNITS"] - if args.machine: - machine = self.values["MACHINES"][args.machine] - self.values["MACHINE_KEY"] = machine["key"] - self.values["MACHINE_NAME"] = machine["name"] - # The deepcopy is necessary to avoid modifying the boundaries in the MACHINES dict. - self.values["BOUNDARIES"] = copy.deepcopy(machine["boundaries"]) + # --machine is a required "option" + machine = self.values["MACHINES"][args.machine] + self.values["MACHINE_KEY"] = machine["key"] + self.values["MACHINE_NAME"] = machine["name"] + # The deepcopy is necessary to avoid modifying the boundaries in the MACHINES dict. + self.values["BOUNDARIES"] = copy.deepcopy(machine["boundaries"]) if args.boundaries: # may override machine boundaries, which is expected self.values["BOUNDARIES"] = args.boundaries