1 from __future__ import absolute_import
2 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
8 from xml.etree import ElementTree
10 from Cura.util.drawingLoader import drawing
12 class DXF(drawing.Drawing):
13 def __init__(self, filename):
14 super(DXF, self).__init__()
21 f = open(filename, "r")
23 groupCode = f.readline().strip()
26 groupCode = int(groupCode)
27 value = f.readline().strip()
29 if entityType == 'SECTION':
30 sectionName = activeObject[2][0]
31 elif entityType == 'ENDSEC':
33 elif sectionName == 'ENTITIES':
34 self._checkForNewPath(entityType, activeObject)
35 elif activeObject is not None:
37 #print sectionName, entityType, activeObject
41 if groupCode in activeObject:
42 activeObject[groupCode].append(value)
44 activeObject[groupCode] = [value]
45 if sectionName == 'ENTITIES':
46 self._checkForNewPath(entityType, activeObject)
49 self._postProcessPaths()
51 def _checkForNewPath(self, type, obj):
53 if self._lastLine is not None and self._lastLinePoint == complex(float(obj[10][0]), float(obj[20][0])):
54 self._lastLine.addLineTo(float(obj[11][0]), float(obj[21][0]))
56 p = self.addPath(float(obj[10][0]), float(obj[20][0]))
57 p.addLineTo(float(obj[11][0]), float(obj[21][0]))
59 self._lastLinePoint = complex(float(obj[11][0]), float(obj[21][0]))
60 elif type == 'POLYLINE':
62 elif type == 'VERTEX':
63 if self._polyLine is None:
64 self._polyLine = self.addPath(float(obj[10][0]), float(obj[20][0]))
66 self._polyLine.addLineTo(float(obj[10][0]), float(obj[20][0]))
67 elif type == 'LWPOLYLINE':
68 p = self.addPath(float(obj[10][0]), float(obj[20][0]))
69 for n in xrange(1, len(obj[10])):
70 p.addLineTo(float(obj[10][n]), float(obj[20][n]))
72 elif type == 'SPLINE':
73 p = self.addPath(float(obj[10][0]), float(obj[20][0]))
74 for n in xrange(1, len(obj[10])):
75 p.addLineTo(float(obj[10][n]), float(obj[20][n]))
78 print 'type=%s' % type
82 if __name__ == '__main__':
83 for n in xrange(1, len(sys.argv)):
84 print 'File: %s' % (sys.argv[n])
85 dxf = DXF(sys.argv[n])
87 dxf.saveAsHtml("test_export.html")