Salome HOME
Merge branch 'V9_9_BR'
[modules/smesh.git] / src / SMESH_PY / smeshstudytools.py
index 5bf1250b06ce045d435bf5ae540ff4acc17dc51c..859b5c25cbe8786843e2894445cec2e47a89a78e 100644 (file)
@@ -1,11 +1,11 @@
 # -*- coding: utf-8 -*-
 #
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2022  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
 #
 # 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.
+# version 2.1 of the License, or (at your option) any later version.
 #
 # This library is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 #
 # This library is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 #
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 #
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
+
+## \package smeshstudytools Python API to access SMESH objects in the study.
+
+## \defgroup smeshstudytools Accessing SMESH object in the study
+#  \{ 
+#  \details
+#  Module \b smeshstudytools provides a new class SMeshStudyTools to facilitate the
+#  use of mesh objects in Salome study.
+#  \}
+
 """
 """
-This module provides a new class :class:`SMeshStudyTools` to facilitate the
+This module provides a class :class:`SMeshStudyTools` to facilitate the
 use of mesh objects in Salome study.
 """
 
 use of mesh objects in Salome study.
 """
 
@@ -27,11 +37,19 @@ import salome
 SMESH = None    # SMESH module is loaded only when needed
 
 from salome.kernel.studyedit import getStudyEditor
 SMESH = None    # SMESH module is loaded only when needed
 
 from salome.kernel.studyedit import getStudyEditor
-try:
-    from salome.gui import helper
-except ImportError:
-    pass
-
+from salome.kernel.deprecation import is_called_by_sphinx
+if not is_called_by_sphinx():
+  from salome.gui import helper
+
+## This class provides several methods to manipulate mesh objects in Salome
+#  study. The parameter \em studyEditor defines a \b StudyEditor
+#  object used to access the study. If \b None, the method returns a 
+#  \b StudyEditor object on the current study.
+#
+#  \b editor
+#  This instance attribute contains the underlying \b StudyEditor object. 
+#  It can be used to access the study but the attribute itself should not be modified.
+#  \ingroup smeshstudytools
 class SMeshStudyTools:
     """
     This class provides several methods to manipulate mesh objects in Salome
 class SMeshStudyTools:
     """
     This class provides several methods to manipulate mesh objects in Salome
@@ -57,13 +75,18 @@ class SMeshStudyTools:
         self.editor = studyEditor
         self.smeshGui = None
 
         self.editor = studyEditor
         self.smeshGui = None
 
-    def updateStudy(self, studyId=None):
+    ## This function updates the tools so that it works on the
+    #  specified study.
+    def updateStudy(self):
         """
         This function updates the tools so that it works on the
         specified study.
         """
         """
         This function updates the tools so that it works on the
         specified study.
         """
-        self.editor = getStudyEditor(studyId)
-        
+        self.editor = getStudyEditor()
+
+    ## Get the mesh item owning the mesh group \em meshGroupItem.
+    #  \param  meshGroupItem (SObject) mesh group belonging to the searched mesh.
+    #  \return The SObject corresponding to the mesh, or None if it was not found.        
     def getMeshFromGroup(self, meshGroupItem):
         """
         Get the mesh item owning the mesh group `meshGroupItem`.
     def getMeshFromGroup(self, meshGroupItem):
         """
         Get the mesh item owning the mesh group `meshGroupItem`.
@@ -82,32 +105,38 @@ class SMeshStudyTools:
             meshItem = salome.ObjectToSObject(meshObj)
         return meshItem
 
             meshItem = salome.ObjectToSObject(meshObj)
         return meshItem
 
-
+    ## Returns the MESH object currently selected in the active study.
     def getMeshObjectSelected(self):
     def getMeshObjectSelected(self):
-        '''
+        """
         Returns the MESH object currently selected in the active study.
         Returns the MESH object currently selected in the active study.
-        '''
+        """
         sobject, entry = helper.getSObjectSelected()
         meshObject = self.getMeshObjectFromEntry(entry)
         return meshObject
 
         sobject, entry = helper.getSObjectSelected()
         meshObject = self.getMeshObjectFromEntry(entry)
         return meshObject
 
+    ## Returns the MESH object associated to the specified entry,
+    #  (the entry is the identifier of an item in the objects browser).
     def getMeshObjectFromEntry(self, entry):
     def getMeshObjectFromEntry(self, entry):
-        '''
+        """
         Returns the MESH object associated to the specified entry,
         (the entry is the identifier of an item in the objects browser).
         Returns the MESH object associated to the specified entry,
         (the entry is the identifier of an item in the objects browser).
