Version: 6.3.1

src/SMESH_PY/smeshstudytools.py

Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 #
00003 # Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
00004 #
00005 # This library is free software; you can redistribute it and/or
00006 # modify it under the terms of the GNU Lesser General Public
00007 # License as published by the Free Software Foundation; either
00008 # version 2.1 of the License.
00009 #
00010 # This library is distributed in the hope that it will be useful,
00011 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 # Lesser General Public License for more details.
00014 #
00015 # You should have received a copy of the GNU Lesser General Public
00016 # License along with this library; if not, write to the Free Software
00017 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00018 #
00019 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00020 #
00021 """
00022 This module provides a new class :class:`SMeshStudyTools` to facilitate the
00023 use of mesh objects in Salome study.
00024 """
00025 
00026 import salome
00027 SMESH = None    # SMESH module is loaded only when needed
00028 
00029 from salome.kernel.studyedit import getStudyEditor
00030 
00031 class SMeshStudyTools:
00032     """
00033     This class provides several methods to manipulate mesh objects in Salome
00034     study. The parameter `studyEditor` defines a
00035     :class:`~salome.kernel.studyedit.StudyEditor` object used to access the study. If
00036     :const:`None`, the method returns a :class:`~salome.kernel.studyedit.StudyEditor`
00037     object on the current study.
00038 
00039     .. attribute:: editor
00040     
00041        This instance attribute contains the underlying
00042        :class:`~salome.kernel.studyedit.StudyEditor` object. It can be used to access
00043        the study but the attribute itself should not be modified.
00044 
00045     """
00046 
00047     def __init__(self, studyEditor = None):
00048         global SMESH
00049         if SMESH is None:
00050             SMESH = __import__("SMESH")
00051         if studyEditor is None:
00052             studyEditor = getStudyEditor()
00053         self.editor = studyEditor
00054 
00055     def getMeshFromGroup(self, meshGroupItem):
00056         """
00057         Get the mesh item owning the mesh group `meshGroupItem`.
00058 
00059         :type   meshGroupItem: SObject
00060         :param  meshGroupItem: Mesh group belonging to the searched mesh.
00061         
00062         :return: The SObject corresponding to the mesh, or None if it was not
00063                  found.
00064         """
00065         meshItem = None
00066         obj = self.editor.getOrLoadObject(meshGroupItem)
00067         group = obj._narrow(SMESH.SMESH_GroupBase)
00068         if group is not None: # The type of the object is ok
00069             meshObj = group.GetMesh()
00070             meshItem = salome.ObjectToSObject(meshObj)
00071         return meshItem
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS