Added support for imperial shopbot output and some standard post processor arguments.

This commit is contained in:
Markus Lampert
2017-07-08 21:15:32 -07:00
committed by Yorik van Havre
parent 2ebf430cf9
commit ce14884eae

View File

@@ -34,12 +34,15 @@ inside FreeCAD, via the GUI importer or via python scripts with:
import Path
Path.write(object,"/path/to/file.ncc","post_opensbp")
'''
'''
DONE:
uses native commands
handles feed and jog moves
handles XY, Z, and XYZ feed speeds
handles arcs
support for inch output
ToDo
comments may not format correctly
drilling. Haven't looked at it.
@@ -47,6 +50,14 @@ ToDo
'''
TOOLTIP_ARGS='''
Arguments for opensbp:
--comments ... insert comments - mostly for debugging
--inches ... convert output to inches
--no-header ... suppress header output
--no-show-editor ... don't show editor, just save result
'''
now = datetime.datetime.now()
OUTPUT_COMMENTS = False
@@ -74,9 +85,31 @@ if open.__module__ == '__builtin__':
CurrentState = {}
def getMetricValue(val):
return val
def getImperialValue(val):
return val / 25.4
GetValue = getMetricValue
def export(objectslist, filename, argstring):
global OUTPUT_COMMENTS
global OUTPUT_HEADER
global SHOW_EDITOR
global CurrentState
global GetValue
for arg in argstring.split():
if arg == '--comments':
OUTPUT_COMMENTS = True
if arg == '--inches':
GetValue = getImperialValue
if arg == '--no-header':
OUTPUT_HEADER = False
if arg == '--no-show-editor':
SHOW_EDITOR = False
for obj in objectslist:
if not hasattr(obj, "Path"):
@@ -169,9 +202,9 @@ def move(command):
zspeed = ""
xyspeed = ""
if 'Z' in axis:
zspeed = "{:f}".format(speed)
zspeed = "{:f}".format(GetValue(speed))
if ('X' in axis) or ('Y' in axis):
xyspeed = "{:f}".format(speed)
xyspeed = "{:f}".format(GetValue(speed))
txt += "{},{},{}\n".format(movetype, zspeed, xyspeed)
if command.Name in ['G0', 'G00']:
@@ -181,40 +214,40 @@ def move(command):
if axis == "X":
txt += pref + "X"
txt += "," + format(command.Parameters["X"], '.4f')
txt += "," + format(GetValue(command.Parameters["X"]), '.4f')
txt += "\n"
elif axis == "Y":
txt += pref + "Y"
txt += "," + format(command.Parameters["Y"], '.4f')
txt += "," + format(GetValue(command.Parameters["Y"]), '.4f')
txt += "\n"
elif axis == "Z":
txt += pref + "Z"
txt += "," + format(command.Parameters["Z"], '.4f')
txt += "," + format(GetValue(command.Parameters["Z"]), '.4f')
txt += "\n"
elif axis == "XY":
txt += pref + "2"
txt += "," + format(command.Parameters["X"], '.4f')
txt += "," + format(command.Parameters["Y"], '.4f')
txt += "," + format(GetValue(command.Parameters["X"]), '.4f')
txt += "," + format(GetValue(command.Parameters["Y"]), '.4f')
txt += "\n"
elif axis == "XZ":
txt += pref + "X"
txt += "," + format(command.Parameters["X"], '.4f')
txt += "," + format(GetValue(command.Parameters["X"]), '.4f')
txt += "\n"
txt += pref + "Z"
txt += "," + format(command.Parameters["Z"], '.4f')
txt += "," + format(GetValue(command.Parameters["Z"]), '.4f')
txt += "\n"
elif axis == "XYZ":
txt += pref + "3"
txt += "," + format(command.Parameters["X"], '.4f')
txt += "," + format(command.Parameters["Y"], '.4f')
txt += "," + format(command.Parameters["Z"], '.4f')
txt += "," + format(GetValue(command.Parameters["X"]), '.4f')
txt += "," + format(GetValue(command.Parameters["Y"]), '.4f')
txt += "," + format(GetValue(command.Parameters["Z"]), '.4f')
txt += "\n"
elif axis == "YZ":
txt += pref + "Y"
txt += "," + format(command.Parameters["Y"], '.4f')
txt += "," + format(GetValue(command.Parameters["Y"]), '.4f')
txt += "\n"
txt += pref + "Z"
txt += "," + format(command.Parameters["Z"], '.4f')
txt += "," + format(GetValue(command.Parameters["Z"]), '.4f')
txt += "\n"
elif axis == "":
print("warning: skipping duplicate move.")
@@ -232,10 +265,10 @@ def arc(command):
else: # G3 means CCW
dirstring = "-1"
txt = "CG,,"
txt += format(command.Parameters['X'], '.4f') + ","
txt += format(command.Parameters['Y'], '.4f') + ","
txt += format(command.Parameters['I'], '.4f') + ","
txt += format(command.Parameters['J'], '.4f') + ","
txt += format(GetValue(command.Parameters['X']), '.4f') + ","
txt += format(GetValue(command.Parameters['Y']), '.4f') + ","
txt += format(GetValue(command.Parameters['I']), '.4f') + ","
txt += format(GetValue(command.Parameters['J']), '.4f') + ","
txt += "T" + ","
txt += dirstring
txt += "\n"