]> SALOME platform Git repositories - modules/paravis.git/blob - src/Macro/ShowSalomeObject.py
Salome HOME
Issue '0022741: [CEA 1251] Display the groups of a med file with one color per family...
[modules/paravis.git] / src / Macro / ShowSalomeObject.py
1 # Copyright (C) 2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 ###
20 # Macro to show SALOME object in ParaView viewer.
21
22 # The macro inspects current selection obtained from SALOME GUI
23 # and displays supported objects in the viewer:
24 # - GEOM object
25 # - SMESH mesh object
26 ###
27
28 import tempfile, os
29
30 import SALOME
31
32 import salome
33 salome.salome_init()
34
35 session = salome.naming_service.Resolve('/Kernel/Session')
36
37 from pvsimple import *
38
39 selection = session.getSelection()
40
41 for entry in selection:
42     obj = salome.myStudy.FindObjectID(entry).GetObject()
43     try:
44         import GEOM
45         go = obj._narrow(GEOM.GEOM_Object)
46         if go:
47             from salome.geom import geomBuilder
48             geompy = geomBuilder.New(salome.myStudy)
49             tmpf = tempfile.NamedTemporaryFile(suffix='.vtk')
50             fname = tmpf.name
51             tmpf.close()
52             geompy.ExportVTK(go, fname)
53             ShowParaviewView()
54             p = LegacyVTKReader(FileNames=[fname])
55             renderView = GetActiveViewOrCreate('RenderView')
56             pd = Show(p, renderView)
57             renderView.ResetCamera()
58             os.remove(fname)
59             pass
60     except:
61         # not geom object
62         pass
63     try: 
64         import SMESH
65         mo = obj._narrow(SMESH.SMESH_Mesh)
66         if mo:
67             from salome.smesh import smeshBuilder
68             mesh = smeshBuilder.New(salome.myStudy)
69             tmpf = tempfile.NamedTemporaryFile(suffix='.med')
70             fname = tmpf.name
71             tmpf.close()
72             mo.ExportToMEDX(fname, True, SMESH.MED_V2_2, True, True)
73             ShowParaviewView()
74             p = MEDReader(FileName=fname)
75             renderView = GetActiveViewOrCreate('RenderView')
76             pd = Show(p, renderView)
77             renderView.ResetCamera()
78             os.remove(fname)
79             pass
80     except:
81         # not mesh object
82         pass
83     pass
84
85     
86