]> SALOME platform Git repositories - modules/paravis.git/commitdiff
Salome HOME
0022739: [CEA 812] Create source plug-in to display a GEOM object via CORBA
authorvsr <vsr@opencascade.com>
Thu, 5 Feb 2015 14:52:29 +0000 (17:52 +0300)
committervsr <vsr@opencascade.com>
Thu, 5 Feb 2015 14:55:50 +0000 (17:55 +0300)
0022740: [CEA 1250] Create source plug-in to display a SMESH object via CORBA

Alternative solution via Python macro

src/Macro/CMakeLists.txt
src/Macro/ShowSalomeObject.py [new file with mode: 0644]

index 5a1e2ed3b15b2f47a14ac5a07c131e10315690ba..78d7dd8d872066ca7e2acbac1a49ebf92f7cc7f2 100644 (file)
@@ -20,6 +20,7 @@
 SET(_PYFILES_TO_INSTALL
   modes.py
   annotate_groups.py
 SET(_PYFILES_TO_INSTALL
   modes.py
   annotate_groups.py
+  ShowSalomeObject.py
   )
 
 INSTALL_AND_COMPILE_PYTHON_FILE("${_PYFILES_TO_INSTALL}" ${SALOME_INSTALL_SCRIPT_PYTHON}/Macro)
   )
 
 INSTALL_AND_COMPILE_PYTHON_FILE("${_PYFILES_TO_INSTALL}" ${SALOME_INSTALL_SCRIPT_PYTHON}/Macro)
diff --git a/src/Macro/ShowSalomeObject.py b/src/Macro/ShowSalomeObject.py
new file mode 100644 (file)
index 0000000..ba5433e
--- /dev/null
@@ -0,0 +1,86 @@
+# Copyright (C) 2014  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, 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
+# 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
+#
+###
+# Macro to show SALOME object in ParaView viewer.
+# 
+# The macro inspects current selection obtained from SALOME GUI
+# and displays supported objects in the viewer:
+# - GEOM object
+# - SMESH mesh object
+###
+
+import tempfile, os
+
+import SALOME
+
+import salome
+salome.salome_init()
+
+session = salome.naming_service.Resolve('/Kernel/Session')
+
+from pvsimple import *
+
+selection = session.getSelection()
+
+for entry in selection:
+    obj = salome.myStudy.FindObjectID(entry).GetObject()
+    try:
+        import GEOM
+        go = obj._narrow(GEOM.GEOM_Object)
+        if go:
+            from salome.geom import geomBuilder
+            geompy = geomBuilder.New(salome.myStudy)
+            tmpf = tempfile.NamedTemporaryFile(suffix='.vtk')
+            fname = tmpf.name
+            tmpf.close()
+            geompy.ExportVTK(go, fname)
+            ShowParaviewView()
+            p = LegacyVTKReader(FileNames=[fname])
+            renderView = GetActiveViewOrCreate('RenderView')
+            pd = Show(p, renderView)
+            renderView.ResetCamera()
+            os.remove(fname)
+            pass
+    except:
+        # not geom object
+        pass
+    try: 
+        import SMESH
+        mo = obj._narrow(SMESH.SMESH_Mesh)
+        if mo:
+            from salome.smesh import smeshBuilder
+            mesh = smeshBuilder.New(salome.myStudy)
+            tmpf = tempfile.NamedTemporaryFile(suffix='.med')
+            fname = tmpf.name
+            tmpf.close()
+            mo.ExportToMEDX(fname, True, SMESH.MED_V2_2, True, True)
+            ShowParaviewView()
+            p = MEDReader(FileName=fname)
+            renderView = GetActiveViewOrCreate('RenderView')
+            pd = Show(p, renderView)
+            renderView.ResetCamera()
+            os.remove(fname)
+            pass
+    except:
+        # not mesh object
+        pass
+    pass
+
+    
+