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 / list_attribute.py
1 """
2 List 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, listObject):
18         'Get the accessible attribute.'
19         if attributeName in globalNativeFunctionSet:
20                 return getattr(listObject, attributeName, None)
21         if attributeName in globalGetAccessibleAttributeSet:
22                 stringAttribute = ListAttribute(listObject)
23                 return getattr(stringAttribute, attributeName, None)
24         return None
25
26
27 class ListAttribute(object):
28         'Class to handle a list.'
29         def __init__(self, listObject):
30                 'Initialize.'
31                 self.listObject = listObject
32
33         def __repr__(self):
34                 "Get the list representation of this ListAttribute."
35                 return str(self.listObject)
36
37         def add(self, value):
38                 'Get the concatenation, same as append.'
39                 return self.listObject + [value]
40
41         def copy(self):
42                 'Get the copy.'
43                 return self.listObject[:]
44
45         def delete(self, arguments):
46                 'Get the delete list.'
47                 deleteList = []
48                 enumeratorSet = set(euclidean.getEnumeratorKeysAlwaysList(self.listObject, arguments))
49                 for elementIndex, element in enumerate(self.listObject):
50                         if elementIndex not in enumeratorSet:
51                                 deleteList.append(element)
52                 return deleteList
53
54         def get(self, itemIndex):
55                 'Get value by index'
56                 return self.listObject[itemIndex]
57
58         def getExpansion(self, items):
59                 'Get the concatenated copies.'
60                 expansion = []
61                 for itemIndex in xrange(items):
62                         expansion += self.listObject[:]
63                 return expansion
64
65         def getIsIn(self, value):
66                 'Determine if the value is in.'
67                 return value in self.listObject
68
69         def getIsNotIn(self, value):
70                 'Determine if the value is in.'
71                 return not(value in self.listObject)
72
73         def getLength(self):
74                 'Get the length.'
75                 return len(self.listObject)
76
77         def getMax(self):
78                 'Get the max.'
79                 return max(self.listObject)
80
81         def getMin(self):
82                 'Get the min.'
83                 return min(self.listObject)
84
85         def insert(self, insertIndex, value):
86                 'Get the insert list.'
87                 if insertIndex < 0:
88                         insertIndex += len(self.listObject)
89                 insertIndex = max(0, insertIndex)
90                 return self.listObject[: insertIndex] + [value] + self.listObject[insertIndex :]
91
92         def keys(self):
93                 'Get the keys.'
94                 return range(len(self.listObject))
95
96         def length(self):
97                 'Get the length.'
98                 return len(self.listObject)
99
100         def rindex(self, value):
101                 'Get the rindex element.'
102                 for elementIndex, element in enumerate(self.listObject):
103                         if element == value:
104                                 return elementIndex
105                 raise ValueError('Value (%s) not found in rindex in ListAttribute for (%s).' % (value, self.listObject))
106
107         def set(self, itemIndex, value):
108                 'Set value.'
109                 self.listObject[itemIndex] = value
110                 return self.listObject
111
112         def values(self, arguments=None):
113                 'Get the values.'
114                 return self.listObject
115
116
117 globalAccessibleAttributeDictionary = 'add copy count delete get getExpansion getIsIn getIsNotIn getLength getMax getMin'.split()
118 globalAccessibleAttributeDictionary += 'insert keys length rindex set values'.split()
119 globalGetAccessibleAttributeSet = set(globalAccessibleAttributeDictionary)
120 globalNativeFunctions = 'append extend index pop remove reverse sort'.split()
121 globalNativeFunctionSet = set(globalNativeFunctions)