Salome HOME
Merge Python 3 porting.
[modules/paravis.git] / test / VisuPrs / SWIG_scripts / A7.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/A7 case
21
22 import time
23
24 from paravistest import datadir
25 from presentations import *
26 import pvsimple
27
28 view = pvsimple.GetRenderView()
29 reset_view(view)
30 delay = 1
31
32 def after_set(error_string, prop_name, old_value, new_value):
33     print(prop_name, ": old_value = ", old_value, "new_value  = ", new_value)
34     if error_string == "":
35         time.sleep(delay)
36     else:
37         print(prop_name, " error = ", error_string)
38         pass
39     pass
40
41
42 def change_representation(prs, repres, opacity, linew):
43     if prs is None:
44         print("FAILED")
45         return
46     else:
47         print("OK")
48
49     display_only(prs, view)
50     view.ResetCamera()
51
52     time.sleep(delay)
53
54     old_prs_type = prs.Representation
55     if old_prs_type != repres:
56         err_str = ''
57         try:
58             prs.Representation = repres
59         except:
60             err_str = "Error"
61         after_set(err_str, "Representation", old_prs_type, repres)
62         pass
63
64     old_opacity = prs.Opacity
65     if old_opacity != opacity:
66         err_str = ''
67         try:
68             prs.Opacity = opacity  # double value [0, 1]
69         except:
70             err_str = "Error"
71         after_set(err_str, "Opacity", old_opacity, opacity)
72         pass
73
74     old_linew = prs.LineWidth
75     if old_linew != linew:
76         err_str = ''
77         try:
78             prs.LineWidth = linew  # double value, recommended round [1, 10]
79         except:
80             err_str = "Error"
81         after_set(err_str, "LineWidth", old_linew, linew)
82         pass
83
84     print("")
85     pass
86
87
88 # ResOK_0000.med
89
90 print('Import "ResOK_0000.med"...............', end=' ')
91 file_path = datadir + "ResOK_0000.med"
92 field_name = 'vitesse'
93 node_entity = EntityType.NODE
94
95 pvsimple.OpenDataFile(file_path)
96 med_reader = pvsimple.GetActiveSource()
97
98 if med_reader is None:
99     print("FAILED")
100 else:
101     print("OK")
102
103 print("Creating Scalar Map.......", end=' ')
104 scmap = ScalarMapOnField(med_reader, node_entity, field_name, 1)
105 change_representation(scmap, 'Surface With Edges', 0.3, 5)
106
107 print("Creating Stream Lines.......", end=' ')
108 slines = StreamLinesOnField(med_reader, node_entity, field_name, 1)
109 change_representation(slines, 'Wireframe', 0.5, 3)
110
111 print("Creating Vectors..........", end=' ')
112 vec = VectorsOnField(med_reader, node_entity, field_name, 1)
113 change_representation(vec, 'Wireframe', 0.7, 2)
114
115 print("Creating Iso Surfaces.....", end=' ')
116 iso = IsoSurfacesOnField(med_reader, node_entity, field_name, 1)
117 change_representation(iso, 'Surface', 0.4, 8)
118
119 print("Creating Cut Planes.......", end=' ')
120 clines = CutPlanesOnField(med_reader, node_entity, field_name, 1)
121 change_representation(clines, 'Points', 0.6, 4)
122
123
124 # fra.med
125
126 print('Import "fra.med"...............', end=' ')
127 file_path = datadir + "fra.med"
128 field_name = 'VITESSE'
129
130 pvsimple.SetActiveSource(None)
131 pvsimple.OpenDataFile(file_path)
132 med_reader = pvsimple.GetActiveSource()
133
134 if med_reader is None:
135     print("FAILED")
136 else:
137     print("OK")
138
139 print("Creating Scalar Map.......", end=' ')
140 scmap = ScalarMapOnField(med_reader, node_entity, field_name, 1)
141 change_representation(scmap, 'Wireframe', 0.5, 3)
142
143 print("Creating Iso Surfaces.....", end=' ')
144 iso = IsoSurfacesOnField(med_reader, node_entity, field_name, 1)
145 change_representation(iso, 'Wireframe', 0.5, 3)
146
147 print("Creating Cut Planes.......", end=' ')
148 cplanes = CutPlanesOnField(med_reader, node_entity, field_name, 1)
149 change_representation(cplanes, 'Surface', 0.5, 3)
150
151 print("Creating Scalar Map On Deformed Shape.......", end=' ')
152 defmap = DeformedShapeAndScalarMapOnField(med_reader, node_entity,
153                                           field_name, 1)
154 change_representation(defmap, 'Surface', 0.5, 3)
155
156 print("Creating Deformed Shape.......", end=' ')
157 defshape = DeformedShapeOnField(med_reader, node_entity, field_name, 1)
158 defshape.ColorArrayName = field_name
159 change_representation(defshape, 'Wireframe', 0.5, 3)
160
161 print("Creating Cut Lines.......", end=' ')
162 clines = CutLinesOnField(med_reader, node_entity, field_name, 1)
163 change_representation(clines, 'Wireframe', 0.5, 3)
164
165 print("Creating Plot 3D.......", end=' ')
166 plot3d = Plot3DOnField(med_reader, node_entity, field_name, 1)
167 change_representation(plot3d, 'Surface', 0.5, 3)
168 change_representation(plot3d, 'Outline', 0.8, 2)