Salome HOME
Merge branch 'akl/tests_update'
[modules/paravis.git] / test / VisuPrs / united / A1.py
1 # Copyright (C) 2010-2014  CEA/DEN, EDF R&D
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 # This case corresponds to: /visu/united/A1 case
21
22 from paravistest import datadir
23 from presentations import *
24 import paravis
25 import pvsimple
26
27 my_paravis = paravis.myParavis
28
29 # 1. Import MED file
30 print "**** Step1: Import MED file"
31
32 print 'Import "ResOK_0000.med"...',
33 file_path = datadir + "ResOK_0000.med"
34 my_paravis.ImportFile(file_path)
35 med_reader = pvsimple.GetActiveSource()
36
37 if med_reader is None:
38     print "FAILED"
39 else:
40     print "OK"
41
42 print 'Get view...................',
43 view = pvsimple.GetRenderView()
44 if view is None:
45     print "FAILED"
46 else:
47     reset_view(view)
48     print "OK"
49
50 cell_entity = EntityType.CELL
51 node_entity = EntityType.NODE
52
53 # 2. Displaying vector field
54 print "**** Step2: Displaying vector field"
55
56 print "Creating Scalar Map.......",
57 scalarmap = ScalarMapOnField(med_reader, node_entity, 'vitesse', 1)
58 if scalarmap is None:
59     print "FAILED"
60 else:
61     bar = get_bar()
62     bar.Orientation = 'Horizontal'
63     bar.Position = [0.1, 0.1]
64     bar.Position2 = [0.1, 0.25]
65     bar.AspectRatio = 3
66
67     display_only(scalarmap, view)
68     print "OK"
69
70 reset_view(view)
71
72 print "Creating Stream Lines.....",
73 streamlines = StreamLinesOnField(med_reader, node_entity, 'vitesse', 1)
74 if streamlines is None:
75     print "FAILED"
76 else:
77     display_only(streamlines, view)
78     print "OK"
79
80 print "Creating Vectors..........",
81 vectors = VectorsOnField(med_reader, node_entity, 'vitesse', 1)
82 if vectors is None:
83     print "FAILED"
84 else:
85     display_only(vectors, view)
86     print "OK"
87
88 print "Creating Iso Surfaces.....",
89 isosurfaces = IsoSurfacesOnField(med_reader, node_entity, 'vitesse', 1)
90 contour_filter = pvsimple.GetActiveSource()
91 if isosurfaces is None:
92     print "FAILED"
93 else:
94     display_only(isosurfaces, view)
95     print "OK"
96
97 print "Creating Cut Planes.......",
98 cutplanes = CutPlanesOnField(med_reader, node_entity, 'vitesse', 1,
99                              nb_planes=30, orientation=Orientation.YZ)
100 if cutplanes is None:
101     print "FAILED"
102 else:
103     display_only(cutplanes, view)
104     print "OK"
105
106 # 3. Another MED file import
107 print "**** Step3: Import another MED file"
108
109 print 'Import "Fields_group3D.med"...............',
110 file_path = datadir + "Fields_group3D.med"
111 my_paravis.ImportFile(file_path)
112 med_reader1 = pvsimple.GetActiveSource()
113
114 if med_reader1 is None:
115     print "FAILED"
116 else:
117     print "OK"
118
119 # 4. Displaying scalar field
120 print "**** Step4: Displaying scalar field"
121
122 print "Creating Scalar Map.......",
123 scalarmap1 = ScalarMapOnField(med_reader1, cell_entity, 'scalar_field', 1)
124 if scalarmap1 is None:
125     print "FAILED"
126 else:
127     display_only(scalarmap1, view)
128     print "OK"
129
130 reset_view(view)
131
132 print "Creating Iso Surfaces.....",
133 isosurfaces1 = IsoSurfacesOnField(med_reader1, cell_entity, 'scalar_field', 1)
134 if isosurfaces1 is None:
135     print "FAILED"
136 else:
137     display_only(isosurfaces1, view)
138     print "OK"
139
140 print "Creating Cut Planes.......",
141 cutplanes1 = CutPlanesOnField(med_reader1, cell_entity, 'scalar_field', 1,
142                               orientation=Orientation.YZ)
143 if cutplanes1 is None:
144     print "FAILED"
145 else:
146     slice_filter = pvsimple.GetActiveSource()
147     slice_filter.SliceType.Normal = [1.0, 0.0, 0.0]
148     display_only(cutplanes1, view)
149     print "OK"
150
151 # 5. Object browser popup
152
153 print "**** Step5: Object browser popup"
154
155 mesh_name = 'mailles_MED'
156
157 print "Creating mesh.............",
158 mesh = MeshOnEntity(med_reader1, mesh_name, cell_entity)
159 if mesh is None:
160     print "FAILED"
161 else:
162     display_only(mesh, view)
163     print "OK"
164
165 print "Changing type of presentation of mesh:"
166 mesh.Representation = 'Wireframe'
167 pvsimple.Render()
168 prs_type = mesh.Representation
169 print "Presentation type..", prs_type
170
171 mesh.Representation = 'Points'
172 pvsimple.Render()
173 prs_type = mesh.Representation
174 print "Presentation type..", prs_type
175
176 mesh.Representation = 'Surface'
177 pvsimple.Render()
178 prs_type = mesh.Representation
179 print "Presentation type..", prs_type
180
181 shrink = pvsimple.Shrink(med_reader1)
182 mesh_shrinked = pvsimple.GetRepresentation(shrink)
183 display_only(mesh_shrinked, view)
184
185 print "Changing color of mesh....",
186 color = [0, 0, 1]
187 mesh.DiffuseColor = color
188 display_only(mesh, view)
189 print "OK"
190
191 print "Changing first IsoSurfaces",
192 display_only(isosurfaces, view)
193 reset_view(view)
194 rgb_points = isosurfaces.LookupTable.RGBPoints
195 scalar_range = [rgb_points[0], rgb_points[4]]
196 surfaces = get_contours(scalar_range, 25)
197 contour_filter.Isosurfaces = surfaces
198 pvsimple.Render(view=view)
199 print "OK"
200
201 print "Hide IsoSurfaces..........",
202 isosurfaces.Visibility = 0
203 pvsimple.Render(view=view)
204 print "OK"