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