From: barate Date: Thu, 31 Mar 2011 09:57:05 +0000 (+0000) Subject: Added doc for salome.kernel.varlist module X-Git-Tag: Start_BR_19998_21191~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5ca8870e64991433daff8408ff89c3d0622e784d;p=modules%2Fkernel.git Added doc for salome.kernel.varlist module --- diff --git a/doc/docutils/docapi.rst b/doc/docutils/docapi.rst index 9634eb428..b0b2b5348 100644 --- a/doc/docutils/docapi.rst +++ b/doc/docutils/docapi.rst @@ -44,3 +44,10 @@ code documentation included in source python files. .. automodule:: salome.kernel.studyedit :members: + + +:mod:`varlist` -- Handle Exchange Variables +------------------------------------------- + +.. automodule:: salome.kernel.varlist + :members: diff --git a/src/KERNEL_PY/kernel/varlist.py b/src/KERNEL_PY/kernel/varlist.py index 538c891cc..a2cadeb47 100644 --- a/src/KERNEL_PY/kernel/varlist.py +++ b/src/KERNEL_PY/kernel/varlist.py @@ -14,9 +14,17 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# See http://www.salome-platform.org/ or +# email : webmaster.salome@opencascade.com # +""" +This module provides classes and functions to handle "Exchange Variables", +i.e. description of variables to be exchanged between a supervision code and a +computation code. These Exchange Variables can be stored in a SObject in +Salome study. +""" + from studyedit import getStudyEditor DEFAULT_NAME = "Variables" @@ -25,8 +33,13 @@ OUTPUT_VAR_NAMES = "ExchangeVariables.OutputVarNames" REF_ENTRY = "ExchangeVariables.RefEntry" class Variable: + """ + This class describes a single variable. For now, it is only described by + its name. Other attributes are reserved for future use. + """ - def __init__(self, name, dimension = [], minValue = None, maxValue = None, initialValue = None): + def __init__(self, name, dimension = [], minValue = None, maxValue = None, + initialValue = None): self.name = name # Reserved for future use @@ -37,15 +50,62 @@ class Variable: class ExchangeVariables: + """ + This class describes "Exchange Variables", i.e. a structure containing all + the necessary information to exchange variables between a supervision code + and a computation code. + + .. attribute:: inputVarList + + This instance attribute is a list of :class:`Variable` objects, + describing the input variables for the computation code. + + .. attribute:: outputVarList - def __init__(self, inputVarList = [], outputVarList = [], refEntry = None): + This instance attribute is a list of :class:`Variable` objects, + describing the output variables for the computation code. + + .. attribute:: refEntry + + This instance attribute is optional and can be used to store a + reference to a Salome entry containing an "Exchange Variable" SObject + that was used to build this one (when the current object has been built + by selecting variables of interest in a list of potential variables). + + """ + + def __init__(self, inputVarList = [], outputVarList = [], + refEntry = None): self.inputVarList = inputVarList self.outputVarList = outputVarList self.refEntry = refEntry def createSObjectForExchangeVariables(fatherSobj, exchangeVariables, - name = DEFAULT_NAME, icon = None, typeId = None): + name = DEFAULT_NAME, + icon = None, typeId = None): + """ + Create a SObject to store an :class:`ExchangeVariables` instance. + + :type fatherSobj: SObject + :param fatherSobj: parent of the SObject to create. + + :type exchangeVariables: :class:`ExchangeVariables` + :param exchangeVariables: :class:`ExchangeVariables` instance to store in + Salome study. + + :type name: string + :param name: name of the SObject to create. + + :type icon: string + :param icon: icon of the SObject to create. + + :type typeId: integer + :param typeId: type of the SObject to create. + + :return: the newly created SObject. + + """ studyId = fatherSobj.GetStudy()._get_StudyId() editor = getStudyEditor(studyId) sobj = editor.createItem(fatherSobj, @@ -55,7 +115,18 @@ def createSObjectForExchangeVariables(fatherSobj, exchangeVariables, _setSObjectForExchangeVariables(editor, sobj, exchangeVariables) def updateSObjectForExchangeVariables(sobj, exchangeVariables, - name = DEFAULT_NAME, icon = None, typeId = None): + name = DEFAULT_NAME, + icon = None, typeId = None): + """ + Update an existing SObject storing an :class:`ExchangeVariables` instance. + + :type sobj: SObject + :param sobj: the SObject to update. + + See :func:`createSObjectForExchangeVariables` for the description of the + other parameters. + + """ studyId = sobj.GetStudy()._get_StudyId() editor = getStudyEditor(studyId) editor.setItem(sobj, name = name, icon = icon, typeId = typeId) @@ -64,18 +135,31 @@ def updateSObjectForExchangeVariables(sobj, exchangeVariables, def _setSObjectForExchangeVariables(editor, sobj, exchangeVariables): attr = editor.builder.FindOrCreateAttribute(sobj, "AttributeParameter") - attr.SetStrArray(INPUT_VAR_NAMES, [x.name for x in exchangeVariables.inputVarList]) - attr.SetStrArray(OUTPUT_VAR_NAMES, [x.name for x in exchangeVariables.outputVarList]) + attr.SetStrArray(INPUT_VAR_NAMES, + [x.name for x in exchangeVariables.inputVarList]) + attr.SetStrArray(OUTPUT_VAR_NAMES, + [x.name for x in exchangeVariables.outputVarList]) if exchangeVariables.refEntry is not None: attr.SetString(REF_ENTRY, exchangeVariables.refEntry) def getExchangeVariablesFromSObject(sobj): + """ + Get an :class:`ExchangeVariables` instance from a SObject that stores it. + + :type sobj: SObject + :param sobj: the SObject from which to read the :class:`ExchangeVariables` + instance. + + :return: the newly created :class:`ExchangeVariables` instance. + + """ (found, attr) = sobj.FindAttribute("AttributeParameter") if not found: return None refEntry = None if attr.IsSet(REF_ENTRY, 3): refEntry = attr.GetString(REF_ENTRY) - return ExchangeVariables([Variable(name) for name in attr.GetStrArray(INPUT_VAR_NAMES)], - [Variable(name) for name in attr.GetStrArray(OUTPUT_VAR_NAMES)], - refEntry) + return ExchangeVariables( + [Variable(name) for name in attr.GetStrArray(INPUT_VAR_NAMES)], + [Variable(name) for name in attr.GetStrArray(OUTPUT_VAR_NAMES)], + refEntry)