chiark / gitweb /
Add uppercase STL and HEX to file dialog filters for linux/MacOS
[cura.git] / Cura / fabmetheus_utilities / geometry / manipulation_shapes / _bottom.py
1 """
2 Boolean geometry bottom.
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.creation import solid
11 from fabmetheus_utilities.geometry.geometry_utilities.evaluate_elements import setting
12 from fabmetheus_utilities.geometry.geometry_utilities import boolean_geometry
13 from fabmetheus_utilities.geometry.geometry_utilities import evaluate
14 from fabmetheus_utilities.geometry.geometry_utilities import matrix
15 from fabmetheus_utilities import euclidean
16
17
18 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
19 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
20 __date__ = '$Date: 2008/02/05 $'
21 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
22
23
24 globalExecutionOrder = 400
25
26
27 def bottomElementNode(derivation, target):
28         "Bottom target."
29         xmlObject = target.xmlObject
30         if xmlObject == None:
31                 print('Warning, bottomTarget in bottom could not get xmlObject for:')
32                 print(target)
33                 print(derivation.elementNode)
34                 return
35         targetMatrix = matrix.getBranchMatrixSetElementNode(target)
36         lift = derivation.altitude
37         transformedPaths = xmlObject.getTransformedPaths()
38         if len(transformedPaths) > 0:
39                 lift += derivation.getAdditionalPathLift() - euclidean.getBottomByPaths(transformedPaths)
40         else:
41                 lift -= boolean_geometry.getMinimumZ(xmlObject)
42         targetMatrix.tetragrid = matrix.getIdentityTetragrid(targetMatrix.tetragrid)
43         targetMatrix.tetragrid[2][3] += lift
44         matrix.setElementNodeDictionaryMatrix(target, targetMatrix)
45
46 def getManipulatedGeometryOutput(elementNode, geometryOutput, prefix):
47         'Get bottomed geometryOutput.'
48         derivation = BottomDerivation(elementNode, prefix)
49         copyShallow = elementNode.getCopyShallow()
50         solid.processElementNodeByGeometry(copyShallow, geometryOutput)
51         targetMatrix = matrix.getBranchMatrixSetElementNode(elementNode)
52         matrix.setElementNodeDictionaryMatrix(copyShallow, targetMatrix)
53         minimumZ = boolean_geometry.getMinimumZ(copyShallow.xmlObject)
54         copyShallow.parentNode.xmlObject.archivableObjects.remove(copyShallow.xmlObject)
55         lift = derivation.altitude - minimumZ
56         vertexes = matrix.getVertexes(geometryOutput)
57         for vertex in vertexes:
58                 vertex.z += lift
59         return geometryOutput
60
61 def getManipulatedPaths(close, elementNode, loop, prefix, sideLength):
62         'Get flipped paths.'
63         if len(loop) < 1:
64                 return [[]]
65         derivation = BottomDerivation(elementNode, prefix)
66         targetMatrix = matrix.getBranchMatrixSetElementNode(elementNode)
67         transformedLoop = matrix.getTransformedVector3s(matrix.getIdentityTetragrid(targetMatrix.tetragrid), loop)
68         lift = derivation.altitude + derivation.getAdditionalPathLift() - euclidean.getBottomByPath(transformedLoop)
69         for point in loop:
70                 point.z += lift
71         return [loop]
72
73 def getNewDerivation(elementNode, prefix, sideLength):
74         'Get new derivation.'
75         return BottomDerivation(elementNode, '')
76
77 def processElementNode(elementNode):
78         "Process the xml element."
79         processElementNodeByDerivation(None, elementNode)
80
81 def processElementNodeByDerivation(derivation, elementNode):
82         'Process the xml element by derivation.'
83         if derivation == None:
84                 derivation = BottomDerivation(elementNode, '')
85         targets = evaluate.getElementNodesByKey(elementNode, 'target')
86         if len(targets) < 1:
87                 print('Warning, processElementNode in bottom could not get targets for:')
88                 print(elementNode)
89                 return
90         for target in targets:
91                 bottomElementNode(derivation, target)
92
93
94 class BottomDerivation:
95         "Class to hold bottom variables."
96         def __init__(self, elementNode, prefix):
97                 'Set defaults.'
98                 self.altitude = evaluate.getEvaluatedFloat(0.0, elementNode, prefix + 'altitude')
99                 self.elementNode = elementNode
100                 self.liftPath = evaluate.getEvaluatedBoolean(True, elementNode, prefix + 'liftPath')
101
102         def getAdditionalPathLift(self):
103                 "Get path lift."
104                 return 0.5 * setting.getLayerHeight(self.elementNode) * float(self.liftPath)