Commits

Anonymous committed b2f3d2a

Add RS-274X Phototplotter option

  • Participants
  • Parent commits 916164e

Comments (0)

Files changed (4)

File src/export_gcode.inx

 	      	name="useScaleVariables" 
 	      	type="boolean" 
 	      	_gui-text="Use variables to scale X and Y dimensions">false</param>
+	      <param 
+	      	name="rs274x" 
+	      	type="boolean" 
+	      	_gui-text="RS-274X Photoplotter Output">false</param>
 	    </page>
 	    <page name="help" _gui-text="Help">
 	      <param name="help_text" type="description">
     <script>
         <command reldir="extensions" interpreter="python">export_gcode.py</command>
     </script>
-</inkscape-extension>
+</inkscape-extension>

File src/export_gcode.py

 logWarning = inkex.debug
 g_toolPath = "ToolPath"
 option_filenameBase = ""
-option_machineTolerance = 0.005
+option_machineTolerance = 0.005
+option_rs274x = False
 option_traverseZ = 1.0
 option_defaultCutZ = -1.0
 option_defaultFeedRate  = 1.0
         self.lines.append("G20 (All units in inches)")
     def defineVariable(self,index,defaultValue,comment):
         self.lines.append( "#%i=%.4f (%s)" % (index, defaultValue, comment) )
+
+
+class GcodeRS274xOperationList(object):        
+    def __init__(self):
+        self.lines = []
+	# Common preamble
+	self.lines.append("%FSLAX24Y24*%")
+	self.lines.append("%MOIN*%")
+	self.lines.append("%ADD10C,0.005000*%")
+	self.lines.append("G04 Created by export_gcode.py Inkscape extension*")
+	self.lines.append("G04 Absolute positioning*")
+	self.lines.append("G90*")
+	self.lines.append("G04 Select default tool D10*")
+	self.lines.append("G54D10*")
+
+    def appendInstruction(self, code, **arguments):
+        line = code
+        argnames = arguments.keys()
+        argnames.sort()
+        for name in argnames : 
+            value = arguments[name]
+            if isinstance(value,basestring):
+                line +=  "%c%s" % (name[0].upper(),arguments[name])
+            else:
+                assert isinstance(value,float)
+                line +=  "%c%s" % (name[0].upper(),format(arguments[name]*10000," 07.0f").strip())
+	if code == 'G00':
+		line += 'D02' #rapid move with exposure off
+	elif code == 'G01':
+		line += 'D01' # milling with exposure on
+	elif code == 'G02':
+		line += 'D01' # arc with exposure on
+	elif code == 'G03':
+		line += 'D01' # arc with exposure on
+	line += '*' # append end of line
+        self.lines.append( line )
+        
+    def appendToolChange(self, tool):
+        self.lines.append("G54%s" % tool)
+
+    def appendEnd(self):
+	self.lines.append("M00*")
+        self.lines.append("M02*")
+
+    def appendMove(self, code, **arguments):
+	# Drop z movements and feed rates from photoplotter output
+	if 'z' in arguments:
+		del arguments['z']
+	if 'f' in arguments:
+		del arguments['f']
+	if len(arguments) != 0:
+		# skip the whole instruction if there is no motion to be done
+	        self.appendInstruction(code, **arguments)
+        
+    def appendRapidMove(self, **arguments):
+	self.appendMove("G00",**arguments)
+        
+    def appendFeedMove(self,**arguments):
+        self.appendMove("G01",**arguments)
+
+    def appendFeedArc(self,clockwise,**arguments):
+        if clockwise:
+            self.appendInstruction("G02",**arguments)
+        else:
+            self.appendInstruction("G03",**arguments)
+
+    def appendComment(self, comment):
+        self.lines.append( "G04 " + comment + "*" )
+        
+    def setUnitsToMillimeters(self):
+        self.lines.append("G04 All units in mm*")
+        self.lines.append("G71*")
+    def setUnitsToInches(self):
+        self.lines.append("G04 All units in inches*")
+        self.lines.append("G70*")
+    def defineVariable(self,index,defaultValue,comment):
+        self.lines.append( "#%i=%.4f (%s)" % (index, defaultValue, comment) )
 
 
 def calculateBounds(cutPath):
                         action="store", type="string",
                         dest="filenameBase", default=option_filenameBase,
                         help="Base filename (layer names will be appended)")
