summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 31a8d61)
raw | patch | inline | side by side (parent: 31a8d61)
author | alvinpenner <alvinpenner@users.sourceforge.net> | |
Sun, 22 Mar 2009 19:48:13 +0000 (19:48 +0000) | ||
committer | alvinpenner <alvinpenner@users.sourceforge.net> | |
Sun, 22 Mar 2009 19:48:13 +0000 (19:48 +0000) |
share/extensions/dxf_input.py | patch | blob | history |
index 2f55eacffc8ef2a985f009dd2df57f701225a85e..6937825a2fbd66c1c62cd9dc2e329c452d440fd9 100644 (file)
'''\r
dxf_input.py - input a DXF file >= (AutoCAD Release 13 == AC1012)\r
\r
-Copyright (C) 2008 Alvin Penner, penner@vaxxine.com\r
+Copyright (C) 2008, 2009 Alvin Penner, penner@vaxxine.com\r
+Copyright (C) 2009 Christian Mayer, inkscape@christianmayer.de\r
- thanks to Aaron Spike for inkex.py and simplestyle.py\r
- without which this would not have been possible\r
\r
attribs = {'d': path, 'style': style}\r
inkex.etree.SubElement(layer, 'path', attribs)\r
\r
+def export_DIMENSION():\r
+ # mandatory group codes : (10, 11, 13, 14, 20, 21, 23, 24) (x1..4, y1..4)\r
+ if vals[groups['10']] and vals[groups['11']] and vals[groups['13']] and vals[groups['14']] and vals[groups['20']] and vals[groups['21']] and vals[groups['23']] and vals[groups['24']]:\r
+ dx = abs(vals[groups['10']][0] - vals[groups['13']][0])\r
+ dy = abs(vals[groups['20']][0] - vals[groups['23']][0])\r
+ if (vals[groups['10']][0] == vals[groups['14']][0]) and dx > 0.00001:\r
+ d = dx/scale\r
+ dy = 0\r
+ path = 'M %f,%f %f,%f' % (vals[groups['10']][0], vals[groups['20']][0], vals[groups['13']][0], vals[groups['20']][0])\r
+ elif (vals[groups['20']][0] == vals[groups['24']][0]) and dy > 0.00001:\r
+ d = dy/scale\r
+ dx = 0\r
+ path = 'M %f,%f %f,%f' % (vals[groups['10']][0], vals[groups['20']][0], vals[groups['10']][0], vals[groups['23']][0])\r
+ else:\r
+ return\r
+ attribs = {'d': path, 'style': style + '; marker-start: url(#DistanceX); marker-end: url(#DistanceX)'}\r
+ inkex.etree.SubElement(layer, 'path', attribs)\r
+ x = scale*(vals[groups['11']][0] - xmin)\r
+ y = - scale*(vals[groups['21']][0] - ymax)\r
+ size = 3 # default fontsize in px\r
+ attribs = {'x': '%f' % x, 'y': '%f' % y, 'style': 'font-size: %dpx; fill: %s' % (size, color)}\r
+ if dx == 0:\r
+ attribs.update({'transform': 'rotate (%f %f %f)' % (-90, x, y)})\r
+ node = inkex.etree.SubElement(layer, 'text', attribs)\r
+ tspan = inkex.etree.SubElement(node , 'tspan', {inkex.addNS('role','sodipodi'): 'line'})\r
+ tspan.text = '%.2f' % d\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
- if xm < 0:\r
- a += math.pi\r
+ a = math.atan2(ym, xm)\r
diff = (a2 - a1 + 2*math.pi) % (2*math.pi)\r
if diff: # open arc\r
large = 0 # large-arc-flag\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, '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
+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, 'DIMENSION': export_DIMENSION, 'ENDSEC': ''}\r
+groups = {'1': 0, '8': 1, '10': 2, '11': 3, '13': 4, '14': 5, '20': 6, '21': 7, '23': 8, '24': 9, '40': 10, '41': 11, '42': 12, '50': 13, '51': 14, '62': 15, '70': 16, '72': 17, '73': 18, '93': 19, '370': 20}\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
\r
doc = inkex.etree.parse(StringIO('<svg xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"></svg>'))\r
+defs = inkex.etree.SubElement(doc.getroot(), 'defs', {} )\r
+marker = inkex.etree.SubElement(defs, 'marker', {'id': 'DistanceX', 'orient': 'auto', 'refX': '0.0', 'refY': '0.0', 'style': 'overflow:visible'})\r
+inkex.etree.SubElement(marker, 'path', {'d': 'M 3,-3 L -3,3 M 0,-5 L 0,5', 'style': 'stroke:#000000; stroke-width:0.5'})\r
stream = open(inkex.sys.argv[1], 'r')\r
xmax = xmin = 0.0\r
ymax = 297.0 # default A4 height in mm\r
xmax = get_group('10')\r
ymax = get_group('20')\r
if flag and line[0] == '2':\r
- name = line[1]\r
+ name = unicode(line[1], "iso-8859-1")\r
attribs = {inkex.addNS('groupmode','inkscape'): 'layer', inkex.addNS('label','inkscape'): '%s' % name}\r
layer_nodes[name] = inkex.etree.SubElement(doc.getroot(), 'g', attribs)\r
if line[0] == '2' and line[1] == 'LAYER':\r
val = unicode(val, "iso-8859-1")\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
+ elif line[0] == '10' or line[0] == '13' or line[0] == '14': # scaled float x value\r
val = scale*(float(line[1]) - xmin)\r
- elif line[0] == '20': # scaled float y value\r
+ elif line[0] == '20' or line[0] == '23' or line[0] == '24': # scaled float y value\r
val = - scale*(float(line[1]) - ymax)\r
else: # unscaled float value\r
val = float(line[1])\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