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
13 def __init__(self, filename):
18 entityType = 'UNKNOWN'
19 sectionName = 'UNKNOWN'
21 f = open(filename, "r")
23 groupCode = f.readline().strip()
26 groupCode = int(groupCode)
27 value = f.readline().strip()
29 if sectionName == 'ENTITIES':
30 self._checkForNewPath(entityType, activeObject)
33 elif entityType == 'SECTION':
37 activeObject[groupCode] = value
38 if sectionName == 'ENTITIES':
39 self._checkForNewPath(entityType, activeObject)
42 for path in self.paths:
43 if not path.isClosed():
46 def _checkForNewPath(self, type, obj):
48 if self._lastLine is not None and self._lastLinePoint == complex(float(obj[10]), float(obj[20])):
49 self._lastLine.addLineTo(float(obj[11]), float(obj[21]))
51 p = drawing.Path(float(obj[10]), float(obj[20]))
52 p.addLineTo(float(obj[11]), float(obj[21]))
55 self._lastLinePoint = complex(float(obj[11]), float(obj[21]))
56 elif type == 'POLYLINE':
58 elif type == 'VERTEX':
59 if self._polyLine is None:
60 self._polyLine = drawing.Path(float(obj[10]), float(obj[20]))
61 self.paths.append(self._polyLine)
63 self._polyLine.addLineTo(float(obj[10]), float(obj[20]))
67 if __name__ == '__main__':
68 for n in xrange(1, len(sys.argv)):
69 print 'File: %s' % (sys.argv[n])
70 dxf = DXF(sys.argv[n])
72 drawing.saveAsHtml(dxf, "test_export.html")