Commit c148938f authored by sumpfralle's avatar sumpfralle

add some optional configuration settings to the gcode exporter:

 * tool-id (e.g. "T1")
 * allow to use general IO streams instead of a file output
 * allow to skip the "M2" command ("end program") for multiple assembled toolpaths


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@175 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent e8367461
...@@ -5,40 +5,56 @@ from gcode import gcode ...@@ -5,40 +5,56 @@ from gcode import gcode
class SimpleGCodeExporter: class SimpleGCodeExporter:
def __init__(self, filename, unit, startx, starty, startz, feedrate, speed, safety_height=None, tool_id=1): def __init__(self, destination, unit, startx, starty, startz, feedrate,
self.file = file(filename,"w") speed, safety_height=None, tool_id=1, finish_program=False):
if isinstance(destination, basestring):
# open the file
self.destination = file(destination,"w")
self._close_stream_on_exit = True
else:
# assume that "destination" is something like a StringIO instance
# or an open file
self.destination = destination
# don't close the stream if we did not open it on our own
self._close_stream_on_exit = False
if unit == "mm": if unit == "mm":
self.file.write("G21\n") self.destination.write("G21\n")
else: else:
self.file.write("G20\n") self.destination.write("G20\n")
self.gcode = gcode(startx, starty, startz, safetyheight=safety_height, tool_id=tool_id) self.gcode = gcode(startx, starty, startz, safetyheight=safety_height, tool_id=tool_id)
gc = self.gcode gc = self.gcode
self.file.write(gc.begin() + "\n") self._finish_program_on_exit = finish_program
self.file.write("F" + str(feedrate) + "\n") self.destination.write(gc.begin() + "\n")
self.file.write("S" + str(speed) + "\n") self.destination.write("F" + str(feedrate) + "\n")
self.file.write(gc.safety() + "\n") self.destination.write("S" + str(speed) + "\n")
self.destination.write(gc.safety() + "\n")
def close(self): def close(self):
gc = self.gcode gc = self.gcode
self.file.write(gc.safety() + "\n") self.destination.write(gc.safety() + "\n")
self.file.write(gc.end() + "\n") if self._finish_program_on_exit:
self.file.close() self.destination.write(gc.end() + "\n")
if self._close_stream_on_exit:
self.destination.close()
def AddPath(self, path): def AddPath(self, path):
gc = self.gcode gc = self.gcode
point = path.points[0] point = path.points[0]
self.file.write(gc.rapid(point.x, point.y, gc.safetyheight) + "\n") self.destination.write(gc.rapid(point.x, point.y, gc.safetyheight) + "\n")
for point in path.points: for point in path.points:
self.file.write(gc.cut(point.x, point.y, point.z) + "\n") self.destination.write(gc.cut(point.x, point.y, point.z) + "\n")
self.file.write(gc.rapid(point.x, point.y, gc.safetyheight) + "\n") self.destination.write(gc.rapid(point.x, point.y, gc.safetyheight) + "\n")
def AddPathList(self, pathlist): def AddPathList(self, pathlist):
for path in pathlist: for path in pathlist:
self.AddPath(path) self.AddPath(path)
def ExportPathList(filename, pathlist, unit, startx, starty, startz, feedrate, speed, safety_height=None): def ExportPathList(destination, pathlist, unit, startx, starty, startz,
exporter = SimpleGCodeExporter(filename, unit, startx, starty, startz, feedrate, speed, safety_height) feedrate, speed, safety_height=None, tool_id=1, finish_program=False):
exporter = SimpleGCodeExporter(destination, unit, startx, starty, startz,
feedrate, speed, safety_height=safety_height, tool_id=tool_id,
finish_program=finish_program)
exporter.AddPathList(pathlist) exporter.AddPathList(pathlist)
exporter.close() exporter.close()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment