chiark / gitweb /
Add back the ultimaker platform, and made the platform mesh simpler.
[cura.git] / Cura / slice / cura_sf / fabmetheus_utilities / geometry / manipulation_shapes / _bottom.py
1 """
2 Boolean geometry bottom.
3
4 """
5
6 from __future__ import absolute_import
7
8 from fabmetheus_utilities.geometry.creation import solid
9 from fabmetheus_utilities.geometry.geometry_utilities.evaluate_elements import setting
10 from fabmetheus_utilities.geometry.geometry_utilities import boolean_geometry
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 globalExecutionOrder = 400
23
24
25 def bottomElementNode(derivation, target):
26         "Bottom target."
27         xmlObject = target.xmlObject
28         if xmlObject == None:
29                 print('Warning, bottomTarget in bottom could not get xmlObject for:')
30                 print(target)
31                 print(derivation.elementNode)
32                 return
33         targetMatrix = matrix.getBranchMatrixSetElementNode(target)
34         lift = derivation.altitude
35         transformedPaths = xmlObject.getTransformedPaths()
36         if len(transformedPaths) > 0:
37                 lift += derivation.getAdditionalPathLift() - euclidean.getBottomByPaths(transformedPaths)
38         else:
39                 lift -= boolean_geometry.getMinimumZ(xmlObject)
40         targetMatrix.tetragrid = matrix.getIdentityTetragrid(targetMatrix.tetragrid)
41         targetMatrix.tetragrid[2][3] += lift
42         matrix.setElementNodeDictionaryMatrix(target, targetMatrix)
43
44 def getManipulatedGeometryOutput(elementNode, geometryOutput, prefix):
45         'Get bottomed geometryOutput.'
46         derivation = BottomDerivation(elementNode, prefix)
47         copyShallow = elementNode.getCopyShallow()
48         solid.processElementNodeByGeometry(copyShallow, geometryOutput)
49         targetMatrix = matrix.getBranchMatrixSetElementNode(elementNode)
50         matrix.setElementNodeDictionaryMatrix(copyShallow, targetMatrix)
51         minimumZ = boolean_geometry.getMinimumZ(copyShallow.xmlObject)
52         copyShallow.parentNode.xmlObject.archivableObjects.remove(copyShallow.xmlObject)
53         lift = derivation.altitude - minimumZ
54         vertexes = matrix.getVertexes(geometryOutput)
55         for vertex in vertexes:
56                 vertex.z += lift
57         return geometryOutput
58
59 def getManipulatedPaths(close, elementNode, loop, prefix, sideLength):
60         'Get flipped paths.'
61         if len(loop) < 1:
62                 return [[]]
63         derivation = BottomDerivation(elementNode, prefix)
64         targetMatrix = matrix.getBranchMatrixSetElementNode(elementNode)
65         transformedLoop = matrix.getTransformedVector3s(matrix.getIdentityTetragrid(targetMatrix.tetragrid), loop)
66         lift = derivation.altitude + derivation.getAdditionalPathLift() - euclidean.getBottomByPath(transformedLoop)
67         for point in loop:
68                 point.z += lift
69         return [loop]
70
71 def getNewDerivation(elementNode, prefix, sideLength):
72         'Get new derivation.'
73         return BottomDerivation(elementNode, '')
74
75 def processElementNode(elementNode):
76         "Process the xml element."
77         processElementNodeByDerivation(None, elementNode)
78
79 def processElementNodeByDerivation(derivation, elementNode):
80         'Process the xml element by derivation.'
81         if derivation == None:
82                 derivation = BottomDerivation(elementNode, '')
83         targets = evaluate.getElementNodesByKey(elementNode, 'target')
84         if len(targets) < 1:
85                 print('Warning, processElementNode in bottom could not get targets for:')
86                 print(elementNode)
87                 return
88         for target in targets:
89                 bottomElementNode(derivation, target)
90
91
92 class BottomDerivation(object):
93         "Class to hold bottom variables."
94         def __init__(self, elementNode, prefix):
95                 'Set defaults.'
96                 self.altitude = evaluate.getEvaluatedFloat(0.0, elementNode, prefix + 'altitude')
97                 self.elementNode = elementNode
98                 self.liftPath = evaluate.getEvaluatedBoolean(True, elementNode, prefix + 'liftPath')
99
100         def getAdditionalPathLift(self):
101                 "Get path lift."
102                 return 0.5 * setting.getLayerHeight(self.elementNode) * float(self.liftPath)