dxf_input.py revision e23297675ca3cc0247403cbc142aa2710f9ad469
'''
dxf_input.py - input a DXF file >= (AutoCAD Release 13 == AC1012)
Copyright (C) 2008 Alvin Penner, penner@vaxxine.com
- thanks to Aaron Spike for inkex.py and simplestyle.py
- without which this would not have been possible
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
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
'''
def export_MTEXT():
# mandatory group codes : (1, 10, 20) (text, x, y)
# optional group codes : (40, 50) (text height mm, text angle)
while found > -1:
def export_POINT():
# mandatory group codes : (10, 20) (x, y)
def export_LINE():
# mandatory group codes : (10, 11, 20, 21) (x1, x2, y1, y2)
path = 'M %f,%f %f,%f' % (vals[groups['10']][0], vals[groups['20']][0], scale*(vals[groups['11']][0] - xmin), - scale*(vals[groups['21']][0] - ymax))
def export_SPLINE():
# mandatory group codes : (10, 20, 70) (x, y, flags)
path = 'M %f,%f C %f,%f %f,%f %f,%f' % (vals[groups['10']][0], vals[groups['20']][0], vals[groups['10']][1], vals[groups['20']][1], vals[groups['10']][2], vals[groups['20']][2], vals[groups['10']][3], vals[groups['20']][3])
def export_CIRCLE():
# mandatory group codes : (10, 20, 40) (x, y, radius)
generate_ellipse(vals[groups['10']][0], vals[groups['20']][0], scale*vals[groups['40']][0], 0.0, 1.0, 0.0, 0.0)
def export_ARC():
# mandatory group codes : (10, 20, 40, 50, 51) (x, y, radius, angle1, angle2)
if vals[groups['10']] and vals[groups['20']] and vals[groups['40']] and vals[groups['50']] and vals[groups['51']]:
generate_ellipse(vals[groups['10']][0], vals[groups['20']][0], scale*vals[groups['40']][0], 0.0, 1.0, vals[groups['50']][0]*math.pi/180.0, vals[groups['51']][0]*math.pi/180.0)
def export_ELLIPSE():
# mandatory group codes : (10, 11, 20, 21, 40, 41, 42) (xc, xm, yc, ym, width ratio, angle1, angle2)
if vals[groups['10']] and vals[groups['11']] and vals[groups['20']] and vals[groups['21']] and vals[groups['40']] and vals[groups['41']] and vals[groups['42']]:
generate_ellipse(vals[groups['10']][0], vals[groups['20']][0], scale*vals[groups['11']][0], scale*vals[groups['21']][0], vals[groups['40']][0], vals[groups['41']][0], vals[groups['42']][0])
def export_LEADER():
# mandatory group codes : (10, 20) (x, y)
def export_LWPOLYLINE():
# mandatory group codes : (10, 20, 70) (x, y, flags)
# optional group codes : (42) (bulge)
iseqs = 0
ibulge = 0
iseqs += 1
bulge = 0
iseqs += 1
ibulge += 1
iseqs += 1
if bulge:
if bulge < 0:
if bulge > 1:
large = 1
path += ' A %f,%f 0.0 %d %d %f,%f' % (r, r, large, sweep, vals[groups['10']][i], vals[groups['20']][i])
else:
path += ' z'
if xm < 0:
if diff: # open arc
large = 1
path = 'M %f,%f A %f,%f %f %d 0 %f,%f' % (xc+x1, yc-y1, rm, w*rm, -180.0*a/math.pi, large, xc+x2, yc-y2)
else: # closed arc
path = 'M %f,%f A %f,%f %f 1 0 %f,%f %f,%f %f 1 0 %f,%f z' % (xc+xm, yc-ym, rm, w*rm, -180.0*a/math.pi, xc-xm, yc+ym, rm, w*rm, -180.0*a/math.pi, xc+xm, yc-ym)
def get_line():
else:
return 0.0
# define DXF Entities and specify which Group Codes to monitor
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': ''}
groups = {'1': 0, '10': 1, '11': 2, '20': 3, '21': 4, '40': 5, '41': 6, '42': 7, '50': 8, '51': 9, '62': 10, '70': 11, '370': 12}
colors = {1: '#FF0000', 2: '#FFFF00', 3: '#00FF00', 4: '#00FFFF', 5: '#0000FF', 6: '#FF00FF', 7: '#FFFFFF', 8: '#414141', 9: '#808080'}
doc = inkex.etree.parse(StringIO('<svg xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"></svg>'))
entity = ''
else: # unscaled float value
w = 0.5 # default lineweight for POINT
style = simplestyle.formatStyle({'stroke': '%s' % color, 'fill': 'none', 'stroke-width': '%.1f' % w})
vals = [[],[],[],[],[],[],[],[],[],[],[],[],[]]
seqs = []
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99