2 Boolean geometry dictionary object.
7 from __future__ import absolute_import
8 #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.
11 from fabmetheus_utilities.geometry.geometry_utilities import evaluate
12 from fabmetheus_utilities.geometry.geometry_utilities import matrix
13 from fabmetheus_utilities import euclidean
14 from fabmetheus_utilities import xml_simple_writer
18 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
19 __credits__ = 'Nophead <http://hydraraptor.blogspot.com/>\nArt of Illusion <http://www.artofillusion.org/>'
20 __date__ = '$Date: 2008/21/04 $'
21 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
24 def getAllPaths(paths, xmlObject):
26 for archivableObject in xmlObject.archivableObjects:
27 paths += archivableObject.getPaths()
30 def getAllTransformedPaths(transformedPaths, xmlObject):
31 'Get all transformed paths.'
32 for archivableObject in xmlObject.archivableObjects:
33 transformedPaths += archivableObject.getTransformedPaths()
34 return transformedPaths
36 def getAllTransformedVertexes(transformedVertexes, xmlObject):
37 'Get all transformed vertexes.'
38 for archivableObject in xmlObject.archivableObjects:
39 transformedVertexes += archivableObject.getTransformedVertexes()
40 return transformedVertexes
42 def getAllVertexes(vertexes, xmlObject):
44 for archivableObject in xmlObject.archivableObjects:
45 vertexes += archivableObject.getVertexes()
48 def processElementNode(elementNode):
49 'Process the xml element.'
50 evaluate.processArchivable( Dictionary, elementNode)
54 'A dictionary object.'
57 self.archivableObjects = []
58 self.elementNode = None
61 'Get the string representation of this object info.'
62 output = xml_simple_writer.getBeginGeometryXMLOutput(self.elementNode)
63 self.addXML( 1, output )
64 return xml_simple_writer.getEndGeometryXMLString(output)
66 def addXML(self, depth, output):
67 'Add xml for this object.'
69 if self.elementNode != None:
70 attributeCopy = evaluate.getEvaluatedDictionaryByCopyKeys(['paths', 'target', 'vertexes'], self.elementNode)
71 euclidean.removeElementsFromDictionary(attributeCopy, matrix.getKeysM())
72 euclidean.removeTrueFromDictionary(attributeCopy, 'visible')
73 innerOutput = cStringIO.StringIO()
74 self.addXMLInnerSection(depth + 1, innerOutput)
75 self.addXMLArchivableObjects(depth + 1, innerOutput)
76 xml_simple_writer.addBeginEndInnerXMLTag(attributeCopy, depth, innerOutput.getvalue(), self.getXMLLocalName(), output)
78 def addXMLArchivableObjects(self, depth, output):
79 'Add xml for this object.'
80 xml_simple_writer.addXMLFromObjects( depth, self.archivableObjects, output )
82 def addXMLInnerSection(self, depth, output):
83 'Add xml section for this object.'
86 def createShape(self):
90 def getAttributes(self):
91 'Get attribute table.'
92 if self.elementNode == None:
94 return self.elementNode.attributes
96 def getComplexTransformedPathLists(self):
97 'Get complex transformed path lists.'
98 complexTransformedPathLists = []
99 for archivableObject in self.archivableObjects:
100 complexTransformedPathLists.append(euclidean.getComplexPaths(archivableObject.getTransformedPaths()))
101 return complexTransformedPathLists
103 def getFabricationExtension(self):
104 'Get fabrication extension.'
107 def getFabricationText(self, addLayerTemplate):
108 'Get fabrication text.'
109 return self.__repr__()
111 def getGeometryOutput(self):
112 'Get geometry output dictionary.'
114 for visibleObject in evaluate.getVisibleObjects(self.archivableObjects):
115 geometryOutput = visibleObject.getGeometryOutput()
116 if geometryOutput != None:
117 visibleObject.transformGeometryOutput(geometryOutput)
118 shapeOutput.append(geometryOutput)
119 if len(shapeOutput) < 1:
121 return {self.getXMLLocalName() : {'shapes' : shapeOutput}}
123 def getMatrix4X4(self):
127 def getMatrixChainTetragrid(self):
128 'Get the matrix chain tetragrid.'
129 return self.elementNode.parentNode.xmlObject.getMatrixChainTetragrid()
131 def getMinimumZ(self):
137 return getAllPaths([], self)
139 def getTransformedPaths(self):
140 'Get all transformed paths.'
141 return getAllTransformedPaths([], self)
143 def getTransformedVertexes(self):
144 'Get all transformed vertexes.'
145 return getAllTransformedVertexes([], self)
147 def getTriangleMeshes(self):
148 'Get all triangleMeshes.'
150 for archivableObject in self.archivableObjects:
151 triangleMeshes += archivableObject.getTriangleMeshes()
152 return triangleMeshes
156 return self.__class__.__name__
158 def getVertexes(self):
160 return getAllVertexes([], self)
162 def getVisible(self):
166 def getXMLLocalName(self):
167 'Get xml local name.'
168 return self.__class__.__name__.lower()
170 def setToElementNode(self, elementNode):
171 'Set the shape of this carvable object info.'
172 self.elementNode = elementNode
173 elementNode.parentNode.xmlObject.archivableObjects.append(self)
175 def transformGeometryOutput(self, geometryOutput):
176 'Transform the geometry output by the local matrix4x4.'
177 if self.getMatrix4X4() != None:
178 matrix.transformVector3sByMatrix(self.getMatrix4X4().tetragrid, matrix.getVertexes(geometryOutput))