1 # Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG
2 # PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 import SALOME_Session_idl
33 _AP_LISTS_LIST_ = "AP_LISTS_LIST"
34 _AP_ENTRIES_LIST_ = "AP_ENTRIES_LIST"
35 _AP_PROPERTIES_LIST_ = "AP_PROPERTIES_LIST"
36 _AP_DUMP_PYTHON_ = "AP_DUMP_PYTHON"
42 if vp_session is None:
43 vp_session = salome.naming_service.Resolve("/Kernel/Session")
44 vp_session = vp_session._narrow(SALOME.Session)
50 Interface IParameters was designed to provide a common way to set up
51 named parameters. The interface is initialized by AttributeParameter that
52 is used as a container of stored data.
53 The interface supports 3 types of named parameters:
54 1. Named list - a named list consists of string values.
55 One can append value to list (method 'append'), get a number of values
56 in the list (method 'nbValues'), get all values of the given list
57 (method 'getValues') and get names of all created named lists.
58 2. Parameters - that is a set of named string values associated with some named
59 entity. Parameter consists of tree elements: entity name, a parameter name
60 and a parameter value. Thus for one named entity there are an arbitrary number
61 of pair 'name parameter : value'.
62 One can add a new parameter to entry (method 'setParameter'), get a value of
63 a given named parameter of the given entry (method 'getParameter'), get a number
64 of parameters of the given entry (method 'getNbParameters'), get all names of
65 parameters for the given entry (method 'getAllParameterNames'), get all
66 values of parameters for the entry (method 'getAllParameterValues') and get all
67 stored entries (method 'getEntries')
68 3. Property - a property has a name and a string value.
69 One can set property (method 'setProperty'), getProperty (method 'getProperty') and
70 get a list of all stored properties (method 'getProperties').
73 Methods not mentioned above are private and is not supposed to be used
74 by module's developers.
77 def __init__(self, attributeParameter):
78 """Initializes the instance"""
79 self._ap = attributeParameter
82 def append(self, listName, value):
83 """Appends a value to the named list"""
84 if self._ap is None: return -1
86 if self._ap.IsSet(listName, PT_STRARRAY) == 0:
87 if self._ap.IsSet(_AP_LISTS_LIST_, PT_STRARRAY) == 0: self._ap.SetStrArray(_AP_LISTS_LIST_, v);
88 if listName != _AP_ENTRIES_LIST_ and listName != _AP_PROPERTIES_LIST_:
89 self.append(_AP_LISTS_LIST_, listName)
91 self._ap.SetStrArray(listName, v)
94 v = self._ap.GetStrArray(listName)
96 self._ap.SetStrArray(listName, v)
99 def nbValues(self, listName):
100 """Returns a number of values in the named list"""
101 if self._ap is None: return -1
102 if self._ap.IsSet(listName, PT_STRARRAY) == 0: return 0
103 v = self._ap.GetStrArray(listName)
106 def getValues(self, listName):
107 """Returns a list of values in the named list"""
109 if self._ap is None: return v
110 if self._ap.IsSet(listName, PT_STRARRAY) == 0: return v
111 return self._ap.GetStrArray(listName)
114 """Returns a list of named lists' names"""
116 if self._ap is None: return v
117 if self._ap.IsSet(_AP_LISTS_LIST_, PT_STRARRAY) == 0: return v
118 return self._ap.GetStrArray(_AP_LISTS_LIST_)
120 def setParameter(self, entry, parameterName, value):
121 """Sets a value of the named parameter for the entry"""
122 if self._ap is None: return
124 if self._ap.IsSet(entry, PT_STRARRAY) ==0:
125 self.append(_AP_ENTRIES_LIST_, entry) #Add the entry to the internal list of entries
126 self._ap.SetStrArray(entry, v)
129 v = self._ap.GetStrArray(entry)
130 v.append(parameterName)
132 self._ap.SetStrArray(entry, v)
135 def getParameter(self, entry, parameterName):
136 """Returns a value of the named parameter for the entry"""
137 if self._ap is None: return ""
138 if self._ap.IsSet(entry, PT_STRARRAY) == 0: return ""
139 v = self._ap.GetStrArray(entry)
143 if v[i] == parameterName: return v[i+1]
149 def getAllParameterNames(self, entry):
150 """Returns all parameter names of the given entry"""
153 if self._ap is None: return v
154 if self._ap.IsSet(entry, PT_STRARRAY) == 0: return v
155 v = self._ap.GetStrArray(entry)
165 def getAllParameterValues(self, entry):
166 """Returns all parameter values of the given entry"""
169 if self._ap is None: return v
170 if self._ap.IsSet(entry, PT_STRARRAY) == 0: return v
171 v = self._ap.GetStrArray(entry)
175 values.append(v[i]+1)
181 def getNbParameters(self, entry):
182 """Returns a number of parameters of the entry"""
183 if self._ap is None: return -1
184 if self._ap.IsSet(entry, PT_STRARRAY) == 0: return -1
185 return len(self._ap.GetStrArray(entry))/2
187 def getEntries(self):
188 """Returns all entries"""
190 if self._ap is None: return v
191 if self._ap.IsSet(_AP_ENTRIES_LIST_, PT_STRARRAY) == 0: return v
192 return self._ap.GetStrArray(_AP_ENTRIES_LIST_)
194 def setProperty(self, name, value):
195 """Sets a property value"""
196 if self._ap is None: return
197 if self._ap.IsSet(name, PT_STRING) == 0:
198 self.append(_AP_PROPERTIES_LIST_, name) #Add the property to the internal list of properties
200 self._ap.SetString(name, value)
203 def getProperty(self, name):
204 """Returns a value of the named property"""
205 if self._ap is None: return ""
206 if self._ap.IsSet(name, PT_STRING) == 0: return ""
207 return self._ap.GetString(name)
209 def getProperties(self):
210 """Returns all propetries"""
212 if self._ap is None: return v
213 if self._ap.IsSet(_AP_PROPERTIES_LIST_, PT_STRARRAY) == 0: return v
214 return self._ap.GetStrArray(_AP_PROPERTIES_LIST_)
216 def parseValue(self, value, separator, fromEnd):
217 """Breaks a value string in two parts which is divided by separator."""
220 if fromEnd == 1: pos = value.rfind(separator)
221 else: pos = value.find(separator)
228 part2 = value[pos+1:len(value)]
233 def setDumpPython(self, isDumping):
234 """Enables/Disables the dumping to Python"""
235 if self._ap is None: return
236 _ap.SetBool(_AP_DUMP_PYTHON_, isDumping)
239 def isDumpPython(self):
240 """Returns whether there is the dumping to Python"""
241 if self._ap is None: return 0
242 if self._ap.IsSet(_AP_DUMP_PYTHON_, PT_BOOLEAN) == 0: return 0
243 return self._ap.GetBool(_AP_DUMP_PYTHON_)