chiark / gitweb /
Move SF into its own directory, to seperate SF and Cura. Rename newui to gui.
[cura.git] / Cura / cura_sf / fabmetheus_utilities / geometry / statements / for.py
1 """
2 Polygon path.
3
4 """
5
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.
8 import __init__
9
10 from fabmetheus_utilities.geometry.geometry_utilities import evaluate
11
12
13 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
14 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
15 __date__ = '$Date: 2008/02/05 $'
16 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
17
18
19 def processChildNodesByIndexValue( elementNode, function, index, indexValue, value ):
20         "Process childNodes by index value."
21         if indexValue.indexName != '':
22                 function.localDictionary[ indexValue.indexName ] = index
23         if indexValue.valueName != '':
24                 function.localDictionary[ indexValue.valueName ] = value
25         function.processChildNodes(elementNode)
26
27 def processElementNode(elementNode):
28         "Process the xml element."
29         if elementNode.xmlObject == None:
30                 elementNode.xmlObject = IndexValue(elementNode)
31         if elementNode.xmlObject.inSplitWords == None:
32                 return
33         xmlProcessor = elementNode.getXMLProcessor()
34         if len( xmlProcessor.functions ) < 1:
35                 print('Warning, "for" element is not in a function in processElementNode in for.py for:')
36                 print(elementNode)
37                 return
38         function = xmlProcessor.functions[-1]
39         inValue = evaluate.getEvaluatedExpressionValueBySplitLine(elementNode, elementNode.xmlObject.inSplitWords)
40         if inValue.__class__ == list or inValue.__class__ == str:
41                 for index, value in enumerate( inValue ):
42                         processChildNodesByIndexValue( elementNode, function, index, elementNode.xmlObject, value )
43                 return
44         if inValue.__class__ == dict:
45                 inKeys = inValue.keys()
46                 inKeys.sort()
47                 for inKey in inKeys:
48                         processChildNodesByIndexValue( elementNode, function, inKey, elementNode.xmlObject, inValue[ inKey ] )
49
50
51 class IndexValue:
52         "Class to get the in attribute, the index name and the value name."
53         def __init__(self, elementNode):
54                 "Initialize."
55                 self.inSplitWords = None
56                 self.indexName = ''
57                 if 'index' in elementNode.attributes:
58                         self.indexName = elementNode.attributes['index']
59                 self.valueName = ''
60                 if 'value' in elementNode.attributes:
61                         self.valueName = elementNode.attributes['value']
62                 if 'in' in elementNode.attributes:
63                         self.inSplitWords = evaluate.getEvaluatorSplitWords( elementNode.attributes['in'] )
64                 else:
65                         print('Warning, could not find the "in" attribute in IndexValue in for.py for:')
66                         print(elementNode)
67                         return
68                 if len( self.inSplitWords ) < 1:
69                         self.inSplitWords = None
70                         print('Warning, could not get split words for the "in" attribute in IndexValue in for.py for:')
71                         print(elementNode)
72