summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Wüst <sebi@timewaster.de>2013-11-10 13:06:03 +0000
committerSebastian Wüst <sebi@timewaster.de>2013-11-10 13:06:03 +0000
commit297f45e2e4ab293f036a7199ec80f9c3008cdcb5 (patch)
treec33ab6983d609f23949eea4f54cd7dda55787a30
parentRevert unintentional change. (diff)
downloadinkscape-297f45e2e4ab293f036a7199ec80f9c3008cdcb5.tar.gz
inkscape-297f45e2e4ab293f036a7199ec80f9c3008cdcb5.zip
fixed and optimized pyserial usage, added dmpl support, small stuff
(bzr r12787)
-rw-r--r--share/extensions/hpgl_decoder.py13
-rw-r--r--share/extensions/hpgl_encoder.py2
-rw-r--r--share/extensions/hpgl_input.py14
-rwxr-xr-xshare/extensions/hpgl_output.py8
-rw-r--r--share/extensions/plotter.inx10
-rw-r--r--share/extensions/plotter.py84
6 files changed, 74 insertions, 57 deletions
diff --git a/share/extensions/hpgl_decoder.py b/share/extensions/hpgl_decoder.py
index 870775cb2..0af2d5f5f 100644
--- a/share/extensions/hpgl_decoder.py
+++ b/share/extensions/hpgl_decoder.py
@@ -38,17 +38,18 @@ class hpglDecoder:
self.options = options
self.scaleX = options.resolutionX / 90.0 # dots/inch to dots/pixels
self.scaleY = options.resolutionY / 90.0 # dots/inch to dots/pixels
- self.warnings = []
+ self.warning = ''
+ self.textMovements = _("Movements")
+ self.textPenNumber = _("Pen #")
def getSvg(self):
- # parse hpgl data
# prepare document
self.doc = inkex.etree.parse(StringIO('<svg xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" width="%s" height="%s"></svg>' %
(self.options.docWidth, self.options.docHeight)))
actualLayer = 0
self.layers = {}
if self.options.showMovements:
- self.layers[0] = inkex.etree.SubElement(self.doc.getroot(), 'g', {inkex.addNS('groupmode', 'inkscape'): 'layer', inkex.addNS('label', 'inkscape'): 'Movements'})
+ self.layers[0] = inkex.etree.SubElement(self.doc.getroot(), 'g', {inkex.addNS('groupmode', 'inkscape'): 'layer', inkex.addNS('label', 'inkscape'): self.textMovements})
# parse paths
hpglData = self.hpglString.split(';')
if len(hpglData) < 3:
@@ -89,14 +90,14 @@ class hpglDecoder:
parameterString = ','.join(parameter)
path += ' L %s' % parameterString
else:
- self.warnings.append('UNKNOWN_COMMANDS')
+ self.warning = 'UNKNOWN_COMMANDS'
if ' L ' in path:
self.addPathToLayer(path, actualLayer)
- return (self.doc, self.warnings)
+ return (self.doc, self.warning)
def createLayer(self, layerNumber):
self.layers[layerNumber] = inkex.etree.SubElement(self.doc.getroot(), 'g',
- {inkex.addNS('groupmode', 'inkscape'): 'layer', inkex.addNS('label', 'inkscape'): 'Drawing Pen ' + layerNumber})
+ {inkex.addNS('groupmode', 'inkscape'): 'layer', inkex.addNS('label', 'inkscape'): self.textPenNumber + layerNumber})
def addPathToLayer(self, path, layerNumber):
lineColor = '000000'
diff --git a/share/extensions/hpgl_encoder.py b/share/extensions/hpgl_encoder.py
index 90d2734be..4523afb7f 100644
--- a/share/extensions/hpgl_encoder.py
+++ b/share/extensions/hpgl_encoder.py
@@ -125,7 +125,7 @@ class hpglEncoder:
style = group.get('style')
if style:
style = simplestyle.parseStyle(style)
- if style.has_key('display'):
+ if 'display' in style:
if style['display'] == 'none':
return
trans = group.get('transform')
diff --git a/share/extensions/hpgl_input.py b/share/extensions/hpgl_input.py
index d1d46c76f..93dd5a6c2 100644
--- a/share/extensions/hpgl_input.py
+++ b/share/extensions/hpgl_input.py
@@ -53,18 +53,20 @@ hpglString = ';'.join(hpglString)
myHpglDecoder = hpgl_decoder.hpglDecoder(hpglString, options)
try:
doc, warnings = myHpglDecoder.getSvg()
- # issue warning if unknown commands where found
- if 'UNKNOWN_COMMANDS' in warnings:
- inkex.errormsg(_("The HPGL data contained unknown (unsupported) commands, there is a possibility that the drawing is missing some content."))
- # deliver document to inkscape
- doc.write(inkex.sys.stdout)
except Exception as inst:
if inst.args[0] == 'NO_HPGL_DATA':
# issue error if no hpgl data found
inkex.errormsg(_("No HPGL data found."))
- print 1
+ exit(1)
else:
type, value, traceback = sys.exc_info()
raise ValueError, ("", type, value), traceback
+# issue warning if unknown commands where found
+if 'UNKNOWN_COMMANDS' in warnings:
+ inkex.errormsg(_("The HPGL data contained unknown (unsupported) commands, there is a possibility that the drawing is missing some content."))
+
+# deliver document to inkscape
+doc.write(inkex.sys.stdout)
+
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99 \ No newline at end of file
diff --git a/share/extensions/hpgl_output.py b/share/extensions/hpgl_output.py
index c5fec0ec8..94596a4a0 100755
--- a/share/extensions/hpgl_output.py
+++ b/share/extensions/hpgl_output.py
@@ -35,7 +35,7 @@ class MyEffect(inkex.Effect):
self.OptionParser.add_option('--resolutionX', action='store', type='float', dest='resolutionX', default=1016.0, help='Resolution X (dpi)')
self.OptionParser.add_option('--resolutionY', action='store', type='float', dest='resolutionY', default=1016.0, help='Resolution Y (dpi)')
self.OptionParser.add_option('--pen', action='store', type='int', dest='pen', default=1, help='Pen number')
- self.OptionParser.add_option('--orientation', action='store', type='string', dest='orientation', default='90', help='orientation')
+ self.OptionParser.add_option('--orientation', action='store', type='string', dest='orientation', default='90', help='Rotation (Clockwise)')
self.OptionParser.add_option('--mirrorX', action='store', type='inkbool', dest='mirrorX', default='FALSE', help='Mirror X-axis')
self.OptionParser.add_option('--mirrorY', action='store', type='inkbool', dest='mirrorY', default='FALSE', help='Mirror Y-axis')
self.OptionParser.add_option('--center', action='store', type='inkbool', dest='center', default='FALSE', help='Center zero point')
@@ -57,14 +57,16 @@ class MyEffect(inkex.Effect):
if inst.args[0] == 'NO_PATHS':
# issue error if no paths found
inkex.errormsg(_("No paths where found. Please convert all objects you want to save into paths."))
- self.hpgl = 1
+ self.hpgl = ''
+ return
else:
type, value, traceback = sys.exc_info()
raise ValueError, ("", type, value), traceback
def output(self):
# print to file
- print self.hpgl
+ if self.hpgl != '':
+ print self.hpgl
if __name__ == '__main__':
# Raise recursion limit to avoid exceptions on big documents
diff --git a/share/extensions/plotter.inx b/share/extensions/plotter.inx
index 526ab1bd3..49bcf837e 100644
--- a/share/extensions/plotter.inx
+++ b/share/extensions/plotter.inx
@@ -26,11 +26,15 @@
<option value="57600">57600</option>
<option value="115200">115200</option>
</param>
- <param name="flowControl" type="optiongroup" appearance="minimal" _gui-text="Flow control" _gui-description="Software / Hardware flow control - Try different settings to find the one that fits your plotter (Default: None)">
- <_option value="">None</_option>
+ <param name="flowControl" type="optiongroup" appearance="minimal" _gui-text="Flow control" _gui-description="Software / Hardware flow control - Try different settings to find the one that fits your plotter (Default: Software)">
<_option value="xonxoff">Software (XON/XOFF)</_option>
<_option value="rtscts">Hardware (RTS/CTS)</_option>
<_option value="dsrdtrrtscts">Hardware (DSR/DTR + RTS/CTS)</_option>
+ <_option value="">None</_option>
+ </param>
+ <param name="commandLanguage" type="optiongroup" appearance="minimal" _gui-text="Command Language" _gui-description="The command language to use - Try different settings to find the one that fits your plotter (Default: HPGL)">
+ <option value="hpgl">HPGL</option>
+ <option value="dmpl">DMPL</option>
</param>
<param name="space" type="description">&#xa0;</param>
<_param name="serialHelp" type="description">This can be a physical serial connection or a USB-to-Serial bridge. Ask your plotter manufacturer for drivers if needed.</_param>
@@ -38,7 +42,7 @@
<_param name="hpglNote" type="description">Please note that only the HPGL command language is supported at the moment.</_param>
</page>
<page name="plotter" _gui-text="Plotter Settings">
- <param name="pen" type="int" min="0" max="10" _gui-text="Pen number" _gui-description="The number of the pen (tool) to use, on most plotters 1 (Standard: '1')">1</param>
+ <param name="pen" type="int" min="0" max="99" _gui-text="Pen number" _gui-description="The number of the pen (tool) to use, on most plotters 1 (Standard: '1')">1</param>
<param name="resolutionX" type="float" min="1.0" max="4096.0" precision="1" _gui-text="Resolution X (dpi)" _gui-description="The amount of steps the cutter moves if it moves for 1 inch on the X axis - Try different settings to find the one that fits your plotter (Default: 1016.0)">1016.0</param>
<param name="resolutionY" type="float" min="1.0" max="4096.0" precision="1" _gui-text="Resolution Y (dpi)" _gui-description="The amount of steps the cutter moves if it moves for 1 inch on the Y axis - Try different settings to find the one that fits your plotter (Default: 1016.0)">1016.0</param>
<param name="mirrorX" type="boolean" _gui-text="Mirror X-axis" _gui-description="Check this to mirror the X axis (Default: Unchecked)">false</param>
diff --git a/share/extensions/plotter.py b/share/extensions/plotter.py
index d518de4c9..e1d20c01b 100644
--- a/share/extensions/plotter.py
+++ b/share/extensions/plotter.py
@@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
'''
# standard library
+import re
import sys
# local libraries
import gettext
@@ -28,31 +29,31 @@ import inkex
inkex.localize()
-# TODO: Unittests
-# TODO: Material feed after plot, plot rectangles
+# TODO: Unittests, Material feed after plot, plot rectangles and circles (convert to paths), maybe interpret layers as pens
class MyEffect(inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
- self.OptionParser.add_option('--tab', action='store', type='string', dest='tab')
- self.OptionParser.add_option('--resolutionX', action='store', type='float', dest='resolutionX', default=1016.0, help='Resolution X (dpi)')
- self.OptionParser.add_option('--resolutionY', action='store', type='float', dest='resolutionY', default=1016.0, help='Resolution Y (dpi)')
- self.OptionParser.add_option('--pen', action='store', type='int', dest='pen', default=1, help='Pen number')
- self.OptionParser.add_option('--orientation', action='store', type='string', dest='orientation', default='90', help='orientation')
- self.OptionParser.add_option('--mirrorX', action='store', type='inkbool', dest='mirrorX', default='FALSE', help='Mirror X-axis')
- self.OptionParser.add_option('--mirrorY', action='store', type='inkbool', dest='mirrorY', default='FALSE', help='Mirror Y-axis')
- self.OptionParser.add_option('--center', action='store', type='inkbool', dest='center', default='FALSE', help='Center zero point')
- self.OptionParser.add_option('--flat', action='store', type='float', dest='flat', default=1.2, help='Curve flatness')
- self.OptionParser.add_option('--useOvercut', action='store', type='inkbool', dest='useOvercut', default='TRUE', help='Use overcut')
- self.OptionParser.add_option('--overcut', action='store', type='float', dest='overcut', default=1.0, help='Overcut (mm)')
- self.OptionParser.add_option('--useToolOffset', action='store', type='inkbool', dest='useToolOffset', default='TRUE', help='Correct tool offset')
- self.OptionParser.add_option('--toolOffset', action='store', type='float', dest='toolOffset', default=0.25, help='Tool offset (mm)')
- self.OptionParser.add_option('--precut', action='store', type='inkbool', dest='precut', default='TRUE', help='Use precut')
- self.OptionParser.add_option('--offsetX', action='store', type='float', dest='offsetX', default=0.0, help='X offset (mm)')
- self.OptionParser.add_option('--offsetY', action='store', type='float', dest='offsetY', default=0.0, help='Y offset (mm)')
- self.OptionParser.add_option('--serialPort', action='store', type='string', dest='serialPort', default='COM1', help='Serial port')
- self.OptionParser.add_option('--serialBaudRate', action='store', type='string', dest='serialBaudRate', default='9600', help='Serial Baud rate')
- self.OptionParser.add_option('--flowControl', action='store', type='string', dest='flowControl', default='0', help='Flow control')
+ self.OptionParser.add_option('--tab', action='store', type='string', dest='tab')
+ self.OptionParser.add_option('--resolutionX', action='store', type='float', dest='resolutionX', default=1016.0, help='Resolution X (dpi)')
+ self.OptionParser.add_option('--resolutionY', action='store', type='float', dest='resolutionY', default=1016.0, help='Resolution Y (dpi)')
+ self.OptionParser.add_option('--pen', action='store', type='int', dest='pen', default=1, help='Pen number')
+ self.OptionParser.add_option('--orientation', action='store', type='string', dest='orientation', default='90', help='Rotation (Clockwise)')
+ self.OptionParser.add_option('--mirrorX', action='store', type='inkbool', dest='mirrorX', default='FALSE', help='Mirror X-axis')
+ self.OptionParser.add_option('--mirrorY', action='store', type='inkbool', dest='mirrorY', default='FALSE', help='Mirror Y-axis')
+ self.OptionParser.add_option('--center', action='store', type='inkbool', dest='center', default='FALSE', help='Center zero point')
+ self.OptionParser.add_option('--flat', action='store', type='float', dest='flat', default=1.2, help='Curve flatness')
+ self.OptionParser.add_option('--useOvercut', action='store', type='inkbool', dest='useOvercut', default='TRUE', help='Use overcut')
+ self.OptionParser.add_option('--overcut', action='store', type='float', dest='overcut', default=1.0, help='Overcut (mm)')
+ self.OptionParser.add_option('--useToolOffset', action='store', type='inkbool', dest='useToolOffset', default='TRUE', help='Correct tool offset')
+ self.OptionParser.add_option('--toolOffset', action='store', type='float', dest='toolOffset', default=0.25, help='Tool offset (mm)')
+ self.OptionParser.add_option('--precut', action='store', type='inkbool', dest='precut', default='TRUE', help='Use precut')
+ self.OptionParser.add_option('--offsetX', action='store', type='float', dest='offsetX', default=0.0, help='X offset (mm)')
+ self.OptionParser.add_option('--offsetY', action='store', type='float', dest='offsetY', default=0.0, help='Y offset (mm)')
+ self.OptionParser.add_option('--serialPort', action='store', type='string', dest='serialPort', default='COM1', help='Serial port')
+ self.OptionParser.add_option('--serialBaudRate', action='store', type='string', dest='serialBaudRate', default='9600', help='Serial Baud rate')
+ self.OptionParser.add_option('--flowControl', action='store', type='string', dest='flowControl', default='0', help='Flow control')
+ self.OptionParser.add_option('--commandLanguage', action='store', type='string', dest='commandLanguage', default='hpgl', help='Command Language')
def effect(self):
# gracefully exit script when pySerial is missing
@@ -64,7 +65,6 @@ class MyEffect(inkex.Effect):
+ "\n2. Extract the \"serial\" subfolder from the zip to the following folder: C:\\[Program files]\\inkscape\\python\\Lib\\"
+ "\n3. Restart Inkscape."))
return
- # TODO: Maybe implement DMPL?
# get hpgl data
myHpglEncoder = hpgl_encoder.hpglEncoder(self)
try:
@@ -76,7 +76,7 @@ class MyEffect(inkex.Effect):
return 1
else:
type, value, traceback = sys.exc_info()
- raise ValueError, ("", type, value), traceback
+ raise ValueError, ('', type, value), traceback
# TODO: Get preview to work. This requires some work on the C++ side to be able to determine if it is
# a preview or a final run. (Remember to set <effect needs-live-preview='false'> to true)
'''
@@ -95,31 +95,39 @@ class MyEffect(inkex.Effect):
pass
else:
type, value, traceback = sys.exc_info()
- raise ValueError, ("", type, value), traceback
+ raise ValueError, ('', type, value), traceback
'''
+ if self.options.commandLanguage == 'dmpl':
+ # convert HPGL to DMPL
+ self.hpgl = self.hpgl.replace(';', ',')
+ self.hpgl = self.hpgl.replace('PU', 'U')
+ self.hpgl = self.hpgl.replace('PD', 'D')
+ self.hpgl = re.sub(r'IN,SP([0-9]{1,2}),', r';:HAEC1L0P\1', self.hpgl)
+ self.hpgl += 'Z'
# send data to plotter
+ mySerial = serial.Serial()
+ mySerial.port = self.options.serialPort
+ mySerial.baudrate = self.options.serialBaudRate
if self.options.flowControl == 'xonxoff':
- mySerial = serial.Serial(port=self.options.serialPort, baudrate=self.options.serialBaudRate, timeout=0.1, writeTimeout=10, xonxoff=True)
- elif self.options.flowControl == 'rtscts':
- mySerial = serial.Serial(port=self.options.serialPort, baudrate=self.options.serialBaudRate, timeout=0.1, writeTimeout=10, rtscts=True)
- elif self.options.flowControl == 'dsrdtrrtscts':
- mySerial = serial.Serial(port=self.options.serialPort, baudrate=self.options.serialBaudRate, timeout=0.1, writeTimeout=10, dsrdtr=True, rtscts=True)
- else:
- mySerial = serial.Serial(port=self.options.serialPort, baudrate=self.options.serialBaudRate, timeout=0.1, writeTimeout=10)
+ mySerial.xonxoff = True
+ if self.options.flowControl == 'rtscts' or self.options.flowControl == 'dsrdtrrtscts':
+ mySerial.rtscts = True
+ if self.options.flowControl == 'dsrdtrrtscts':
+ mySerial.dsrdtr = True
try:
- mySerial.write(self.hpgl)
+ mySerial.open()
except Exception as inst:
- if inst.args[0] == 'Write timeout':
- inkex.errormsg(_("Could not send data. Please check that your plotter is running, connected and the settings are correct."))
+ if 'ould not open port' in inst.args[0]:
+ inkex.errormsg(_("Could not open port. Please check that your plotter is running, connected and the settings are correct."))
+ return
else:
type, value, traceback = sys.exc_info()
- raise ValueError, ("", type, value), traceback
- # Read back 2 chars to avoid plotter not plotting last command (I have no idea why this is necessary)
- mySerial.read(2)
+ raise ValueError, ('', type, value), traceback
+ mySerial.write(self.hpgl)
mySerial.close()
if __name__ == '__main__':
- # Raise recursion limit to avoid exceptions on big documents
+ # raise recursion limit to avoid exceptions on big documents
sys.setrecursionlimit(20000)
# start extension
e = MyEffect()