1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2011-2014 CEA/DEN, EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # Author : Guillaume Boulant (EDF)
24 __mapMedType2VisuType={
25 MEDCoupling.ON_CELLS:VISU.CELL,
26 MEDCoupling.ON_NODES:VISU.NODE,
27 MEDCoupling.ON_GAUSS_PT:VISU.TGAUSSPOINTS
30 def visu_typeOfField(medTypeOfField):
32 This function gives the visu type corresponding to the specified
36 return __mapMedType2VisuType[medTypeOfField]
42 from libSALOME_Swig import SALOMEGUI_Swig
44 def visu_scalarmap(filename,meshname,fieldname,typeOfField,iteration=-1):
46 This is the minimalist function to render a scalar map on a field
47 load from a med file using the VISU module.
50 # We first have to prepare a pointer to the VISU component engine.
51 visuComp = salome.lcc.FindOrLoadComponent("FactoryServer", "VISU")
52 visuComp.SetCurrentStudy(salome.myStudy)
54 visumed = visuComp.CreateResult(filename)
55 visumed.SetBuildGroups(True)
56 visumed.SetBuildFields(True, True)
57 visumed.Build(False, True)
58 if not visumed.IsDone() :
59 print "ERR: can't create a representation of med data"
62 visuComp.RenameEntityInStudy(visumed, meshname, VISU.NODE, 'onNodes')
63 visuComp.RenameEntityInStudy(visumed, meshname, VISU.CELL, 'onCells')
65 visuType = visu_typeOfField(typeOfField)
66 scalarmap = visuComp.ScalarMapOnField(visumed,
72 print "ERR: can't create a scalar map"
75 # __GBO__ maybe it could be appreciated to select the component to
76 # display. In this interface, the modulus of the field is
79 scalarmap.SetScalarMode(component)
80 scalarmap.SetSourceRange()
81 scalarmap.SetScaling(VISU.LINEAR)
82 scalarmap.SetTitle(fieldname)
84 # This final part is to automatically display the scalar map in a
87 sg.updateObjBrowser(1)
89 # Display the scalar map in the viewer
90 myViewManager = visuComp.GetViewManager()
91 myView = myViewManager.Create3DView()
93 myView.Display(scalarmap);
94 myView.SetFocalPoint([0,0,0]);
100 def TEST_scalarmap():
102 from xmed import properties
103 #properties.setup(properties.testdata_02) # test with nodes
104 properties.setup(properties.testdata_03) # test with cells
106 # __GBO__: WARN due to a specific feature of VISU, when only one
107 # field timestamps exists in the med file, we have to specify an
108 # iteration number of 1, whatever the iteration value is in the
110 #iteration = properties.testFieldIt
113 visu_scalarmap(properties.testFilePath,
114 properties.testMeshName,
115 properties.testFieldName,
116 properties.testTypeOfField,
119 if __name__ == "__main__":