diff --git a/src/Mod/CAM/CAMTests/TestRefactoredTestPost.py b/src/Mod/CAM/CAMTests/TestRefactoredTestPost.py index c781bdce76..d1a33d5554 100644 --- a/src/Mod/CAM/CAMTests/TestRefactoredTestPost.py +++ b/src/Mod/CAM/CAMTests/TestRefactoredTestPost.py @@ -99,12 +99,12 @@ class TestRefactoredTestPost(PathTestUtils.PathTestBase): """ pass - def single_compare(self, path, expected, args, debug=False): + def single_compare(self, test_path, expected, args, debug=False): """Perform a test with a single line of gcode comparison.""" nl = "\n" self.job.PostProcessorArgs = args # replace the original path (that came with the job and operation) with our path - self.profile_op.Path = Path.Path(path) + self.profile_op.Path = Path.Path(test_path) # the gcode is in the first section for this particular job and operation gcode = self.post.export()[0][1] if debug: @@ -112,13 +112,13 @@ class TestRefactoredTestPost(PathTestUtils.PathTestBase): # there are 3 lines of "other stuff" before the line we are interested in self.assertEqual(gcode.splitlines()[3], expected) - def multi_compare(self, path, expected, args, debug=False): + def multi_compare(self, test_path, expected, args, debug=False): """Perform a test with multiple lines of gcode comparison.""" nl = "\n" self.job.PostProcessorArgs = args # replace the original path (that came with the job and operation) with our path - self.profile_op.Path = Path.Path(path) + self.profile_op.Path = Path.Path(test_path) # the gcode is in the first section for this particular job and operation gcode = self.post.export()[0][1] if debug: @@ -201,7 +201,7 @@ G54 def test00125(self) -> None: """Test chipbreaking amount.""" - path = [ + test_path = [ Path.Command("G0 X1 Y2"), Path.Command("G0 Z8"), Path.Command("G90"), @@ -212,7 +212,7 @@ G54 ] # check the default chipbreaking amount self.multi_compare( - path, + test_path, """G90 G21 G54 @@ -238,7 +238,7 @@ G90 ) # check for a metric chipbreaking amount self.multi_compare( - path, + test_path, """G90 G21 G54 @@ -263,7 +263,7 @@ G90 "--translate_drill --chipbreaking_amount='1.23456 mm'", ) # check for an inch/imperial chipbreaking amount - path = [ + test_path = [ Path.Command("G0 X25.4 Y50.8"), Path.Command("G0 Z203.2"), Path.Command("G90"), @@ -273,7 +273,7 @@ G90 Path.Command("G90"), ] self.multi_compare( - path, + test_path, """G90 G20 G54 @@ -305,9 +305,9 @@ G90 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)")] + test_path = [Path.Command("(comment with spaces)")] self.multi_compare( - path, + test_path, """(Begin preamble) G90 G21 @@ -327,7 +327,7 @@ G54 "--command_space=' ' --comments", ) self.multi_compare( - path, + test_path, """(Begin preamble) G90 G21 @@ -351,9 +351,9 @@ G54 def test00127(self) -> None: """Test comment symbol.""" - path = [Path.Command("(comment with spaces)")] + test_path = [Path.Command("(comment with spaces)")] self.multi_compare( - path, + test_path, """(Begin preamble) G90 G21 @@ -373,7 +373,7 @@ G54 "--comments", ) self.multi_compare( - path, + test_path, """;Begin preamble G90 G21 @@ -393,7 +393,7 @@ G54 "--comment_symbol=';' --comments", ) self.multi_compare( - path, + test_path, """!Begin preamble G90 G21 @@ -970,6 +970,127 @@ G54 def test00160(self): """Test Line Numbers.""" self.single_compare("G0 X10 Y20 Z30", "N130 G0 X10.000 Y20.000 Z30.000", "--line-numbers") + self.single_compare("G0 X10 Y20 Z30", "G0 X10.000 Y20.000 Z30.000", "--no-line-numbers") + + ############################################################################# + + def test00165(self) -> None: + """Test line number increment and line number start.""" + test_path = [ + Path.Command("G0 X1 Y2"), + Path.Command("G0 Z8"), + ] + # check the default line number increment + self.multi_compare( + test_path, + """N100 G90 +N110 G21 +N120 G54 +N130 G0 X1.000 Y2.000 +N140 G0 Z8.000 +""", + "--line-numbers", + ) + + # check a non-default line number increment + self.multi_compare( + test_path, + """N150 G90 +N153 G21 +N156 G54 +N159 G0 X1.000 Y2.000 +N162 G0 Z8.000 +""", + "--line-numbers --line_number_increment=3", + ) + + # check a non-default starting line number + self.multi_compare( + test_path, + """N123 G90 +N126 G21 +N129 G54 +N132 G0 X1.000 Y2.000 +N135 G0 Z8.000 +""", + "--line-numbers --line_number_increment=3 --line_number_start=123", + ) + + ############################################################################# + + def test00166(self) -> None: + """Test listing tools in the preamble.""" + test_path = [ + Path.Command("G0 X1 Y2"), + Path.Command("G0 Z8"), + ] + # test listing tools in the preamble + self.multi_compare( + test_path, + """(T1=TC__Default_Tool) +(Begin preamble) +G90 +G21 +(Begin operation) +G54 +(Finish operation) +(Begin operation) +(TC: Default Tool) +(Begin toolchange) +M6 T1 +(Finish operation) +(Begin operation) +G0 X1.000 Y2.000 +G0 Z8.000 +(Finish operation) +(Begin postamble) +""", + "--comments --tool_change --list_tools_in_preamble", + ) + # test not listing tools in the preamble + self.multi_compare( + test_path, + """(Begin preamble) +G90 +G21 +(Begin operation) +G54 +(Finish operation) +(Begin operation) +(TC: Default Tool) +(Begin toolchange) +M6 T1 +(Finish operation) +(Begin operation) +G0 X1.000 Y2.000 +G0 Z8.000 +(Finish operation) +(Begin postamble) +""", + "--comments --tool_change --no-list_tools_in_preamble", + ) + # test the default behavior for listing tools in the preamble + self.multi_compare( + test_path, + """(Begin preamble) +G90 +G21 +(Begin operation) +G54 +(Finish operation) +(Begin operation) +(TC: Default Tool) +(Begin toolchange) +M6 T1 +(Finish operation) +(Begin operation) +G0 X1.000 Y2.000 +G0 Z8.000 +(Finish operation) +(Begin postamble) +""", + "--comments --tool_change", + ) ############################################################################# @@ -1059,8 +1180,16 @@ G54 is 3 --header Output headers (default) --no-header Suppress header output + --line_number_increment LINE_NUMBER_INCREMENT + Amount to increment the line numbers, default is 10 + --line_number_start LINE_NUMBER_START + The number the line numbers start at, default is 100 --line-numbers Prefix with line numbers --no-line-numbers Don't prefix with line numbers (default) + --list_tools_in_preamble + List the tools used in the operation in the preamble + --no-list_tools_in_preamble + Don't list the tools used in the operation (default) --modal Don't output the G-command name if it is the same as the previous line --no-modal Output the G-command name even if it is the same as diff --git a/src/Mod/CAM/Path/Post/UtilsArguments.py b/src/Mod/CAM/Path/Post/UtilsArguments.py index fb13aa7574..3642bbad35 100644 --- a/src/Mod/CAM/Path/Post/UtilsArguments.py +++ b/src/Mod/CAM/Path/Post/UtilsArguments.py @@ -78,6 +78,7 @@ def init_argument_defaults(argument_defaults: Dict[str, bool]) -> None: argument_defaults["enable_machine_specific_commands"] = False argument_defaults["header"] = True argument_defaults["line-numbers"] = False + argument_defaults["list_tools_in_preamble"] = False argument_defaults["metric_inches"] = True argument_defaults["modal"] = False argument_defaults["output_all_arguments"] = False @@ -102,7 +103,10 @@ def init_arguments_visible(arguments_visible: Dict[str, bool]) -> None: arguments_visible["end_of_line_characters"] = False arguments_visible["feed-precision"] = True arguments_visible["header"] = True + arguments_visible["line_number_increment"] = False + arguments_visible["line_number_start"] = False arguments_visible["line-numbers"] = True + arguments_visible["list_tools_in_preamble"] = False arguments_visible["metric_inches"] = True arguments_visible["modal"] = True arguments_visible["output_all_arguments"] = True @@ -268,6 +272,30 @@ def init_shared_arguments( "Suppress header output", arguments_visible["header"], ) + if arguments_visible["line_number_increment"]: + help_message = ( + f'Amount to increment the line numbers, default is {str(values["LINE_INCREMENT"])}' + ) + else: + help_message = argparse.SUPPRESS + shared.add_argument( + "--line_number_increment", + default=-1, + type=int, + help=help_message, + ) + if arguments_visible["line_number_start"]: + help_message = ( + f'The number the line numbers start at, default is {str(values["line_number"])}' + ) + else: + help_message = argparse.SUPPRESS + shared.add_argument( + "--line_number_start", + default=-1, + type=int, + help=help_message, + ) add_flag_type_arguments( shared, argument_defaults["line-numbers"], @@ -277,6 +305,15 @@ def init_shared_arguments( "Don't prefix with line numbers", arguments_visible["line-numbers"], ) + add_flag_type_arguments( + shared, + argument_defaults["list_tools_in_preamble"], + "--list_tools_in_preamble", + "--no-list_tools_in_preamble", + "List the tools used in the operation in the preamble", + "Don't list the tools used in the operation", + arguments_visible["list_tools_in_preamble"], + ) add_flag_type_arguments( shared, argument_defaults["modal"], @@ -784,10 +821,18 @@ def process_shared_arguments( values["OUTPUT_HEADER"] = True if args.no_header: values["OUTPUT_HEADER"] = False + if args.line_number_increment != -1: + values["LINE_INCREMENT"] = args.line_number_increment + if args.line_number_start != -1: + values["line_number"] = args.line_number_start if args.line_numbers: values["OUTPUT_LINE_NUMBERS"] = True if args.no_line_numbers: values["OUTPUT_LINE_NUMBERS"] = False + if args.list_tools_in_preamble: + values["LIST_TOOLS_IN_PREAMBLE"] = True + if args.no_list_tools_in_preamble: + values["LIST_TOOLS_IN_PREAMBLE"] = False if args.modal: values["MODAL"] = True if args.no_modal: