Salome HOME
Update copyright
[modules/smesh.git] / src / SMESH_PY / smeshstudytools.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21 """
22 This module provides a new class :class:`SMeshStudyTools` to facilitate the
23 use of mesh objects in Salome study.
24 """
25
26 import salome
27 SMESH = None    # SMESH module is loaded only when needed
28
29 from salome.kernel.studyedit import getStudyEditor
30
31 class SMeshStudyTools:
32     """
33     This class provides several methods to manipulate mesh objects in Salome
34     study. The parameter `studyEditor` defines a
35     :class:`~salome.kernel.studyedit.StudyEditor` object used to access the study. If
36     :const:`None`, the method returns a :class:`~salome.kernel.studyedit.StudyEditor`
37     object on the current study.
38
39     .. attribute:: editor
40     
41        This instance attribute contains the underlying
42        :class:`~salome.kernel.studyedit.StudyEditor` object. It can be used to access
43        the study but the attribute itself should not be modified.
44
45     """
46
47     def __init__(self, studyEditor = None):
48         global SMESH
49         if SMESH is None:
50             SMESH = __import__("SMESH")
51         if studyEditor is None:
52             studyEditor = getStudyEditor()
53         self.editor = studyEditor
54
55     def getMeshFromGroup(self, meshGroupItem):
56         """
57         Get the mesh item owning the mesh group `meshGroupItem`.
58
59         :type   meshGroupItem: SObject
60         :param  meshGroupItem: Mesh group belonging to the searched mesh.
61         
62         :return: The SObject corresponding to the mesh, or None if it was not
63                  found.
64         """
65         meshItem = None
66         obj = self.editor.getOrLoadObject(meshGroupItem)
67         group = obj._narrow(SMESH.SMESH_GroupBase)
68         if group is not None: # The type of the object is ok
69             meshObj = group.GetMesh()
70             meshItem = salome.ObjectToSObject(meshObj)
71         return meshItem