From 926415fa1f9ea69f18df89a1f2a039ad7dbd3e58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20W=C3=BCst?= Date: Sun, 2 Feb 2014 19:00:38 +0100 Subject: added parameter to switch off auto alignment for engraving machines (bzr r12994) --- share/extensions/hpgl_encoder.py | 51 +++++++++++++++++++++++++++++++--------- share/extensions/hpgl_input.inx | 4 ++-- share/extensions/hpgl_output.inx | 19 +++++++-------- share/extensions/hpgl_output.py | 1 + share/extensions/plotter.inx | 22 ++++++++--------- share/extensions/plotter.py | 10 ++++---- 6 files changed, 69 insertions(+), 38 deletions(-) diff --git a/share/extensions/hpgl_encoder.py b/share/extensions/hpgl_encoder.py index 98993cd79..2304ce261 100644 --- a/share/extensions/hpgl_encoder.py +++ b/share/extensions/hpgl_encoder.py @@ -61,15 +61,18 @@ class hpglEncoder: "precut":bool "offsetX":float "offsetY":float + "autoAlign":bool "debug":bool ''' - self.doc = effect.document.getroot() self.options = effect.options + self.doc = effect.document.getroot() self.documentUnit = self.doc.xpath('//sodipodi:namedview/@inkscape:document-units', namespaces=inkex.NSS) if self.documentUnit: self.documentUnit = self.documentUnit[0] else: self.documentUnit = 'px' + self.docWidth = self.unitToUserUnit(self.doc.get('width'), True) + self.docHeight = self.unitToUserUnit(self.doc.get('height'), True) self.divergenceX = 'False' self.divergenceY = 'False' self.sizeX = 'False' @@ -93,13 +96,12 @@ class hpglEncoder: self.mirrorY = 1.0 if self.options.debug: self.debugValues = [0, 0, 0, 0, 0, 0, 0, 0] + self.debugValues[0] = self.docWidth + self.debugValues[1] = self.docHeight # process viewBox attribute to correct page scaling - viewBox = self.doc.get('viewBox') self.viewBoxTransformX = 1 self.viewBoxTransformY = 1 - if self.options.debug: - self.debugValues[0] = self.unitToUserUnit(self.doc.get('width'), True) - self.debugValues[1] = self.unitToUserUnit(self.doc.get('height'), True) + viewBox = self.doc.get('viewBox') if viewBox: viewBox = string.split(viewBox, ' ') if viewBox[2] and viewBox[3]: @@ -108,8 +110,8 @@ class hpglEncoder: if self.options.debug: self.debugValues[2] = self.unitToUserUnit(viewBox[0]) self.debugValues[3] = self.unitToUserUnit(viewBox[1]) - self.viewBoxTransformX = self.unitToUserUnit(self.doc.get('width'), True) / self.unitToUserUnit(viewBox[0]) - self.viewBoxTransformY = self.unitToUserUnit(self.doc.get('height'), True) / self.unitToUserUnit(viewBox[1]) + self.viewBoxTransformX = self.docWidth / self.unitToUserUnit(viewBox[0]) + self.viewBoxTransformY = self.docHeight / self.unitToUserUnit(viewBox[1]) def getHpgl(self): # dryRun to find edges @@ -126,12 +128,39 @@ class hpglEncoder: self.debugValues[5] = self.sizeY - self.divergenceY self.debugValues[6] = self.unitToUserUnit(str(self.debugValues[4] / self.scaleX)) self.debugValues[7] = self.unitToUserUnit(str(self.debugValues[5] / self.scaleY)) - if self.options.center: - self.divergenceX += (self.sizeX - self.divergenceX) / 2 - self.divergenceY += (self.sizeY - self.divergenceY) / 2 - elif self.options.useToolOffset: + # move drawing according to various modifiers + if self.options.autoAlign: + if self.options.center: + self.divergenceX += (self.sizeX - self.divergenceX) / 2 + self.divergenceY += (self.sizeY - self.divergenceY) / 2 + else: + self.divergenceX = 0.0 + self.divergenceY = 0.0 + if self.options.center: + if self.options.orientation == '0': + self.offsetX -= (self.docWidth * self.scaleX) / 2 + self.offsetY += (self.docHeight * self.scaleY) / 2 + if self.options.orientation == '90': + self.offsetY += (self.docWidth * self.scaleX) / 2 + self.offsetX += (self.docHeight * self.scaleY) / 2 + if self.options.orientation == '180': + self.offsetX += (self.docWidth * self.scaleX) / 2 + self.offsetY -= (self.docHeight * self.scaleY) / 2 + if self.options.orientation == '270': + self.offsetY -= (self.docWidth * self.scaleX) / 2 + self.offsetX -= (self.docHeight * self.scaleY) / 2 + else: + if self.options.orientation == '0': + self.offsetY += self.docHeight * self.scaleY + if self.options.orientation == '90': + self.offsetY += self.docWidth * self.scaleX + self.offsetX += self.docHeight * self.scaleY + if self.options.orientation == '180': + self.offsetX += self.docWidth * self.scaleX + if not self.options.center and self.options.useToolOffset: self.offsetX += self.toolOffset self.offsetY += self.toolOffset + # initialize transformation matrix and cache groupmat = [[self.mirrorX * self.scaleX * self.viewBoxTransformX, 0.0, - self.divergenceX + self.offsetX], [0.0, self.mirrorY * self.scaleY * self.viewBoxTransformY, - self.divergenceY + self.offsetY]] groupmat = simpletransform.composeTransform(groupmat, simpletransform.parseTransform('rotate(' + self.options.orientation + ')')) diff --git a/share/extensions/hpgl_input.inx b/share/extensions/hpgl_input.inx index aba7a9308..f40fd4ec0 100644 --- a/share/extensions/hpgl_input.inx +++ b/share/extensions/hpgl_input.inx @@ -7,8 +7,8 @@ inkex.py <_param name="introduction" type="description">Please note that you can only open HPGL files written by Inkscape, to open other HPGL files please change their file extension to .plt, make sure you have UniConverter installed and open them again.   - 1016.0 - 1016.0 + 1016.0 + 1016.0 false .hpgl diff --git a/share/extensions/hpgl_output.inx b/share/extensions/hpgl_output.inx index a8ce7c7e0..bb0809386 100644 --- a/share/extensions/hpgl_output.inx +++ b/share/extensions/hpgl_output.inx @@ -6,15 +6,15 @@ hpgl_output.py hpgl_encoder.py inkex.py - <_param name="introduction" type="description">Please make sure that all objects you want to save are converted to paths. The drawing will be automatically aligned to the zero point. Please use the plotter extension (Extensions menu) to plot directly on a plotter. + <_param name="introduction" type="description">Please make sure that all objects you want to save are converted to paths. Please use the plotter extension (Extensions menu) to plot directly over a serial connection. - 1016.0 - 1016.0 + 1016.0 + 1016.0 1 0 - 0 - + 0 + @@ -30,14 +30,13 @@   true 0.25 - true -   - <_param name="offsetNote" type="description">Please note that using the tool offset correction will move your plot away from the zero point by one tool offset length. + true 1.2 - 0.00 - 0.00 + 0.00 + 0.00 + true <_param name="settingsHelp" type="description">All these settings depend on the plotter you use, for more information please consult the manual or homepage for your plotter. diff --git a/share/extensions/hpgl_output.py b/share/extensions/hpgl_output.py index d6f6b8eec..02157eb95 100755 --- a/share/extensions/hpgl_output.py +++ b/share/extensions/hpgl_output.py @@ -49,6 +49,7 @@ class MyEffect(inkex.Effect): 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('--autoAlign', action='store', type='inkbool', dest='autoAlign', default='TRUE', help='Auto align') def effect(self): self.options.debug = False diff --git a/share/extensions/plotter.inx b/share/extensions/plotter.inx index 673922d2e..e30d61418 100644 --- a/share/extensions/plotter.inx +++ b/share/extensions/plotter.inx @@ -6,7 +6,7 @@ hpgl_decoder.py hpgl_encoder.py inkex.py - <_param name="introduction" type="description">Please make sure that all objects you want to plot are converted to paths. The plot will automatically be aligned to the zero point. + <_param name="introduction" type="description">Please make sure that all objects you want to plot are converted to paths. COM1 @@ -39,17 +39,17 @@   - <_param name="freezeHelp" type="description">Using wrong settings can under certain circumstances cause Inkscape to freeze. Always save your work before plotting. + <_param name="freezeHelp" type="description">Using wrong settings can under certain circumstances cause Inkscape to freeze. Always save your work before plotting! <_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">Parallel (LPT) connections are not supported. - 1016.0 - 1016.0 + 1016.0 + 1016.0 1 0 - 0 - + 0 + @@ -65,14 +65,14 @@   true 0.25 - true -   - <_param name="offsetNote" type="description">Please note that using the tool offset correction will move your plot away from the zero point by one tool offset length. + true 1.2 - 0.00 - 0.00 + 0.00 + 0.00 + true +   false diff --git a/share/extensions/plotter.py b/share/extensions/plotter.py index 394f83786..84027b132 100644 --- a/share/extensions/plotter.py +++ b/share/extensions/plotter.py @@ -36,6 +36,10 @@ 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('--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') 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') @@ -53,10 +57,7 @@ class MyEffect(inkex.Effect): 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') + self.OptionParser.add_option('--autoAlign', action='store', type='inkbool', dest='autoAlign', default='TRUE', help='Auto align') self.OptionParser.add_option('--debug', action='store', type='inkbool', dest='debug', default='FALSE', help='Show debug information') def effect(self): @@ -181,6 +182,7 @@ class MyEffect(inkex.Effect): inkex.errormsg(' Curve flatness: ' + str(self.options.flat)) inkex.errormsg(' X offset (mm): ' + str(self.options.offsetX)) inkex.errormsg(' Y offset (mm): ' + str(self.options.offsetY)) + inkex.errormsg(' Auto align: ' + str(self.options.autoAlign)) inkex.errormsg(' Show debug information: ' + str(self.options.debug)) inkex.errormsg("\nDocument properties:\n") version = self.document.getroot().xpath('//@inkscape:version', namespaces=inkex.NSS) -- cgit v1.2.3