From f831523ce0e1abd14a65f97312ebb0e176d6cd70 Mon Sep 17 00:00:00 2001 From: srn Date: Thu, 2 Feb 2006 09:17:37 +0000 Subject: [PATCH] added a VisualParameters interface --- bin/vparams.py | 334 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 334 insertions(+) create mode 100644 bin/vparams.py diff --git a/bin/vparams.py b/bin/vparams.py new file mode 100644 index 000000000..8528a7748 --- /dev/null +++ b/bin/vparams.py @@ -0,0 +1,334 @@ +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 + +_ONE_ENTRY_DBL_ARGS_LENGTH = 12 +_IDX_COLOR_R = 0 +_IDX_COLOR_G = 1 +_IDX_COLOR_B = 2 +_IDX_TRANSPARENCY = 3 +_IDX_LINE_WIDTH = 4 +_IDX_CLIPPING = 5 +_CLIPPING_LENGTH = 6 + +_ONE_ENTRY_INT_ARGS_LENGTH = 4 +_IDX_DISPLAY_MODE = 0 +_IDX_DISPLAYED = 1 +_IDX_TYPE = 2 + +_AP_ENTRIES = 0 +_AP_DOUBLE_ARGS = 1 +_AP_INT_ARGS = 1 +_AP_MODULE_NAME = 1 + +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 + +def getStateParameters(study, savePoint): + """Returns AttributeParameters that corresponds the given savePoint""" + builder = study.NewBuilder(); + so = study.FindComponent("Interface Applicative"); + if so is None: + so = builder.NewComponent("Interface Applicative") + pass + newSO = builder.NewObjectToTag(so, savePoint); + return builder.FindOrCreateAttribute(newSO, "AttributeParameter"); + + +class VisualParameters: + def __init__(self, study, moduleName, savePoint): + """Initializes the instance""" + main_ap = getStateParameters(study, savePoint) + main_so = main_ap.GetSObject() + + it = study.NewChildIterator(main_so) + while it.More(): + so = it.Value() + isFound, param = so.FindAttribute("AttributeParameter") + if isFound: + param = param._narrow(SALOMEDS.AttributeParameter) + if param.IsSet(_AP_MODULE_NAME, PT_STRING) == 0: + continue + if param.GetString(_AP_MODULE_NAME) == moduleName: + self._ap = param + return + it.Next() + pass + + builder = study.NewBuilder() + so = builder.NewObject(main_so) + self._ap = builder.FindOrCreateAttribute(so, "AttributeParameter") + self.setModuleName(moduleName) + pass + + def setModuleName(self, moduleName): + """Sets a name of a GUI module to mark the save point for the module""" + if self._ap is None: return + self._ap.SetString(_AP_MODULE_NAME, moduleName) + pass + + def setColor(self, entry, color): + """Sets a color of the entry""" + entryID = self.getEntryID(entry) + if entryID < 0 and len(color) < 3: return + if self._ap.IsSet(_AP_DOUBLE_ARGS, _PT_REALARRAY) == 0: return + vr = self._ap.GetRealArray(_AP_DOUBLE_ARGS) + idx = entryID*_ONE_ENTRY_DBL_ARGS_LENGTH + + vr[idx+_IDX_COLOR_R] = color[0] + vr[idx+_IDX_COLOR_G] = color[1] + vr[idx+_IDX_COLOR_B] = color[2] + self._ap.SetRealArray(_AP_DOUBLE_ARGS, vr) + pass + + def setTransparency(self, entry, value): + """Sets a transparency of the entry""" + entryID = self.getEntryID(entry) + if entryID < 0: return + if self._ap.IsSet(_AP_DOUBLE_ARGS, _PT_REALARRAY) == 0: return + vr = self._ap.GetRealArray(_AP_DOUBLE_ARGS) + idx = entryID*_ONE_ENTRY_DBL_ARGS_LENGTH + + vr[idx+_IDX_TRANSPARENCY] = value + self._ap.SetRealArray(_AP_DOUBLE_ARGS, vr) + pass + + def setLineWidth(self, entry, value): + """Sets a line width of the entry""" + entryID = self.getEntryID(entry) + if entryID < 0: return + if self._ap.IsSet(_AP_DOUBLE_ARGS, _PT_REALARRAY) == 0: return + vr = self._ap.GetRealArray(_AP_DOUBLE_ARGS) + idx = entryID*_ONE_ENTRY_DBL_ARGS_LENGTH + + vr[idx+_IDX_LINE_WIDTH] = value + self._ap.SetRealArray(_AP_DOUBLE_ARGS, vr) + pass + + def setPresentationMode(self, entry, mode): + """Sets a presentation mode of the displayed object""" + entryID = self.getEntryID(entry) + if entryID < 0: return + if self._ap.IsSet(_AP_INT_ARGS, _PT_INTARRAY) == 0: return + vr = self._ap.GetIntArray(_AP_INT_ARGS); + idx = entryID*_ONE_ENTRY_INT_ARGS_LENGTH + + vr[idx+_IDX_DISPLAY_MODE] = mode + self._ap.SetIntArray(_AP_INT_ARGS, vr) + pass + + def setDisplayed(self, entry): + """Sets a flag Displayed to True""" + entryID = self.getEntryID(entry) + if entryID < 0: return + if self._ap.IsSet(_AP_INT_ARGS, _PT_INTARRAY) == 0: return + vr = self._ap.GetIntArray(_AP_INT_ARGS); + idx = entryID*_ONE_ENTRY_INT_ARGS_LENGTH; + + vr[idx+_IDX_DISPLAYED] = 1 + self._ap.SetIntArray(_AP_INT_ARGS, vr) + pass + + def setTypeOfDisplayed(self, entry, type): + """Sets a type of the displayed object""" + entryID = self.getEntryID(entry) + if entryID < 0: return + if self._ap.IsSet(_AP_INT_ARGS, _PT_INTARRAY) == 0: return + vr = self._ap.GetIntArray(_AP_INT_ARGS); + idx = entryID*_ONE_ENTRY_INT_ARGS_LENGTH + + vr[idx+_IDX_TYPE] = type + self._ap.SetIntArray(_AP_INT_ARGS, vr) + pass + + def setClipping(self, entry, clipping): + """Sets clipping planes for the entry""" + entryID = self.getEntryID(entry) + if entryID < 0: return + if self._ap.IsSet(_AP_DOUBLE_ARGS, _PT_REALARRAY) == 0: return + vr = self._ap.GetRealArray(_AP_DOUBLE_ARGS) + idx = entryID*_ONE_ENTRY_DBL_ARGS_LENGTH + + i = 0 + while i