6 from __future__ import absolute_import
8 from fabmetheus_utilities.geometry.geometry_utilities import evaluate
11 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
12 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
13 __date__ = '$Date: 2008/02/05 $'
14 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
17 def processChildNodesByIndexValue( elementNode, function, index, indexValue, value ):
18 "Process childNodes by index value."
19 if indexValue.indexName != '':
20 function.localDictionary[ indexValue.indexName ] = index
21 if indexValue.valueName != '':
22 function.localDictionary[ indexValue.valueName ] = value
23 function.processChildNodes(elementNode)
25 def processElementNode(elementNode):
26 "Process the xml element."
27 if elementNode.xmlObject == None:
28 elementNode.xmlObject = IndexValue(elementNode)
29 if elementNode.xmlObject.inSplitWords == None:
31 xmlProcessor = elementNode.getXMLProcessor()
32 if len( xmlProcessor.functions ) < 1:
33 print('Warning, "for" element is not in a function in processElementNode in for.py for:')
36 function = xmlProcessor.functions[-1]
37 inValue = evaluate.getEvaluatedExpressionValueBySplitLine(elementNode, elementNode.xmlObject.inSplitWords)
38 if inValue.__class__ == list or inValue.__class__ == str:
39 for index, value in enumerate( inValue ):
40 processChildNodesByIndexValue( elementNode, function, index, elementNode.xmlObject, value )
42 if inValue.__class__ == dict:
43 inKeys = inValue.keys()
46 processChildNodesByIndexValue( elementNode, function, inKey, elementNode.xmlObject, inValue[ inKey ] )
49 class IndexValue(object):
50 "Class to get the in attribute, the index name and the value name."
51 def __init__(self, elementNode):
53 self.inSplitWords = None
55 if 'index' in elementNode.attributes:
56 self.indexName = elementNode.attributes['index']
58 if 'value' in elementNode.attributes:
59 self.valueName = elementNode.attributes['value']
60 if 'in' in elementNode.attributes:
61 self.inSplitWords = evaluate.getEvaluatorSplitWords( elementNode.attributes['in'] )
63 print('Warning, could not find the "in" attribute in IndexValue in for.py for:')
66 if len( self.inSplitWords ) < 1:
67 self.inSplitWords = None
68 print('Warning, could not get split words for the "in" attribute in IndexValue in for.py for:')