2 This page is in the table of contents.
3 The svg.py script is an import translator plugin to get a carving from an svg file. This script will read an svg file made by skeinforge or by inkscape.
5 An example inkscape svg file is inkscape_star.svg in the models folder.
7 An import plugin is a script in the interpret_plugins folder which has the function getCarving. It is meant to be run from the interpret tool. To ensure that the plugin works on platforms which do not handle file capitalization properly, give the plugin a lower case name.
9 The getCarving function takes the file name of an svg file and returns the carving.
14 from __future__ import absolute_import
15 #Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module.
18 from fabmetheus_utilities.svg_reader import SVGReader
19 from fabmetheus_utilities.vector3 import Vector3
20 from fabmetheus_utilities import archive
21 from fabmetheus_utilities import euclidean
22 from fabmetheus_utilities import gcodec
23 from fabmetheus_utilities import svg_writer
24 from fabmetheus_utilities import xml_simple_writer
28 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
29 __credits__ = 'Nophead <http://hydraraptor.blogspot.com/>\nArt of Illusion <http://www.artofillusion.org/>'
30 __date__ = '$Date: 2008/21/04 $'
31 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
34 def getCarving(fileName=''):
35 'Get the triangle mesh for the gts file.'
36 carving = SVGCarving()
37 carving.parseSVG(fileName, archive.getFileText(fileName))
45 self.layerHeight = 1.0
46 self.maximumZ = - 987654321.0
47 self.minimumZ = 987654321.0
48 self.svgReader = SVGReader()
51 'Get the string representation of this carving.'
52 return self.getCarvedSVG()
54 def addXML(self, depth, output):
55 'Add xml for this object.'
56 xml_simple_writer.addXMLFromObjects(depth, self.svgReader.loopLayers, output)
58 def getCarveBoundaryLayers(self):
59 'Get the boundary layers.'
60 return self.svgReader.loopLayers
62 def getCarveCornerMaximum(self):
63 'Get the corner maximum of the vertexes.'
64 return self.cornerMaximum
66 def getCarveCornerMinimum(self):
67 'Get the corner minimum of the vertexes.'
68 return self.cornerMinimum
70 def getCarvedSVG(self):
71 'Get the carved svg text.'
72 return svg_writer.getSVGByLoopLayers(True, self, self.svgReader.loopLayers)
74 def getCarveLayerHeight(self):
75 'Get the layer height.'
76 return self.layerHeight
78 def getFabmetheusXML(self):
79 'Return the fabmetheus XML.'
82 def getInterpretationSuffix(self):
83 'Return the suffix for a carving.'
86 def parseSVG(self, fileName, svgText):
87 'Parse SVG text and store the layers.'
90 self.fileName = fileName
91 self.svgReader.parseSVG(fileName, svgText)
92 self.layerHeight = euclidean.getFloatDefaultByDictionary(
93 self.layerHeight, self.svgReader.sliceDictionary, 'layerHeight')
94 self.cornerMaximum = Vector3(-987654321.0, -987654321.0, self.maximumZ)
95 self.cornerMinimum = Vector3(987654321.0, 987654321.0, self.minimumZ)
96 svg_writer.setSVGCarvingCorners(
97 self.cornerMaximum, self.cornerMinimum, self.layerHeight, self.svgReader.loopLayers)
99 def setCarveImportRadius(self, importRadius):
100 'Set the import radius.'
103 def setCarveIsCorrectMesh(self, isCorrectMesh):
104 'Set the is correct mesh flag.'
107 def setCarveLayerHeight(self, layerHeight):
108 'Set the layer height.'
109 self.layerHeight = layerHeight