summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fb6bca3)
raw | patch | inline | side by side (parent: fb6bca3)
author | alvinpenner <alvinpenner@users.sourceforge.net> | |
Sun, 15 Mar 2009 20:01:56 +0000 (20:01 +0000) | ||
committer | alvinpenner <alvinpenner@users.sourceforge.net> | |
Sun, 15 Mar 2009 20:01:56 +0000 (20:01 +0000) |
share/extensions/dxf_input.py | patch | blob | history |
index b518969fe522b6c9cd6538c59b7556533579a6e5..2f55eacffc8ef2a985f009dd2df57f701225a85e 100644 (file)
if vals[groups['50']]:\r
angle = vals[groups['50']][0]\r
attribs.update({'transform': 'rotate (%f %f %f)' % (-angle, x, y)})\r
- attribs.update({'sodipodi:linespacing': '125%'})\r
+ attribs.update({inkex.addNS('linespacing','sodipodi'): '125%'})\r
node = inkex.etree.SubElement(layer, 'text', attribs)\r
text = vals[groups['1']][0]\r
found = text.find('\P') # new line\r
while found > -1:\r
- tspan = inkex.etree.SubElement(node , 'tspan', {'sodipodi:role': 'line'})\r
+ tspan = inkex.etree.SubElement(node , 'tspan', {inkex.addNS('role','sodipodi'): 'line'})\r
tspan.text = text[:found]\r
text = text[(found+2):]\r
found = text.find('\P')\r
- tspan = inkex.etree.SubElement(node , 'tspan', {'sodipodi:role': 'line'})\r
+ tspan = inkex.etree.SubElement(node , 'tspan', {inkex.addNS('role','sodipodi'): 'line'})\r
tspan.text = text\r
\r
def export_POINT():\r
attribs = {'d': path, 'style': style}\r
inkex.etree.SubElement(layer, 'path', attribs)\r
\r
+def export_HATCH():\r
+ # mandatory group codes : (10, 20, 72, 93) (x, y, Edge Type, Number of edges)\r
+ if vals[groups['10']] and vals[groups['20']] and vals[groups['72']] and vals[groups['93']]:\r
+ if len(vals[groups['10']]) > 1 and len(vals[groups['20']]) == len(vals[groups['10']]):\r
+ # optional group codes : (11, 21, 40, 50, 51, 73) (x, y, r, angle1, angle2, CCW)\r
+ i10 = 1 # count start points\r
+ i11 = 0 # count line end points\r
+ i40 = 0 # count circles\r
+ i72 = 0 # count edge type flags\r
+ path = ''\r
+ for i in range (0, len(vals[groups['93']])):\r
+ xc = vals[groups['10']][i10]\r
+ yc = vals[groups['20']][i10]\r
+ if vals[groups['72']][i72] == 2: # arc\r
+ rm = scale*vals[groups['40']][i40]\r
+ a1 = vals[groups['50']][i40]\r
+ path += 'M %f,%f ' % (xc + rm*math.cos(a1*math.pi/180.0), yc + rm*math.sin(a1*math.pi/180.0))\r
+ else:\r
+ a1 = 0\r
+ path += 'M %f,%f ' % (xc, yc)\r
+ for j in range(0, vals[groups['93']][i]):\r
+ if vals[groups['72']][i72] == 2: # arc\r
+ xc = vals[groups['10']][i10]\r
+ yc = vals[groups['20']][i10]\r
+ rm = scale*vals[groups['40']][i40]\r
+ a2 = vals[groups['51']][i40]\r
+ diff = (a2 - a1 + 360) % (360)\r
+ sweep = 1 - vals[groups['73']][i40] # sweep CCW\r
+ large = 0 # large-arc-flag\r
+ if diff:\r
+ path += 'A %f,%f 0.0 %d %d %f,%f ' % (rm, rm, large, sweep, xc + rm*math.cos(a2*math.pi/180.0), yc + rm*math.sin(a2*math.pi/180.0))\r
+ else:\r
+ path += 'A %f,%f 0.0 %d %d %f,%f ' % (rm, rm, large, sweep, xc + rm*math.cos((a1+180.0)*math.pi/180.0), yc + rm*math.sin((a1+180.0)*math.pi/180.0))\r
+ path += 'A %f,%f 0.0 %d %d %f,%f ' % (rm, rm, large, sweep, xc + rm*math.cos(a1*math.pi/180.0), yc + rm*math.sin(a1*math.pi/180.0))\r
+ i40 += 1\r
+ i72 += 1\r
+ elif vals[groups['72']][i72] == 1: # line\r
+ path += 'L %f,%f ' % (scale*(vals[groups['11']][i11] - xmin), -scale*(vals[groups['21']][i11] - ymax))\r
+ i11 += 1\r
+ i72 += 1\r
+ elif vals[groups['72']][i72] == 0: # polyline\r
+ if j > 0:\r
+ path += 'L %f,%f ' % (vals[groups['10']][i10], vals[groups['20']][i10])\r
+ if j == vals[groups['93']][i] - 1:\r
+ i72 += 1\r
+ i10 += 1\r
+ path += "z "\r
+ style = simplestyle.formatStyle({'fill': '%s' % color})\r
+ attribs = {'d': path, 'style': style}\r
+ inkex.etree.SubElement(layer, 'path', attribs)\r
+\r
def generate_ellipse(xc, yc, xm, ym, w, a1, a2):\r
rm = math.sqrt(xm*xm + ym*ym)\r
a = math.atan(ym/xm)\r
\r
# define DXF Entities and specify which Group Codes to monitor\r
\r
-entities = {'MTEXT': export_MTEXT, 'TEXT': export_MTEXT, 'POINT': export_POINT, 'LINE': export_LINE, 'SPLINE': export_SPLINE, 'CIRCLE': export_CIRCLE, 'ARC': export_ARC, 'ELLIPSE': export_ELLIPSE, 'LEADER': export_LEADER, 'LWPOLYLINE': export_LWPOLYLINE, 'ENDSEC': ''}\r
-groups = {'1': 0, '8': 1, '10': 2, '11': 3, '20': 4, '21': 5, '40': 6, '41': 7, '42': 8, '50': 9, '51': 10, '62': 11, '70': 12, '370': 13}\r
+entities = {'MTEXT': export_MTEXT, 'TEXT': export_MTEXT, 'POINT': export_POINT, 'LINE': export_LINE, 'SPLINE': export_SPLINE, 'CIRCLE': export_CIRCLE, 'ARC': export_ARC, 'ELLIPSE': export_ELLIPSE, 'LEADER': export_LEADER, 'LWPOLYLINE': export_LWPOLYLINE, 'HATCH': export_HATCH, 'ENDSEC': ''}\r
+groups = {'1': 0, '8': 1, '10': 2, '11': 3, '20': 4, '21': 5, '40': 6, '41': 7, '42': 8, '50': 9, '51': 10, '62': 11, '70': 12, '72': 13, '73': 14, '93': 15, '370': 16}\r
colors = { 1: '#FF0000', 2: '#FFFF00', 3: '#00FF00', 4: '#00FFFF', 5: '#0000FF',\r
6: '#FF00FF', 8: '#414141', 9: '#808080', 30: '#FF7F00',\r
250: '#333333', 251: '#505050', 252: '#696969', 253: '#828282', 254: '#BEBEBE', 255: '#FFFFFF'}\r
seqs.append(line[0]) # list of group codes\r
if line[0] == '1' or line[0] == '8': # text value\r
val = line[1].replace('\~', ' ')\r
+ val = inkex.re.sub( '\\\\A.*;', '', val)\r
+ val = inkex.re.sub( '\\\\H.*;', '', val)\r
+ val = inkex.re.sub( '\\\\S.*;', '', val)\r
+ val = inkex.re.sub( '\\\\W.*;', '', val)\r
val = unicode(val, "iso-8859-1")\r
- elif line[0] == '62' or line[0] == '70': # unscaled integer value\r
+ elif line[0] == '62' or line[0] == '70' or line[0] == '93':\r
val = int(line[1])\r
elif line[0] == '10': # scaled float x value\r
val = scale*(float(line[1]) - xmin)\r
w = 0.5 # default lineweight for POINT\r
if vals[groups['370']]: # Common Lineweight\r
if vals[groups['370']][0] > 0:\r
- w = scale*vals[groups['370']][0]/100.0\r
+ w = 90.0/25.4*vals[groups['370']][0]/100.0\r
if w < 0.5:\r
w = 0.5\r
style = simplestyle.formatStyle({'stroke': '%s' % color, 'fill': 'none', 'stroke-width': '%.1f' % w})\r
entities[entity]()\r
entity = line[1]\r
- vals = [[],[],[],[],[],[],[],[],[],[],[],[],[],[]]\r
+ vals = [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]]\r
seqs = []\r
\r
doc.write(inkex.sys.stdout)\r