From 5186d2133df414468014deaa8eddb2fb233b7f5b Mon Sep 17 00:00:00 2001 From: srn Date: Tue, 7 Feb 2006 08:11:24 +0000 Subject: [PATCH] added IParameters Python interface --- src/KERNEL_PY/Makefile.in | 2 +- src/KERNEL_PY/iparameters.py | 186 +++++++++++++++++++++++++++++++++++ 2 files changed, 187 insertions(+), 1 deletion(-) create mode 100755 src/KERNEL_PY/iparameters.py diff --git a/src/KERNEL_PY/Makefile.in b/src/KERNEL_PY/Makefile.in index f5f079c20..8fdcdf806 100755 --- a/src/KERNEL_PY/Makefile.in +++ b/src/KERNEL_PY/Makefile.in @@ -31,7 +31,7 @@ VPATH=.:@srcdir@:@top_srcdir@/idl @COMMENCE@ -EXPORT_PYSCRIPTS = Help.py PyInterp.py salome.py salome_shared_modules.py batchmode_salome.py import_hook.py salome_test.py salome_kernel.py salome_study.py salome_iapp.py salome_ComponentGUI.py omnipatch.py +EXPORT_PYSCRIPTS = Help.py PyInterp.py salome.py salome_shared_modules.py batchmode_salome.py import_hook.py salome_test.py salome_kernel.py salome_study.py salome_iapp.py salome_ComponentGUI.py omnipatch.py iparameters.py EXPORT_SHAREDPYSCRIPTS=kernel_shared_modules.py diff --git a/src/KERNEL_PY/iparameters.py b/src/KERNEL_PY/iparameters.py new file mode 100755 index 000000000..5519e2924 --- /dev/null +++ b/src/KERNEL_PY/iparameters.py @@ -0,0 +1,186 @@ +import salome +import string +import SALOME +import SALOMEDS +import SALOME_Session_idl + +PT_INTEGER = 0 +PT_REAL = 1 +PT_BOOLEAN = 2 +PT_STRING = 3 +PT_REALARRAY = 4 +PT_INTARRAY = 5 +PT_STRARRAY = 6 + +_AP_LISTS_LIST_ = "AP_LISTS_LIST" +_AP_ENTRIES_LIST_ = "AP_ENTRIES_LIST" +_AP_PROPERTIES_LIST_ = "AP_PROPERTIES_LIST" + +vp_session = None + +def getSession(): + global vp_session + if vp_session is None: + vp_session = salome.naming_service.Resolve("/Kernel/Session") + vp_session = vp_session._narrow(SALOME.Session) + pass + return vp_session + +class IParameters: + def __init__(self, attributeParameter): + """Initializes the instance""" + self._ap = attributeParameter + pass + + def append(self, listName, value): + """Appends a value to the named list""" + if self._ap is None: return -1 + v = [] + if self._ap.IsSet(listName, PT_STRARRAY) == 0: + if self._ap.IsSet(_AP_LISTS_LIST_, PT_STRARRAY) == 0: self._ap.SetStrArray(_AP_LISTS_LIST_, v); + if listName != _AP_ENTRIES_LIST_ and listName != _AP_PROPERTIES_LIST_: + self.append(_AP_LISTS_LIST_, listName) + pass + self._ap.SetStrArray(listName, v) + pass + + v = _ap.GetStrArray(listName) + v.append(value) + self._ap.SetStrArray(listName, v) + return (len(v)-1) + + def nbValues(self, listName): + """Returns a number of values in the named list""" + if self._ap is None: return -1 + if self._ap.IsSet(listName, PT_STRARRAY) == 0: return 0 + v = self._ap.GetStrArray(listName) + return len(v) + + def getValues(self, listName): + """Returns a list of values in the named list""" + v = [] + if self._ap is None: return v + if self._ap.IsSet(listName, PT_STRARRAY) == 0: return v + return self._ap.GetStrArray(listName) + + def getLists(self): + """Returns a list of named lists' names""" + v = [] + if self._ap is None: return v + if self._ap.IsSet(_AP_LISTS_LIST_, PT_STRARRAY) == 0: return v + return self._ap.GetStrArray(_AP_LISTS_LIST_) + + def setParameter(self, entry, parameterName, value): + """Sets a value of the named parameter for the entry""" + if self._ap is None: return + v = [] + if self._ap.IsSet(entry, PT_STRARRAY) ==0: + self.append(_AP_ENTRIES_LIST_, entry) #Add the entry to the internal list of entries + self._ap.SetStrArray(entry, v) + pass + + v = self._ap.GetStrArray(entry) + v.append(parameterName) + v.append(value) + self._ap.SetStrArray(entry, v) + pass + + def getParameter(self, entry, parameterName): + """Returns a value of the named parameter for the entry""" + if self._ap is None: return "" + if self._ap.IsSet(entry, PT_STRARRAY) == 0: return "" + v = self._ap.GetStrArray(entry) + length = len(v); + i = 0 + while i