From: vsr Date: Thu, 5 Feb 2015 14:52:29 +0000 (+0300) Subject: 0022739: [CEA 812] Create source plug-in to display a GEOM object via CORBA X-Git-Tag: V7_6_0a1~15 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1869664cc5fb2c69608f1894e7e108e73445e747;p=modules%2Fparavis.git 0022739: [CEA 812] Create source plug-in to display a GEOM object via CORBA 0022740: [CEA 1250] Create source plug-in to display a SMESH object via CORBA Alternative solution via Python macro --- diff --git a/src/Macro/CMakeLists.txt b/src/Macro/CMakeLists.txt index 5a1e2ed3..78d7dd8d 100644 --- a/src/Macro/CMakeLists.txt +++ b/src/Macro/CMakeLists.txt @@ -20,6 +20,7 @@ SET(_PYFILES_TO_INSTALL modes.py annotate_groups.py + ShowSalomeObject.py ) 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 index 00000000..ba5433e7 --- /dev/null +++ b/src/Macro/ShowSalomeObject.py @@ -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 + + +