From 52309907643a585c3765551c04d2da20cbd467a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20W=C3=BCst?= Date: Thu, 14 Nov 2013 18:54:59 +0100 Subject: small optimizations (bzr r12815) --- share/extensions/hpgl_encoder.py | 9 ++++----- share/extensions/plotter.inx | 3 ++- share/extensions/plotter.py | 20 +++++++------------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/share/extensions/hpgl_encoder.py b/share/extensions/hpgl_encoder.py index 3a0523391..b4191e7c0 100644 --- a/share/extensions/hpgl_encoder.py +++ b/share/extensions/hpgl_encoder.py @@ -166,21 +166,20 @@ class hpglEncoder: simpletransform.applyTransformToPath(mat, paths) cspsubdiv.cspsubdiv(paths, self.options.flat) # path to HPGL commands - oldPosX = '' - oldPosY = '' + oldPosX = 0.0 + oldPosY = 0.0 # TODO: Plot smallest parts first to avid plotter dragging parts of foil around (on text) for singlePath in paths: cmd = 'PU' for singlePathPoint in singlePath: posX, posY = singlePathPoint[1] # check if point is repeating, if so, ignore - if posX != oldPosX or posY != oldPosY: + if int(round(posX)) != int(round(oldPosX)) or int(round(posY)) != int(round(oldPosY)): self.processOffset(cmd, posX, posY) cmd = 'PD' oldPosX = posX oldPosY = posY # perform overcut - # TODO: Find that evasive bug that produces an extra point between the end of the path and the overcut if self.options.useOvercut and not self.dryRun: # check if last and first points are the same, otherwise the path is not closed and no overcut can be performed if int(round(oldPosX)) == int(round(singlePath[0][1][0])) and int(round(oldPosY)) == int(round(singlePath[0][1][1])): @@ -188,7 +187,7 @@ class hpglEncoder: for singlePathPoint in singlePath: posX, posY = singlePathPoint[1] # check if point is repeating, if so, ignore - if posX != oldPosX or posY != oldPosY: + if int(round(posX)) != int(round(oldPosX)) or int(round(posY)) != int(round(oldPosY)): overcutLength += self.getLength(oldPosX, oldPosY, posX, posY) if overcutLength >= self.options.overcut: newLength = self.changeLength(oldPosX, oldPosY, posX, posY, - (overcutLength - self.options.overcut)) diff --git a/share/extensions/plotter.inx b/share/extensions/plotter.inx index f33e3088b..7cc9f1c94 100644 --- a/share/extensions/plotter.inx +++ b/share/extensions/plotter.inx @@ -39,7 +39,8 @@   <_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 name="parallelHelp" type="description">Please note that Parallel (LPT) connections are not supported. + <_param name="freezeHelp" type="description">Using wrong settings can under certain circumstances cause Inkscape to freeze. Always save your work before plotting. + <_param name="parallelHelp" type="description">Parallel (LPT) connections are not supported. 1 diff --git a/share/extensions/plotter.py b/share/extensions/plotter.py index 427e9401b..f57057435 100644 --- a/share/extensions/plotter.py +++ b/share/extensions/plotter.py @@ -82,20 +82,12 @@ class MyEffect(inkex.Effect): ''' # reparse data for preview self.options.showMovements = True - self.options.docWidth = float(inkex.unittouu(self.document.getroot().get('width'))) - self.options.docHeight = float(inkex.unittouu(self.document.getroot().get('height'))) + self.options.docWidth = float(self.unittouu(self.document.getroot().get('width'))) + self.options.docHeight = float(self.unittouu(self.document.getroot().get('height'))) myHpglDecoder = hpgl_decoder.hpglDecoder(self.hpgl, self.options) - try: - doc, warnings = myHpglDecoder.getSvg() - # deliver document to inkscape - self.document = doc - except Exception as inst: - if inst.args[0] == 'NO_HPGL_DATA': - # do nothing - pass - else: - type, value, traceback = sys.exc_info() - raise ValueError, ('', type, value), traceback + doc, warnings = myHpglDecoder.getSvg() + # deliver document to inkscape + self.document = doc ''' if self.options.commandLanguage == 'dmpl': # convert HPGL to DMPL @@ -108,6 +100,7 @@ class MyEffect(inkex.Effect): mySerial = serial.Serial() mySerial.port = self.options.serialPort mySerial.baudrate = self.options.serialBaudRate + mySerial.timeout = 0.1 if self.options.flowControl == 'xonxoff': mySerial.xonxoff = True if self.options.flowControl == 'rtscts' or self.options.flowControl == 'dsrdtrrtscts': @@ -124,6 +117,7 @@ class MyEffect(inkex.Effect): type, value, traceback = sys.exc_info() raise ValueError, ('', type, value), traceback mySerial.write(self.hpgl) + mySerial.read(2) mySerial.close() if __name__ == '__main__': -- cgit v1.2.3