Package fabmetheus_utilities :: Package fabmetheus_tools :: Package interpret_plugins :: Module svg
[hide private]
[frames] | no frames]

Source Code for Module fabmetheus_utilities.fabmetheus_tools.interpret_plugins.svg

  1  """ 
  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. 
  4   
  5  An example inkscape svg file is inkscape_star.svg in the models folder. 
  6   
  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. 
  8   
  9  The getCarving function takes the file name of an svg file and returns the carving. 
 10   
 11  """ 
 12   
 13  from fabmetheus_utilities.svg_reader import SVGReader 
 14  from fabmetheus_utilities.vector3 import Vector3 
 15  from fabmetheus_utilities import archive 
 16  from fabmetheus_utilities import euclidean 
 17  from fabmetheus_utilities import svg_writer 
 18  from fabmetheus_utilities import xml_simple_writer 
 19  import math 
 20   
 21   
 22  __author__ = 'Enrique Perez (perez_enrique@yahoo.com)' 
 23  __credits__ = 'Nophead <http://hydraraptor.blogspot.com/>\nArt of Illusion <http://www.artofillusion.org/>' 
 24  __date__ = '$Date: 2008/21/04 $' 
 25  __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html' 
 26   
 27   
28 -def getCarving(fileName=''):
29 'Get the triangle mesh for the gts file.' 30 carving = SVGCarving() 31 carving.parseSVG(fileName, archive.getFileText(fileName)) 32 return carving
33 34
35 -class SVGCarving:
36 'An svg carving.'
37 - def __init__(self):
38 'Add empty lists.' 39 self.layerThickness = 1.0 40 self.maximumZ = - 987654321.0 41 self.minimumZ = 987654321.0 42 self.svgReader = SVGReader()
43
44 - def __repr__(self):
45 'Get the string representation of this carving.' 46 return self.getCarvedSVG()
47
48 - def addXML(self, depth, output):
49 'Add xml for this object.' 50 xml_simple_writer.addXMLFromObjects(depth, self.svgReader.rotatedLoopLayers, output)
51
52 - def getCarveCornerMaximum(self):
53 'Get the corner maximum of the vertexes.' 54 return self.cornerMaximum
55
56 - def getCarveCornerMinimum(self):
57 'Get the corner minimum of the vertexes.' 58 return self.cornerMinimum
59
60 - def getCarvedSVG(self):
61 'Get the carved svg text.' 62 return svg_writer.getSVGByLoopLayers(True, self, self.svgReader.rotatedLoopLayers)
63
64 - def getCarveLayerThickness(self):
65 'Get the layer thickness.' 66 return self.layerThickness
67
69 'Get the rotated boundary layers.' 70 return self.svgReader.rotatedLoopLayers
71
72 - def getFabmetheusXML(self):
73 'Return the fabmetheus XML.' 74 return None
75
76 - def getInterpretationSuffix(self):
77 'Return the suffix for a carving.' 78 return 'svg'
79
80 - def parseSVG(self, fileName, svgText):
81 'Parse SVG text and store the layers.' 82 if svgText == '': 83 return 84 self.fileName = fileName 85 self.svgReader.parseSVG(fileName, svgText) 86 self.layerThickness = euclidean.getFloatDefaultByDictionary( 87 self.layerThickness, self.svgReader.sliceDictionary, 'layerThickness') 88 self.cornerMaximum = Vector3(-987654321.0, -987654321.0, self.maximumZ) 89 self.cornerMinimum = Vector3(987654321.0, 987654321.0, self.minimumZ) 90 svg_writer.setSVGCarvingCorners( 91 self.cornerMaximum, self.cornerMinimum, self.layerThickness, self.svgReader.rotatedLoopLayers)
92
93 - def setCarveInfillInDirectionOfBridge(self, infillInDirectionOfBridge):
94 'Set the infill in direction of bridge.' 95 pass
96
97 - def setCarveLayerThickness(self, layerThickness):
98 'Set the layer thickness.' 99 self.layerThickness = layerThickness
100
101 - def setCarveImportRadius(self, importRadius):
102 'Set the import radius.' 103 pass
104
105 - def setCarveIsCorrectMesh(self, isCorrectMesh):
106 'Set the is correct mesh flag.' 107 pass
108