6 from __future__ import absolute_import
8 from fabmetheus_utilities.geometry.geometry_utilities import evaluate
9 from fabmetheus_utilities.geometry.geometry_utilities import matrix
10 from fabmetheus_utilities import euclidean
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'
20 globalExecutionOrder = -100
23 def equate(point, returnValue):
24 "Get equation for rectangular."
25 point.setToVector3(evaluate.getVector3ByDictionaryListValue(returnValue, point))
27 def equatePoints(elementNode, points, prefix, revolutions):
29 derivation = EquationDerivation(elementNode, prefix)
30 for equationResult in derivation.equationResults:
32 returnValue = equationResult.getReturnValue(point, revolutions)
33 if returnValue == None:
34 print('Warning, returnValue in alterVertexesByEquation in equation is None for:')
38 equationResult.equationFunction(point, returnValue)
40 def equateX(point, returnValue):
41 "Get equation for rectangular x."
44 def equateY(point, returnValue):
45 "Get equation for rectangular y."
48 def equateZ(point, returnValue):
49 "Get equation for rectangular z."
52 def getManipulatedGeometryOutput(elementNode, geometryOutput, prefix):
53 "Get equated geometryOutput."
54 equatePoints(elementNode, matrix.getVertexes(geometryOutput), prefix, None)
57 def getManipulatedPaths(close, elementNode, loop, prefix, sideLength):
59 equatePoints(elementNode, loop, prefix, 0.0)
62 def getNewDerivation(elementNode, prefix, sideLength):
64 return EquationDerivation(elementNode, prefix)
67 class EquationDerivation(object):
68 "Class to hold equation variables."
69 def __init__(self, elementNode, prefix):
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)
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))
84 class EquationResult(object):
85 "Class to get equation results."
86 def __init__(self, elementNode, equationFunction, key):
89 elementNode.xmlObject = evaluate.getEvaluatorSplitWords(elementNode.attributes[key])
90 self.equationFunction = equationFunction
91 self.function = evaluate.Function(elementNode)
94 def getReturnValue(self, point, revolutions):
96 if self.function == None:
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()