Salome HOME
Names of fields are changed.
[modules/paravis.git] / test / VisuPrs / 3D_viewer / A9.py
1 # Copyright (C) 2010-2013  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.
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/3D_viewer/A9 case
21 # Create 3D Viewer and test set view properties for Deformed Shape presentation
22 # Author:       POLYANSKIKH VERA
23 from paravistest import *
24 from presentations import *
25 from pvsimple import *
26 import sys
27 import paravis
28 import time
29
30
31 def check_value(prs, property_name, value, do_raise=1, compare_toler=-1.0):
32     # compare just set value and the one got from presentation
33     really_set_value = prs.GetPropertyValue(property_name)
34     is_equal = 1
35     if compare_toler > 0:
36         is_equal = (fabs(really_set_value - value) < compare_toler)
37     else:
38         is_equal = (really_set_value == value)
39     if not is_equal:
40         msg = str(really_set_value) + " has been set instead"
41         if do_raise:
42             raise RuntimeError(msg)
43         else:
44             print (msg)
45
46     return (not is_equal)
47
48
49 def check_all_params(prs, pres_type,  shad, opac, lwid):
50     err = check_value(prs, "Representation", pres_type, 0, -1.0)
51     err = err + check_value(prs, "Shading", shad, 0, -1.0)
52     err = err + check_value(prs, "Opacity", opac, 0, compare_prec)
53     err = err + check_value(prs, "LineWidth", lwid,  0, compare_prec)
54     return err
55
56 # Directory for saving snapshots
57 picturedir = get_picture_dir("3D_viewer/A9")
58
59 # Add path separator to the end of picture path if necessery
60 if not picturedir.endswith(os.sep):
61     picturedir += os.sep
62
63 #import file
64 myParavis = paravis.myParavis
65
66 # Get view
67 my_view = GetRenderView()
68 reset_view(my_view)
69 Render(my_view)
70
71 theFileName = datadir + "cube_hexa8_quad4.med"
72 print " --------------------------------- "
73 print "file ", theFileName
74 print " --------------------------------- "
75
76 myParavis.ImportFile(theFileName)
77 proxy = GetActiveSource()
78 if proxy is None:
79     raise RuntimeError("Error: can't import file.")
80 else:
81     print "OK"
82
83 field_name = 'fieldcelldouble'
84
85 print "\nCreating scalar_map.......",
86 scalar_map = ScalarMapOnField(proxy, EntityType.CELL, field_name, 1)
87 if scalar_map is None:
88     raise RuntimeError("Error!!! Presentation wasn't created...")
89
90 display_only(scalar_map, my_view)
91 reset_view(my_view)
92 Render(my_view)
93
94 compare_prec = 0.00001
95
96 print "\nChange Presentation Parameters..."
97 # Group 1 (SHADED)
98
99 print "\nCheck in SURFACE:"
100
101 call_and_check(scalar_map, "Representation",
102 RepresentationType.get_name(RepresentationType.SURFACE))
103 shrink_filter = Shrink(scalar_map.Input)
104 shrink_filter.ShrinkFactor = 0.8
105 shrink_filter.UpdatePipeline()
106 shrinked_scalar_map = GetRepresentation(shrink_filter)
107 shrinked_scalar_map.ColorAttributeType = EntityType.get_pvtype(EntityType.CELL)
108 shrinked_scalar_map.ColorArrayName = field_name
109 shrinked_scalar_map.Representation = scalar_map.Representation
110 lookup_table = scalar_map.LookupTable
111 shrinked_scalar_map.LookupTable = lookup_table
112 scalar_map.Visibility = 0
113 shrinked_scalar_map.Visibility = 1
114 Render(my_view)
115
116 shape_to_show = shrinked_scalar_map
117 setShaded(my_view, 1)
118 call_and_check(shape_to_show, "Shading", 1)
119 Render(my_view)
120 call_and_check(shape_to_show, "Opacity", 0.8, 1, compare_prec)
121 call_and_check(shape_to_show, "LineWidth", 5.0,  1, compare_prec)
122
123 time.sleep(1)
124
125 # save picture in file
126 # Construct image file name
127 pic_name = picturedir + "params_SURFACE_1." + pictureext
128 # Show and record the presentation
129 process_prs_for_test(shape_to_show, my_view, pic_name)
130
131
132 call_and_check(shape_to_show, "Representation",
133 RepresentationType.get_name(RepresentationType.WIREFRAME))
134 call_and_check(shape_to_show, "Representation",
135 RepresentationType.get_name(RepresentationType.SURFACE))
136
137 time.sleep(1)
138 picture_name = picturedir + "params_SURFACE_2." + pictureext
139
140 # save picture in file
141 # Construct image file name
142 pic_name = picturedir + "params_SURFACE_2." + pictureext
143 # Show and record the presentation
144 process_prs_for_test(shape_to_show, my_view, pic_name)
145
146 err = check_all_params(shape_to_show,
147 RepresentationType.get_name(RepresentationType.SURFACE), 1, 0.8, 5.0)
148
149 ##call_and_check(scalar_map, "Shrinked", 0, "Shrinked")
150 ##call_and_check(scalar_map, "Shrinked", 1, "Shrinked")
151
152 time.sleep(1)
153
154 # save picture in file
155 # Construct image file name
156 pic_name = picturedir + "params_SURFACE_3." + pictureext
157 # Show and record the presentation
158 process_prs_for_test(shape_to_show, my_view, pic_name)
159
160 err = err + check_all_params(shape_to_show,
161 RepresentationType.get_name(RepresentationType.SURFACE), 1, 0.8, 5.0)
162
163 call_and_check(shape_to_show, "Shading", 0)
164 call_and_check(shape_to_show, "Shading", 1)
165
166 time.sleep(1)
167
168 # save picture in file
169 # Construct image file name
170 pic_name = picturedir + "params_SURFACE_4." + pictureext
171 # Show and record the presentation
172 process_prs_for_test(shape_to_show, my_view, pic_name)
173
174 err = err + check_all_params(shape_to_show,
175 RepresentationType.get_name(RepresentationType.SURFACE), 1, 0.8, 5.0)
176
177 call_and_check(shape_to_show, "Opacity", 1.0,  1, compare_prec)
178 call_and_check(shape_to_show, "Opacity", 0.8,  1, compare_prec)
179
180 time.sleep(1)
181
182 # save picture in file
183 # Construct image file name
184 pic_name = picturedir + "params_SURFACE_5." + pictureext
185 # Show and record the presentation
186 process_prs_for_test(shape_to_show, my_view, pic_name)
187
188 err = err + check_all_params(shape_to_show,
189 RepresentationType.get_name(RepresentationType.SURFACE), 1, 0.8, 5.0)
190
191 # Reset
192 ##call_and_check(shape_to_show, "Shrinked", 0, "Shrinked")
193 setShaded(my_view, 0)
194 call_and_check(shape_to_show, "Shading", 0,)
195 Render(my_view)
196 call_and_check(shape_to_show, "Opacity", 1.0, 1, compare_prec)
197 call_and_check(shape_to_show, "LineWidth", 1.0, 1, compare_prec)
198
199 # Group 2 (WIREFRAME)
200 hide_all(my_view)
201 print "\nCheck in WIREFRAME:"
202 scalar_map.Visibility = 1
203 call_and_check(scalar_map, "Representation",
204 RepresentationType.get_name(RepresentationType.WIREFRAME), "Representation")
205 shrink_filter = Shrink(scalar_map.Input)
206 shrink_filter.ShrinkFactor = 0.8
207 shrink_filter.UpdatePipeline()
208 shrinked_scalar_map = GetRepresentation(shrink_filter)
209 shrinked_scalar_map.ColorAttributeType = EntityType.get_pvtype(EntityType.CELL)
210 shrinked_scalar_map.ColorArrayName = field_name
211 shrinked_scalar_map.Representation = scalar_map.Representation
212 lookup_table = scalar_map.LookupTable
213 shrinked_scalar_map.LookupTable = lookup_table
214 scalar_map.Visibility = 0
215 shrinked_scalar_map.Visibility = 1
216 shape_to_show = shrinked_scalar_map
217
218 setShaded(my_view, 1)
219 call_and_check(shape_to_show, "Shading", 1)
220 Render(my_view)
221 call_and_check(shape_to_show, "Opacity", 0.8, 1, compare_prec)
222 call_and_check(shape_to_show, "LineWidth", 5.0, 1, compare_prec)
223
224 time.sleep(1)
225
226 # save picture in file
227 # Construct image file name
228 pic_name = picturedir + "params_WIREFRAME_1." + pictureext
229 # Show and record the presentation
230 process_prs_for_test(shape_to_show, my_view, pic_name)
231
232
233 call_and_check(shape_to_show, "Representation",
234 RepresentationType.get_name(RepresentationType.SURFACE))
235 call_and_check(shape_to_show, "Representation",
236 RepresentationType.get_name(RepresentationType.WIREFRAME))
237
238 time.sleep(1)
239 # save picture in file
240 # Construct image file name
241 pic_name = picturedir + "params_WIREFRAME_2." + pictureext
242 # Show and record the presentation
243 process_prs_for_test(shape_to_show, my_view, pic_name)
244
245 err = err + check_all_params(shape_to_show,
246 RepresentationType.get_name(RepresentationType.WIREFRAME), 1, 0.8, 5.0)
247
248 ##call_and_check(shape_to_show, "Shrinked", 0)
249 ##call_and_check(shape_to_show, "Shrinked", 1)
250
251 time.sleep(1)
252 # save picture in file
253 # Construct image file name
254 pic_name = picturedir + "params_WIREFRAME_3." + pictureext
255 # Show and record the presentation
256 process_prs_for_test(shrinked_scalar_map, my_view, pic_name)
257
258 err = err + check_all_params(shape_to_show,
259 RepresentationType.get_name(RepresentationType.WIREFRAME), 1, 0.8, 5.0)
260
261 call_and_check(shape_to_show, "Shading", 0)
262 call_and_check(shape_to_show, "Shading", 1)
263
264 time.sleep(1)
265 # save picture in file
266 # Construct image file name
267 pic_name = picturedir + "params_WIREFRAME_4." + pictureext
268 # Show and record the presentation
269 process_prs_for_test(shape_to_show, my_view, pic_name)
270
271 err = err + check_all_params(shape_to_show,
272 RepresentationType.get_name(RepresentationType.WIREFRAME), 1, 0.8, 5.0)
273
274 call_and_check(shape_to_show, "Opacity", 1.0, 1, compare_prec)
275 call_and_check(shape_to_show, "Opacity", 0.8, 1, compare_prec)
276
277 time.sleep(1)
278 # save picture in file
279 # Construct image file name
280 pic_name = picturedir + "params_WIREFRAME_5." + pictureext
281 # Show and record the presentation
282 process_prs_for_test(shape_to_show, my_view, pic_name)
283
284 err = err + check_all_params(shape_to_show,
285 RepresentationType.get_name(RepresentationType.WIREFRAME), 1, 0.8, 5.0)
286
287 if err:
288     raise RuntimeError("Presentation parameters are not stable")