]> SALOME platform Git repositories - modules/yacs.git/blob - src/KERNEL_PY/iparameters.py
Salome HOME
96abfbedc706c95794225fc3754ee81d437103fd
[modules/yacs.git] / src / KERNEL_PY / iparameters.py
1 import salome
2 import string
3 import SALOME
4 import SALOMEDS
5 import SALOME_Session_idl
6
7 PT_INTEGER = 0
8 PT_REAL = 1
9 PT_BOOLEAN = 2
10 PT_STRING = 3
11 PT_REALARRAY = 4
12 PT_INTARRAY = 5
13 PT_STRARRAY = 6
14
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"
19
20 vp_session = None
21
22 def getSession():
23     global vp_session
24     if vp_session is None:
25         vp_session = salome.naming_service.Resolve("/Kernel/Session")
26         vp_session = vp_session._narrow(SALOME.Session)
27         pass
28     return vp_session 
29
30 class IParameters:
31     def __init__(self, attributeParameter):
32         """Initializes the instance"""
33         self._ap = attributeParameter
34         pass
35
36     def append(self, listName, value):
37         """Appends a value to the named list"""
38         if self._ap is None: return -1
39         v = []
40         if self._ap.IsSet(listName, PT_STRARRAY) == 0:
41             if self._ap.IsSet(_AP_LISTS_LIST_, PT_STRARRAY) == 0: self._ap.SetStrArray(_AP_LISTS_LIST_, v);
42             if listName != _AP_ENTRIES_LIST_ and listName != _AP_PROPERTIES_LIST_:
43                 self.append(_AP_LISTS_LIST_, listName)
44                 pass
45             self._ap.SetStrArray(listName, v)
46             pass
47         
48         v = self._ap.GetStrArray(listName)
49         v.append(value)
50         self._ap.SetStrArray(listName, v)
51         return (len(v)-1)
52     
53     def nbValues(self, listName):
54         """Returns a number of values in the named list"""
55         if self._ap is None: return -1
56         if self._ap.IsSet(listName, PT_STRARRAY) == 0: return 0
57         v = self._ap.GetStrArray(listName)
58         return len(v)
59
60     def getValues(self, listName):
61         """Returns a list of values in the named list"""
62         v = []
63         if self._ap is None: return v
64         if self._ap.IsSet(listName, PT_STRARRAY) == 0: return v
65         return self._ap.GetStrArray(listName)
66
67     def getLists(self):
68         """Returns a list of named lists' names"""
69         v = []
70         if self._ap is None: return v
71         if self._ap.IsSet(_AP_LISTS_LIST_, PT_STRARRAY) == 0: return v
72         return self._ap.GetStrArray(_AP_LISTS_LIST_)
73
74     def setParameter(self, entry, parameterName, value):
75         """Sets a value of the named parameter for the entry"""
76         if self._ap is None: return
77         v = []
78         if self._ap.IsSet(entry, PT_STRARRAY) ==0: 
79             self.append(_AP_ENTRIES_LIST_, entry) #Add the entry to the internal list of entries
80             self._ap.SetStrArray(entry, v)
81             pass
82         
83         v = self._ap.GetStrArray(entry)
84         v.append(parameterName)
85         v.append(value)
86         self._ap.SetStrArray(entry, v)
87         pass
88
89     def getParameter(self, entry, parameterName):
90         """Returns a value of the named parameter for the entry"""
91         if self._ap is None: return ""
92         if self._ap.IsSet(entry, PT_STRARRAY) == 0: return ""
93         v = self._ap.GetStrArray(entry)
94         length = len(v);
95         i = 0
96         while i<length:
97             if v[i] == parameterName: return v[i+1]
98             i+=1
99             pass
100         
101         return ""
102
103     def getAllParameterNames(self, entry):
104         """Returns all parameter names of the given entry"""
105         v = []
106         names = []
107         if self._ap is None: return v
108         if self._ap.IsSet(entry, PT_STRARRAY) == 0: return v
109         v = self._ap.GetStrArray(entry)
110         length = len(v)
111         i = 0
112         while i<length:
113             names.append(v[i])
114             i+=2
115             pass
116         
117         return names
118
119     def getAllParameterValues(self, entry):
120         """Returns all parameter values of the given entry"""
121         v = []
122         values = []
123         if self._ap is None: return v
124         if self._ap.IsSet(entry, PT_STRARRAY) == 0: return v
125         v = self._ap.GetStrArray(entry)
126         length = len(v)
127         i = 1
128         while i<length:
129             values.append(v[i]+1)
130             i+=2
131             pass
132         
133         return values
134
135     def getNbParameters(self, entry):
136         """Returns a number of parameters of the entry"""
137         if self._ap is None: return -1
138         if self._ap.IsSet(entry, PT_STRARRAY) == 0: return -1
139         return len(self._ap.GetStrArray(entry))/2
140
141     def getEntries(self):
142         """Returns all entries"""
143         v = []
144         if self._ap is None: return v
145         if self._ap.IsSet(_AP_ENTRIES_LIST_, PT_STRARRAY) == 0: return v
146         return self._ap.GetStrArray(_AP_ENTRIES_LIST_)
147
148     def setProperty(self, name, value):
149         """Sets a property value"""
150         if self._ap is None: return
151         if self._ap.IsSet(name, PT_STRING) == 0: 
152             self.append(_AP_PROPERTIES_LIST_, name) #Add the property to the internal list of properties
153             pass
154         self._ap.SetString(name, value)
155         pass
156
157     def getProperty(self, name):
158         """Returns a value of the named property"""
159         if self._ap is None: return ""
160         if self._ap.IsSet(name, PT_STRING) == 0: return ""
161         return self._ap.GetString(name)
162
163     def getProperties(self):
164         """Returns all propetries"""
165         v = []
166         if self._ap is None: return v
167         if self._ap.IsSet(_AP_PROPERTIES_LIST_, PT_STRARRAY) == 0: return v
168         return self._ap.GetStrArray(_AP_PROPERTIES_LIST_)
169
170     def parseValue(self, value, separator, fromEnd):
171         """Breaks a value string in two parts which is divided by separator."""
172         v = []
173         pos = - 1
174         if fromEnd == 1: pos = value.rfind(separator)
175         else: pos = value.find(separator)
176
177         if pos < 0: 
178             v.append(value)
179             return v
180         
181         part1 = value[0:pos]
182         part2 = value[pos+1:len(value)]
183         v.append(part1)
184         v.append(part2)
185         return v
186
187     def setDumpPython(self, isDumping):
188         """Enables/Disables the dumping to Python"""
189         if self._ap is None: return
190         _ap.SetBool(_AP_DUMP_PYTHON_, isDumping)
191         pass
192
193     def isDumpPython(self):
194         """Returns whether there is the dumping to Python"""
195         if self._ap is None: return 0
196         if self._ap.IsSet(_AP_DUMP_PYTHON_, PT_BOOLEAN) == 0: return 0
197         return self._ap.GetBool(_AP_DUMP_PYTHON_)
198
199     pass