chiark / gitweb /
37de4edb0fdc47314af003ab9f4e9c2764d7efc7
[cura.git] / Cura / fabmetheus_utilities / geometry / solids / group.py
1 """
2 Boolean geometry group of solids.
3
4 """
5
6 from __future__ import absolute_import
7 #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.
8 import __init__
9
10 from fabmetheus_utilities.geometry.geometry_tools import dictionary
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
15
16 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
17 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
18 __date__ = '$Date: 2008/02/05 $'
19 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
20
21
22 def convertContainerElementNode(elementNode, geometryOutput, xmlObject):
23         "Convert the xml element to a group xml element."
24         elementNode.linkObject(xmlObject)
25         matrix.getBranchMatrixSetElementNode(elementNode)
26         elementNode.getXMLProcessor().createChildNodes(geometryOutput['shapes'], elementNode)
27
28 def convertElementNode(elementNode, geometryOutput):
29         "Convert the xml element to a group xml element."
30         convertContainerElementNode(elementNode, geometryOutput, Group())
31
32 def getNewDerivation(elementNode):
33         'Get new derivation.'
34         return evaluate.EmptyObject(elementNode)
35
36 def processElementNode(elementNode):
37         "Process the xml element."
38         evaluate.processArchivable(Group, elementNode)
39
40
41 class Group(dictionary.Dictionary):
42         "A group."
43         def __init__(self):
44                 "Add empty lists."
45                 dictionary.Dictionary.__init__(self)
46                 self.matrix4X4 = matrix.Matrix()
47
48         def addXMLInnerSection(self, depth, output):
49                 "Add xml inner section for this object."
50                 if self.matrix4X4 != None:
51                         self.matrix4X4.addXML(depth, output)
52                 self.addXMLSection(depth, output)
53
54         def addXMLSection(self, depth, output):
55                 "Add the xml section for this object."
56                 pass
57
58         def getLoops(self, importRadius, z):
59                 "Get loops sliced through shape."
60                 visibleObjects = evaluate.getVisibleObjects(self.archivableObjects)
61                 loops = []
62                 for visibleObject in visibleObjects:
63                         loops += visibleObject.getLoops(importRadius, z)
64                 return loops
65
66         def getMatrix4X4(self):
67                 "Get the matrix4X4."
68                 return self.matrix4X4
69
70         def getMatrixChainTetragrid(self):
71                 "Get the matrix chain tetragrid."
72                 return matrix.getTetragridTimesOther(self.elementNode.parentNode.xmlObject.getMatrixChainTetragrid(), self.matrix4X4.tetragrid)
73
74         def getVisible(self):
75                 "Get visible."
76                 return euclidean.getBooleanFromDictionary(True, self.getAttributes(), 'visible')
77
78         def setToElementNode(self, elementNode):
79                 'Set to elementNode.'
80                 self.elementNode = elementNode
81                 elementNode.parentNode.xmlObject.archivableObjects.append(self)
82                 matrix.getBranchMatrixSetElementNode(elementNode)