5 import SALOME_Session_idl
15 _AP_LISTS_LIST_ = "AP_LISTS_LIST"
16 _AP_ENTRIES_LIST_ = "AP_ENTRIES_LIST"
17 _AP_PROPERTIES_LIST_ = "AP_PROPERTIES_LIST"
18 _AP_DUMP_PYTHON_ = "AP_DUMP_PYTHON"
24 if vp_session is None:
25 vp_session = salome.naming_service.Resolve("/Kernel/Session")
26 vp_session = vp_session._narrow(SALOME.Session)
32 Interface IParameters was designed to provide a common way to set up
33 named parameters. The interface is initialized by AttributeParameter that
34 is used as a container of stored data.
35 The interface supports 3 types of named parameters:
36 1. Named list - a named list consists of string values.
37 One can append value to list (method 'append'), get a number of values
38 in the list (method 'nbValues'), get all values of the given list
39 (method 'getValues') and get names of all created named lists.
40 2. Parameters - that is a set of named string values associated with some named
41 entity. Parameter consists of tree elements: entity name, a parameter name
42 and a parameter value. Thus for one named entity there are an arbitrary number
43 of pair 'name parameter : value'.
44 One can add a new parameter to entry (method 'setParameter'), get a value of
45 a given named parameter of the given entry (method 'getParameter'), get a number
46 of parameters of the given entry (method 'getNbParameters'), get all names of
47 parameters for the given entry (method 'getAllParameterNames'), get all
48 values of parameters for the entry (method 'getAllParameterValues') and get all
49 stored entries (method 'getEntries')
50 3. Property - a property has a name and a string value.
51 One can set property (method 'setProperty'), getProperty (method 'getProperty') and
52 get a list of all stored properties (method 'getProperties').
55 Methods not mentioned above are private and is not supposed to be used
56 by module's developers.
59 def __init__(self, attributeParameter):
60 """Initializes the instance"""
61 self._ap = attributeParameter
64 def append(self, listName, value):
65 """Appends a value to the named list"""
66 if self._ap is None: return -1
68 if self._ap.IsSet(listName, PT_STRARRAY) == 0:
69 if self._ap.IsSet(_AP_LISTS_LIST_, PT_STRARRAY) == 0: self._ap.SetStrArray(_AP_LISTS_LIST_, v);
70 if listName != _AP_ENTRIES_LIST_ and listName != _AP_PROPERTIES_LIST_:
71 self.append(_AP_LISTS_LIST_, listName)
73 self._ap.SetStrArray(listName, v)
76 v = self._ap.GetStrArray(listName)
78 self._ap.SetStrArray(listName, v)
81 def nbValues(self, listName):
82 """Returns a number of values in the named list"""
83 if self._ap is None: return -1
84 if self._ap.IsSet(listName, PT_STRARRAY) == 0: return 0
85 v = self._ap.GetStrArray(listName)
88 def getValues(self, listName):
89 """Returns a list of values in the named list"""
91 if self._ap is None: return v
92 if self._ap.IsSet(listName, PT_STRARRAY) == 0: return v
93 return self._ap.GetStrArray(listName)
96 """Returns a list of named lists' names"""
98 if self._ap is None: return v
99 if self._ap.IsSet(_AP_LISTS_LIST_, PT_STRARRAY) == 0: return v
100 return self._ap.GetStrArray(_AP_LISTS_LIST_)
102 def setParameter(self, entry, parameterName, value):
103 """Sets a value of the named parameter for the entry"""
104 if self._ap is None: return
106 if self._ap.IsSet(entry, PT_STRARRAY) ==0:
107 self.append(_AP_ENTRIES_LIST_, entry) #Add the entry to the internal list of entries
108 self._ap.SetStrArray(entry, v)
111 v = self._ap.GetStrArray(entry)
112 v.append(parameterName)
114 self._ap.SetStrArray(entry, v)
117 def getParameter(self, entry, parameterName):
118 """Returns a value of the named parameter for the entry"""
119 if self._ap is None: return ""
120 if self._ap.IsSet(entry, PT_STRARRAY) == 0: return ""
121 v = self._ap.GetStrArray(entry)
125 if v[i] == parameterName: return v[i+1]
131 def getAllParameterNames(self, entry):
132 """Returns all parameter names of the given entry"""
135 if self._ap is None: return v
136 if self._ap.IsSet(entry, PT_STRARRAY) == 0: return v
137 v = self._ap.GetStrArray(entry)
147 def getAllParameterValues(self, entry):
148 """Returns all parameter values of the given entry"""
151 if self._ap is None: return v
152 if self._ap.IsSet(entry, PT_STRARRAY) == 0: return v
153 v = self._ap.GetStrArray(entry)
157 values.append(v[i]+1)
163 def getNbParameters(self, entry):
164 """Returns a number of parameters of the entry"""
165 if self._ap is None: return -1
166 if self._ap.IsSet(entry, PT_STRARRAY) == 0: return -1
167 return len(self._ap.GetStrArray(entry))/2
169 def getEntries(self):
170 """Returns all entries"""
172 if self._ap is None: return v
173 if self._ap.IsSet(_AP_ENTRIES_LIST_, PT_STRARRAY) == 0: return v
174 return self._ap.GetStrArray(_AP_ENTRIES_LIST_)
176 def setProperty(self, name, value):
177 """Sets a property value"""
178 if self._ap is None: return
179 if self._ap.IsSet(name, PT_STRING) == 0:
180 self.append(_AP_PROPERTIES_LIST_, name) #Add the property to the internal list of properties
182 self._ap.SetString(name, value)
185 def getProperty(self, name):
186 """Returns a value of the named property"""
187 if self._ap is None: return ""
188 if self._ap.IsSet(name, PT_STRING) == 0: return ""
189 return self._ap.GetString(name)
191 def getProperties(self):
192 """Returns all propetries"""
194 if self._ap is None: return v
195 if self._ap.IsSet(_AP_PROPERTIES_LIST_, PT_STRARRAY) == 0: return v
196 return self._ap.GetStrArray(_AP_PROPERTIES_LIST_)
198 def parseValue(self, value, separator, fromEnd):
199 """Breaks a value string in two parts which is divided by separator."""
202 if fromEnd == 1: pos = value.rfind(separator)
203 else: pos = value.find(separator)
210 part2 = value[pos+1:len(value)]
215 def setDumpPython(self, isDumping):
216 """Enables/Disables the dumping to Python"""
217 if self._ap is None: return
218 _ap.SetBool(_AP_DUMP_PYTHON_, isDumping)
221 def isDumpPython(self):
222 """Returns whether there is the dumping to Python"""
223 if self._ap is None: return 0
224 if self._ap.IsSet(_AP_DUMP_PYTHON_, PT_BOOLEAN) == 0: return 0
225 return self._ap.GetBool(_AP_DUMP_PYTHON_)