1 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
26 import SALOME_Session_idl
36 _AP_LISTS_LIST_ = "AP_LISTS_LIST"
37 _AP_ENTRIES_LIST_ = "AP_ENTRIES_LIST"
38 _AP_PROPERTIES_LIST_ = "AP_PROPERTIES_LIST"
39 _AP_DUMP_PYTHON_ = "AP_DUMP_PYTHON"
45 if vp_session is None:
46 vp_session = salome.naming_service.Resolve("/Kernel/Session")
47 vp_session = vp_session._narrow(SALOME.Session)
53 Interface IParameters was designed to provide a common way to set up
54 named parameters. The interface is initialized by AttributeParameter that
55 is used as a container of stored data.
56 The interface supports 3 types of named parameters:
57 1. Named list - a named list consists of string values.
58 One can append value to list (method 'append'), get a number of values
59 in the list (method 'nbValues'), get all values of the given list
60 (method 'getValues') and get names of all created named lists.
61 2. Parameters - that is a set of named string values associated with some named
62 entity. Parameter consists of tree elements: entity name, a parameter name
63 and a parameter value. Thus for one named entity there are an arbitrary number
64 of pair 'name parameter : value'.
65 One can add a new parameter to entry (method 'setParameter'), get a value of
66 a given named parameter of the given entry (method 'getParameter'), get a number
67 of parameters of the given entry (method 'getNbParameters'), get all names of
68 parameters for the given entry (method 'getAllParameterNames'), get all
69 values of parameters for the entry (method 'getAllParameterValues') and get all
70 stored entries (method 'getEntries')
71 3. Property - a property has a name and a string value.
72 One can set property (method 'setProperty'), getProperty (method 'getProperty') and
73 get a list of all stored properties (method 'getProperties').
76 Methods not mentioned above are private and is not supposed to be used
77 by module's developers.
80 def __init__(self, attributeParameter):
81 """Initializes the instance"""
82 self._ap = attributeParameter
85 def append(self, listName, value):
86 """Appends a value to the named list"""
87 if self._ap is None: return -1
89 if self._ap.IsSet(listName, PT_STRARRAY) == 0:
90 if self._ap.IsSet(_AP_LISTS_LIST_, PT_STRARRAY) == 0: self._ap.SetStrArray(_AP_LISTS_LIST_, v);
91 if listName != _AP_ENTRIES_LIST_ and listName != _AP_PROPERTIES_LIST_:
92 self.append(_AP_LISTS_LIST_, listName)
94 self._ap.SetStrArray(listName, v)
97 v = self._ap.GetStrArray(listName)
99 self._ap.SetStrArray(listName, v)
102 def nbValues(self, listName):
103 """Returns a number of values in the named list"""
104 if self._ap is None: return -1
105 if self._ap.IsSet(listName, PT_STRARRAY) == 0: return 0
106 v = self._ap.GetStrArray(listName)
109 def getValues(self, listName):
110 """Returns a list of values in the named list"""
112 if self._ap is None: return v
113 if self._ap.IsSet(listName, PT_STRARRAY) == 0: return v
114 return self._ap.GetStrArray(listName)
117 """Returns a list of named lists' names"""
119 if self._ap is None: return v
120 if self._ap.IsSet(_AP_LISTS_LIST_, PT_STRARRAY) == 0: return v
121 return self._ap.GetStrArray(_AP_LISTS_LIST_)
123 def setParameter(self, entry, parameterName, value):
124 """Sets a value of the named parameter for the entry"""
125 if self._ap is None: return
127 if self._ap.IsSet(entry, PT_STRARRAY) ==0:
128 self.append(_AP_ENTRIES_LIST_, entry) #Add the entry to the internal list of entries
129 self._ap.SetStrArray(entry, v)
132 v = self._ap.GetStrArray(entry)
133 v.append(parameterName)
135 self._ap.SetStrArray(entry, v)
138 def getParameter(self, entry, parameterName):
139 """Returns a value of the named parameter for the entry"""
140 if self._ap is None: return ""
141 if self._ap.IsSet(entry, PT_STRARRAY) == 0: return ""
142 v = self._ap.GetStrArray(entry)
146 if v[i] == parameterName: return v[i+1]
152 def getAllParameterNames(self, entry):
153 """Returns all parameter names of the given entry"""
156 if self._ap is None: return v
157 if self._ap.IsSet(entry, PT_STRARRAY) == 0: return v
158 v = self._ap.GetStrArray(entry)
168 def getAllParameterValues(self, entry):
169 """Returns all parameter values of the given entry"""
172 if self._ap is None: return v
173 if self._ap.IsSet(entry, PT_STRARRAY) == 0: return v
174 v = self._ap.GetStrArray(entry)
178 values.append(v[i]+1)
184 def getNbParameters(self, entry):
185 """Returns a number of parameters of the entry"""
186 if self._ap is None: return -1
187 if self._ap.IsSet(entry, PT_STRARRAY) == 0: return -1
188 return len(self._ap.GetStrArray(entry))/2
190 def getEntries(self):
191 """Returns all entries"""
193 if self._ap is None: return v
194 if self._ap.IsSet(_AP_ENTRIES_LIST_, PT_STRARRAY) == 0: return v
195 return self._ap.GetStrArray(_AP_ENTRIES_LIST_)
197 def setProperty(self, name, value):
198 """Sets a property value"""
199 if self._ap is None: return
200 if self._ap.IsSet(name, PT_STRING) == 0:
201 self.append(_AP_PROPERTIES_LIST_, name) #Add the property to the internal list of properties
203 self._ap.SetString(name, value)
206 def getProperty(self, name):
207 """Returns a value of the named property"""
208 if self._ap is None: return ""
209 if self._ap.IsSet(name, PT_STRING) == 0: return ""
210 return self._ap.GetString(name)
212 def getProperties(self):
213 """Returns all propetries"""
215 if self._ap is None: return v
216 if self._ap.IsSet(_AP_PROPERTIES_LIST_, PT_STRARRAY) == 0: return v
217 return self._ap.GetStrArray(_AP_PROPERTIES_LIST_)
219 def parseValue(self, value, separator, fromEnd):
220 """Breaks a value string in two parts which is divided by separator."""
223 if fromEnd == 1: pos = value.rfind(separator)
224 else: pos = value.find(separator)
231 part2 = value[pos+1:len(value)]
236 def setDumpPython(self, isDumping):
237 """Enables/Disables the dumping to Python"""
238 if self._ap is None: return
239 _ap.SetBool(_AP_DUMP_PYTHON_, isDumping)
242 def isDumpPython(self):
243 """Returns whether there is the dumping to Python"""
244 if self._ap is None: return 0
245 if self._ap.IsSet(_AP_DUMP_PYTHON_, PT_BOOLEAN) == 0: return 0
246 return self._ap.GetBool(_AP_DUMP_PYTHON_)