chiark / gitweb /
Add back the ultimaker platform, and made the platform mesh simpler.
[cura.git] / Cura / slice / cura_sf / fabmetheus_utilities / geometry / statements / for.py
1 """
2 Polygon path.
3
4 """
5
6 from __future__ import absolute_import
7
8 from fabmetheus_utilities.geometry.geometry_utilities import evaluate
9
10
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'
15
16
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)
24
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:
30                 return
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:')
34                 print(elementNode)
35                 return
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 )
41                 return
42         if inValue.__class__ == dict:
43                 inKeys = inValue.keys()
44                 inKeys.sort()
45                 for inKey in inKeys:
46                         processChildNodesByIndexValue( elementNode, function, inKey, elementNode.xmlObject, inValue[ inKey ] )
47
48
49 class IndexValue(object):
50         "Class to get the in attribute, the index name and the value name."
51         def __init__(self, elementNode):
52                 "Initialize."
53                 self.inSplitWords = None
54                 self.indexName = ''
55                 if 'index' in elementNode.attributes:
56                         self.indexName = elementNode.attributes['index']
57                 self.valueName = ''
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'] )
62                 else:
63                         print('Warning, could not find the "in" attribute in IndexValue in for.py for:')
64                         print(elementNode)
65                         return
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:')
69                         print(elementNode)
70