]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Reorganized Python modules for parametric studies (and corresponding doc)
authorbarate <barate>
Fri, 22 Apr 2011 14:01:25 +0000 (14:01 +0000)
committerbarate <barate>
Fri, 22 Apr 2011 14:01:25 +0000 (14:01 +0000)
configure.ac
doc/docutils/Makefile.am
doc/docutils/docapi.rst
doc/docutils/kernel.rst [new file with mode: 0644]
doc/docutils/parametric.rst [new file with mode: 0644]
src/KERNEL_PY/kernel/Makefile.am
src/KERNEL_PY/kernel/parametric/Makefile.am [new file with mode: 0644]
src/KERNEL_PY/kernel/parametric/__init__.py [new file with mode: 0644]
src/KERNEL_PY/kernel/parametric/compo_utils.py [new file with mode: 0644]
src/KERNEL_PY/kernel/parametric/study_exchange_vars.py [new file with mode: 0644]
src/KERNEL_PY/kernel/varlist.py [deleted file]

index 95133756f65094ec643bf9502a95e2464000b6ab..afe7ef2f35e6509e8ae8eb2a446df47edb2a8fb0 100644 (file)
@@ -578,6 +578,7 @@ AC_OUTPUT([ \
   src/KERNEL_PY/Makefile \
   src/KERNEL_PY/kernel/Makefile \
   src/KERNEL_PY/kernel/logconfig.py \
+  src/KERNEL_PY/kernel/parametric/Makefile \
   src/Launcher/Makefile \
   src/LifeCycleCORBA/Makefile \
   src/LifeCycleCORBA/Test/Makefile \
index dbed1cc9155370d0c671f992e2205630efd0d77b..b8bee607e142f0a800b6b09a5d9c78a0038a167c 100644 (file)
@@ -70,7 +70,9 @@ RSTFILES= \
        index.rst \
        overview.rst \
        docapi.rst \
-       salomepypkg.rst
+       salomepypkg.rst \
+       kernel.rst \
+       parametric.rst
 
 EXTRA_DIST+= $(RSTFILES)
 
index b0b2b53488273dbf6c05511a6a3c7eccd89c8e12..fd36cbc191f48cd2b38d665a8333bd6884ab04a7 100644 (file)
@@ -7,47 +7,8 @@ This section describes the python modules of the
 ``salome.kernel`` python package. The main part is generated from the
 code documentation included in source python files.
 
-:mod:`salome.kernel` -- Package containing the KERNEL python utilities
-======================================================================
+.. toctree::
+   :maxdepth: 3
 
-:mod:`deprecation` -- Indication of deprecated modules and functions
---------------------------------------------------------------------
-
-.. automodule:: salome.kernel.deprecation
-   :members:
-
-
-:mod:`termcolor` -- Display colored text in terminal
-----------------------------------------------------
-
-.. automodule:: salome.kernel.termcolor
-   :members:
-   :exclude-members: TEST_termcolor
-
-
-:mod:`logger` -- Logging utility
---------------------------------
-
-.. automodule:: salome.kernel.logger
-
-.. autoclass:: Logger
-   :members:
-   :show-inheritance:
-
-.. autoclass:: ExtLogger
-   :members:
-   :show-inheritance:
-
-
-:mod:`studyedit` -- Study editor
---------------------------------
-
-.. automodule:: salome.kernel.studyedit
-   :members:
-
-
-:mod:`varlist` -- Handle Exchange Variables
--------------------------------------------
-
-.. automodule:: salome.kernel.varlist
-   :members:
+   kernel.rst
+   parametric.rst
diff --git a/doc/docutils/kernel.rst b/doc/docutils/kernel.rst
new file mode 100644 (file)
index 0000000..f73f234
--- /dev/null
@@ -0,0 +1,37 @@
+:mod:`salome.kernel` -- Package containing the KERNEL python utilities
+======================================================================
+
+:mod:`deprecation` -- Indication of deprecated modules and functions
+--------------------------------------------------------------------
+
+.. automodule:: salome.kernel.deprecation
+   :members:
+
+
+:mod:`termcolor` -- Display colored text in terminal
+----------------------------------------------------
+
+.. automodule:: salome.kernel.termcolor
+   :members:
+   :exclude-members: TEST_termcolor
+
+
+:mod:`logger` -- Logging utility
+--------------------------------
+
+.. automodule:: salome.kernel.logger
+
+.. autoclass:: Logger
+   :members:
+   :show-inheritance:
+
+.. autoclass:: ExtLogger
+   :members:
+   :show-inheritance:
+
+
+:mod:`studyedit` -- Study editor
+--------------------------------
+
+.. automodule:: salome.kernel.studyedit
+   :members:
diff --git a/doc/docutils/parametric.rst b/doc/docutils/parametric.rst
new file mode 100644 (file)
index 0000000..25e815c
--- /dev/null
@@ -0,0 +1,15 @@
+:mod:`salome.kernel.parametric` -- Package for parametric studies
+=================================================================
+
+:mod:`study_exchange_vars` -- Handle Exchange Variables
+-------------------------------------------------------
+
+.. automodule:: salome.kernel.parametric.study_exchange_vars
+   :members:
+
+
+:mod:`compo_utils` -- Useful functions for SALOME components used in parametric studies
+---------------------------------------------------------------------------------------
+
+.. automodule:: salome.kernel.parametric.compo_utils
+   :members:
index 36f2674145c86cb3289da839292b93482a08bab9..847220f33af9589e0c570d613d56f812f60e4bca 100644 (file)
@@ -8,5 +8,6 @@ mypkgpython_PYTHON = \
        logger.py \
        studyedit.py \
        termcolor.py \
-       logconfig.py \
-       varlist.py
+       logconfig.py
+
+SUBDIRS = parametric
diff --git a/src/KERNEL_PY/kernel/parametric/Makefile.am b/src/KERNEL_PY/kernel/parametric/Makefile.am
new file mode 100644 (file)
index 0000000..f8062fb
--- /dev/null
@@ -0,0 +1,8 @@
+include $(top_srcdir)/salome_adm/unix/make_common_starter.am
+
+mypkgpythondir =$(salomepypkgdir)/kernel/parametric
+
+mypkgpython_PYTHON = \
+       __init__.py \
+       study_exchange_vars.py \
+       compo_utils.py
diff --git a/src/KERNEL_PY/kernel/parametric/__init__.py b/src/KERNEL_PY/kernel/parametric/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/KERNEL_PY/kernel/parametric/compo_utils.py b/src/KERNEL_PY/kernel/parametric/compo_utils.py
new file mode 100644 (file)
index 0000000..c966759
--- /dev/null
@@ -0,0 +1,49 @@
+#  Copyright (C) 2011  CEA/DEN, EDF R&D, OPEN CASCADE
+#
+#  This library is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  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
+#
+
+import SALOME_TYPES
+
+def create_input_dict(deterministic_dict, parametric_input):
+    # Simply get the first point from input (no time series, single observation)
+    input_point = parametric_input.inputValues[0][0]
+
+    if len(input_point) != len(parametric_input.inputVarList):
+        raise Exception("Size mismatch between inputVarList and point to evaluate")
+
+    input_dict = deterministic_dict
+    for i in range(len(input_point)):
+        input_dict[parametric_input.inputVarList[i]] = input_point[i][0]
+
+    return input_dict
+
+def create_normal_parametric_output(output_dict, parametric_input):
+    output_values = [[[]]]
+    for output_var in parametric_input.outputVarList:
+        output_values[0][0].append([output_dict[output_var]])
+    return SALOME_TYPES.ParametricOutput(outputValues = output_values,
+                                         specificOutputInfos = [],
+                                         returnCode = 0,
+                                         errorMessage = "")
+
+def create_error_parametric_output(error_message):
+    return SALOME_TYPES.ParametricOutput(outputValues = [],
+                                         specificOutputInfos = [],
+                                         returnCode = 1,
+                                         errorMessage = error_message)
diff --git a/src/KERNEL_PY/kernel/parametric/study_exchange_vars.py b/src/KERNEL_PY/kernel/parametric/study_exchange_vars.py
new file mode 100644 (file)
index 0000000..8c03165
--- /dev/null
@@ -0,0 +1,165 @@
+#  Copyright (C) 2011  CEA/DEN, EDF R&D, OPEN CASCADE
+#
+#  This library is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  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
+#
+
+"""
+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 salome.kernel.studyedit import getStudyEditor
+
+DEFAULT_NAME = "Variables"
+INPUT_VAR_NAMES = "ExchangeVariables.InputVarNames"
+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):
+        self.name = name
+        
+        # Reserved for future use
+        self.dimension = dimension
+        self.minValue = minValue
+        self.maxValue = maxValue
+        self.initialValue = initialValue
+
+
+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
+    
+       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):
+    """
+    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,
+                             name = name,
+                             icon = icon,
+                             typeId = typeId)
+    _setSObjectForExchangeVariables(editor, sobj, exchangeVariables)
+
+def updateSObjectForExchangeVariables(sobj, exchangeVariables,
+                                      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)
+    editor.builder.RemoveAttribute(sobj, "AttributeParameter")
+    _setSObjectForExchangeVariables(editor, 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])
+    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)
diff --git a/src/KERNEL_PY/kernel/varlist.py b/src/KERNEL_PY/kernel/varlist.py
deleted file mode 100644 (file)
index a2cadeb..0000000
+++ /dev/null
@@ -1,165 +0,0 @@
-#  Copyright (C) 2011  CEA/DEN, EDF R&D, OPEN CASCADE
-#
-#  This library is free software; you can redistribute it and/or
-#  modify it under the terms of the GNU Lesser General Public
-#  License as published by the Free Software Foundation; either
-#  version 2.1 of the License.
-#
-#  This library is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-#  Lesser General Public License for more details.
-#
-#  You should have received a copy of the GNU Lesser General Public
-#  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
-#
-
-"""
-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"
-INPUT_VAR_NAMES = "ExchangeVariables.InputVarNames"
-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):
-        self.name = name
-        
-        # Reserved for future use
-        self.dimension = dimension
-        self.minValue = minValue
-        self.maxValue = maxValue
-        self.initialValue = initialValue
-
-
-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
-    
-       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):
-    """
-    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,
-                             name = name,
-                             icon = icon,
-                             typeId = typeId)
-    _setSObjectForExchangeVariables(editor, sobj, exchangeVariables)
-
-def updateSObjectForExchangeVariables(sobj, exchangeVariables,
-                                      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)
-    editor.builder.RemoveAttribute(sobj, "AttributeParameter")
-    _setSObjectForExchangeVariables(editor, 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])
-    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)