1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2007-2009 EDF R&D
5 # This file is part of PAL_SRC.
7 # PAL_SRC is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # PAL_SRC is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with PAL_SRC; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 This module provides a new class :class:`SMeshStudyTools` to facilitate the
23 use of mesh objects in Salome study.
27 SMESH = None # SMESH module is loaded only when needed
29 from salome.kernel.studyedit import getStudyEditor
31 class SMeshStudyTools:
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.
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.
47 def __init__(self, studyEditor = None):
50 SMESH = __import__("SMESH")
51 if studyEditor is None:
52 studyEditor = getStudyEditor()
53 self.editor = studyEditor
55 def getMeshFromGroup(self, meshGroupItem):
57 Get the mesh item owning the mesh group `meshGroupItem`.
59 :type meshGroupItem: SObject
60 :param meshGroupItem: Mesh group belonging to the searched mesh.
62 :return: The SObject corresponding to the mesh, or None if it was not
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)