diff --git a/src/Mod/Path/PathScripts/PostUtilsArguments.py b/src/Mod/Path/PathScripts/PostUtilsArguments.py index df0895ccda..d1a6fb22e2 100644 --- a/src/Mod/Path/PathScripts/PostUtilsArguments.py +++ b/src/Mod/Path/PathScripts/PostUtilsArguments.py @@ -34,6 +34,14 @@ import argparse import os import shlex +import FreeCAD + +from FreeCAD import Units + +# to distinguish python built-in open function from the one declared below +if open.__module__ in ["__builtin__", "io"]: + pythonopen = open + def add_flag_type_arguments( argument_group, @@ -64,6 +72,8 @@ def init_argument_defaults(argument_defaults): argument_defaults["line-numbers"] = False argument_defaults["metric_inches"] = True argument_defaults["modal"] = False + argument_defaults["output_all_arguments"] = False + argument_defaults["output_visible_arguments"] = False argument_defaults["show-editor"] = True argument_defaults["tlo"] = True argument_defaults["tool_change"] = True @@ -81,6 +91,8 @@ def init_arguments_visible(arguments_visible): arguments_visible["line-numbers"] = True arguments_visible["metric_inches"] = True arguments_visible["modal"] = True + arguments_visible["output_all_arguments"] = True + arguments_visible["output_visible_arguments"] = True arguments_visible["postamble"] = True arguments_visible["preamble"] = True arguments_visible["precision"] = True @@ -188,6 +200,24 @@ def init_shared_arguments(values, argument_defaults, arguments_visible): "Output the G-command name even if it is the same as the previous line", arguments_visible["modal"], ) + add_flag_type_arguments( + shared, + argument_defaults["output_all_arguments"], + "--output_all_arguments", + "--no-output_all_arguments", + "Output all of the available arguments", + "Don't output all of the available arguments", + arguments_visible["output_all_arguments"], + ) + add_flag_type_arguments( + shared, + argument_defaults["output_visible_arguments"], + "--output_visible_arguments", + "--no-output_visible_arguments", + "Output all of the visible arguments", + "Don't output the visible arguments", + arguments_visible["output_visible_arguments"], + ) if arguments_visible["postamble"]: help_message = ( 'Set commands to be issued after the last command, default is "' @@ -283,6 +313,11 @@ def init_shared_values(values): # The starting axis precision is 3 digits after the decimal point. # values["AXIS_PRECISION"] = 3 + # + # How far to move up (in millimeters) in the Z axis when chipbreaking with a G73 command. + # + values["CHIPBREAKING_AMOUNT"] = Units.Quantity(0.25, FreeCAD.Units.Length) + # # If this is set to "", all spaces are removed from between commands and parameters. # @@ -319,7 +354,7 @@ def init_shared_values(values): # If TRANSLATE_DRILL_CYCLES is True, these are the drill cycles # that get translated to G0 and G1 commands. # - values["DRILL_CYCLES_TO_TRANSLATE"] = ("G81", "G82", "G83") + values["DRILL_CYCLES_TO_TRANSLATE"] = ("G73", "G81", "G82", "G83") # # The default value of drill retractations (CURRENT_Z). # The other possible value is G99. @@ -352,10 +387,6 @@ def init_shared_values(values): # values["FINISH_LABEL"] = "Finish" # - # The name of the machine the postprocessor is for - # - values["MACHINE_NAME"] = "unknown machine" - # # The line number increment value # values["LINE_INCREMENT"] = 10 @@ -369,6 +400,10 @@ def init_shared_values(values): # values["LIST_TOOLS_IN_PREAMBLE"] = False # + # The name of the machine the postprocessor is for + # + values["MACHINE_NAME"] = "unknown machine" + # # If this value is true G-code commands are suppressed if they are # the same as the previous line. # @@ -441,6 +476,9 @@ def init_shared_values(values): # This list controls the order of parameters in a line during output. # values["PARAMETER_ORDER"] = [ + "D", + "H", + "L", "X", "Y", "Z", @@ -453,13 +491,13 @@ def init_shared_values(values): "I", "J", "K", + "R", + "P", + "E", + "Q", "F", "S", "T", - "Q", - "R", - "L", - "P", ] # # Any commands in this value will be output as the last commands @@ -557,10 +595,26 @@ def init_shared_values(values): values["USE_TLO"] = True -def process_shared_arguments(values, parser, argstring): +def process_shared_arguments(values, parser, argstring, all_visible, filename): """Process the arguments to the postprocessor.""" try: args = parser.parse_args(shlex.split(argstring)) + if args.output_all_arguments: + argument_text = all_visible.format_help() + if not filename == "-": + gfile = pythonopen(filename, "w", newline=values["END_OF_LINE_CHARACTERS"]) + gfile.write(argument_text) + gfile.close() + return (False, argument_text) + if args.output_visible_arguments: + argument_text = parser.format_help() + if not filename == "-": + gfile = pythonopen(filename, "w", newline=values["END_OF_LINE_CHARACTERS"]) + gfile.write(argument_text) + gfile.close() + return (False, argument_text) + # Default to metric unless an argument overrides it + values["UNITS"] = "G21" if args.metric: values["UNITS"] = "G21" if args.inches: @@ -650,6 +704,81 @@ def process_shared_arguments(values, parser, argstring): values["SPINDLE_WAIT"] = args.wait_for_spindle except Exception: - return (False, None) + return (False, "") return (True, args) + +# +# LinuxCNC (and GRBL) G-Code Parameter/word Patterns +# __________________________________________________ +# +# LinuxCNC words (called parameters in this code in many places) may be +# reordered in any way without changing the meaning of the line. +# However, the documentation shows the examples with the parameters/words +# in a certain order that people might be used to and want to see. +# +# axes one or more of "X Y Z A B C U V W", usually in that order +# +# default parameter order D H L axes I J K R P E Q F S T $ +# +# G10 L P axes R I J Q +# +# G33.1 X Y Z K I $ +# +# G53 G00|G01 or G00|G01 G53 X Y Z +# +# G73, G74, G81 to G86, G89 (X Y Z) or (U V W) R Q L P F K $ +# +# G76 P Z I J R K Q H E L $ +# +# M19 R Q P $ +# +# M66 P|E L Q +# +# M98 P Q L +# +# N and O are associated with line numbers +# +# +# +# Tormach PathPilot (based on LinuxCNC, mostly) G-Code Patterns +# _____________________________________________________________ +# +# (Just the exceptions to the LinuxCNC patterns shown above) +# +# G47 Z R X Y P Q D +# +# +# Mach4 G-Code Patterns +# _____________________ +# +# (Just the exceptions to the LinuxCNC patterns shown above) +# +# G10 L1 P Z W D R X U Y V Q +# +# G30 P axes +# +# G41, G42 D|P X Y F +# +# G65, G66 P A B C +# +# G73, G74, G76, G81-9 X Y Z Q R I J P L F +# +# G84.2, G84.3 X Y Z R P L F J +# +# +# +# Centroid G-Code Patterns +# ________________________ +# +# (Just the exceptions to the LinuxCNC patterns shown above) +# +# E1-E6 are equivalent to G54-G59 +# +# G10 P D H R +# +# G65 P L arguments (arguments are A-Z excluding G, L, N, O, and P) +# G65 "program.cnc" L arguments +# +# G117, G118, G119 P X Y Z I J K P Q +# diff --git a/src/Mod/Path/PathScripts/PostUtilsParse.py b/src/Mod/Path/PathScripts/PostUtilsParse.py index ea2ed95663..9c559c9d21 100644 --- a/src/Mod/Path/PathScripts/PostUtilsParse.py +++ b/src/Mod/Path/PathScripts/PostUtilsParse.py @@ -94,130 +94,125 @@ def drill_translate(values, outstring, cmd, params): # get the other parameters drill_feedrate = Units.Quantity(params["F"], FreeCAD.Units.Velocity) - if cmd == "G83": + if cmd in ("G73", "G83"): drill_Step = Units.Quantity(params["Q"], FreeCAD.Units.Length) - a_bit = ( - drill_Step * 0.05 - ) # NIST 3.5.16.4 G83 Cycle: "current hole bottom, backed off a bit." + # NIST 3.5.16.4 G83 Cycle: "current hole bottom, backed off a bit." + a_bit = drill_Step * 0.05 elif cmd == "G82": drill_DwellTime = params["P"] - # wrap this block to ensure machine's values["MOTION_MODE"] is restored - # in case of error - try: - if values["MOTION_MODE"] == "G91": - trBuff += ( - linenumber(values) + "G90\n" - ) # force absolute coordinates during cycles + # wrap this block to ensure machine's values["MOTION_MODE"] is restored in case of error + # try: + if values["MOTION_MODE"] == "G91": + # force absolute coordinates during cycles + trBuff += linenumber(values) + "G90\n" - strG0_RETRACT_Z = ( - "G0 Z" - + format( - float(RETRACT_Z.getValueAs(values["UNIT_FORMAT"])), - axis_precision_string, - ) - + "\n" + strG0_RETRACT_Z = ( + "G0 Z" + + format(float(RETRACT_Z.getValueAs(values["UNIT_FORMAT"])), axis_precision_string) + + "\n" + ) + strF_Feedrate = ( + " F" + + format( + float(drill_feedrate.getValueAs(values["UNIT_SPEED_FORMAT"])), feed_precision_string ) - strF_Feedrate = ( - " F" - + format( - float(drill_feedrate.getValueAs(values["UNIT_SPEED_FORMAT"])), - feed_precision_string, - ) - + "\n" - ) - # print(strF_Feedrate) + + "\n" + ) + # print(strF_Feedrate) - # preliminary movement(s) - if values["CURRENT_Z"] < RETRACT_Z: - trBuff += linenumber(values) + strG0_RETRACT_Z + # preliminary movement(s) + if values["CURRENT_Z"] < RETRACT_Z: + trBuff += linenumber(values) + strG0_RETRACT_Z + trBuff += ( + linenumber(values) + + "G0 X" + + format(float(drill_X.getValueAs(values["UNIT_FORMAT"])), axis_precision_string) + + " Y" + + format(float(drill_Y.getValueAs(values["UNIT_FORMAT"])), axis_precision_string) + + "\n" + ) + if values["CURRENT_Z"] > RETRACT_Z: + # NIST GCODE 3.5.16.1 Preliminary and In-Between Motion says G0 to RETRACT_Z + # Here use G1 since retract height may be below surface ! trBuff += ( linenumber(values) - + "G0 X" - + format( - float(drill_X.getValueAs(values["UNIT_FORMAT"])), axis_precision_string - ) - + " Y" - + format( - float(drill_Y.getValueAs(values["UNIT_FORMAT"])), axis_precision_string - ) - + "\n" + + "G1 Z" + + format(float(RETRACT_Z.getValueAs(values["UNIT_FORMAT"])), axis_precision_string) + + strF_Feedrate ) - if values["CURRENT_Z"] > RETRACT_Z: - # NIST GCODE 3.5.16.1 Preliminary and In-Between Motion says G0 to RETRACT_Z - # Here use G1 since retract height may be below surface ! - trBuff += ( - linenumber(values) - + "G1 Z" - + format( - float(RETRACT_Z.getValueAs(values["UNIT_FORMAT"])), - axis_precision_string, - ) - + strF_Feedrate - ) - last_Stop_Z = RETRACT_Z + last_Stop_Z = RETRACT_Z - # drill moves - if cmd in ("G81", "G82"): - trBuff += ( - linenumber(values) - + "G1 Z" - + format( - float(drill_Z.getValueAs(values["UNIT_FORMAT"])), - axis_precision_string, - ) - + strF_Feedrate - ) - # pause where applicable - if cmd == "G82": - trBuff += linenumber(values) + "G4 P" + str(drill_DwellTime) + "\n" - trBuff += linenumber(values) + strG0_RETRACT_Z - else: # 'G83' - if params["Q"] != 0: - while 1: - if last_Stop_Z != RETRACT_Z: - clearance_depth = ( - last_Stop_Z + a_bit - ) # rapid move to just short of last drilling depth + # drill moves + if cmd in ("G81", "G82"): + trBuff += ( + linenumber(values) + + "G1 Z" + + format(float(drill_Z.getValueAs(values["UNIT_FORMAT"])), axis_precision_string) + + strF_Feedrate + ) + # pause where applicable + if cmd == "G82": + trBuff += linenumber(values) + "G4 P" + str(drill_DwellTime) + "\n" + trBuff += linenumber(values) + strG0_RETRACT_Z + else: # "G73" or "G83" + if params["Q"] != 0: + while 1: + if last_Stop_Z != RETRACT_Z: + # rapid move to just short of last drilling depth + clearance_depth = last_Stop_Z + a_bit + trBuff += ( + linenumber(values) + + "G0 Z" + + format( + float(clearance_depth.getValueAs(values["UNIT_FORMAT"])), + axis_precision_string, + ) + + "\n" + ) + next_Stop_Z = last_Stop_Z - drill_Step + if next_Stop_Z > drill_Z: + trBuff += ( + linenumber(values) + + "G1 Z" + + format( + float(next_Stop_Z.getValueAs(values["UNIT_FORMAT"])), + axis_precision_string, + ) + + strF_Feedrate + ) + if cmd == "G73": + # Rapid up "a small amount". + chip_breaker_height = next_Stop_Z + values["CHIPBREAKING_AMOUNT"] trBuff += ( linenumber(values) + "G0 Z" + format( - float( - clearance_depth.getValueAs(values["UNIT_FORMAT"]) - ), + float(chip_breaker_height.getValueAs(values["UNIT_FORMAT"])), axis_precision_string, ) + "\n" ) - next_Stop_Z = last_Stop_Z - drill_Step - if next_Stop_Z > drill_Z: - trBuff += ( - linenumber(values) - + "G1 Z" - + format( - float(next_Stop_Z.getValueAs(values["UNIT_FORMAT"])), - axis_precision_string, - ) - + strF_Feedrate - ) + else: # "G83" + # Rapid up to the retract height trBuff += linenumber(values) + strG0_RETRACT_Z - last_Stop_Z = next_Stop_Z - else: - trBuff += ( - linenumber(values) - + "G1 Z" - + format( - float(drill_Z.getValueAs(values["UNIT_FORMAT"])), - axis_precision_string, - ) - + strF_Feedrate + last_Stop_Z = next_Stop_Z + else: + trBuff += ( + linenumber(values) + + "G1 Z" + + format( + float(drill_Z.getValueAs(values["UNIT_FORMAT"])), + axis_precision_string, ) - trBuff += linenumber(values) + strG0_RETRACT_Z - break + + strF_Feedrate + ) + trBuff += linenumber(values) + strG0_RETRACT_Z + break - except Exception: - pass + # except Exception: + # print("exception occurred") + # pass if values["MOTION_MODE"] == "G91": trBuff += linenumber(values) + "G91\n" # Restore if changed @@ -365,12 +360,21 @@ def parse(values, pathobj): ) else: continue - elif param in ["H", "L", "T"]: + elif param in ("H", "L", "T"): outstring.append(param + str(int(c.Parameters[param]))) elif param == "D": - if command in ["G41", "G42"]: + if command in ("G41", "G42"): outstring.append(param + str(int(c.Parameters[param]))) - elif command in ["G96", "G97"]: + elif command in ("G41.1", "G42.1"): + pos = Units.Quantity(c.Parameters[param], FreeCAD.Units.Length) + outstring.append( + param + + format( + float(pos.getValueAs(values["UNIT_FORMAT"])), + axis_precision_string, + ) + ) + elif command in ("G96", "G97"): outstring.append( param + PostUtils.fmt( @@ -379,25 +383,25 @@ def parse(values, pathobj): "G21", ) ) - else: # anything else that is supported (G41.1?, G42.1?) + else: # anything else that is supported outstring.append(param + str(float(c.Parameters[param]))) elif param == "P": - if command in ["G2", "G02", "G3", "G03", "G5.2", "G5.3", "G10"]: + if command in ( + "G2", + "G02", + "G3", + "G03", + "G5.2", + "G5.3", + "G10", + "G54.1", + "G59", + ): outstring.append(param + str(int(c.Parameters[param]))) - elif command in [ - "G4", - "G04", - "G64", - "G76", - "G82", - "G86", - "G89", - ]: + elif command in ("G4", "G04", "G76", "G82", "G86", "G89"): outstring.append(param + str(float(c.Parameters[param]))) - elif command in ["G5", "G05"]: - pos = Units.Quantity( - c.Parameters[param], FreeCAD.Units.Length - ) + elif command in ("G5", "G05", "G64"): + pos = Units.Quantity(c.Parameters[param], FreeCAD.Units.Length) outstring.append( param + format( @@ -407,6 +411,18 @@ def parse(values, pathobj): ) else: # anything else that is supported outstring.append(param + str(c.Parameters[param])) + elif param == "Q": + if command == "G10": + outstring.append(param + str(int(c.Parameters[param]))) + elif command in ("G64", "G73", "G83"): + pos = Units.Quantity(c.Parameters[param], FreeCAD.Units.Length) + outstring.append( + param + + format( + float(pos.getValueAs(values["UNIT_FORMAT"])), + axis_precision_string, + ) + ) elif param == "S": outstring.append( param diff --git a/src/Mod/Path/PathScripts/post/refactored_centroid_post.py b/src/Mod/Path/PathScripts/post/refactored_centroid_post.py index 0aaa107ab6..a9b57a4287 100644 --- a/src/Mod/Path/PathScripts/post/refactored_centroid_post.py +++ b/src/Mod/Path/PathScripts/post/refactored_centroid_post.py @@ -228,6 +228,14 @@ parser = init_arguments(values, argument_defaults, arguments_visible) # The TOOLTIP_ARGS value is created from the help information about the arguments. # TOOLTIP_ARGS = parser.format_help() +# +# Create another parser just to get a list of all possible arguments +# that may be output using --output_all_arguments. +# +all_arguments_visible = {} +for k in iter(arguments_visible): + all_arguments_visible[k] = True +all_visible = init_arguments(values, argument_defaults, all_arguments_visible) def export(objectslist, filename, argstring): @@ -239,9 +247,11 @@ def export(objectslist, filename, argstring): # print(parser.format_help()) - (flag, args) = PostUtilsArguments.process_shared_arguments(values, parser, argstring) + (flag, args) = PostUtilsArguments.process_shared_arguments( + values, parser, argstring, all_visible, filename + ) if not flag: - return None + return args # # Process any additional arguments here # diff --git a/src/Mod/Path/PathScripts/post/refactored_grbl_post.py b/src/Mod/Path/PathScripts/post/refactored_grbl_post.py index 61efea92ac..9e11a5ee76 100644 --- a/src/Mod/Path/PathScripts/post/refactored_grbl_post.py +++ b/src/Mod/Path/PathScripts/post/refactored_grbl_post.py @@ -195,6 +195,14 @@ parser = init_arguments(values, argument_defaults, arguments_visible) # The TOOLTIP_ARGS value is created from the help information about the arguments. # TOOLTIP_ARGS = parser.format_help() +# +# Create another parser just to get a list of all possible arguments +# that may be output using --output_all_arguments. +# +all_arguments_visible = {} +for k in iter(arguments_visible): + all_arguments_visible[k] = True +all_visible = init_arguments(values, argument_defaults, all_arguments_visible) def export(objectslist, filename, argstring): @@ -206,9 +214,11 @@ def export(objectslist, filename, argstring): # print(parser.format_help()) - (flag, args) = PostUtilsArguments.process_shared_arguments(values, parser, argstring) + (flag, args) = PostUtilsArguments.process_shared_arguments( + values, parser, argstring, all_visible, filename + ) if not flag: - return None + return args # # Process any additional arguments here # diff --git a/src/Mod/Path/PathScripts/post/refactored_linuxcnc_post.py b/src/Mod/Path/PathScripts/post/refactored_linuxcnc_post.py index 87bc34f6bc..b6a250d835 100644 --- a/src/Mod/Path/PathScripts/post/refactored_linuxcnc_post.py +++ b/src/Mod/Path/PathScripts/post/refactored_linuxcnc_post.py @@ -162,6 +162,14 @@ parser = init_arguments(values, argument_defaults, arguments_visible) # The TOOLTIP_ARGS value is created from the help information about the arguments. # TOOLTIP_ARGS = parser.format_help() +# +# Create another parser just to get a list of all possible arguments +# that may be output using --output_all_arguments. +# +all_arguments_visible = {} +for k in iter(arguments_visible): + all_arguments_visible[k] = True +all_visible = init_arguments(values, argument_defaults, all_arguments_visible) def export(objectslist, filename, argstring): @@ -173,9 +181,11 @@ def export(objectslist, filename, argstring): # print(parser.format_help()) - (flag, args) = PostUtilsArguments.process_shared_arguments(values, parser, argstring) + (flag, args) = PostUtilsArguments.process_shared_arguments( + values, parser, argstring, all_visible, filename + ) if not flag: - return None + return args # # Process any additional arguments here # diff --git a/src/Mod/Path/PathScripts/post/refactored_mach3_mach4_post.py b/src/Mod/Path/PathScripts/post/refactored_mach3_mach4_post.py index 17d0e40f60..e0078f6a1d 100644 --- a/src/Mod/Path/PathScripts/post/refactored_mach3_mach4_post.py +++ b/src/Mod/Path/PathScripts/post/refactored_mach3_mach4_post.py @@ -169,6 +169,14 @@ parser = init_arguments(values, argument_defaults, arguments_visible) # The TOOLTIP_ARGS value is created from the help information about the arguments. # TOOLTIP_ARGS = parser.format_help() +# +# Create another parser just to get a list of all possible arguments +# that may be output using --output_all_arguments. +# +all_arguments_visible = {} +for k in iter(arguments_visible): + all_arguments_visible[k] = True +all_visible = init_arguments(values, argument_defaults, all_arguments_visible) def export(objectslist, filename, argstring): @@ -180,9 +188,11 @@ def export(objectslist, filename, argstring): # print(parser.format_help()) - (flag, args) = PostUtilsArguments.process_shared_arguments(values, parser, argstring) + (flag, args) = PostUtilsArguments.process_shared_arguments( + values, parser, argstring, all_visible, filename + ) if not flag: - return None + return args # # Process any additional arguments here # diff --git a/src/Mod/Path/PathScripts/post/refactored_test_post.py b/src/Mod/Path/PathScripts/post/refactored_test_post.py index 0c8dce879c..eb019200af 100644 --- a/src/Mod/Path/PathScripts/post/refactored_test_post.py +++ b/src/Mod/Path/PathScripts/post/refactored_test_post.py @@ -82,32 +82,6 @@ def init_values(values): # which are then suppressed by default. # values["OUTPUT_TOOL_CHANGE"] = False - # - # Enable as many parameters as possible to be output by default - # - values["PARAMETER_ORDER"] = [ - "X", - "Y", - "Z", - "A", - "B", - "C", - "U", - "V", - "W", - "I", - "J", - "K", - "F", - "S", - "T", - "Q", - "R", - "L", - "H", - "D", - "P", - ] values["POSTPROCESSOR_FILE_NAME"] = __name__ # # Do not show the editor by default since we are testing. @@ -189,20 +163,31 @@ parser = init_arguments(values, argument_defaults, arguments_visible) # The TOOLTIP_ARGS value is created from the help information about the arguments. # TOOLTIP_ARGS = parser.format_help() +# +# Create another parser just to get a list of all possible arguments +# that may be output using --output_all_arguments. +# +all_arguments_visible = {} +for k in iter(arguments_visible): + all_arguments_visible[k] = True +all_visible = init_arguments(values, argument_defaults, all_arguments_visible) def export(objectslist, filename, argstring): """Postprocess the objects in objectslist to filename.""" # + global all_visible global parser global UNITS global values # print(parser.format_help()) - (flag, args) = PostUtilsArguments.process_shared_arguments(values, parser, argstring) + (flag, args) = PostUtilsArguments.process_shared_arguments( + values, parser, argstring, all_visible, filename + ) if not flag: - return None + return args # # Process any additional arguments here # diff --git a/src/Mod/Path/PathTests/TestRefactoredTestPost.py b/src/Mod/Path/PathTests/TestRefactoredTestPost.py index 20be8a9f19..5b196fc338 100644 --- a/src/Mod/Path/PathTests/TestRefactoredTestPost.py +++ b/src/Mod/Path/PathTests/TestRefactoredTestPost.py @@ -75,9 +75,11 @@ class TestRefactoredTestPost(PathTestUtils.PathTestBase): self.doc = FreeCAD.ActiveDocument self.con = FreeCAD.Console self.docobj = FreeCAD.ActiveDocument.addObject("Path::Feature", "testpath") - reload( - postprocessor - ) # technical debt. This shouldn't be necessary but here to bypass a bug + # + # Re-initialize all of the values before doing a test. + # + postprocessor.UNITS = "G21" + postprocessor.init_values(postprocessor.values) def tearDown(self): """tearDown()... @@ -87,6 +89,36 @@ class TestRefactoredTestPost(PathTestUtils.PathTestBase): """ FreeCAD.ActiveDocument.removeObject("testpath") + def single_compare(self, path, expected, args, debug=False): + """Perform a test with a single comparison.""" + self.docobj.Path = Path.Path(path) + postables = [self.docobj] + gcode = postprocessor.export(postables, "gcode.tmp", args) + if debug: + print("--------\n" + gcode + "--------\n") + self.assertEqual(gcode, expected) + + def compare_third_line(self, path_string, expected, args, debug=False): + """Perform a test with a single comparison only to the third line of the output.""" + if path_string: + self.docobj.Path = Path.Path([Path.Command(path_string)]) + else: + self.docobj.Path = Path.Path([]) + postables = [self.docobj] + gcode = postprocessor.export(postables, "gcode.tmp", args) + if debug: + print("--------\n" + gcode + "--------\n") + self.assertEqual(gcode.splitlines()[2], expected) + + # + # The tests are organized into groups: + # + # 00000 - 00099 tests that don't fit any other category + # 00100 - 00999 tests for all of the various arguments/options + # 01000 - 01999 tests for the various G codes at 1000 + 10 * g_code_value + # 02000 - 02999 tests for the various M codes at 2000 + 10 * m_code_value + # + def test00000(self): """Test Output Generation. @@ -154,13 +186,89 @@ G21 # print("--------\n" + gcode + "--------\n") self.assertEqual(gcode, expected) + def test00010(self): + """Test Outputting all arguments. + + Empty path. Outputs all arguments. + """ + self.single_compare( + [], + """Arguments that are shared with all postprocessors: + --metric Convert output for Metric mode (G21) (default) + --inches Convert output for US imperial mode (G20) + --axis-modal Don't output axis values if they are the same as the + previous line + --no-axis-modal Output axis values even if they are the same as the + previous line (default) + --axis-precision AXIS_PRECISION + Number of digits of precision for axis moves, default + is 3 + --bcnc Add Job operations as bCNC block headers. Consider + suppressing comments by adding --no-comments + --no-bcnc Suppress bCNC block header output (default) + --comments Output comments (default) + --no-comments Suppress comment output + --feed-precision FEED_PRECISION + Number of digits of precision for feed rate, default + is 3 + --header Output headers (default) + --no-header Suppress header output + --line-numbers Prefix with line numbers + --no-line-numbers Don't prefix with line numbers (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 + the previous line (default) + --output_all_arguments + Output all of the available arguments + --no-output_all_arguments + Don't output all of the available arguments (default) + --output_visible_arguments + Output all of the visible arguments + --no-output_visible_arguments + Don't output the visible arguments (default) + --postamble POSTAMBLE + Set commands to be issued after the last command, + default is "" + --preamble PREAMBLE Set commands to be issued before the first command, + default is "" + --precision PRECISION + Number of digits of precision for both feed rate and + axis moves, default is 3 for metric or 4 for inches + --return-to RETURN_TO + Move to the specified x,y,z coordinates at the end, + e.g. --return-to=0,0,0 (default is do not move) + --show-editor Pop up editor before writing output (default) + --no-show-editor Don't pop up editor before writing output + --tlo Output tool length offset (G43) following tool changes + (default) + --no-tlo Suppress tool length offset (G43) following tool + changes + --tool_change Insert M6 and any other tool change G-code for all + tool changes (default) + --no-tool_change Convert M6 to a comment for all tool changes + --translate_drill Translate drill cycles G81, G82 & G83 into G0/G1 + movements + --no-translate_drill Don't translate drill cycles G81, G82 & G83 into G0/G1 + movements (default) + --wait-for-spindle WAIT_FOR_SPINDLE + Time to wait (in seconds) after M3, M4 (default = 0.0) +""", + "--output_all_arguments", + ) + + def test00020(self): + """Test Outputting visible arguments. + + Empty path. Outputs visible arguments. + """ + self.single_compare([], "", "--output_visible_arguments") + def test00100(self): """Test bcnc.""" - # - self.docobj.Path = Path.Path([]) - postables = [self.docobj] - - expected = """G90 + self.single_compare( + [], + """G90 G21 (Block-name: testpath) (Block-expand: 0) @@ -168,19 +276,16 @@ G21 (Block-name: post_amble) (Block-expand: 0) (Block-enable: 1) -""" - args = "--bcnc" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - - expected = """G90 +""", + "--bcnc", + ) + self.single_compare( + [], + """G90 G21 -""" - args = "--no-bcnc" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) +""", + "--no-bcnc", + ) def test00110(self): """Test axis modal. @@ -205,25 +310,13 @@ G21 def test00120(self): """Test axis-precision.""" - # - c = Path.Command("G0 X10 Y20 Z30") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - args = "--axis-precision=2" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode.splitlines()[2], "G0 X10.00 Y20.00 Z30.00") + self.compare_third_line("G0 X10 Y20 Z30", "G0 X10.00 Y20.00 Z30.00", "--axis-precision=2") def test00130(self): """Test comments.""" - # c = Path.Command("(comment)") - self.docobj.Path = Path.Path([c]) postables = [self.docobj] - args = "--comments" gcode = postprocessor.export(postables, "gcode.tmp", args) # print("--------\n" + gcode + "--------\n") @@ -253,30 +346,23 @@ G21 def test00150(self): """Test Line Numbers.""" - # - c = Path.Command("G0 X10 Y20 Z30") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - args = "--line-numbers" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode.splitlines()[2], "N120 G0 X10.000 Y20.000 Z30.000") + self.compare_third_line( + "G0 X10 Y20 Z30", "N120 G0 X10.000 Y20.000 Z30.000", "--line-numbers" + ) def test00160(self): """Test inches.""" - # - c = Path.Command("G0 X10 Y20 Z30") - + c = Path.Command("G0 X10 Y20 Z30 A10 B20 C30 U10 V20 W30") self.docobj.Path = Path.Path([c]) postables = [self.docobj] - args = "--inches" gcode = postprocessor.export(postables, "gcode.tmp", args) # print("--------\n" + gcode + "--------\n") self.assertEqual(gcode.splitlines()[1], "G20") - self.assertEqual(gcode.splitlines()[2], "G0 X0.3937 Y0.7874 Z1.1811") + self.assertEqual( + gcode.splitlines()[2], + "G0 X0.3937 Y0.7874 Z1.1811 A0.3937 B0.7874 C1.1811 U0.3937 V0.7874 W1.1811", + ) def test00170(self): """Test modal. @@ -285,15 +371,12 @@ G21 """ c = Path.Command("G0 X10 Y20 Z30") c1 = Path.Command("G0 X10 Y30 Z30") - self.docobj.Path = Path.Path([c, c1]) postables = [self.docobj] - args = "--modal" gcode = postprocessor.export(postables, "gcode.tmp", args) # print("--------\n" + gcode + "--------\n") self.assertEqual(gcode.splitlines()[3], "X10.000 Y30.000 Z30.000") - args = "--no-modal" gcode = postprocessor.export(postables, "gcode.tmp", args) # print("--------\n" + gcode + "--------\n") @@ -301,10 +384,8 @@ G21 def test00180(self): """Test Post-amble.""" - # self.docobj.Path = Path.Path([]) postables = [self.docobj] - args = "--postamble='G0 Z50\nM2'" gcode = postprocessor.export(postables, "gcode.tmp", args) # print("--------\n" + gcode + "--------\n") @@ -313,10 +394,8 @@ G21 def test00190(self): """Test Pre-amble.""" - # self.docobj.Path = Path.Path([]) postables = [self.docobj] - args = "--preamble='G18 G55'" gcode = postprocessor.export(postables, "gcode.tmp", args) # print("--------\n" + gcode + "--------\n") @@ -324,53 +403,33 @@ G21 def test00200(self): """Test precision.""" - # - c = Path.Command("G1 X10 Y20 Z30 F100") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - args = "--precision=2" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode.splitlines()[2], "G1 X10.00 Y20.00 Z30.00 F6000.00") - - args = "--inches --precision=2" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode.splitlines()[2], "G1 X0.39 Y0.79 Z1.18 F236.22") + self.compare_third_line( + "G1 X10 Y20 Z30 F100", + "G1 X10.00 Y20.00 Z30.00 F6000.00", + "--precision=2", + ) + self.compare_third_line( + "G1 X10 Y20 Z30 F100", + "G1 X0.39 Y0.79 Z1.18 F236.22", + "--inches --precision=2", + ) def test00210(self): """Test return-to.""" - # - self.docobj.Path = Path.Path([]) - postables = [self.docobj] - - expected = """G90 -G21 -G0 X12 Y34 Z56 -""" - args = "--return-to='12,34,56'" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) + self.compare_third_line("", "G0 X12 Y34 Z56", "--return-to='12,34,56'") def test00220(self): """Test tlo.""" - # c = Path.Command("M6 T2") c2 = Path.Command("M3 S3000") - self.docobj.Path = Path.Path([c, c2]) postables = [self.docobj] - args = "--tlo" gcode = postprocessor.export(postables, "gcode.tmp", args) # print("--------\n" + gcode + "--------\n") self.assertEqual(gcode.splitlines()[2], "M6 T2") self.assertEqual(gcode.splitlines()[3], "G43 H2") self.assertEqual(gcode.splitlines()[4], "M3 S3000") - # suppress TLO args = "--no-tlo" gcode = postprocessor.export(postables, "gcode.tmp", args) @@ -380,516 +439,44 @@ G0 X12 Y34 Z56 def test00230(self): """Test tool_change.""" - # c = Path.Command("M6 T2") c2 = Path.Command("M3 S3000") - self.docobj.Path = Path.Path([c, c2]) postables = [self.docobj] - args = "--tool_change" gcode = postprocessor.export(postables, "gcode.tmp", args) # print("--------\n" + gcode + "--------\n") self.assertEqual(gcode.splitlines()[2], "M6 T2") self.assertEqual(gcode.splitlines()[3], "M3 S3000") - args = "--comments --no-tool_change" gcode = postprocessor.export(postables, "gcode.tmp", args) # print("--------\n" + gcode + "--------\n") self.assertEqual(gcode.splitlines()[5], "( M6 T2 )") self.assertEqual(gcode.splitlines()[6], "M3 S3000") - def test00240(self): - """Test translate_drill with G81.""" - # - c = Path.Command("G0 X1 Y2") - c1 = Path.Command("G0 Z8") - c2 = Path.Command("G90") - c3 = Path.Command("G99") - c4 = Path.Command("G81 X1 Y2 Z0 F123 R5") - c5 = Path.Command("G80") - c6 = Path.Command("G90") - - self.docobj.Path = Path.Path([c, c1, c2, c3, c4, c5, c6]) - postables = [self.docobj] - - expected = """G90 -G21 -G0 X1.000 Y2.000 -G0 Z8.000 -G90 -G99 -G81 X1.000 Y2.000 Z0.000 F7380.000 R5.000 -G80 -G90 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - - expected = """G90 -G21 -G0 X1.000 Y2.000 -G0 Z8.000 -G90 -G0 X1.000 Y2.000 -G1 Z5.000 F7380.000 -G1 Z0.000 F7380.000 -G0 Z5.000 -G90 -""" - args = "--translate_drill" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - - expected = """(Begin preamble) -G90 -G21 -(Begin operation) -G0 X1.000 Y2.000 -G0 Z8.000 -G90 -( G99 ) -( G81 X1.000 Y2.000 Z0.000 F7380.000 R5.000 ) -G0 X1.000 Y2.000 -G1 Z5.000 F7380.000 -G1 Z0.000 F7380.000 -G0 Z5.000 -( G80 ) -G90 -(Finish operation: testpath) -(Begin postamble) -""" - args = "--comments --translate_drill" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - - def test00250(self): - """Test translate_drill with G82.""" - # - c = Path.Command("G0 X1 Y2") - c1 = Path.Command("G0 Z8") - c2 = Path.Command("G90") - c3 = Path.Command("G99") - c4 = Path.Command("G82 X1 Y2 Z0 F123 R5 P1.23456") - c5 = Path.Command("G80") - c6 = Path.Command("G90") - - self.docobj.Path = Path.Path([c, c1, c2, c3, c4, c5, c6]) - postables = [self.docobj] - - expected = """G90 -G21 -G0 X1.000 Y2.000 -G0 Z8.000 -G90 -G99 -G82 X1.000 Y2.000 Z0.000 F7380.000 R5.000 P1.23456 -G80 -G90 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - - expected = """G90 -G21 -G0 X1.000 Y2.000 -G0 Z8.000 -G90 -G0 X1.000 Y2.000 -G1 Z5.000 F7380.000 -G1 Z0.000 F7380.000 -G4 P1.23456 -G0 Z5.000 -G90 -""" - args = "--translate_drill" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - - expected = """(Begin preamble) -G90 -G21 -(Begin operation) -G0 X1.000 Y2.000 -G0 Z8.000 -G90 -( G99 ) -( G82 X1.000 Y2.000 Z0.000 F7380.000 R5.000 P1.23456 ) -G0 X1.000 Y2.000 -G1 Z5.000 F7380.000 -G1 Z0.000 F7380.000 -G4 P1.23456 -G0 Z5.000 -( G80 ) -G90 -(Finish operation: testpath) -(Begin postamble) -""" - args = "--comments --translate_drill" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - - def test00260(self): - """Test translate_drill with G83.""" - # - c = Path.Command("G0 X1 Y2") - c1 = Path.Command("G0 Z8") - c2 = Path.Command("G90") - c3 = Path.Command("G99") - c4 = Path.Command("G83 X1 Y2 Z0 F123 Q1.5 R5") - c5 = Path.Command("G80") - c6 = Path.Command("G90") - - self.docobj.Path = Path.Path([c, c1, c2, c3, c4, c5, c6]) - postables = [self.docobj] - - expected = """G90 -G21 -G0 X1.000 Y2.000 -G0 Z8.000 -G90 -G99 -G83 X1.000 Y2.000 Z0.000 F7380.000 Q1.500 R5.000 -G80 -G90 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - - expected = """G90 -G21 -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 Z5.000 -G0 Z3.575 -G1 Z2.000 F7380.000 -G0 Z5.000 -G0 Z2.075 -G1 Z0.500 F7380.000 -G0 Z5.000 -G0 Z0.575 -G1 Z0.000 F7380.000 -G0 Z5.000 -G90 -""" - args = "--translate_drill" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - - expected = """(Begin preamble) -G90 -G21 -(Begin operation) -G0 X1.000 Y2.000 -G0 Z8.000 -G90 -( G99 ) -( G83 X1.000 Y2.000 Z0.000 F7380.000 Q1.500 R5.000 ) -G0 X1.000 Y2.000 -G1 Z5.000 F7380.000 -G1 Z3.500 F7380.000 -G0 Z5.000 -G0 Z3.575 -G1 Z2.000 F7380.000 -G0 Z5.000 -G0 Z2.075 -G1 Z0.500 F7380.000 -G0 Z5.000 -G0 Z0.575 -G1 Z0.000 F7380.000 -G0 Z5.000 -( G80 ) -G90 -(Finish operation: testpath) -(Begin postamble) -""" - args = "--comments --translate_drill" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - - def test00270(self): - """Test translate_drill with G81 and G91.""" - # - c = Path.Command("G0 X1 Y2") - c1 = Path.Command("G0 Z8") - c2 = Path.Command("G91") - c3 = Path.Command("G99") - c4 = Path.Command("G81 X1 Y2 Z0 F123 R5") - c5 = Path.Command("G80") - c6 = Path.Command("G90") - - self.docobj.Path = Path.Path([c, c1, c2, c3, c4, c5, c6]) - postables = [self.docobj] - - expected = """G90 -G21 -G0 X1.000 Y2.000 -G0 Z8.000 -G91 -G99 -G81 X1.000 Y2.000 Z0.000 F7380.000 R5.000 -G80 -G90 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - - expected = """G90 -G21 -G0 X1.000 Y2.000 -G0 Z8.000 -G91 -G90 -G0 Z13.000 -G0 X2.000 Y4.000 -G1 Z8.000 F7380.000 -G0 Z13.000 -G91 -G90 -""" - args = "--translate_drill" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - - expected = """(Begin preamble) -G90 -G21 -(Begin operation) -G0 X1.000 Y2.000 -G0 Z8.000 -G91 -( G99 ) -( G81 X1.000 Y2.000 Z0.000 F7380.000 R5.000 ) -G90 -G0 Z13.000 -G0 X2.000 Y4.000 -G1 Z8.000 F7380.000 -G0 Z13.000 -G91 -( G80 ) -G90 -(Finish operation: testpath) -(Begin postamble) -""" - args = "--comments --translate_drill" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - - def test00280(self): - """Test translate_drill with G82 and G91.""" - # - c = Path.Command("G0 X1 Y2") - c1 = Path.Command("G0 Z8") - c2 = Path.Command("G91") - c3 = Path.Command("G99") - c4 = Path.Command("G82 X1 Y2 Z0 F123 R5 P1.23456") - c5 = Path.Command("G80") - c6 = Path.Command("G90") - - self.docobj.Path = Path.Path([c, c1, c2, c3, c4, c5, c6]) - postables = [self.docobj] - - expected = """G90 -G21 -G0 X1.000 Y2.000 -G0 Z8.000 -G91 -G99 -G82 X1.000 Y2.000 Z0.000 F7380.000 R5.000 P1.23456 -G80 -G90 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - - expected = """G90 -G21 -G0 X1.000 Y2.000 -G0 Z8.000 -G91 -G90 -G0 Z13.000 -G0 X2.000 Y4.000 -G1 Z8.000 F7380.000 -G4 P1.23456 -G0 Z13.000 -G91 -G90 -""" - args = "--translate_drill" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - - expected = """(Begin preamble) -G90 -G21 -(Begin operation) -G0 X1.000 Y2.000 -G0 Z8.000 -G91 -( G99 ) -( G82 X1.000 Y2.000 Z0.000 F7380.000 R5.000 P1.23456 ) -G90 -G0 Z13.000 -G0 X2.000 Y4.000 -G1 Z8.000 F7380.000 -G4 P1.23456 -G0 Z13.000 -G91 -( G80 ) -G90 -(Finish operation: testpath) -(Begin postamble) -""" - args = "--comments --translate_drill" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - - def test00290(self): - """Test translate_drill with G83 and G91.""" - # - c = Path.Command("G0 X1 Y2") - c1 = Path.Command("G0 Z8") - c2 = Path.Command("G91") - c3 = Path.Command("G99") - c4 = Path.Command("G83 X1 Y2 Z0 F123 Q1.5 R5") - c5 = Path.Command("G80") - c6 = Path.Command("G90") - - self.docobj.Path = Path.Path([c, c1, c2, c3, c4, c5, c6]) - postables = [self.docobj] - - expected = """G90 -G21 -G0 X1.000 Y2.000 -G0 Z8.000 -G91 -G99 -G83 X1.000 Y2.000 Z0.000 F7380.000 Q1.500 R5.000 -G80 -G90 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - - expected = """G90 -G21 -G0 X1.000 Y2.000 -G0 Z8.000 -G91 -G90 -G0 Z13.000 -G0 X2.000 Y4.000 -G1 Z11.500 F7380.000 -G0 Z13.000 -G0 Z11.575 -G1 Z10.000 F7380.000 -G0 Z13.000 -G0 Z10.075 -G1 Z8.500 F7380.000 -G0 Z13.000 -G0 Z8.575 -G1 Z8.000 F7380.000 -G0 Z13.000 -G91 -G90 -""" - args = "--translate_drill" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - - expected = """(Begin preamble) -G90 -G21 -(Begin operation) -G0 X1.000 Y2.000 -G0 Z8.000 -G91 -( G99 ) -( G83 X1.000 Y2.000 Z0.000 F7380.000 Q1.500 R5.000 ) -G90 -G0 Z13.000 -G0 X2.000 Y4.000 -G1 Z11.500 F7380.000 -G0 Z13.000 -G0 Z11.575 -G1 Z10.000 F7380.000 -G0 Z13.000 -G0 Z10.075 -G1 Z8.500 F7380.000 -G0 Z13.000 -G0 Z8.575 -G1 Z8.000 F7380.000 -G0 Z13.000 -G91 -( G80 ) -G90 -(Finish operation: testpath) -(Begin postamble) -""" - args = "--comments --translate_drill" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - def test00300(self): """Test wait-for-spindle.""" - # c = Path.Command("M3 S3000") - self.docobj.Path = Path.Path([c]) postables = [self.docobj] - args = "" gcode = postprocessor.export(postables, "gcode.tmp", args) # print("--------\n" + gcode + "--------\n") self.assertEqual(gcode.splitlines()[2], "M3 S3000") - args = "--wait-for-spindle=1.23456" gcode = postprocessor.export(postables, "gcode.tmp", args) # print("--------\n" + gcode + "--------\n") self.assertEqual(gcode.splitlines()[2], "M3 S3000") self.assertEqual(gcode.splitlines()[3], "G4 P1.23456") - c = Path.Command("M4 S3000") - self.docobj.Path = Path.Path([c]) postables = [self.docobj] - # This also tests that the default for --wait-for-spindle # goes back to 0.0 (no wait) args = "" gcode = postprocessor.export(postables, "gcode.tmp", args) # print("--------\n" + gcode + "--------\n") self.assertEqual(gcode.splitlines()[2], "M4 S3000") - args = "--wait-for-spindle=1.23456" gcode = postprocessor.export(postables, "gcode.tmp", args) # print("--------\n" + gcode + "--------\n") @@ -898,114 +485,97 @@ G90 def test01000(self): """Test G0 command Generation.""" - # - c = Path.Command("G0 X10 Y20 Z30 A40 B50 C60 U70 V80 W90") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - expected = """G90 -G21 -G0 X10.000 Y20.000 Z30.000 A40.000 B50.000 C60.000 U70.000 V80.000 W90.000 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) + self.compare_third_line( + "G0 X10 Y20 Z30 A40 B50 C60 U70 V80 W90", + "G0 X10.000 Y20.000 Z30.000 A40.000 B50.000 C60.000 U70.000 V80.000 W90.000", + "", + ) + self.compare_third_line( + "G00 X10 Y20 Z30 A40 B50 C60 U70 V80 W90", + "G00 X10.000 Y20.000 Z30.000 A40.000 B50.000 C60.000 U70.000 V80.000 W90.000", + "", + ) def test01010(self): """Test G1 command Generation.""" - # - c = Path.Command("G1 X10 Y20 Z30 A40 B50 C60 U70 V80 W90 F1.23456") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - expected = """G90 -G21 -G1 X10.000 Y20.000 Z30.000 A40.000 B50.000 C60.000 U70.000 V80.000 W90.000 F74.074 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - + self.compare_third_line( + "G1 X10 Y20 Z30 A40 B50 C60 U70 V80 W90 F1.23456", + "G1 X10.000 Y20.000 Z30.000 A40.000 B50.000 C60.000 U70.000 V80.000 W90.000 F74.074", + "", + ) + self.compare_third_line( + "G01 X10 Y20 Z30 A40 B50 C60 U70 V80 W90 F1.23456", + "G01 X10.000 Y20.000 Z30.000 A40.000 B50.000 C60.000 U70.000 V80.000 W90.000 F74.074", + "", + ) # Test argument order - c = Path.Command("G1 F1.23456 Z30 V80 C60 W90 X10 B50 U70 Y20 A40") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - expected = """G90 -G21 -G1 X10.000 Y20.000 Z30.000 A40.000 B50.000 C60.000 U70.000 V80.000 W90.000 F74.074 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) + self.compare_third_line( + "G1 F1.23456 Z30 V80 C60 W90 X10 B50 U70 Y20 A40", + "G1 X10.000 Y20.000 Z30.000 A40.000 B50.000 C60.000 U70.000 V80.000 W90.000 F74.074", + "", + ) + self.compare_third_line( + "G1 X10 Y20 Z30 A40 B50 C60 U70 V80 W90 F1.23456", + "G1 X0.3937 Y0.7874 Z1.1811 A1.5748 B1.9685 C2.3622 U2.7559 V3.1496 W3.5433 F2.9163", + "--inches", + ) def test01020(self): """Test G2 command Generation.""" # - c = Path.Command("G2 X10 Y20 Z30 I40 J50 P60 F1.23456") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - expected = """G90 -G21 -G2 X10.000 Y20.000 Z30.000 I40.000 J50.000 F74.074 P60 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - # - c = Path.Command("G2 X10 Y20 Z30 R40 P60 F1.23456") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - expected = """G90 -G21 -G2 X10.000 Y20.000 Z30.000 F74.074 R40.000 P60 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) + self.compare_third_line( + "G2 X10 Y20 Z30 I40 J50 P60 F1.23456", + "G2 X10.000 Y20.000 Z30.000 I40.000 J50.000 P60 F74.074", + "", + ) + self.compare_third_line( + "G02 X10 Y20 Z30 I40 J50 P60 F1.23456", + "G02 X10.000 Y20.000 Z30.000 I40.000 J50.000 P60 F74.074", + "", + ) + self.compare_third_line( + "G2 X10 Y20 Z30 R40 P60 F1.23456", + "G2 X10.000 Y20.000 Z30.000 R40.000 P60 F74.074", + "", + ) + self.compare_third_line( + "G2 X10 Y20 Z30 I40 J50 P60 F1.23456", + "G2 X0.3937 Y0.7874 Z1.1811 I1.5748 J1.9685 P60 F2.9163", + "--inches", + ) + self.compare_third_line( + "G2 X10 Y20 Z30 R40 P60 F1.23456", + "G2 X0.3937 Y0.7874 Z1.1811 R1.5748 P60 F2.9163", + "--inches", + ) def test01030(self): """Test G3 command Generation.""" - # - c = Path.Command("G3 X10 Y20 Z30 I40 J50 P60 F1.23456") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - expected = """G90 -G21 -G3 X10.000 Y20.000 Z30.000 I40.000 J50.000 F74.074 P60 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - # - c = Path.Command("G3 X10 Y20 Z30 R40 P60 F1.23456") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - expected = """G90 -G21 -G3 X10.000 Y20.000 Z30.000 F74.074 R40.000 P60 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) + self.compare_third_line( + "G3 X10 Y20 Z30 I40 J50 P60 F1.23456", + "G3 X10.000 Y20.000 Z30.000 I40.000 J50.000 P60 F74.074", + "", + ) + self.compare_third_line( + "G03 X10 Y20 Z30 I40 J50 P60 F1.23456", + "G03 X10.000 Y20.000 Z30.000 I40.000 J50.000 P60 F74.074", + "", + ) + self.compare_third_line( + "G3 X10 Y20 Z30 R40 P60 F1.23456", + "G3 X10.000 Y20.000 Z30.000 R40.000 P60 F74.074", + "", + ) + self.compare_third_line( + "G3 X10 Y20 Z30 I40 J50 P60 F1.23456", + "G3 X0.3937 Y0.7874 Z1.1811 I1.5748 J1.9685 P60 F2.9163", + "--inches", + ) + self.compare_third_line( + "G3 X10 Y20 Z30 R40 P60 F1.23456", + "G3 X0.3937 Y0.7874 Z1.1811 R1.5748 P60 F2.9163", + "--inches", + ) def test01040(self): """Test G4 command Generation.""" @@ -1014,265 +584,1061 @@ G3 X10.000 Y20.000 Z30.000 F74.074 R40.000 P60 # The P parameter indicates "time to wait" where a 0.001 would # be a millisecond wait, so more than 3 or 4 digits of precision # might be useful. - c = Path.Command("G4 P1.23456") + self.compare_third_line("G4 P1.23456", "G4 P1.23456", "") + self.compare_third_line("G04 P1.23456", "G04 P1.23456", "") + self.compare_third_line("G4 P1.23456", "G4 P1.23456", "--inches") - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] + def test01070(self): + """Test G7 command Generation.""" + self.compare_third_line("G7", "G7", "") - expected = """G90 -G21 -G4 P1.23456 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) + def test01080(self): + """Test G8 command Generation.""" + self.compare_third_line("G8", "G8", "") + + def test01100(self): + """Test G10 command Generation.""" + self.compare_third_line("G10 L1 P2 Z1.23456", "G10 L1 Z1.235 P2", "") + self.compare_third_line( + "G10 L1 P2 R1.23456 I2.34567 J3.456789 Q3", "G10 L1 I2.346 J3.457 R1.235 P2 Q3", "" + ) + self.compare_third_line( + "G10 L2 P3 X1.23456 Y2.34567 Z3.456789", "G10 L2 X1.235 Y2.346 Z3.457 P3", "" + ) + self.compare_third_line("G10 L2 P0 X0 Y0 Z0", "G10 L2 X0.000 Y0.000 Z0.000 P0", "") + self.compare_third_line( + "G10 L10 P1 X1.23456 Y2.34567 Z3.456789", "G10 L10 X1.235 Y2.346 Z3.457 P1", "" + ) + self.compare_third_line( + "G10 L10 P2 R1.23456 I2.34567 J3.456789 Q3", "G10 L10 I2.346 J3.457 R1.235 P2 Q3", "" + ) + self.compare_third_line( + "G10 L11 P1 X1.23456 Y2.34567 Z3.456789", "G10 L11 X1.235 Y2.346 Z3.457 P1", "" + ) + self.compare_third_line( + "G10 L11 P2 R1.23456 I2.34567 J3.456789 Q3", "G10 L11 I2.346 J3.457 R1.235 P2 Q3", "" + ) + self.compare_third_line( + "G10 L20 P9 X1.23456 Y2.34567 Z3.456789", "G10 L20 X1.235 Y2.346 Z3.457 P9", "" + ) def test01170(self): """Test G17 command Generation.""" - # - c = Path.Command("G17") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - expected = """G90 -G21 -G17 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) + self.compare_third_line("G17", "G17", "") def test01171(self): """Test G17.1 command Generation.""" - # - c = Path.Command("G17.1") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - expected = """G90 -G21 -G17.1 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) + self.compare_third_line("G17.1", "G17.1", "") def test01180(self): """Test G18 command Generation.""" - # - c = Path.Command("G18") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - expected = """G90 -G21 -G18 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) + self.compare_third_line("G18", "G18", "") def test01181(self): """Test G18.1 command Generation.""" - # - c = Path.Command("G18.1") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - expected = """G90 -G21 -G18.1 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) + self.compare_third_line("G18.1", "G18.1", "") def test01190(self): """Test G19 command Generation.""" - # - c = Path.Command("G19") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - expected = """G90 -G21 -G19 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) + self.compare_third_line("G19", "G19", "") def test01191(self): """Test G19.1 command Generation.""" - # - c = Path.Command("G19.1") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - expected = """G90 -G21 -G19.1 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) + self.compare_third_line("G19.1", "G19.1", "") def test01200(self): """Test G20 command Generation.""" - # - c = Path.Command("G20") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - expected = """G90 -G21 -G20 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) + self.compare_third_line("G20", "G20", "") def test01210(self): """Test G21 command Generation.""" - # - c = Path.Command("G21") + self.compare_third_line("G21", "G21", "") - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] + def test01280(self): + """Test G28 command Generation.""" + self.compare_third_line("G28", "G28", "") + self.compare_third_line( + "G28 X10 Y20 Z30 A40 B50 C60 U70 V80 W90", + "G28 X10.000 Y20.000 Z30.000 A40.000 B50.000 C60.000 U70.000 V80.000 W90.000", + "", + ) - expected = """G90 -G21 -G21 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) + def test01281(self): + """Test G28.1 command Generation.""" + self.compare_third_line("G28.1", "G28.1", "") + + def test01300(self): + """Test G30 command Generation.""" + self.compare_third_line("G30", "G30", "") + self.compare_third_line( + "G30 X10 Y20 Z30 A40 B50 C60 U70 V80 W90", + "G30 X10.000 Y20.000 Z30.000 A40.000 B50.000 C60.000 U70.000 V80.000 W90.000", + "", + ) + + def test01382(self): + """Test G38.2 command Generation.""" + self.compare_third_line( + "G38.2 X10 Y20 Z30 A40 B50 C60 U70 V80 W90 F123", + "G38.2 X10.000 Y20.000 Z30.000 A40.000 B50.000 C60.000 U70.000 V80.000 W90.000 F7380.000", + "", + ) + + def test01383(self): + """Test G38.3 command Generation.""" + self.compare_third_line( + "G38.3 X10 Y20 Z30 A40 B50 C60 U70 V80 W90 F123", + "G38.3 X10.000 Y20.000 Z30.000 A40.000 B50.000 C60.000 U70.000 V80.000 W90.000 F7380.000", + "", + ) + + def test01384(self): + """Test G38.4 command Generation.""" + self.compare_third_line( + "G38.4 X10 Y20 Z30 A40 B50 C60 U70 V80 W90 F123", + "G38.4 X10.000 Y20.000 Z30.000 A40.000 B50.000 C60.000 U70.000 V80.000 W90.000 F7380.000", + "", + ) + + def test01385(self): + """Test G38.5 command Generation.""" + self.compare_third_line( + "G38.5 X10 Y20 Z30 A40 B50 C60 U70 V80 W90 F123", + "G38.5 X10.000 Y20.000 Z30.000 A40.000 B50.000 C60.000 U70.000 V80.000 W90.000 F7380.000", + "", + ) + + def test01301(self): + """Test G30.1 command Generation.""" + self.compare_third_line("G30.1", "G30.1", "") def test01400(self): """Test G40 command Generation.""" - # - c = Path.Command("G40") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - expected = """G90 -G21 -G40 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) + self.compare_third_line("G40", "G40", "") + self.compare_third_line("G40", "G40", "--inches") def test01410(self): """Test G41 command Generation.""" - # - c = Path.Command("G41 D1.23456") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - expected = """G90 -G21 -G41 D1 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - - c = Path.Command("G41 D0") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - expected = """G90 -G21 -G41 D0 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) + self.compare_third_line("G41 D1.23456", "G41 D1", "") + self.compare_third_line("G41 D0", "G41 D0", "") + self.compare_third_line("G41 D1.23456", "G41 D1", "--inches") def test01411(self): """Test G41.1 command Generation.""" - # - c = Path.Command("G41.1 D1.23456 L3") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - expected = """G90 -G21 -G41.1 L3 D1.23456 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) + self.compare_third_line("G41.1 D1.23456 L3", "G41.1 D1.235 L3", "") + self.compare_third_line("G41.1 D1.23456 L3", "G41.1 D0.0486 L3", "--inches") def test01420(self): """Test G42 command Generation.""" - # - c = Path.Command("G42 D1.23456") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - expected = """G90 -G21 -G42 D1 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) - - c = Path.Command("G42 D0") - - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] - - expected = """G90 -G21 -G42 D0 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) + self.compare_third_line("G42 D1.23456", "G42 D1", "") + self.compare_third_line("G42 D0", "G42 D0", "") + self.compare_third_line("G42 D1.23456", "G42 D1", "--inches") def test01421(self): """Test G42.1 command Generation.""" - # - c = Path.Command("G42.1 D1.23456 L3") + self.compare_third_line("G42.1 D1.23456 L3", "G42.1 D1.235 L3", "") + self.compare_third_line("G42.1 D1.23456 L3", "G42.1 D0.0486 L3", "--inches") - self.docobj.Path = Path.Path([c]) - postables = [self.docobj] + def test01430(self): + """Test G43 command Generation.""" + self.compare_third_line("G43", "G43", "") + self.compare_third_line("G43 H1.23456", "G43 H1", "") + self.compare_third_line("G43 H0", "G43 H0", "") + self.compare_third_line("G43 H1.23456", "G43 H1", "--inches") - expected = """G90 + def test01431(self): + """Test G43.1 command Generation.""" + self.compare_third_line( + "G43.1 X1.234567 Y2.345678 Z3.456789 A4.567891 B5.678912 C6.789123 U7.891234 V8.912345 W9.123456", + "G43.1 X1.235 Y2.346 Z3.457 A4.568 B5.679 C6.789 U7.891 V8.912 W9.123", + "", + ) + self.compare_third_line( + "G43.1 X1.234567 Y2.345678 Z3.456789 A4.567891 B5.678912 C6.789123 U7.891234 V8.912345 W9.123456", + "G43.1 X0.0486 Y0.0923 Z0.1361 A0.1798 B0.2236 C0.2673 U0.3107 V0.3509 W0.3592", + "--inches", + ) + + def test01432(self): + """Test G43.2 command Generation.""" + self.compare_third_line("G43.2 H1.23456", "G43.2 H1", "") + + def test01490(self): + """Test G49 command Generation.""" + self.compare_third_line("G49", "G49", "") + + def test01520(self): + """Test G52 command Generation.""" + self.single_compare( + [ + Path.Command( + "G52 X1.234567 Y2.345678 Z3.456789 A4.567891 B5.678912 C6.789123 U7.891234 V8.912345 W9.123456" + ), + Path.Command("G52 X0 Y0.0 Z0.00 A0.000 B0.0000 C0.00000 U0.000000 V0 W0"), + ], + """G90 G21 -G42.1 L3 D1.23456 -""" - args = "" - gcode = postprocessor.export(postables, "gcode.tmp", args) - # print("--------\n" + gcode + "--------\n") - self.assertEqual(gcode, expected) +G52 X1.235 Y2.346 Z3.457 A4.568 B5.679 C6.789 U7.891 V8.912 W9.123 +G52 X0.000 Y0.000 Z0.000 A0.000 B0.000 C0.000 U0.000 V0.000 W0.000 +""", + "", + ) + self.single_compare( + [ + Path.Command( + "G52 X1.234567 Y2.345678 Z3.456789 A4.567891 B5.678912 C6.789123 U7.891234 V8.912345 W9.123456" + ), + Path.Command("G52 X0 Y0.0 Z0.00 A0.000 B0.0000 C0.00000 U0.000000 V0 W0"), + ], + """G90 +G20 +G52 X0.0486 Y0.0923 Z0.1361 A0.1798 B0.2236 C0.2673 U0.3107 V0.3509 W0.3592 +G52 X0.0000 Y0.0000 Z0.0000 A0.0000 B0.0000 C0.0000 U0.0000 V0.0000 W0.0000 +""", + "--inches", + ) + + # def test01530(self): + # """Test G53 command Generation.""" + # # + # # G53 is handled differently in different gcode interpreters. + # # It always means "absolute machine coordinates", but it is + # # used like G0 in Centroid and Mach4, and used in front of + # # G0 or G1 on the same line in Fanuc, Grbl, LinuxCNC, and Tormach. + # # It is not modal in any gcode interpreter I currently know about. + # # The current FreeCAD code treats G53 as modal (like G54-G59.9). + # # The current refactored postprocessor code does not + # # handle having two G-commands on the same line. + # # + # c = Path.Command("G53 G0 X10 Y20 Z30 A40 B50 C60 U70 V80 W90") + + # self.docobj.Path = Path.Path([c]) + # postables = [self.docobj] + + # expected = """G90 + # G21 + # G53 G0 X10.000 Y20.000 Z30.000 A40.000 B50.000 C60.000 U70.000 V80.000 W90.000 + # """ + # args = "" + # gcode = postprocessor.export(postables, "gcode.tmp", args) + # print("--------\n" + gcode + "--------\n") + # self.assertEqual(gcode, expected) + + def test01540(self): + """Test G54 command Generation.""" + self.compare_third_line("G54", "G54", "") + + def test01541(self): + """Test G54.1 command Generation.""" + # + # Some gcode interpreters use G54.1 P- to select additional + # work coordinate systems. + # + self.compare_third_line("G54.1 P2.34567", "G54.1 P2", "") + + def test01550(self): + """Test G55 command Generation.""" + self.compare_third_line("G55", "G55", "") + + def test01560(self): + """Test G56 command Generation.""" + self.compare_third_line("G56", "G56", "") + + def test01570(self): + """Test G57 command Generation.""" + self.compare_third_line("G57", "G57", "") + + def test01580(self): + """Test G58 command Generation.""" + self.compare_third_line("G58", "G58", "") + + def test01590(self): + """Test G59 command Generation.""" + self.compare_third_line("G59", "G59", "") + # + # Some gcode interpreters us G59 P- to select additional + # work coordinate systems. This is considered somewhat + # obsolete and is being replaces by G54.1 P- instead. + # + self.compare_third_line("G59 P2.34567", "G59 P2", "") + + def test01591(self): + """Test G59.1 command Generation.""" + self.compare_third_line("G59.1", "G59.1", "") + + def test01592(self): + """Test G59.2 command Generation.""" + self.compare_third_line("G59.2", "G59.2", "") + + def test01593(self): + """Test G59.3 command Generation.""" + self.compare_third_line("G59.3", "G59.3", "") + + def test01594(self): + """Test G59.4 command Generation.""" + self.compare_third_line("G59.4", "G59.4", "") + + def test01595(self): + """Test G59.5 command Generation.""" + self.compare_third_line("G59.5", "G59.5", "") + + def test01596(self): + """Test G59.6 command Generation.""" + self.compare_third_line("G59.6", "G59.6", "") + + def test01597(self): + """Test G59.7 command Generation.""" + self.compare_third_line("G59.7", "G59.7", "") + + def test01598(self): + """Test G59.8 command Generation.""" + self.compare_third_line("G59.8", "G59.8", "") + + def test01599(self): + """Test G59.9 command Generation.""" + self.compare_third_line("G59.9", "G59.9", "") + + def test01610(self): + """Test G61 command Generation.""" + self.compare_third_line("G61", "G61", "") + + def test01611(self): + """Test G61.1 command Generation.""" + self.compare_third_line("G61.1", "G61.1", "") + + def test01640(self): + """Test G64 command Generation.""" + self.compare_third_line("G64", "G64", "") + self.compare_third_line("G64 P3.456789", "G64 P3.457", "") + self.compare_third_line("G64 P3.456789 Q4.567891", "G64 P3.457 Q4.568", "") + self.compare_third_line("G64 P3.456789 Q4.567891", "G64 P0.1361 Q0.1798", "--inches") + + def test01730(self): + """Test G73 command Generation.""" + 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"), + ] + self.single_compare( + path, + """G90 +G21 +G0 X1.000 Y2.000 +G0 Z8.000 +G90 +G99 +G73 X1.000 Y2.000 Z0.000 R5.000 Q1.500 F7380.000 +G80 +G90 +""", + "", + ) + self.single_compare( + path, + """G90 +G21 +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", + ) + self.single_compare( + path, + """(Begin preamble) +G90 +G21 +(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 ) +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 +( G80 ) +G90 +(Finish operation: testpath) +(Begin postamble) +""", + "--comments --translate_drill", + ) + # + # Re-initialize all of the values before doing more tests. + # + postprocessor.init_values(postprocessor.values) + # + # Test translate_drill with G83 and G91. + path = [ + Path.Command("G0 X1 Y2"), + Path.Command("G0 Z8"), + Path.Command("G91"), + Path.Command("G99"), + Path.Command("G73 X1 Y2 Z0 F123 Q1.5 R5"), + Path.Command("G80"), + Path.Command("G90"), + ] + self.single_compare( + path, + """G90 +G21 +G0 X1.000 Y2.000 +G0 Z8.000 +G91 +G99 +G73 X1.000 Y2.000 Z0.000 R5.000 Q1.500 F7380.000 +G80 +G90 +""", + "--no-comments --no-translate_drill", + ) + self.single_compare( + path, + """G90 +G21 +G0 X1.000 Y2.000 +G0 Z8.000 +G91 +G90 +G0 Z13.000 +G0 X2.000 Y4.000 +G1 Z11.500 F7380.000 +G0 Z11.750 +G0 Z11.575 +G1 Z10.000 F7380.000 +G0 Z10.250 +G0 Z10.075 +G1 Z8.500 F7380.000 +G0 Z8.750 +G0 Z8.575 +G1 Z8.000 F7380.000 +G0 Z13.000 +G91 +G90 +""", + "--translate_drill", + ) + self.single_compare( + path, + """(Begin preamble) +G90 +G21 +(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 ) +G90 +G0 Z13.000 +G0 X2.000 Y4.000 +G1 Z11.500 F7380.000 +G0 Z11.750 +G0 Z11.575 +G1 Z10.000 F7380.000 +G0 Z10.250 +G0 Z10.075 +G1 Z8.500 F7380.000 +G0 Z8.750 +G0 Z8.575 +G1 Z8.000 F7380.000 +G0 Z13.000 +G91 +( G80 ) +G90 +(Finish operation: testpath) +(Begin postamble) +""", + "--comments --translate_drill", + ) + + def test01810(self): + """Test G81 command Generation.""" + path = [ + Path.Command("G0 X1 Y2"), + Path.Command("G0 Z8"), + Path.Command("G90"), + Path.Command("G99"), + Path.Command("G81 X1 Y2 Z0 F123 R5"), + Path.Command("G80"), + Path.Command("G90"), + ] + self.single_compare( + path, + """G90 +G21 +G0 X1.000 Y2.000 +G0 Z8.000 +G90 +G99 +G81 X1.000 Y2.000 Z0.000 R5.000 F7380.000 +G80 +G90 +""", + "", + ) + self.single_compare( + path, + """G90 +G21 +G0 X1.000 Y2.000 +G0 Z8.000 +G90 +G0 X1.000 Y2.000 +G1 Z5.000 F7380.000 +G1 Z0.000 F7380.000 +G0 Z5.000 +G90 +""", + "--translate_drill", + ) + self.single_compare( + path, + """(Begin preamble) +G90 +G21 +(Begin operation) +G0 X1.000 Y2.000 +G0 Z8.000 +G90 +( 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 ) +G90 +(Finish operation: testpath) +(Begin postamble) +""", + "--comments --translate_drill", + ) + # + # Re-initialize all of the values before doing more tests. + # + postprocessor.init_values(postprocessor.values) + # + # Test translate_drill with G81 and G91. + path = [ + Path.Command("G0 X1 Y2"), + Path.Command("G0 Z8"), + Path.Command("G91"), + Path.Command("G99"), + Path.Command("G81 X1 Y2 Z0 F123 R5"), + Path.Command("G80"), + Path.Command("G90"), + ] + self.single_compare( + path, + """G90 +G21 +G0 X1.000 Y2.000 +G0 Z8.000 +G91 +G99 +G81 X1.000 Y2.000 Z0.000 R5.000 F7380.000 +G80 +G90 +""", + "--no-comments --no-translate_drill", + ) + self.single_compare( + path, + """G90 +G21 +G0 X1.000 Y2.000 +G0 Z8.000 +G91 +G90 +G0 Z13.000 +G0 X2.000 Y4.000 +G1 Z8.000 F7380.000 +G0 Z13.000 +G91 +G90 +""", + "--translate_drill", + ) + self.single_compare( + path, + """(Begin preamble) +G90 +G21 +(Begin operation) +G0 X1.000 Y2.000 +G0 Z8.000 +G91 +( 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 ) +G90 +(Finish operation: testpath) +(Begin postamble) +""", + "--comments --translate_drill", + ) + + def test01820(self): + """Test G82 command Generation.""" + path = [ + Path.Command("G0 X1 Y2"), + Path.Command("G0 Z8"), + Path.Command("G90"), + Path.Command("G99"), + Path.Command("G82 X1 Y2 Z0 F123 R5 P1.23456"), + Path.Command("G80"), + Path.Command("G90"), + ] + self.single_compare( + path, + """G90 +G21 +G0 X1.000 Y2.000 +G0 Z8.000 +G90 +G99 +G82 X1.000 Y2.000 Z0.000 R5.000 P1.23456 F7380.000 +G80 +G90 +""", + "", + ) + self.single_compare( + path, + """G90 +G21 +G0 X1.000 Y2.000 +G0 Z8.000 +G90 +G0 X1.000 Y2.000 +G1 Z5.000 F7380.000 +G1 Z0.000 F7380.000 +G4 P1.23456 +G0 Z5.000 +G90 +""", + "--translate_drill", + ) + self.single_compare( + path, + """(Begin preamble) +G90 +G21 +(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 ) +G0 X1.000 Y2.000 +G1 Z5.000 F7380.000 +G1 Z0.000 F7380.000 +G4 P1.23456 +G0 Z5.000 +( G80 ) +G90 +(Finish operation: testpath) +(Begin postamble) +""", + "--comments --translate_drill", + ) + # + # Re-initialize all of the values before doing more tests. + # + postprocessor.init_values(postprocessor.values) + # + # Test translate_drill with G82 and G91. + path = [ + Path.Command("G0 X1 Y2"), + Path.Command("G0 Z8"), + Path.Command("G91"), + Path.Command("G99"), + Path.Command("G82 X1 Y2 Z0 F123 R5 P1.23456"), + Path.Command("G80"), + Path.Command("G90"), + ] + self.single_compare( + path, + """G90 +G21 +G0 X1.000 Y2.000 +G0 Z8.000 +G91 +G99 +G82 X1.000 Y2.000 Z0.000 R5.000 P1.23456 F7380.000 +G80 +G90 +""", + "--no-comments --no-translate_drill", + ) + self.single_compare( + path, + """G90 +G21 +G0 X1.000 Y2.000 +G0 Z8.000 +G91 +G90 +G0 Z13.000 +G0 X2.000 Y4.000 +G1 Z8.000 F7380.000 +G4 P1.23456 +G0 Z13.000 +G91 +G90 +""", + "--translate_drill", + ) + self.single_compare( + path, + """(Begin preamble) +G90 +G21 +(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 ) +G90 +G0 Z13.000 +G0 X2.000 Y4.000 +G1 Z8.000 F7380.000 +G4 P1.23456 +G0 Z13.000 +G91 +( G80 ) +G90 +(Finish operation: testpath) +(Begin postamble) +""", + "--comments --translate_drill", + ) + + def test01830(self): + """Test G83 command Generation.""" + path = [ + Path.Command("G0 X1 Y2"), + Path.Command("G0 Z8"), + Path.Command("G90"), + Path.Command("G99"), + Path.Command("G83 X1 Y2 Z0 F123 Q1.5 R5"), + Path.Command("G80"), + Path.Command("G90"), + ] + self.single_compare( + path, + """G90 +G21 +G0 X1.000 Y2.000 +G0 Z8.000 +G90 +G99 +G83 X1.000 Y2.000 Z0.000 R5.000 Q1.500 F7380.000 +G80 +G90 +""", + "", + ) + self.single_compare( + path, + """G90 +G21 +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 Z5.000 +G0 Z3.575 +G1 Z2.000 F7380.000 +G0 Z5.000 +G0 Z2.075 +G1 Z0.500 F7380.000 +G0 Z5.000 +G0 Z0.575 +G1 Z0.000 F7380.000 +G0 Z5.000 +G90 +""", + "--translate_drill", + ) + self.single_compare( + path, + """(Begin preamble) +G90 +G21 +(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 ) +G0 X1.000 Y2.000 +G1 Z5.000 F7380.000 +G1 Z3.500 F7380.000 +G0 Z5.000 +G0 Z3.575 +G1 Z2.000 F7380.000 +G0 Z5.000 +G0 Z2.075 +G1 Z0.500 F7380.000 +G0 Z5.000 +G0 Z0.575 +G1 Z0.000 F7380.000 +G0 Z5.000 +( G80 ) +G90 +(Finish operation: testpath) +(Begin postamble) +""", + "--comments --translate_drill", + ) + # + # Re-initialize all of the values before doing more tests. + # + postprocessor.init_values(postprocessor.values) + # + # Test translate_drill with G83 and G91. + path = [ + Path.Command("G0 X1 Y2"), + Path.Command("G0 Z8"), + Path.Command("G91"), + Path.Command("G99"), + Path.Command("G83 X1 Y2 Z0 F123 Q1.5 R5"), + Path.Command("G80"), + Path.Command("G90"), + ] + self.single_compare( + path, + """G90 +G21 +G0 X1.000 Y2.000 +G0 Z8.000 +G91 +G99 +G83 X1.000 Y2.000 Z0.000 R5.000 Q1.500 F7380.000 +G80 +G90 +""", + "--no-comments --no-translate_drill", + ) + self.single_compare( + path, + """G90 +G21 +G0 X1.000 Y2.000 +G0 Z8.000 +G91 +G90 +G0 Z13.000 +G0 X2.000 Y4.000 +G1 Z11.500 F7380.000 +G0 Z13.000 +G0 Z11.575 +G1 Z10.000 F7380.000 +G0 Z13.000 +G0 Z10.075 +G1 Z8.500 F7380.000 +G0 Z13.000 +G0 Z8.575 +G1 Z8.000 F7380.000 +G0 Z13.000 +G91 +G90 +""", + "--translate_drill", + ) + self.single_compare( + path, + """(Begin preamble) +G90 +G21 +(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 ) +G90 +G0 Z13.000 +G0 X2.000 Y4.000 +G1 Z11.500 F7380.000 +G0 Z13.000 +G0 Z11.575 +G1 Z10.000 F7380.000 +G0 Z13.000 +G0 Z10.075 +G1 Z8.500 F7380.000 +G0 Z13.000 +G0 Z8.575 +G1 Z8.000 F7380.000 +G0 Z13.000 +G91 +( G80 ) +G90 +(Finish operation: testpath) +(Begin postamble) +""", + "--comments --translate_drill", + ) + + def test01900(self): + """Test G90 command Generation.""" + self.compare_third_line("G90", "G90", "") + + def test01901(self): + """Test G90.1 command Generation.""" + self.compare_third_line("G90.1", "G90.1", "") + + def test01910(self): + """Test G91 command Generation.""" + self.compare_third_line("G91", "G91", "") + + def test01911(self): + """Test G91.1 command Generation.""" + self.compare_third_line("G91.1", "G91.1", "") + + def test01920(self): + """Test G92 command Generation.""" + self.compare_third_line( + "G92 X10 Y20 Z30 A40 B50 C60 U70 V80 W90", + "G92 X10.000 Y20.000 Z30.000 A40.000 B50.000 C60.000 U70.000 V80.000 W90.000", + "", + ) + + def test01921(self): + """Test G92.1 command Generation.""" + self.compare_third_line("G92.1", "G92.1", "") + + def test01922(self): + """Test G92.2 command Generation.""" + self.compare_third_line("G92.2", "G92.2", "") + + def test01923(self): + """Test G92.3 command Generation.""" + self.compare_third_line("G92.3", "G92.3", "") + + def test01930(self): + """Test G93 command Generation.""" + self.compare_third_line("G93", "G93", "") + + def test01940(self): + """Test G94 command Generation.""" + self.compare_third_line("G94", "G94", "") + + def test01950(self): + """Test G95 command Generation.""" + self.compare_third_line("G95", "G95", "") + + def test01980(self): + """Test G98 command Generation.""" + self.compare_third_line("G98", "G98", "") + + def test01990(self): + """Test G99 command Generation.""" + self.compare_third_line("G99", "G99", "") + + def test02000(self): + """Test M0 command Generation.""" + self.compare_third_line("M0", "M0", "") + self.compare_third_line("M00", "M00", "") + + def test02010(self): + """Test M1 command Generation.""" + self.compare_third_line("M1", "M1", "") + self.compare_third_line("M01", "M01", "") + + def test02020(self): + """Test M2 command Generation.""" + self.compare_third_line("M2", "M2", "") + self.compare_third_line("M02", "M02", "") + + def test02030(self): + """Test M3 command Generation.""" + self.compare_third_line("M3", "M3", "") + self.compare_third_line("M03", "M03", "") + + def test02040(self): + """Test M4 command Generation.""" + self.compare_third_line("M4", "M4", "") + self.compare_third_line("M04", "M04", "") + + def test02050(self): + """Test M5 command Generation.""" + self.compare_third_line("M5", "M5", "") + self.compare_third_line("M05", "M05", "") + + def test02060(self): + """Test M6 command Generation.""" + self.compare_third_line("M6", "M6", "") + self.compare_third_line("M06", "M06", "") + + def test02070(self): + """Test M7 command Generation.""" + self.compare_third_line("M7", "M7", "") + self.compare_third_line("M07", "M07", "") + + def test02080(self): + """Test M8 command Generation.""" + self.compare_third_line("M8", "M8", "") + self.compare_third_line("M08", "M08", "") + + def test02090(self): + """Test M9 command Generation.""" + self.compare_third_line("M9", "M9", "") + self.compare_third_line("M09", "M09", "") + + def test02300(self): + """Test M30 command Generation.""" + self.compare_third_line("M30", "M30", "") + + def test02480(self): + """Test M48 command Generation.""" + self.compare_third_line("M48", "M48", "") + + def test02490(self): + """Test M49 command Generation.""" + self.compare_third_line("M49", "M49", "") + + def test02600(self): + """Test M60 command Generation.""" + self.compare_third_line("M60", "M60", "")