diff options
| author | Sebastian Wüst <sebi@timewaster.de> | 2014-02-02 18:00:38 +0000 |
|---|---|---|
| committer | Sebastian Wüst <sebi@timewaster.de> | 2014-02-02 18:00:38 +0000 |
| commit | 926415fa1f9ea69f18df89a1f2a039ad7dbd3e58 (patch) | |
| tree | d18ad5c19dedb295480002eb5f123f3326c46296 | |
| parent | remove vertical offset when stretching a horizontal line (Bug 1275077) (diff) | |
| download | inkscape-926415fa1f9ea69f18df89a1f2a039ad7dbd3e58.tar.gz inkscape-926415fa1f9ea69f18df89a1f2a039ad7dbd3e58.zip | |
added parameter to switch off auto alignment for engraving machines
(bzr r12994)
| -rw-r--r-- | share/extensions/hpgl_encoder.py | 51 | ||||
| -rw-r--r-- | share/extensions/hpgl_input.inx | 4 | ||||
| -rw-r--r-- | share/extensions/hpgl_output.inx | 19 | ||||
| -rwxr-xr-x | share/extensions/hpgl_output.py | 1 | ||||
| -rw-r--r-- | share/extensions/plotter.inx | 22 | ||||
| -rw-r--r-- | 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 @@ <dependency type="executable" location="extensions">inkex.py</dependency> <_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.</_param> <param name="space" type="description"> </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 in one inch on the X axis. (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 in one inch on the Y axis. (Default: 1016.0)">1016.0</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 plotter moves if it moves for 1 inch on the X axis. (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 plotter moves if it moves for 1 inch on the Y axis. (Default: 1016.0)">1016.0</param> <param name="showMovements" type="boolean" _gui-text="Show movements between paths" _gui-description="Check this to show movements between paths. (Default: Unchecked)">false</param> <input> <extension>.hpgl</extension> 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 @@ <dependency type="executable" location="extensions">hpgl_output.py</dependency> <dependency type="executable" location="extensions">hpgl_encoder.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency> - <_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> + <_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.</_param> <param name="tab" type="notebook"> <page name="plotter" _gui-text="Plotter Settings"> - <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. (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. (Default: 1016.0)">1016.0</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 plotter moves if it moves for 1 inch on the X axis. (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 plotter moves if it moves for 1 inch on the Y axis. (Default: 1016.0)">1016.0</param> <param name="pen" type="int" min="0" max="99" _gui-text="Pen number" _gui-description="The number of the pen (tool) to use. (Standard: '1')">1</param> <param name="force" type="int" min="0" max="1000" _gui-text="Pen force (g)" _gui-description="The amount of force pushing down the pen in grams, set to 0 to omit command. Most plotters ignore this command. (Default: 0)">0</param> - <param name="speed" type="int" min="0" max="10000" _gui-text="Pen speed (cm/s or mm/s)" _gui-description="The speed the pen will move with in centimeters or millimeters per second (dependent on your plotter model), set to 0 to omit command. Most plotters ignore this command. (Default: 0)">0</param> - <param name="orientation" type="optiongroup" appearance="minimal" _gui-text="Rotation (Clockwise)" _gui-description="Rotation of the plot. (Default: 0°)"> + <param name="speed" type="int" min="0" max="10000" _gui-text="Pen speed (cm/s or mm/s)" _gui-description="The speed the pen will move with in centimeters or millimeters per second (depending on your plotter model), set to 0 to omit command. Most plotters ignore this command. (Default: 0)">0</param> + <param name="orientation" type="optiongroup" appearance="minimal" _gui-text="Rotation (Clockwise)" _gui-description="Rotation of the drawing. (Default: 0°)"> <option value="0">0°</option> <option value="90">90°</option> <option value="180">180°</option> @@ -30,14 +30,13 @@ <param name="space" type="description"> </param> <param name="useToolOffset" type="boolean" _gui-text="Use tool offset correction" _gui-description="Check this to use the tool offset correction, if not checked the 'Tool offset' and 'Precut' parameters are unused. (Default: Checked)">true</param> <param name="toolOffset" type="float" min="0.0" max="20.0" precision="2" _gui-text="Tool offset (mm)" _gui-description="The offset from the tool tip to the tool axis in mm. (Default: 0.25)">0.25</param> - <param name="precut" type="boolean" _gui-text="Use precut" _gui-description="Check this to plot a small line before the real plot to align the tool orientation for the first real plot. (Default: Checked)">true</param> - <param name="space" type="description"> </param> - <_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.</_param> + <param name="precut" type="boolean" _gui-text="Use precut" _gui-description="Check this to cut a small line before the real drawing starts to correctly align the tool orientation. (Default: Checked)">true</param> </page> <page name="misc" _gui-text="Miscellaneous"> <param name="flat" type="float" min="0.1" max="10.0" precision="1" _gui-text="Curve flatness" _gui-description="Curves are divided into lines, this number controls how fine the curves will be reproduced, the smaller the finer. (Default: '1.2')">1.2</param> - <param name="offsetX" type="float" min="-10000.0" max="10000.0" precision="2" _gui-text="X offset (mm)" _gui-description="The offset to move your plot away from the zero point on the X axis in mm. (Default: '0.00')">0.00</param> - <param name="offsetY" type="float" min="-10000.0" max="10000.0" precision="2" _gui-text="Y offset (mm)" _gui-description="The offset to move your plot away from the zero point on the Y axis in mm. (Default: '0.00')">0.00</param> + <param name="offsetX" type="float" min="-10000.0" max="10000.0" precision="2" _gui-text="X offset (mm)" _gui-description="Shifts your drawing on the X axis in mm. (Default: '0.00')">0.00</param> + <param name="offsetY" type="float" min="-10000.0" max="10000.0" precision="2" _gui-text="Y offset (mm)" _gui-description="Shifts your drawing on the Y axis in mm. (Default: '0.00')">0.00</param> + <param name="autoAlign" type="boolean" _gui-text="Auto align" _gui-description="Check this to auto align the drawing to the zero point (Plus the tool offset if used). If unchecked you have to make sure that all parts of your drawing are within the document border! (Default: Checked)">true</param> </page> </param> <_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.</_param> 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 @@ <dependency type="executable" location="extensions">hpgl_decoder.py</dependency> <dependency type="executable" location="extensions">hpgl_encoder.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency> - <_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> + <_param name="introduction" type="description">Please make sure that all objects you want to plot are converted to paths.</_param> <param name="tab" type="notebook"> <page name="misc" _gui-text="Connection"> <param name="serialPort" type="string" _gui-text="Serial port" _gui-description="The port of your serial connection, on Windows something like 'COM1', on Linux something like: '/dev/ttyUSB0'. (Default: COM1)">COM1</param> @@ -39,17 +39,17 @@ <option value="ZING">KNK Zing (HPGL variant)</option> </param> <param name="space" type="description"> </param> - <_param name="freezeHelp" type="description">Using wrong settings can under certain circumstances cause Inkscape to freeze. Always save your work before plotting.</_param> + <_param name="freezeHelp" type="description">Using wrong settings can under certain circumstances cause Inkscape to freeze. Always save your work before plotting!</_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> <_param name="parallelHelp" type="description">Parallel (LPT) connections are not supported.</_param> </page> <page name="plotter" _gui-text="Plotter Settings"> - <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. (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. (Default: 1016.0)">1016.0</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 plotter moves if it moves for 1 inch on the X axis. (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 plotter moves if it moves for 1 inch on the Y axis. (Default: 1016.0)">1016.0</param> <param name="pen" type="int" min="0" max="99" _gui-text="Pen number" _gui-description="The number of the pen (tool) to use. (Standard: '1')">1</param> <param name="force" type="int" min="0" max="1000" _gui-text="Pen force (g)" _gui-description="The amount of force pushing down the pen in grams, set to 0 to omit command. Most plotters ignore this command. (Default: 0)">0</param> - <param name="speed" type="int" min="0" max="10000" _gui-text="Pen speed (cm/s or mm/s)" _gui-description="The speed the pen will move with in centimeters or millimeters per second (dependent on your plotter model), set to 0 to omit command. Most plotters ignore this command. (Default: 0)">0</param> - <param name="orientation" type="optiongroup" appearance="minimal" _gui-text="Rotation (Clockwise)" _gui-description="Rotation of the plot. (Default: 0°)"> + <param name="speed" type="int" min="0" max="10000" _gui-text="Pen speed (cm/s or mm/s)" _gui-description="The speed the pen will move with in centimeters or millimeters per second (depending on your plotter model), set to 0 to omit command. Most plotters ignore this command. (Default: 0)">0</param> + <param name="orientation" type="optiongroup" appearance="minimal" _gui-text="Rotation (Clockwise)" _gui-description="Rotation of the drawing. (Default: 0°)"> <option value="0">0°</option> <option value="90">90°</option> <option value="180">180°</option> @@ -65,14 +65,14 @@ <param name="space" type="description"> </param> <param name="useToolOffset" type="boolean" _gui-text="Use tool offset correction" _gui-description="Check this to use the tool offset correction, if not checked the 'Tool offset' and 'Precut' parameters are unused. (Default: Checked)">true</param> <param name="toolOffset" type="float" min="0.0" max="20.0" precision="2" _gui-text="Tool offset (mm)" _gui-description="The offset from the tool tip to the tool axis in mm. (Default: 0.25)">0.25</param> - <param name="precut" type="boolean" _gui-text="Use precut" _gui-description="Check this to plot a small line before the real plot to align the tool orientation for the first real plot. (Default: Checked)">true</param> - <param name="space" type="description"> </param> - <_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.</_param> + <param name="precut" type="boolean" _gui-text="Use precut" _gui-description="Check this to cut a small line before the real drawing starts to correctly align the tool orientation. (Default: Checked)">true</param> </page> <page name="misc" _gui-text="Miscellaneous"> <param name="flat" type="float" min="0.1" max="10.0" precision="1" _gui-text="Curve flatness" _gui-description="Curves are divided into lines, this number controls how fine the curves will be reproduced, the smaller the finer. (Default: '1.2')">1.2</param> - <param name="offsetX" type="float" min="-10000.0" max="10000.0" precision="2" _gui-text="X offset (mm)" _gui-description="The offset to move your plot away from the zero point on the X axis in mm. (Default: '0.00')">0.00</param> - <param name="offsetY" type="float" min="-10000.0" max="10000.0" precision="2" _gui-text="Y offset (mm)" _gui-description="The offset to move your plot away from the zero point on the Y axis in mm. (Default: '0.00')">0.00</param> + <param name="offsetX" type="float" min="-10000.0" max="10000.0" precision="2" _gui-text="X offset (mm)" _gui-description="Shifts your drawing on the X axis in mm. (Default: '0.00')">0.00</param> + <param name="offsetY" type="float" min="-10000.0" max="10000.0" precision="2" _gui-text="Y offset (mm)" _gui-description="Shifts your drawing on the Y axis in mm. (Default: '0.00')">0.00</param> + <param name="autoAlign" type="boolean" _gui-text="Auto align" _gui-description="Check this to auto align the drawing to the zero point (Plus the tool offset if used). If unchecked you have to make sure that all parts of your drawing are within the document border! (Default: Checked)">true</param> + <param name="space" type="description"> </param> <param name="debug" type="boolean" _gui-text="Show debug information" _gui-description="Check this to get verbose information about the plot without actually sending something to the plotter (A.k.a. data dump). (Default: Unchecked)">false</param> </page> </param> 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) |
