1 # Copyright (C) 2010-2014 CEA/DEN, EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 *
27 import pvserver as paravis
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)
36 is_equal = (fabs(really_set_value - value) < compare_toler)
38 is_equal = (really_set_value == value)
40 msg = str(really_set_value) + " has been set instead"
42 raise RuntimeError(msg)
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, "Interpolation", 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)
56 # Directory for saving snapshots
57 picturedir = get_picture_dir("3D_viewer/A9")
59 # Add path separator to the end of picture path if necessery
60 if not picturedir.endswith(os.sep):
64 myParavis = paravis.myParavis
67 my_view = GetRenderView()
71 theFileName = datadir + "cube_hexa8_quad4.med"
72 print " --------------------------------- "
73 print "file ", theFileName
74 print " --------------------------------- "
76 OpenDataFile(theFileName)
77 proxy = GetActiveSource()
79 raise RuntimeError("Error: can't import file.")
83 field_name = 'fieldcelldouble'
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...")
90 display_only(scalar_map, my_view)
94 compare_prec = 0.00001
96 print "\nChange Presentation Parameters..."
99 print "\nCheck in SURFACE:"
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
116 shape_to_show = shrinked_scalar_map
117 setShaded(my_view, 1)
118 call_and_check(shape_to_show, "Interpolation", "Gouraud")
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)
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)
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))
138 picture_name = picturedir + "params_SURFACE_2." + pictureext
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)
146 err = check_all_params(shape_to_show,
147 RepresentationType.get_name(RepresentationType.SURFACE), "Gouraud", 0.8, 5.0)
149 ##call_and_check(scalar_map, "Shrinked", 0, "Shrinked")
150 ##call_and_check(scalar_map, "Shrinked", 1, "Shrinked")
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)
160 err = err + check_all_params(shape_to_show,
161 RepresentationType.get_name(RepresentationType.SURFACE), "Gouraud", 0.8, 5.0)
163 call_and_check(shape_to_show, "Interpolation", "Flat")
164 call_and_check(shape_to_show, "Interpolation", "Gouraud")
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)
174 err = err + check_all_params(shape_to_show,
175 RepresentationType.get_name(RepresentationType.SURFACE), "Gouraud", 0.8, 5.0)
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)
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)
188 err = err + check_all_params(shape_to_show,
189 RepresentationType.get_name(RepresentationType.SURFACE), "Gouraud", 0.8, 5.0)
192 ##call_and_check(shape_to_show, "Shrinked", 0, "Shrinked")
193 setShaded(my_view, 0)
194 call_and_check(shape_to_show, "Interpolation", "Flat",)
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)
199 # Group 2 (WIREFRAME)
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
218 setShaded(my_view, 1)
219 call_and_check(shape_to_show, "Interpolation", "Gouraud")
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)
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)
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))
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)
245 err = err + check_all_params(shape_to_show,
246 RepresentationType.get_name(RepresentationType.WIREFRAME), "Gouraud", 0.8, 5.0)
248 ##call_and_check(shape_to_show, "Shrinked", 0)
249 ##call_and_check(shape_to_show, "Shrinked", 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)
258 err = err + check_all_params(shape_to_show,
259 RepresentationType.get_name(RepresentationType.WIREFRAME), "Gouraud", 0.8, 5.0)
261 call_and_check(shape_to_show, "Interpolation", "Flat")
262 call_and_check(shape_to_show, "Interpolation", "Gouraud")
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)
271 err = err + check_all_params(shape_to_show,
272 RepresentationType.get_name(RepresentationType.WIREFRAME), "Gouraud", 0.8, 5.0)
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)
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)
284 err = err + check_all_params(shape_to_show,
285 RepresentationType.get_name(RepresentationType.WIREFRAME), "Gouraud", 0.8, 5.0)
288 raise RuntimeError("Presentation parameters are not stable")