From 1fecb21db72b3e88b24169f80daa327f4a8a1d49 Mon Sep 17 00:00:00 2001 From: Lawrence Woestman Date: Sun, 2 Mar 2025 15:49:46 -0800 Subject: [PATCH] CAM: Added three options to the refactored postprocessors with tests. Removed extra spaces in comments to work around auto-fix removal of spaces at the end of lines in multi-line python strings. --- .../CAM/CAMTests/TestRefactoredGrblPost.py | 4 +- .../CAM/CAMTests/TestRefactoredTestPost.py | 233 +++++++++++++++++- .../CAMTests/TestRefactoredTestPostGCodes.py | 64 ++--- src/Mod/CAM/Path/Post/UtilsArguments.py | 43 +++- src/Mod/CAM/Path/Post/UtilsParse.py | 21 +- 5 files changed, 309 insertions(+), 56 deletions(-) diff --git a/src/Mod/CAM/CAMTests/TestRefactoredGrblPost.py b/src/Mod/CAM/CAMTests/TestRefactoredGrblPost.py index 17d1a8110c..a942985053 100644 --- a/src/Mod/CAM/CAMTests/TestRefactoredGrblPost.py +++ b/src/Mod/CAM/CAMTests/TestRefactoredGrblPost.py @@ -120,7 +120,7 @@ G54 (Path: TC: Default Tool) (TC: Default Tool) (Begin toolchange) -( M6 T1 ) +(M6 T1) (Finish operation: TC: Default Tool) (Begin operation: Profile) (Path: Profile) @@ -307,7 +307,7 @@ M2 self.job.PostProcessorArgs = "--no-header --no-show-editor" gcode = self.post.export()[0][1] # print(f"--------{nl}{gcode}--------{nl}") - self.assertEqual(gcode.splitlines()[16], "( M6 T2 )") + self.assertEqual(gcode.splitlines()[16], "(M6 T2)") self.assertEqual(gcode.splitlines()[17], "M3 S3000") # suppress TLO diff --git a/src/Mod/CAM/CAMTests/TestRefactoredTestPost.py b/src/Mod/CAM/CAMTests/TestRefactoredTestPost.py index 2b1e23a6cd..1dadfddce0 100644 --- a/src/Mod/CAM/CAMTests/TestRefactoredTestPost.py +++ b/src/Mod/CAM/CAMTests/TestRefactoredTestPost.py @@ -194,6 +194,225 @@ M6 T1 ############################################################################# + def test00125(self) -> None: + """Test chipbreaking amount.""" + path = [ + Path.Command("G0 X1 Y2"), + Path.Command("G0 Z8"), + Path.Command("G90"), + Path.Command("G99"), + Path.Command("G73 X1 Y2 Z0 F123 Q1.5 R5"), + Path.Command("G80"), + Path.Command("G90"), + ] + # check the default chipbreaking amount + self.multi_compare( + path, + """G90 +G21 +G54 +M6 T1 +G0 X1.000 Y2.000 +G0 Z8.000 +G90 +G0 X1.000 Y2.000 +G1 Z5.000 F7380.000 +G1 Z3.500 F7380.000 +G0 Z3.750 +G0 Z3.575 +G1 Z2.000 F7380.000 +G0 Z2.250 +G0 Z2.075 +G1 Z0.500 F7380.000 +G0 Z0.750 +G0 Z0.575 +G1 Z0.000 F7380.000 +G0 Z5.000 +G90 +""", + "--translate_drill", + ) + # check for a metric chipbreaking amount + self.multi_compare( + path, + """G90 +G21 +G54 +M6 T1 +G0 X1.000 Y2.000 +G0 Z8.000 +G90 +G0 X1.000 Y2.000 +G1 Z5.000 F7380.000 +G1 Z3.500 F7380.000 +G0 Z4.735 +G0 Z3.575 +G1 Z2.000 F7380.000 +G0 Z3.235 +G0 Z2.075 +G1 Z0.500 F7380.000 +G0 Z1.735 +G0 Z0.575 +G1 Z0.000 F7380.000 +G0 Z5.000 +G90 +""", + "--translate_drill --chipbreaking_amount='1.23456 mm'", + ) + # check for an inch/imperial chipbreaking amount + path = [ + Path.Command("G0 X25.4 Y50.8"), + Path.Command("G0 Z203.2"), + Path.Command("G90"), + Path.Command("G99"), + Path.Command("G73 X25.4 Y50.8 Z0 F123 Q38.1 R127"), + Path.Command("G80"), + Path.Command("G90"), + ] + self.multi_compare( + path, + """G90 +G20 +G54 +M6 T1 +G0 X1.0000 Y2.0000 +G0 Z8.0000 +G90 +G0 X1.0000 Y2.0000 +G1 Z5.0000 F290.5512 +G1 Z3.5000 F290.5512 +G0 Z3.7500 +G0 Z3.5750 +G1 Z2.0000 F290.5512 +G0 Z2.2500 +G0 Z2.0750 +G1 Z0.5000 F290.5512 +G0 Z0.7500 +G0 Z0.5750 +G1 Z0.0000 F290.5512 +G0 Z5.0000 +G90 +""", + "--translate_drill --chipbreaking_amount='0.25 in' --inches", + ) + + ############################################################################# + + def test00126(self) -> None: + """Test command space.""" + self.single_compare("G0 X10 Y20 Z30", "G0 X10.000 Y20.000 Z30.000", "") + self.single_compare("G0 X10 Y20 Z30", "G0X10.000Y20.000Z30.000", "--command_space=''") + self.single_compare("G0 X10 Y20 Z30", "G0_X10.000_Y20.000_Z30.000", "--command_space='_'") + path = [Path.Command("(comment with spaces)")] + self.multi_compare( + path, + """(Begin preamble) +G90 +G21 +(Begin operation) +G54 +(Finish operation: Fixture) +(Begin operation) +(TC: Default Tool) +(Begin toolchange) +(M6 T1) +(Finish operation: TC: Default Tool) +(Begin operation) +(comment with spaces) +(Finish operation: Profile) +(Begin postamble) +""", + "--command_space=' ' --comments", + ) + self.multi_compare( + path, + """(Begin preamble) +G90 +G21 +(Begin operation) +G54 +(Finish operation: Fixture) +(Begin operation) +(TC: Default Tool) +(Begin toolchange) +(M6T1) +(Finish operation: TC: Default Tool) +(Begin operation) +(comment with spaces) +(Finish operation: Profile) +(Begin postamble) +""", + "--command_space='' --comments", + ) + + ############################################################################# + + def test00127(self) -> None: + """Test comment symbol.""" + path = [Path.Command("(comment with spaces)")] + self.multi_compare( + path, + """(Begin preamble) +G90 +G21 +(Begin operation) +G54 +(Finish operation: Fixture) +(Begin operation) +(TC: Default Tool) +(Begin toolchange) +(M6 T1) +(Finish operation: TC: Default Tool) +(Begin operation) +(comment with spaces) +(Finish operation: Profile) +(Begin postamble) +""", + "--comments", + ) + self.multi_compare( + path, + """;Begin preamble +G90 +G21 +;Begin operation +G54 +;Finish operation: Fixture +;Begin operation +;TC: Default Tool +;Begin toolchange +;M6 T1 +;Finish operation: TC: Default Tool +;Begin operation +;comment with spaces +;Finish operation: Profile +;Begin postamble +""", + "--comment_symbol=';' --comments", + ) + self.multi_compare( + path, + """!Begin preamble +G90 +G21 +!Begin operation +G54 +!Finish operation: Fixture +!Begin operation +!TC: Default Tool +!Begin toolchange +!M6 T1 +!Finish operation: TC: Default Tool +!Begin operation +!comment with spaces +!Finish operation: Profile +!Begin postamble +""", + "--comment_symbol='!' --comments", + ) + + ############################################################################# + def test00130(self): """Test comments.""" nl = "\n" @@ -261,7 +480,7 @@ M6 T1 self.assertEqual(split_gcode[10], "(Begin operation)") self.assertEqual(split_gcode[11], "(TC: Default Tool)") self.assertEqual(split_gcode[12], "(Begin toolchange)") - self.assertEqual(split_gcode[13], "( M6 T1 )") + self.assertEqual(split_gcode[13], "(M6 T1)") self.assertEqual(split_gcode[14], "(Finish operation: TC: Default Tool)") self.assertEqual(split_gcode[15], "(Begin operation)") self.assertEqual(split_gcode[16], "(Finish operation: Profile)") @@ -277,7 +496,7 @@ G54 (Begin operation) (TC: Default Tool) (Begin toolchange) -( M6 T1 ) +(M6 T1) (Finish operation: TC: Default Tool) (Begin operation) (Finish operation: Profile) @@ -384,8 +603,16 @@ M6 T1 --bcnc Add Job operations as bCNC block headers. Consider suppressing comments by adding --no-comments --no-bcnc Suppress bCNC block header output (default) + --chipbreaking_amount CHIPBREAKING_AMOUNT + Amount to move for chipbreaking in a translated G73 + command, default is 0.25 mm + --command_space COMMAND_SPACE + The character to use between parts of a command, + default is a space, may also use a null string --comments Output comments (default) --no-comments Suppress comment output + --comment_symbol COMMENT_SYMBOL + The character used to start a comment, default is "(" --feed-precision FEED_PRECISION Number of digits of precision for feed rate, default is 3 @@ -553,7 +780,7 @@ M6 T1 gcode = self.post.export()[0][1] split_gcode = gcode.splitlines() # print(f"--------{nl}{gcode}--------{nl}") - self.assertEqual(split_gcode[13], "( M6 T2 )") + self.assertEqual(split_gcode[13], "(M6 T2)") self.assertEqual(split_gcode[14], "M3 S3000") ############################################################################# diff --git a/src/Mod/CAM/CAMTests/TestRefactoredTestPostGCodes.py b/src/Mod/CAM/CAMTests/TestRefactoredTestPostGCodes.py index a583095712..edeb10e442 100644 --- a/src/Mod/CAM/CAMTests/TestRefactoredTestPostGCodes.py +++ b/src/Mod/CAM/CAMTests/TestRefactoredTestPostGCodes.py @@ -774,14 +774,14 @@ G54 (Begin operation) (TC: Default Tool) (Begin toolchange) -( M6 T1 ) +(M6 T1) (Finish operation: TC: Default Tool) (Begin operation) G0 X1.000 Y2.000 G0 Z8.000 G90 -( G99 ) -( G73 X1.000 Y2.000 Z0.000 R5.000 Q1.500 F7380.000 ) +(G99) +(G73 X1.000 Y2.000 Z0.000 R5.000 Q1.500 F7380.000) G0 X1.000 Y2.000 G1 Z5.000 F7380.000 G1 Z3.500 F7380.000 @@ -795,7 +795,7 @@ G0 Z0.750 G0 Z0.575 G1 Z0.000 F7380.000 G0 Z5.000 -( G80 ) +(G80) G90 (Finish operation: Profile) (Begin postamble) @@ -873,14 +873,14 @@ G54 (Begin operation) (TC: Default Tool) (Begin toolchange) -( M6 T1 ) +(M6 T1) (Finish operation: TC: Default Tool) (Begin operation) G0 X1.000 Y2.000 G0 Z8.000 G91 -( G99 ) -( G73 X1.000 Y2.000 Z0.000 R5.000 Q1.500 F7380.000 ) +(G99) +(G73 X1.000 Y2.000 Z0.000 R5.000 Q1.500 F7380.000) G90 G0 Z13.000 G0 X2.000 Y4.000 @@ -896,7 +896,7 @@ G0 Z8.575 G1 Z8.000 F7380.000 G0 Z13.000 G91 -( G80 ) +(G80) G90 (Finish operation: Profile) (Begin postamble) @@ -961,19 +961,19 @@ G54 (Begin operation) (TC: Default Tool) (Begin toolchange) -( M6 T1 ) +(M6 T1) (Finish operation: TC: Default Tool) (Begin operation) G0 X1.000 Y2.000 G0 Z8.000 G90 -( G99 ) -( G81 X1.000 Y2.000 Z0.000 R5.000 F7380.000 ) +(G99) +(G81 X1.000 Y2.000 Z0.000 R5.000 F7380.000) G0 X1.000 Y2.000 G1 Z5.000 F7380.000 G1 Z0.000 F7380.000 G0 Z5.000 -( G80 ) +(G80) G90 (Finish operation: Profile) (Begin postamble) @@ -1042,21 +1042,21 @@ G54 (Begin operation) (TC: Default Tool) (Begin toolchange) -( M6 T1 ) +(M6 T1) (Finish operation: TC: Default Tool) (Begin operation) G0 X1.000 Y2.000 G0 Z8.000 G91 -( G99 ) -( G81 X1.000 Y2.000 Z0.000 R5.000 F7380.000 ) +(G99) +(G81 X1.000 Y2.000 Z0.000 R5.000 F7380.000) G90 G0 Z13.000 G0 X2.000 Y4.000 G1 Z8.000 F7380.000 G0 Z13.000 G91 -( G80 ) +(G80) G90 (Finish operation: Profile) (Begin postamble) @@ -1122,20 +1122,20 @@ G54 (Begin operation) (TC: Default Tool) (Begin toolchange) -( M6 T1 ) +(M6 T1) (Finish operation: TC: Default Tool) (Begin operation) G0 X1.000 Y2.000 G0 Z8.000 G90 -( G99 ) -( G82 X1.000 Y2.000 Z0.000 R5.000 P1.23456 F7380.000 ) +(G99) +(G82 X1.000 Y2.000 Z0.000 R5.000 P1.23456 F7380.000) G0 X1.000 Y2.000 G1 Z5.000 F7380.000 G1 Z0.000 F7380.000 G4 P1.23456 G0 Z5.000 -( G80 ) +(G80) G90 (Finish operation: Profile) (Begin postamble) @@ -1205,14 +1205,14 @@ G54 (Begin operation) (TC: Default Tool) (Begin toolchange) -( M6 T1 ) +(M6 T1) (Finish operation: TC: Default Tool) (Begin operation) G0 X1.000 Y2.000 G0 Z8.000 G91 -( G99 ) -( G82 X1.000 Y2.000 Z0.000 R5.000 P1.23456 F7380.000 ) +(G99) +(G82 X1.000 Y2.000 Z0.000 R5.000 P1.23456 F7380.000) G90 G0 Z13.000 G0 X2.000 Y4.000 @@ -1220,7 +1220,7 @@ G1 Z8.000 F7380.000 G4 P1.23456 G0 Z13.000 G91 -( G80 ) +(G80) G90 (Finish operation: Profile) (Begin postamble) @@ -1294,14 +1294,14 @@ G54 (Begin operation) (TC: Default Tool) (Begin toolchange) -( M6 T1 ) +(M6 T1) (Finish operation: TC: Default Tool) (Begin operation) G0 X1.000 Y2.000 G0 Z8.000 G90 -( G99 ) -( G83 X1.000 Y2.000 Z0.000 R5.000 Q1.500 F7380.000 ) +(G99) +(G83 X1.000 Y2.000 Z0.000 R5.000 Q1.500 F7380.000) G0 X1.000 Y2.000 G1 Z5.000 F7380.000 G1 Z3.500 F7380.000 @@ -1315,7 +1315,7 @@ G0 Z5.000 G0 Z0.575 G1 Z0.000 F7380.000 G0 Z5.000 -( G80 ) +(G80) G90 (Finish operation: Profile) (Begin postamble) @@ -1393,14 +1393,14 @@ G54 (Begin operation) (TC: Default Tool) (Begin toolchange) -( M6 T1 ) +(M6 T1) (Finish operation: TC: Default Tool) (Begin operation) G0 X1.000 Y2.000 G0 Z8.000 G91 -( G99 ) -( G83 X1.000 Y2.000 Z0.000 R5.000 Q1.500 F7380.000 ) +(G99) +(G83 X1.000 Y2.000 Z0.000 R5.000 Q1.500 F7380.000) G90 G0 Z13.000 G0 X2.000 Y4.000 @@ -1416,7 +1416,7 @@ G0 Z8.575 G1 Z8.000 F7380.000 G0 Z13.000 G91 -( G80 ) +(G80) G90 (Finish operation: Profile) (Begin postamble) diff --git a/src/Mod/CAM/Path/Post/UtilsArguments.py b/src/Mod/CAM/Path/Post/UtilsArguments.py index bf9abb0200..7896d0a16d 100644 --- a/src/Mod/CAM/Path/Post/UtilsArguments.py +++ b/src/Mod/CAM/Path/Post/UtilsArguments.py @@ -88,10 +88,13 @@ def init_argument_defaults(argument_defaults: Dict[str, bool]) -> None: def init_arguments_visible(arguments_visible: Dict[str, bool]) -> None: """Initialize the flags for which arguments are visible in the arguments tooltip.""" - arguments_visible["bcnc"] = False arguments_visible["axis-modal"] = True arguments_visible["axis-precision"] = True + arguments_visible["bcnc"] = False + arguments_visible["chipbreaking_amount"] = False + arguments_visible["command_space"] = False arguments_visible["comments"] = True + arguments_visible["comment_symbol"] = False arguments_visible["feed-precision"] = True arguments_visible["header"] = True arguments_visible["line-numbers"] = True @@ -167,6 +170,29 @@ def init_shared_arguments( "Suppress bCNC block header output", arguments_visible["bcnc"], ) + if arguments_visible["chipbreaking_amount"]: + help_message = ( + "Amount to move for chipbreaking in a translated G73 command, " + f'default is {str(values["CHIPBREAKING_AMOUNT"])}' + ) + else: + help_message = argparse.SUPPRESS + shared.add_argument( + "--chipbreaking_amount", + help=help_message, + ) + if arguments_visible["command_space"]: + help_message = ( + "The character to use between parts of a command, " + "default is a space, may also use a null string" + ) + else: + help_message = argparse.SUPPRESS + shared.add_argument( + "--command_space", + default=" ", + help=help_message, + ) add_flag_type_arguments( shared, argument_defaults["comments"], @@ -176,6 +202,16 @@ def init_shared_arguments( "Suppress comment output", arguments_visible["comments"], ) + if arguments_visible["comment_symbol"]: + help_message = ( + f'The character used to start a comment, default is "{values["COMMENT_SYMBOL"]}"' + ) + else: + help_message = argparse.SUPPRESS + shared.add_argument( + "--comment_symbol", + help=help_message, + ) if arguments_visible["feed-precision"]: help_message = ( f"Number of digits of precision for feed rate, " @@ -680,10 +716,15 @@ def process_shared_arguments( values["OUTPUT_BCNC"] = True if args.no_bcnc: values["OUTPUT_BCNC"] = False + if args.chipbreaking_amount: + values["CHIPBREAKING_AMOUNT"] = Units.parseQuantity(args.chipbreaking_amount) + values["COMMAND_SPACE"] = args.command_space if args.comments: values["OUTPUT_COMMENTS"] = True if args.no_comments: values["OUTPUT_COMMENTS"] = False + if args.comment_symbol: + values["COMMENT_SYMBOL"] = args.comment_symbol if args.header: values["OUTPUT_HEADER"] = True if args.no_header: diff --git a/src/Mod/CAM/Path/Post/UtilsParse.py b/src/Mod/CAM/Path/Post/UtilsParse.py index 188198f990..bf31a103d2 100644 --- a/src/Mod/CAM/Path/Post/UtilsParse.py +++ b/src/Mod/CAM/Path/Post/UtilsParse.py @@ -82,12 +82,7 @@ def check_for_drill_translate( if values["TRANSLATE_DRILL_CYCLES"] and command in values["DRILL_CYCLES_TO_TRANSLATE"]: if values["OUTPUT_COMMENTS"]: # Comment the original command - comment = create_comment( - values, - values["COMMAND_SPACE"] - + format_command_line(values, command_line) - + values["COMMAND_SPACE"], - ) + comment = create_comment(values, format_command_line(values, command_line)) gcode.append(f"{linenumber(values)}{comment}{nl}") # wrap this block to ensure that the value of values["MOTION_MODE"] # is restored in case of error @@ -147,12 +142,7 @@ def check_for_suppressed_commands( if command in values["SUPPRESS_COMMANDS"]: if values["OUTPUT_COMMENTS"]: # convert the command to a comment - comment = create_comment( - values, - values["COMMAND_SPACE"] - + format_command_line(values, command_line) - + values["COMMAND_SPACE"], - ) + comment = create_comment(values, format_command_line(values, command_line)) gcode.append(f"{linenumber(values)}{comment}{nl}") # remove the command return True @@ -186,12 +176,7 @@ def check_for_tool_change( gcode.append(f"{linenumber(values)}{line}{nl}") elif values["OUTPUT_COMMENTS"]: # convert the tool change to a comment - comment = create_comment( - values, - values["COMMAND_SPACE"] - + format_command_line(values, command_line) - + values["COMMAND_SPACE"], - ) + comment = create_comment(values, format_command_line(values, command_line)) gcode.append(f"{linenumber(values)}{comment}{nl}") return True return False