index bd7e918227aa692d58f6a6d493449a9997cb7b0b..d146a8c7739bcf0f543384546e0ad83ab3a29357 100755 (executable)
Copyright (C) 2008 Alvin Penner, penner@vaxxine.com
- template dxf_outlines.dxf added Feb 2008 by Alvin Penner
-- ROBO-Master output option added Aug 2008 by Alvin Penner
-- ROBO-Master multispline output added Sept 2008 by Alvin Penner
+- ROBO-Master output option added Aug 2008
+- ROBO-Master multispline output added Sept 2008
+- LWPOLYLINE output modification added Dec 2008
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
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, simplepath, cubicsuperpath, dxf_templates, math
+import inkex, simplepath, simplestyle, cubicsuperpath, coloreffect, dxf_templates, math
+import gettext
+_ = gettext.gettext
try:
from numpy import *
from numpy.linalg import solve
except:
- inkex.errormsg("Failed to import the numpy or numpy.linalg modules. These modules are required by this extension. Please install them and try again.")
+ inkex.errormsg(_("Failed to import the numpy or numpy.linalg modules. These modules are required by this extension. Please install them and try again."))
inkex.sys.exit()
def pointdistance((x1,y1),(x2,y2)):
self.handle = 255 # handle for DXF ENTITY
self.csp_old = [[0.0,0.0]]*4 # previous spline
self.d = array([0], float) # knot vector
+ self.poly = [[0.0,0.0]] # LWPOLYLINE data
def output(self):
print ''.join(self.dxf)
def dxf_add(self, str):
self.dxf.append(str)
def dxf_line(self,csp):
- self.dxf_add(" 0\nLINE\n 5\n%x\n100\nAcDbEntity\n 8\n0\n100\nAcDbLine\n" % self.handle)
- self.dxf_add(" 10\n%f\n 20\n%f\n 30\n0.0\n 11\n%f\n 21\n%f\n 31\n0.0\n" % (csp[0][0],csp[0][1],csp[1][0],csp[1][1]))
+ if (abs(csp[0][0] - self.poly[-1][0]) > .0001
+ or abs(csp[0][1] - self.poly[-1][1]) > .0001):
+ self.LWPOLY_output() # terminate current polyline
+ self.poly = [csp[0]] # initiallize new polyline
+ self.color_LWPOLY = self.color
+ self.poly.append(csp[1])
+ def LWPOLY_output(self):
+ if len(self.poly) == 1:
+ return
+ self.handle += 1
+ self.dxf_add(" 0\nLWPOLYLINE\n 5\n%x\n100\nAcDbEntity\n 8\n0\n 62\n%d\n100\nAcDbPolyline\n 90\n%d\n 70\n0\n" % (self.handle, self.color_LWPOLY, len(self.poly)))
+ for i in range(len(self.poly)):
+ self.dxf_add(" 10\n%f\n 20\n%f\n 30\n0.0\n" % (self.poly[i][0],self.poly[i][1]))
def dxf_spline(self,csp):
knots = 8
ctrls = 4
- self.dxf_add(" 0\nSPLINE\n 5\n%x\n100\nAcDbEntity\n 8\n0\n100\nAcDbSpline\n" % self.handle)
+ self.handle += 1
+ self.dxf_add(" 0\nSPLINE\n 5\n%x\n100\nAcDbEntity\n 8\n0\n 62\n%d\n100\nAcDbSpline\n" % (self.handle, self.color))
self.dxf_add(" 70\n8\n 71\n3\n 72\n%d\n 73\n%d\n 74\n0\n" % (knots, ctrls))
for i in range(2):
for j in range(4):
self.xfit = array([csp[0][0]], float) # initiallize new spline
self.yfit = array([csp[0][1]], float)
self.d = array([0], float)
+ self.color_ROBO = self.color
self.xfit = concatenate((self.xfit, zeros((3)))) # append to current spline
self.yfit = concatenate((self.yfit, zeros((3))))
self.d = concatenate((self.d, zeros((3))))
solmatrix[fits+1, fits+1] = (self.d[fits-1] - self.d[fits-3])/self.d[fits-1]
xctrl = solve(solmatrix, self.xfit)
yctrl = solve(solmatrix, self.yfit)
- self.dxf_add(" 0\nSPLINE\n 5\n%x\n100\nAcDbEntity\n 8\n0\n100\nAcDbSpline\n" % self.handle)
+ self.handle += 1
+ self.dxf_add(" 0\nSPLINE\n 5\n%x\n100\nAcDbEntity\n 8\n0\n 62\n%d\n100\nAcDbSpline\n" % (self.handle, self.color_ROBO))
self.dxf_add(" 70\n0\n 71\n3\n 72\n%d\n 73\n%d\n 74\n%d\n" % (knots, ctrls, fits))
for i in range(knots):
self.dxf_add(" 40\n%f\n" % self.d[i-3])
h = inkex.unittouu(self.document.getroot().xpath('@height', namespaces=inkex.NSS)[0])
path = '//svg:path'
for node in self.document.getroot().xpath(path, namespaces=inkex.NSS):
+ style = node.get('style')
+ start = style.find("stroke:")
+ rgb = simplestyle.parseColor(style[(start+7):(start+14)])
+ hsl = coloreffect.ColorEffect.rgb_to_hsl(coloreffect.ColorEffect(),rgb[0]/255.0,rgb[1]/255.0,rgb[2]/255.0)
+ self.color = 7 # default is black
+ if hsl[2]:
+ self.color = 1 + (int(6*hsl[0] + 0.5) % 6) # use 6 hues
d = node.get('d')
sim = simplepath.parsePath(d)
- simplepath.scalePath(sim,scale,-scale)
- simplepath.translatePath(sim,0,h*scale)
- p = cubicsuperpath.CubicSuperPath(sim)
- for sub in p:
- for i in range(len(sub)-1):
- # generate unique handle for DXF ENTITY
- self.handle += 1
- s = sub[i]
- e = sub[i+1]
- if s[1] == s[2] and e[0] == e[1]:
- self.dxf_line([s[1],e[1]])
- elif (self.options.ROBO == 'true'):
- self.ROBO_spline([s[1],s[2],e[0],e[1]])
- else:
- self.dxf_spline([s[1],s[2],e[0],e[1]])
+ if len(sim):
+ simplepath.scalePath(sim,scale,-scale)
+ simplepath.translatePath(sim,0,h*scale)
+ p = cubicsuperpath.CubicSuperPath(sim)
+ for sub in p:
+ for i in range(len(sub)-1):
+ s = sub[i]
+ e = sub[i+1]
+ if s[1] == s[2] and e[0] == e[1]:
+ self.dxf_line([s[1],e[1]])
+ elif (self.options.ROBO == 'true'):
+ self.ROBO_spline([s[1],s[2],e[0],e[1]])
+ else:
+ self.dxf_spline([s[1],s[2],e[0],e[1]])
if self.options.ROBO == 'true':
- self.handle += 1
self.ROBO_output()
+ self.LWPOLY_output()
self.dxf_add(dxf_templates.r14_footer)
if __name__ == '__main__':