-        '''
+        """
         if entry is None:
             return None
         if entry is None:
             return None
-        import smesh
-        smesh.SetCurrentStudy(self.editor.study)
-        meshObject=smesh.IDToObject(entry)
-        return meshObject
+        import SMESH
+        from salome.smesh import smeshBuilder
+        smesh = smeshBuilder.New()
 
 
+        meshObject=salome.IDToObject(entry)
+        return smesh.Mesh( meshObject )
+    
+    ## Returns the SMESH object associated to the specified \em SObject,
+    #  (the SObject is an item in the objects browser).
     def getMeshObjectFromSObject(self, sobject):
     def getMeshObjectFromSObject(self, sobject):
-        '''
+        """
         Returns the SMESH object associated to the specified SObject,
         (the SObject is an item in the objects browser).
         Returns the SMESH object associated to the specified SObject,
         (the SObject is an item in the objects browser).
-        '''
+        """
         if sobject is None:
             return None
         
         if sobject is None:
             return None
         
@@ -115,16 +144,18 @@ class SMeshStudyTools:
         meshObject = obj._narrow(SMESH.SMESH_Mesh)
         return meshObject
 
         meshObject = obj._narrow(SMESH.SMESH_Mesh)
         return meshObject
 
+    ## Display the SMESH object associated to the specified \em entry
+    #  (the entry is the identifier of an item in the objects browser).
     def displayMeshObjectFromEntry(self,entry):
     def displayMeshObjectFromEntry(self,entry):
-        '''
+        """
         Display the SMESH object associated to the specified entry
         (the entry is the identifier of an item in the objects browser).    
         Display the SMESH object associated to the specified entry
         (the entry is the identifier of an item in the objects browser).    
-        '''
+        """
         if self.smeshGui is None:
             self.smeshGui = salome.ImportComponentGUI("SMESH")
 
         if not helper.SalomeGUI.hasDesktop():
         if self.smeshGui is None:
             self.smeshGui = salome.ImportComponentGUI("SMESH")
 
         if not helper.SalomeGUI.hasDesktop():
-            print "displayMeshObject: no desktop available"
+            print("displayMeshObject: no desktop available")
             return
         self.smeshGui.CreateAndDisplayActor(entry)
 
             return
         self.smeshGui.CreateAndDisplayActor(entry)
 
@@ -152,15 +183,18 @@ class SMeshStudyTools:
 
 
 def TEST_createBoxMesh():
 
 
 def TEST_createBoxMesh():
-    theStudy = helper.getActiveStudy()
     
     
-    import geompy
-    geompy.init_geom(theStudy)
+    import GEOM
+    from salome.geom import geomBuilder
+    geompy = geomBuilder.New()
+    
     box = geompy.MakeBoxDXDYDZ(200, 200, 200)
 
     box = geompy.MakeBoxDXDYDZ(200, 200, 200)
 
-    import smesh, SMESH, SALOMEDS    
-    smesh.SetCurrentStudy(theStudy)
-    import StdMeshers
+    import SMESH, SALOMEDS
+    from salome.smesh import smeshBuilder
+    smesh = smeshBuilder.New() 
+
+    from salome.StdMeshers import StdMeshersBuilder
     boxmesh = smesh.Mesh(box)
     Regular_1D = boxmesh.Segment()
     Nb_Segments_1 = Regular_1D.NumberOfSegments(15)
     boxmesh = smesh.Mesh(box)
     Regular_1D = boxmesh.Segment()
     Nb_Segments_1 = Regular_1D.NumberOfSegments(15)
@@ -172,7 +206,7 @@ def TEST_createBoxMesh():
 
     smesh.SetName(boxmesh.GetMesh(), 'boxmesh')
     if salome.sg.hasDesktop():
 
     smesh.SetName(boxmesh.GetMesh(), 'boxmesh')
     if salome.sg.hasDesktop():
-        salome.sg.updateObjBrowser(1)
+        salome.sg.updateObjBrowser()
 
 #
 # Definitions:
 
 #
 # Definitions: