summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlvin Penner <penner@vaxxine.com>2013-03-04 20:10:22 +0000
committerapenner <penner@vaxxine.com>2013-03-04 20:10:22 +0000
commit853690e63d5d065d46f863fae99b2d8137be2817 (patch)
tree9127cd47d012f595ff473889cb7f94daac7bb202
parentDrop dead Inkboard code. Config flag no longer exists (diff)
downloadinkscape-853690e63d5d065d46f863fae99b2d8137be2817.tar.gz
inkscape-853690e63d5d065d46f863fae99b2d8137be2817.zip
extensions. hpgl output. further patch by TimeWaster (Bug 1118663)
Fixed bugs: - https://launchpad.net/bugs/1118663 (bzr r12174)
-rw-r--r--share/extensions/hpgl_output.inx6
-rwxr-xr-xshare/extensions/hpgl_output.py51
2 files changed, 41 insertions, 16 deletions
diff --git a/share/extensions/hpgl_output.inx b/share/extensions/hpgl_output.inx
index 281de27cc..b54276911 100644
--- a/share/extensions/hpgl_output.inx
+++ b/share/extensions/hpgl_output.inx
@@ -9,14 +9,14 @@
<param name="horizontal_guide" type="description">—————————————————————————————</param>
<param name="resolution" type="int" min="90" max="2048" _gui-text="Resolution (dpi)" _gui-description="The amount of steps the cutter moves if it moves for 1 inch, either get this value from your plotter manual or learn it by trial and error (Standard: '1016')">1016</param>
<param name="pen" type="int" min="1" 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="angle" type="optiongroup" appearance="minimal" _gui-text="Orientation" _gui-description="Orientation of the plot, change this if your plotter is plotting horizontal instead of vertical (Standard: '-90°')">
+ <param name="angle" type="optiongroup" appearance="minimal" _gui-text="Orientation" _gui-description="Orientation of the plot, change this if your plotter is plotting horizontal instead of vertical (Standard: '90°')">
+ <option value="90">90°</option>
<option value="-90">-90°</option>
<option value="0">0°</option>
- <option value="90">90°</option>
<option value="180">180°</option>
</param>
<param name="mirror" type="boolean" _gui-text="Mirror Y-axis" _gui-description="Whether to mirror the Y axis. Some plotters need this, some not. Look in your plotter manual or learn it by trial and error (Standard: 'False')">false</param>
- <param name="flat" type="float" min="0.05" max="10.0" precision="2" _gui-text="Curve flatness (mm)" _gui-description="Curves get divided into lines, this is the approximate length of one line in mm (Standard: '0.50')">0.50</param>
+ <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 (Standard: '1.2')">1.2</param>
<param name="horizontal_guide" type="description">—————————————————————————————</param>
<param name="useOvercut" type="boolean" _gui-text="Use Overcut" _gui-description="Whether the overcut will be used, if not the 'Overcut' parameter is unused (Standard: 'True')">true</param>
<param name="overcut" type="float" min="0.0" max="100.0" precision="2" _gui-text="Overcut (mm)" _gui-description="The distance in mm that will be cut over the starting point of the path to prevent open paths (Standard: '1.00')">1.00</param>
diff --git a/share/extensions/hpgl_output.py b/share/extensions/hpgl_output.py
index e8333ac22..38d95ac09 100755
--- a/share/extensions/hpgl_output.py
+++ b/share/extensions/hpgl_output.py
@@ -18,14 +18,14 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
'''
-import inkex, simpletransform, cubicsuperpath, simplestyle, cspsubdiv, sys, math
+import inkex, simpletransform, cubicsuperpath, simplestyle, sys, math, bezmisc, string, cspsubdiv
class MyEffect(inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
self.OptionParser.add_option("-f", "--flatness",
action="store", type="float",
- dest="flat", default=0.5,
+ dest="flat", default=1.2,
help="Minimum flatness of the subdivided curves")
self.OptionParser.add_option("-m", "--mirror",
action="store", type="inkbool",
@@ -73,7 +73,7 @@ class MyEffect(inkex.Effect):
help="Return Factor")
self.OptionParser.add_option("-a", "--angle",
action="store", type="string",
- dest="rotation", default="-90",
+ dest="rotation", default="90",
help="Orientation")
self.OptionParser.add_option("-s", "--sendToPlotter",
action="store", type="inkbool",
@@ -90,26 +90,38 @@ class MyEffect(inkex.Effect):
def effect(self):
# initiate vars
- self.vData = [['', -1.0, -1.0], ['', -1.0, -1.0], ['', -1.0, -1.0], ['', -1.0, -1.0]]
self.xDivergence = 999999999999.0
self.yDivergence = 999999999999.0
scale = float(self.options.resolution) / 90 # dots/inch to dots/pixels
x0 = self.options.xOffset * 3.5433070866 * scale # mm to dots
y0 = self.options.yOffset * 3.5433070866 * scale # mm to dots
- self.options.flat *= 3.5433070866 # mm to pixels
self.options.overcut = self.options.overcut * 3.5433070866 * scale # mm to dots
self.options.toolOffset = self.options.toolOffset * 3.5433070866 * scale # mm to dots
+ self.options.flat = float(self.options.resolution) * self.options.flat / 1000
doc = self.document.getroot()
mirror = 1.0
if self.options.mirror:
mirror = -1.0
+ # get viewBox parameter to correct scaling
+ viewBox = doc.get('viewBox')
+ viewBoxTransformX = 1
+ viewBoxTransformY = 1
+ if viewBox:
+ viewBox = string.split(viewBox, ' ')
+ if viewBox[2] and viewBox[3]:
+ viewBoxTransformX = float(inkex.unittouu(doc.get('width'))) / float(viewBox[2])
+ viewBoxTransformY = float(inkex.unittouu(doc.get('height'))) / float(viewBox[3])
# dryRun to find edges
self.dryRun = True
- self.groupmat = [[[scale, 0.0, 0.0], [0.0, mirror*scale, 0.0]]]
+ self.groupmat = [[[scale*viewBoxTransformX, 0.0, 0.0], [0.0, mirror*scale*viewBoxTransformY, 0.0]]]
+ self.groupmat[0] = simpletransform.composeTransform(self.groupmat[0], simpletransform.parseTransform('rotate(' + self.options.rotation + ')'))
+ self.vData = [['', -1.0, -1.0], ['', -1.0, -1.0], ['', -1.0, -1.0], ['', -1.0, -1.0]]
self.process_group(doc)
# life run
self.dryRun = False
- self.groupmat = [[[scale, 0.0, -self.xDivergence + x0], [0.0, mirror*scale, -self.yDivergence + y0]]]
+ self.groupmat = [[[scale*viewBoxTransformX, 0.0, -self.xDivergence + x0], [0.0, mirror*scale*viewBoxTransformY, -self.yDivergence + y0]]]
+ self.groupmat[0] = simpletransform.composeTransform(self.groupmat[0], simpletransform.parseTransform('rotate(' + self.options.rotation + ')'))
+ self.vData = [['', -1.0, -1.0], ['', -1.0, -1.0], ['', -1.0, -1.0], ['', -1.0, -1.0]]
self.hpgl = 'IN;SP%d;' % self.options.pen
if self.options.sendToPlotter:
try:
@@ -134,7 +146,7 @@ class MyEffect(inkex.Effect):
if style:
style = simplestyle.parseStyle(style)
if style.has_key('display'):
- if style['display']=='none':
+ if style['display'] == 'none':
if not self.options.plotInvisibleLayers:
return
trans = group.get('transform')
@@ -157,7 +169,6 @@ class MyEffect(inkex.Effect):
trans = node.get('transform')
if trans:
mat = simpletransform.composeTransform(mat, simpletransform.parseTransform(trans))
- mat = simpletransform.composeTransform(mat, simpletransform.parseTransform('rotate(' + self.options.rotation + ')'))
simpletransform.applyTransformToPath(mat, p)
cspsubdiv.cspsubdiv(p, self.options.flat)
# break path into HPGL commands
@@ -191,6 +202,14 @@ class MyEffect(inkex.Effect):
if abs: return math.fabs(math.sqrt((x2 - x1) ** 2.0 + (y2 - y1) ** 2.0))
else: return math.sqrt((x2 - x1) ** 2.0 + (y2 - y1) ** 2.0)
+ def getAlpha(self, x1, y1, x2, y2, x3, y3):
+ temp1 = (x1-x2)**2 + (y1-y2)**2 + (x3-x2)**2 + (y3-y2)**2 - (x1-x3)**2 - (y1-y3)**2
+ temp2 = 2 * math.sqrt((x1-x2)**2 + (y1-y2)**2) * math.sqrt((x3-x2)**2 + (y3-y2)**2)
+ temp3 = temp1 / temp2
+ if temp3 < -1:
+ temp3 = -1
+ return math.acos(temp3)
+
def calcOffset(self, cmd, xPos, yPos):
# calculate offset correction (or dont))
if not self.options.correctToolOffset:
@@ -200,16 +219,22 @@ class MyEffect(inkex.Effect):
self.vData.insert(3, [cmd, xPos, yPos])
if self.vData[2][1] != -1.0:
if self.vData[1][1] != -1.0:
+ if self.vData[2][0] == 'PD' and self.vData[3][0] == 'PD':
+ if self.getAlpha(self.vData[1][1], self.vData[1][2], self.vData[2][1], self.vData[2][2], self.vData[3][1], self.vData[3][2]) > 2.748893:
+ self.storeData(self.vData[2][0], self.vData[2][1], self.vData[2][2])
+ return
if self.vData[2][0] == 'PD':
self.storeData('PD',
self.changeLengthX(self.vData[1][1], self.vData[1][2], self.vData[2][1], self.vData[2][2], self.options.toolOffset),
self.changeLengthY(self.vData[1][1], self.vData[1][2], self.vData[2][1], self.vData[2][2], self.options.toolOffset))
elif self.vData[0][1] != -1.0:
- xTemp = self.vData[1][1] - self.changeLengthX(self.vData[0][1], self.vData[0][2], self.vData[1][1], self.vData[1][2], self.options.toolOffset)
- yTemp = self.vData[1][2] - self.changeLengthY(self.vData[0][1], self.vData[0][2], self.vData[1][1], self.vData[1][2], self.options.toolOffset)
- self.storeData('PU', self.vData[2][1] - xTemp, self.vData[2][2] - yTemp)
+ self.storeData('PU',
+ self.vData[2][1] - (self.vData[1][1] - self.changeLengthX(self.vData[0][1], self.vData[0][2], self.vData[1][1], self.vData[1][2], self.options.toolOffset)),
+ self.vData[2][2] - (self.vData[1][2] - self.changeLengthY(self.vData[0][1], self.vData[0][2], self.vData[1][1], self.vData[1][2], self.options.toolOffset)))
else:
- self.storeData('PU', self.vData[2][1], self.vData[2][2])
+ self.storeData('PU',
+ self.vData[2][1],
+ self.vData[2][2])
if self.vData[3][0] == 'PD':
self.storeData('PD',
self.changeLengthX(self.vData[3][1], self.vData[3][2], self.vData[2][1], self.vData[2][2], -(self.options.toolOffset * self.options.toolOffsetReturn)),