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