chiark / gitweb /
Add back the ultimaker platform, and made the platform mesh simpler.
[cura.git] / Cura / slice / cura_sf / fabmetheus_utilities / geometry / manipulation_shapes / equation.py
1 """
2 Equation for vertexes.
3
4 """
5
6 from __future__ import absolute_import
7
8 from fabmetheus_utilities.geometry.geometry_utilities import evaluate
9 from fabmetheus_utilities.geometry.geometry_utilities import matrix
10 from fabmetheus_utilities import euclidean
11 import math
12
13
14 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
15 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
16 __date__ = '$Date: 2008/02/05 $'
17 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
18
19
20 globalExecutionOrder = -100
21
22
23 def equate(point, returnValue):
24         "Get equation for rectangular."
25         point.setToVector3(evaluate.getVector3ByDictionaryListValue(returnValue, point))
26
27 def equatePoints(elementNode, points, prefix, revolutions):
28         "Equate the points."
29         derivation = EquationDerivation(elementNode, prefix)
30         for equationResult in derivation.equationResults:
31                 for point in points:
32                         returnValue = equationResult.getReturnValue(point, revolutions)
33                         if returnValue == None:
34                                 print('Warning, returnValue in alterVertexesByEquation in equation is None for:')
35                                 print(point)
36                                 print(elementNode)
37                         else:
38                                 equationResult.equationFunction(point, returnValue)
39
40 def equateX(point, returnValue):
41         "Get equation for rectangular x."
42         point.x = returnValue
43
44 def equateY(point, returnValue):
45         "Get equation for rectangular y."
46         point.y = returnValue
47
48 def equateZ(point, returnValue):
49         "Get equation for rectangular z."
50         point.z = returnValue
51
52 def getManipulatedGeometryOutput(elementNode, geometryOutput, prefix):
53         "Get equated geometryOutput."
54         equatePoints(elementNode, matrix.getVertexes(geometryOutput), prefix, None)
55         return geometryOutput
56
57 def getManipulatedPaths(close, elementNode, loop, prefix, sideLength):
58         "Get equated paths."
59         equatePoints(elementNode, loop, prefix, 0.0)
60         return [loop]
61
62 def getNewDerivation(elementNode, prefix, sideLength):
63         'Get new derivation.'
64         return EquationDerivation(elementNode, prefix)
65
66
67 class EquationDerivation(object):
68         "Class to hold equation variables."
69         def __init__(self, elementNode, prefix):
70                 'Set defaults.'
71                 self.equationResults = []
72                 self.addEquationResult(elementNode, equate, prefix)
73                 self.addEquationResult(elementNode, equateX, prefix)
74                 self.addEquationResult(elementNode, equateY, prefix)
75                 self.addEquationResult(elementNode, equateZ, prefix)
76
77         def addEquationResult(self, elementNode, equationFunction, prefix):
78                 'Add equation result to equationResults.'
79                 prefixedEquationName = prefix + equationFunction.__name__[ len('equate') : ].replace('Dot', '.').lower()
80                 if prefixedEquationName in elementNode.attributes:
81                         self.equationResults.append(EquationResult(elementNode, equationFunction, prefixedEquationName))
82
83
84 class EquationResult(object):
85         "Class to get equation results."
86         def __init__(self, elementNode, equationFunction, key):
87                 "Initialize."
88                 self.distance = 0.0
89                 elementNode.xmlObject = evaluate.getEvaluatorSplitWords(elementNode.attributes[key])
90                 self.equationFunction = equationFunction
91                 self.function = evaluate.Function(elementNode)
92                 self.points = []
93
94         def getReturnValue(self, point, revolutions):
95                 "Get return value."
96                 if self.function == None:
97                         return point
98                 self.function.localDictionary['azimuth'] = math.degrees(math.atan2(point.y, point.x))
99                 if len(self.points) > 0:
100                         self.distance += abs(point - self.points[-1])
101                 self.function.localDictionary['distance'] = self.distance
102                 self.function.localDictionary['radius'] = abs(point.dropAxis())
103                 if revolutions != None:
104                         if len( self.points ) > 0:
105                                 revolutions += 0.5 / math.pi * euclidean.getAngleAroundZAxisDifference(point, self.points[-1])
106                         self.function.localDictionary['revolutions'] = revolutions
107                 self.function.localDictionary['vertex'] = point
108                 self.function.localDictionary['vertexes'] = self.points
109                 self.function.localDictionary['vertexindex'] = len(self.points)
110                 self.function.localDictionary['x'] = point.x
111                 self.function.localDictionary['y'] = point.y
112                 self.function.localDictionary['z'] = point.z
113                 self.points.append(point)
114                 return self.function.getReturnValueWithoutDeletion()