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.
10 from fabmetheus_utilities.geometry.geometry_utilities import evaluate
11 from fabmetheus_utilities.geometry.geometry_utilities import matrix
12 from fabmetheus_utilities import euclidean
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'
22 globalExecutionOrder = -100
25 def equate(point, returnValue):
26 "Get equation for rectangular."
27 point.setToVector3(evaluate.getVector3ByDictionaryListValue(returnValue, point))
29 def equatePoints(elementNode, points, prefix, revolutions):
31 derivation = EquationDerivation(elementNode, prefix)
32 for equationResult in derivation.equationResults:
34 returnValue = equationResult.getReturnValue(point, revolutions)
35 if returnValue == None:
36 print('Warning, returnValue in alterVertexesByEquation in equation is None for:')
40 equationResult.equationFunction(point, returnValue)
42 def equateX(point, returnValue):
43 "Get equation for rectangular x."
46 def equateY(point, returnValue):
47 "Get equation for rectangular y."
50 def equateZ(point, returnValue):
51 "Get equation for rectangular z."
54 def getManipulatedGeometryOutput(elementNode, geometryOutput, prefix):
55 "Get equated geometryOutput."
56 equatePoints(elementNode, matrix.getVertexes(geometryOutput), prefix, None)
59 def getManipulatedPaths(close, elementNode, loop, prefix, sideLength):
61 equatePoints(elementNode, loop, prefix, 0.0)
64 def getNewDerivation(elementNode, prefix, sideLength):
66 return EquationDerivation(elementNode, prefix)
69 class EquationDerivation:
70 "Class to hold equation variables."
71 def __init__(self, elementNode, prefix):
73 self.equationResults = []
74 self.addEquationResult(elementNode, equate, prefix)
75 self.addEquationResult(elementNode, equateX, prefix)
76 self.addEquationResult(elementNode, equateY, prefix)
77 self.addEquationResult(elementNode, equateZ, prefix)
79 def addEquationResult(self, elementNode, equationFunction, prefix):
80 'Add equation result to equationResults.'
81 prefixedEquationName = prefix + equationFunction.__name__[ len('equate') : ].replace('Dot', '.').lower()
82 if prefixedEquationName in elementNode.attributes:
83 self.equationResults.append(EquationResult(elementNode, equationFunction, prefixedEquationName))
87 "Class to get equation results."
88 def __init__(self, elementNode, equationFunction, key):
91 elementNode.xmlObject = evaluate.getEvaluatorSplitWords(elementNode.attributes[key])
92 self.equationFunction = equationFunction
93 self.function = evaluate.Function(elementNode)
96 def getReturnValue(self, point, revolutions):
98 if self.function == None:
100 self.function.localDictionary['azimuth'] = math.degrees(math.atan2(point.y, point.x))
101 if len(self.points) > 0:
102 self.distance += abs(point - self.points[-1])
103 self.function.localDictionary['distance'] = self.distance
104 self.function.localDictionary['radius'] = abs(point.dropAxis())
105 if revolutions != None:
106 if len( self.points ) > 0:
107 revolutions += 0.5 / math.pi * euclidean.getAngleAroundZAxisDifference(point, self.points[-1])
108 self.function.localDictionary['revolutions'] = revolutions
109 self.function.localDictionary['vertex'] = point
110 self.function.localDictionary['vertexes'] = self.points
111 self.function.localDictionary['vertexindex'] = len(self.points)
112 self.function.localDictionary['x'] = point.x
113 self.function.localDictionary['y'] = point.y
114 self.function.localDictionary['z'] = point.z
115 self.points.append(point)
116 return self.function.getReturnValueWithoutDeletion()