path: cleanup linuxcnc post and fix vertical feed problem

This commit is contained in:
sliptonic
2018-01-18 18:09:43 -06:00
committed by wmayer
parent a3684424ae
commit 4fb676e4b0

View File

@@ -44,20 +44,16 @@ linuxcnc_post.export(object,"/path/to/file.ncc","")
now = datetime.datetime.now()
parser = argparse.ArgumentParser(prog='linuxcnc', add_help=False)
parser.add_argument('--header', action='store_true', help='output headers (default)')
parser.add_argument('--no-header', action='store_true', help='suppress header output')
parser.add_argument('--comments', action='store_true', help='output comment (default)')
parser.add_argument('--no-comments', action='store_true', help='suppress comment output')
parser.add_argument('--line-numbers', action='store_true', help='prefix with line numbers')
parser.add_argument('--no-line-numbers', action='store_true', help='don\'t prefix with line numbers (default)')
parser.add_argument('--show-editor', action='store_true', help='pop up editor before writing output (default)')
parser.add_argument('--no-show-editor', action='store_true', help='don\'t pop up editor before writing output')
parser.add_argument('--precision', default='3', help='number of digits of precision, default=3')
parser.add_argument('--preamble', help='set commands to be issued before the first command, default="G17\nG90"')
parser.add_argument('--postamble', help='set commands to be issued after the last command, default="M05\nG17 G90\nM2"')
parser.add_argument('--inches', action='store_true', help='Convert output for US imperial mode (G20)')
parser.add_argument('--modal', action='store_true', help='Dont output the Same Gcommand Name USE Modal Mode')
parser.add_argument('--no-doubles', action='store_true', help='Dont output the Same Axis Value Mode')
parser.add_argument('--modal', action='store_true', help='Output the Same Gcommand Name USE NonModal Mode')
parser.add_argument('--output-doubles', action='store_true', help='Output the Same Axis Value Mode')
TOOLTIP_ARGS = parser.format_help()
@@ -67,7 +63,7 @@ OUTPUT_HEADER = True
OUTPUT_LINE_NUMBERS = False
SHOW_EDITOR = True
MODAL = False # if true commands are suppressed if the same as previous line.
OUTPUT_DOUBLES = True
OUTPUT_DOUBLES = False
COMMAND_SPACE = " "
LINENR = 100 # line number starting value
@@ -82,16 +78,15 @@ CORNER_MAX = {'x': 500, 'y': 300, 'z': 300}
PRECISION = 3
# Preamble text will appear at the beginning of the GCODE output file.
PREAMBLE = '''G17 G90
PREAMBLE = '''G17 G54 G40 G49 G80 G90
'''
# Postamble text will appear following the last operation.
POSTAMBLE = '''M05
G17 G90
G17 G54 G90 G80 G40
M2
'''
# Pre operation text will be inserted before every operation
PRE_OPERATION = ''''''
@@ -101,7 +96,6 @@ POST_OPERATION = ''''''
# Tool Change commands will be inserted before a tool change
TOOL_CHANGE = ''''''
# to distinguish python built-in open function from the one declared below
if open.__module__ == '__builtin__':
pythonopen = open
@@ -125,20 +119,12 @@ def processArguments(argstring):
args = parser.parse_args(shlex.split(argstring))
if args.no_header:
OUTPUT_HEADER = False
if args.header:
OUTPUT_HEADER = True
if args.no_comments:
OUTPUT_COMMENTS = False
if args.comments:
OUTPUT_COMMENTS = True
if args.no_line_numbers:
OUTPUT_LINE_NUMBERS = False
if args.line_numbers:
OUTPUT_LINE_NUMBERS = True
if args.no_show_editor:
SHOW_EDITOR = False
if args.show_editor:
SHOW_EDITOR = True
print("Show editor = %d" % SHOW_EDITOR)
PRECISION = args.precision
if args.preamble is not None:
@@ -152,8 +138,8 @@ def processArguments(argstring):
PRECISION = 4
if args.modal:
MODAL = True
if args.no_doubles:
OUTPUT_DOUBLES = False
if args.output_doubles:
OUTPUT_DOUBLES = True
except:
return False
@@ -165,6 +151,7 @@ def export(objectslist, filename, argstring):
if not processArguments(argstring):
return None
global UNITS
global UNIT_FORMAT
global UNIT_SPEED_FORMAT
for obj in objectslist:
@@ -201,9 +188,11 @@ def export(objectslist, filename, argstring):
if hasattr(job, "MachineUnits"):
if job.MachineUnits == "Metric":
UNITS = "G21"
UNIT_FORMAT = 'mm'
UNIT_SPEED_FORMAT = 'mm/min'
else:
UNITS = "G20"
UNIT_FORMAT = 'in'
UNIT_SPEED_FORMAT = 'in/min'
# do the pre_op
@@ -222,7 +211,6 @@ def export(objectslist, filename, argstring):
gcode += linenumber() + line
# do the post_amble
if OUTPUT_COMMENTS:
gcode += "(begin postamble)\n"
for line in POSTAMBLE.splitlines(True):
@@ -261,19 +249,19 @@ def parse(pathobj):
global PRECISION
global MODAL
global OUTPUT_DOUBLES
global UNIT_FORMAT
global UNIT_SPEED_FORMAT
out = ""
lastcommand = None
precision_string = '.' + str(PRECISION) + 'f'
currLocation = {} # keep track for no doubles
# params = ['X','Y','Z','A','B','I','J','K','F','S'] #This list control
# the order of parameters
# linuxcnc doesn't want K properties on XY plane Arcs need work.
params = ['X', 'Y', 'Z', 'A', 'B', 'C', 'I', 'J', 'F', 'S', 'T', 'Q', 'R', 'L', 'H', 'D', 'P']
# keep track for no doubles
currLocation = {}
firstmove = Path.Command("G0", {"X": -1, "Y": -1, "Z": -1, "F": 0.0})
currLocation.update(firstmove.Parameters)
currLocation.update(firstmove.Parameters) # set First location Parameters
if hasattr(pathobj, "Group"): # We have a compound or project.
# if OUTPUT_COMMENTS:
@@ -291,24 +279,27 @@ def parse(pathobj):
# out += linenumber() + "(" + pathobj.Label + ")\n"
for c in pathobj.Path.Commands:
outstring = []
command = c.Name
outstring.append(command)
# if modal: only print the command if it is not the same as the
# last one
# if modal: suppress the command if it is the same as the last one
if MODAL is True:
if command == lastcommand:
outstring.pop(0)
if c.Name[0] == '(' and not OUTPUT_COMMENTS: # command is a comment
continue
# Now add the remaining parameters in order
for param in params:
if param in c.Parameters:
if param == 'F' and (currLocation[param] == c.Parameters[param] and OUTPUT_DOUBLES):
if param == 'F' and (currLocation[param] != c.Parameters[param] or OUTPUT_DOUBLES):
if c.Name not in ["G0", "G00"]: # linuxcnc doesn't use rapid speeds
speed = Units.Quantity(c.Parameters['F'], FreeCAD.Units.Velocity)
if speed.getValueAs(UNIT_SPEED_FORMAT) > 0.0:
outstring.append(
param + format(float(speed.getValueAs(UNIT_SPEED_FORMAT)), precision_string))
outstring.append(param + format(float(speed.getValueAs(UNIT_SPEED_FORMAT)), precision_string))
else:
continue
elif param == 'T':
@@ -326,7 +317,6 @@ def parse(pathobj):
pos = Units.Quantity(c.Parameters[param], FreeCAD.Units.Length)
outstring.append(
param + format(float(pos.getValueAs(UNIT_FORMAT)), precision_string))
# param + format(c.Parameters[param], precision_string))
# store the latest command
lastcommand = command
@@ -357,5 +347,4 @@ def parse(pathobj):
return out
print(__name__ + " gcode postprocessor loaded.")