chiark / gitweb /
Add back the ultimaker platform, and made the platform mesh simpler.
[cura.git] / Cura / slice / cura_sf / fabmetheus_utilities / geometry / geometry_utilities / evaluate_enumerables / dictionary_attribute.py
1 """
2 Dictionary object attributes.
3
4 """
5
6 from __future__ import absolute_import
7
8 from fabmetheus_utilities import euclidean
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 _getAccessibleAttribute(attributeName, dictionaryObject):
18         'Get the accessible attribute.'
19         if attributeName in globalNativeFunctionSet:
20                 return getattr(dictionaryObject, attributeName, None)
21         if attributeName in globalGetAccessibleAttributeSet:
22                 stringAttribute = DictionaryAttribute(dictionaryObject)
23                 return getattr(stringAttribute, attributeName, None)
24         return None
25
26
27 class DictionaryAttribute(object):
28         'Class to handle a dictionary.'
29         def __init__(self, dictionaryObject):
30                 'Initialize.'
31                 self.dictionaryObject = dictionaryObject
32
33         def __repr__(self):
34                 "Get the dictionary representation of this DictionaryAttribute."
35                 return str(self.dictionaryObject)
36
37         def count(self, value):
38                 'Get the count.'
39                 countTotal = 0
40                 for key, iteratorValue in self.dictionaryObject.iteritems():
41                         if iteratorValue == value:
42                                 countTotal += 1
43                 return countTotal
44
45         def delete(self, arguments):
46                 'Get the delete dictionary.'
47                 if arguments.__class__ != list:
48                         del self.dictionaryObject[arguments]
49                         return self.dictionaryObject
50                 if len(arguments) == 0:
51                         self.dictionaryObject.clear()
52                         return self.dictionaryObject
53                 if len(arguments) == 1:
54                         del self.dictionaryObject[arguments[0]]
55                         return self.dictionaryObject
56                 for enumeratorKey in euclidean.getEnumeratorKeysAlwaysList(self.dictionaryObject, arguments):
57                         del self.dictionaryObject[enumeratorKey]
58                 return self.dictionaryObject
59
60         def getIsIn(self, value):
61                 'Determine if the value is in.'
62                 return value in self.dictionaryObject
63
64         def getIsNotIn(self, value):
65                 'Determine if the value is in.'
66                 return not(value in self.dictionaryObject)
67
68         def getLength(self):
69                 'Get the length.'
70                 return len(self.dictionaryObject)
71
72         def getMax(self):
73                 'Get the max.'
74                 return max(self.dictionaryObject)
75
76         def getMin(self):
77                 'Get the min.'
78                 return min(self.dictionaryObject)
79
80         def index(self, value):
81                 'Get the index element.'
82                 for key, iteratorValue in self.dictionaryObject.iteritems():
83                         if iteratorValue == value:
84                                 return key
85                 raise ValueError('Value (%s) not found in index in DictionaryAttribute for (%s).' % (value, self.dictionaryObject))
86
87         def length(self):
88                 'Get the length.'
89                 return len(self.dictionaryObject)
90
91         def set(self, itemIndex, value):
92                 'Set value.'
93                 self.dictionaryObject[itemIndex] = value
94                 return self.dictionaryObject
95
96
97 globalAccessibleAttributeDictionary = 'count delete getIsIn getIsNotIn getLength getMax getMin index length set'.split()
98 globalGetAccessibleAttributeSet = set(globalAccessibleAttributeDictionary)
99 globalNativeFunctions = 'clear copy fromkeys get items keys pop popitem remove setdefault update values'.split()
100 globalNativeFunctionSet = set(globalNativeFunctions)