Salome HOME
Merge branch 'master' of ssh://git.salome-platform.org/modules/paravis
[modules/paravis.git] / src / Plugins / MEDReader / Test / testMEDReader15.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2015  CEA/DEN, EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Author : Anthony Geay (EDF R&D)
21
22 from MEDLoader import *
23
24 """ This test is a non regression test that checks the behaviour of MEDReader when a mesh has the same name than a field.
25 """
26
27 fname="testMEDReader15.med"
28 outImgName="testMEDReader15.png"
29
30 zeName="zeName"
31 c=DataArrayDouble([(0.,0.,0.),(1.,0.,0.),(0.,1.,0.)])
32 m=MEDFileUMesh()
33 m.setCoords(c)
34 m.setName(zeName)
35 m.write(fname,2)
36 f=MEDCouplingFieldDouble(ON_NODES)
37 f.setName(zeName)
38 f.setArray(DataArrayDouble([(-1.,1.,0.),(0.,1.,0.),(1.,1.,0.)]))
39 tmp=MEDCouplingUMesh.Build0DMeshFromCoords(m.getCoords()) ; tmp.setName(zeName)
40 f.setMesh(tmp)
41 MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f)
42 #
43
44 from paraview.simple import *
45
46 paraview.simple._DisableFirstRenderCameraReset()
47 reader=MEDReader(FileName=fname)
48 ExpectedEntries=['TS0/zeName/ComSup0/zeName@@][@@P1','TS0/zeName/ComSup0/MESH@zeName@@][@@P1']
49 assert(reader.GetProperty("FieldsTreeInfo")[::2]==ExpectedEntries)
50
51
52 #
53 glyph1=Glyph(Input=reader,GlyphType='Arrow',Scalars='FamilyIdNode',Vectors='zeName',GlyphMode='All Points',ScaleFactor=0.1,GlyphTransform='Transform2')
54
55 renderView1=GetActiveViewOrCreate('RenderView')
56 renderView1.InteractionMode='3D'
57 zeNameLUT = GetColorTransferFunction('zeName')
58 zeNameLUT.RGBPoints = [1.0, 0.231373, 0.298039, 0.752941, 1.2071067811865475, 0.865003, 0.865003, 0.865003, 1.4142135623730951, 0.705882, 0.0156863, 0.14902]
59 zeNameLUT.ScalarRangeInitialized = 1.
60 zeNameLUT.VectorMode = 'Component'
61
62 glyph1Display=Show(glyph1,renderView1)
63 glyph1Display.ColorArrayName = ['POINTS', 'FamilyIdNode']
64 glyph1Display.LookupTable = zeNameLUT
65 glyph1Display.OpacityArray = [None, '']
66 glyph1Display.RadiusArray = [None, '']
67 glyph1Display.RadiusRange = [-0.0707106813788414, 1.0099999904632568]
68 glyph1Display.ConstantRadius = 1.0099999904632568
69 glyph1Display.PointSpriteDefaultsInitialized = 1
70 glyph1Display.SelectInputVectors = ['POINTS', 'GlyphVector']
71 glyph1Display.WriteLog = ''
72 # show color bar/color legend
73 glyph1Display.SetScalarBarVisibility(renderView1, True)
74 # set scalar coloring
75 ColorBy(glyph1Display, ('POINTS', 'zeName'))
76 # rescale color and/or opacity maps used to include current data range
77 glyph1Display.RescaleTransferFunctionToDataRange(True)
78 # show color bar/color legend
79 glyph1Display.SetScalarBarVisibility(renderView1, True)
80 #
81 Render()
82 WriteImage(outImgName)