+        self.OptionParser.add_option("--rs274x",
+                        action="store", type="inkbool",
+                        dest="rs274x", default=option_rs274x,
+                        help="Photoplotter Output (rs274x format)")
         self.OptionParser.add_option("--machineTolerance",
                         action="store", type="float",
                         dest="machineTolerance", default=option_machineTolerance,
         # We need to convert Beziers etc into straight lines or arcs.
         # Currently only one converter is implemented, but a great thing would
         # be to develop a converter that goes from Beziers to Arcs (TBD).   
-        logStage("Converting to GCode primitives...")
+        logStage("Converting to GCode primitives...")
+	# TODO Implement a converter to eliminate the circles/convert to lines.
         for converter in converters:
             for cutList in cutLists:
                 for cutPath in cutList.cutPaths:
     def writeCutList( self, cutList, units):
         assert cutList.hasCutPaths()
         assert cutList.attributes.hasAttribute("Name")
-        name = cutList.attributes.getAttribute("Name")
-        mops = GcodeOperationList()
+        name = cutList.attributes.getAttribute("Name")
+	
+	if self.options.rs274x:
+	        mops = GcodeRS274xOperationList()
+	else:
+		mops = GcodeOperationList()
+
         mops.appendComment("Found %i paths for %s:" % (len(cutList.cutPaths), name) )
         if units == "mm":
             mops.setUnitsToMillimeters()

File src/saveas_gcode.inx

     <script>
         <command reldir="extensions" interpreter="python">export_gcode.py</command>
     </script>
-</inkscape-extension>
+</inkscape-extension>

File src/saveas_rs274x.inx

+<?xml version="1.0" encoding="UTF-8"?>
+<inkscape-extension>
+    <name>Export as RS-274X</name>
+    <id>org.middlegable.gcode.inkscape.saveasrs274x</id>
+	<dependency type="executable" location="extensions">export_gcode.py</dependency>
+	<dependency type="executable" location="extensions">inkex.py</dependency>
+	<dependency type="executable" location="extensions">simplestyle.py</dependency>
+	<dependency type="executable" location="extensions">simplepath.py</dependency>
+	<dependency type="executable" location="extensions">simpletransform.py</dependency>
+	<dependency type="executable" location="extensions">biarc.py</dependency>
+	  <param name="tab" type="notebook">  
+	    <page name="controls" _gui-text="Controls">
+	      <param 
+	      	name="machineTolerance" 
+	      	type="string" 
+	      	_gui-text="Effective resolution of the machine (in drawing units)">0.00416</param>
+	    </page>
+	    <page name="hidden" _gui-text="Hidden Controls">
+	      <param 
+		gui-hidden="true"
+	      	name="rs274x" 
+	      	type="boolean" 
+	      	_gui-text="Photoplotter Output (This must be true)">true</param>
+	      <param name="Notes" type="description">
+Do not change any of the defaults on this page - this forces the parameter that controls rs274x output to be
+true - otherwise you just get the EMC GCode output.  Required for compatibility prior to v0.47 when the 
+gui-hidden attribute can better accomplish this same purpose.
+	      </param>
+	    </page>
+	    <page name="help" _gui-text="Help">
+	      <param name="help_text" type="description">
+This extension will export RS-274X Gerber Photoplotter files.  Not all object types can be converted, so look for error messages.
+
+If any objects are selected when this converter is run, only those selected objects will be exported.
+
+To help generate tool paths with meaningful names, group objects into layers, and name the layers in the format "ToolPath&lt;Id&gt; &lt;Options&gt;" where
+&lt;Id&gt; is some unique identifier, and &lt;Options&gt; are zero or more GCode options such as Z-5.0 (override defaultCutZ),
+F100.0 (override defaultFeedRate) or T1234 (select specific tool).  Each layer will create a separate GCode file named appropriately, and placed
+in the directory filenameBase.
+
+If no "ToolPath" layers are found, then all objects in the file will be exported to a single grb file.
+
+Note that if a layer named "Origin" is found, and contains either a single circle, or two intersecting lines, then
+that position will be used as the origin for the GCode (instead of Inkscape (0,0)). 
+			</param>
+	    </page>
+	  </param>
+    <output>
+        <extension>.grb</extension>
+        <mimetype>text/plain</mimetype>
+        <_filetypename>Gerber RS-274x (*.grb)</_filetypename>
+        <_filetypetooltip>Exports the paths of this document in Gerber RS-274X format</_filetypetooltip>
+    </output>
+    <script>
+        <command reldir="extensions" interpreter="python">export_gcode.py</command>
+    </script>
+</inkscape-extension>