Back to index

salome-paravis  6.5.0
A9.py
Go to the documentation of this file.
00001 # Copyright (C) 2010-2012  CEA/DEN, EDF R&D
00002 #
00003 # This library is free software; you can redistribute it and/or
00004 # modify it under the terms of the GNU Lesser General Public
00005 # License as published by the Free Software Foundation; either
00006 # version 2.1 of the License.
00007 #
00008 # This library is distributed in the hope that it will be useful,
00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 # Lesser General Public License for more details.
00012 #
00013 # You should have received a copy of the GNU Lesser General Public
00014 # License along with this library; if not, write to the Free Software
00015 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 #
00017 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 #
00019 
00020 # This case corresponds to: /visu/3D_viewer/A9 case
00021 # Create 3D Viewer and test set view properties for Deformed Shape presentation
00022 # Author:       POLYANSKIKH VERA
00023 from paravistest import *
00024 from presentations import *
00025 from pvsimple import *
00026 import sys
00027 import paravis
00028 import time
00029 
00030 
00031 def check_value(prs, property_name, value, do_raise=1, compare_toler=-1.0):
00032     # compare just set value and the one got from presentation
00033     really_set_value = prs.GetPropertyValue(property_name)
00034     is_equal = 1
00035     if compare_toler > 0:
00036         is_equal = (fabs(really_set_value - value) < compare_toler)
00037     else:
00038         is_equal = (really_set_value == value)
00039     if not is_equal:
00040         msg = str(really_set_value) + " has been set instead"
00041         if do_raise:
00042             raise RuntimeError(msg)
00043         else:
00044             print (msg)
00045 
00046     return (not is_equal)
00047 
00048 
00049 def check_all_params(prs, pres_type,  shad, opac, lwid):
00050     err = check_value(prs, "Representation", pres_type, 0, -1.0)
00051     err = err + check_value(prs, "Shading", shad, 0, -1.0)
00052     err = err + check_value(prs, "Opacity", opac, 0, compare_prec)
00053     err = err + check_value(prs, "LineWidth", lwid,  0, compare_prec)
00054     return err
00055 
00056 # Directory for saving snapshots
00057 picturedir = get_picture_dir(sys.argv[1], "3D_viewer/A9")
00058 
00059 # Add path separator to the end of picture path if necessery
00060 if not picturedir.endswith(os.sep):
00061     picturedir += os.sep
00062 
00063 #import file
00064 myParavis = paravis.myParavis
00065 
00066 # Get view
00067 my_view = GetRenderView()
00068 reset_view(my_view)
00069 Render(my_view)
00070 
00071 theFileName = datadir + "cube_hexa8_quad4.med"
00072 print " --------------------------------- "
00073 print "file ", theFileName
00074 print " --------------------------------- "
00075 
00076 myParavis.ImportFile(theFileName)
00077 proxy = GetActiveSource()
00078 if proxy is None:
00079     raise RuntimeError("Error: can't import file.")
00080 else:
00081     print "OK"
00082 
00083 field_name = 'fieldcelldouble'
00084 
00085 print "\nCreating scalar_map.......",
00086 scalar_map = ScalarMapOnField(proxy, EntityType.CELL, field_name, 1)
00087 if scalar_map is None:
00088     raise RuntimeError("Error!!! Presentation wasn't created...")
00089 
00090 display_only(scalar_map, my_view)
00091 reset_view(my_view)
00092 Render(my_view)
00093 
00094 compare_prec = 0.00001
00095 
00096 print "\nChange Presentation Parameters..."
00097 # Group 1 (SHADED)
00098 
00099 print "\nCheck in SURFACE:"
00100 
00101 call_and_check(scalar_map, "Representation",
00102 RepresentationType.get_name(RepresentationType.SURFACE))
00103 shrink_filter = Shrink(scalar_map.Input)
00104 shrink_filter.ShrinkFactor = 0.8
00105 shrink_filter.UpdatePipeline()
00106 shrinked_scalar_map = GetRepresentation(shrink_filter)
00107 shrinked_scalar_map.ColorAttributeType = EntityType.get_pvtype(EntityType.CELL)
00108 shrinked_scalar_map.ColorArrayName = field_name
00109 shrinked_scalar_map.Representation = scalar_map.Representation
00110 lookup_table = scalar_map.LookupTable
00111 shrinked_scalar_map.LookupTable = lookup_table
00112 scalar_map.Visibility = 0
00113 shrinked_scalar_map.Visibility = 1
00114 Render(my_view)
00115 
00116 shape_to_show = shrinked_scalar_map
00117 setShaded(my_view, 1)
00118 call_and_check(shape_to_show, "Shading", 1)
00119 Render(my_view)
00120 call_and_check(shape_to_show, "Opacity", 0.8, 1, compare_prec)
00121 call_and_check(shape_to_show, "LineWidth", 5.0,  1, compare_prec)
00122 
00123 time.sleep(1)
00124 
00125 # save picture in file
00126 # Construct image file name
00127 pic_name = picturedir + "params_SURFACE_1." + pictureext
00128 # Show and record the presentation
00129 process_prs_for_test(shape_to_show, my_view, pic_name)
00130 
00131 
00132 call_and_check(shape_to_show, "Representation",
00133 RepresentationType.get_name(RepresentationType.WIREFRAME))
00134 call_and_check(shape_to_show, "Representation",
00135 RepresentationType.get_name(RepresentationType.SURFACE))
00136 
00137 time.sleep(1)
00138 picture_name = picturedir + "params_SURFACE_2." + pictureext
00139 
00140 # save picture in file
00141 # Construct image file name
00142 pic_name = picturedir + "params_SURFACE_2." + pictureext
00143 # Show and record the presentation
00144 process_prs_for_test(shape_to_show, my_view, pic_name)
00145 
00146 err = check_all_params(shape_to_show,
00147 RepresentationType.get_name(RepresentationType.SURFACE), 1, 0.8, 5.0)
00148 
00149 ##call_and_check(scalar_map, "Shrinked", 0, "Shrinked")
00150 ##call_and_check(scalar_map, "Shrinked", 1, "Shrinked")
00151 
00152 time.sleep(1)
00153 
00154 # save picture in file
00155 # Construct image file name
00156 pic_name = picturedir + "params_SURFACE_3." + pictureext
00157 # Show and record the presentation
00158 process_prs_for_test(shape_to_show, my_view, pic_name)
00159 
00160 err = err + check_all_params(shape_to_show,
00161 RepresentationType.get_name(RepresentationType.SURFACE), 1, 0.8, 5.0)
00162 
00163 call_and_check(shape_to_show, "Shading", 0)
00164 call_and_check(shape_to_show, "Shading", 1)
00165 
00166 time.sleep(1)
00167 
00168 # save picture in file
00169 # Construct image file name
00170 pic_name = picturedir + "params_SURFACE_4." + pictureext
00171 # Show and record the presentation
00172 process_prs_for_test(shape_to_show, my_view, pic_name)
00173 
00174 err = err + check_all_params(shape_to_show,
00175 RepresentationType.get_name(RepresentationType.SURFACE), 1, 0.8, 5.0)
00176 
00177 call_and_check(shape_to_show, "Opacity", 1.0,  1, compare_prec)
00178 call_and_check(shape_to_show, "Opacity", 0.8,  1, compare_prec)
00179 
00180 time.sleep(1)
00181 
00182 # save picture in file
00183 # Construct image file name
00184 pic_name = picturedir + "params_SURFACE_5." + pictureext
00185 # Show and record the presentation
00186 process_prs_for_test(shape_to_show, my_view, pic_name)
00187 
00188 err = err + check_all_params(shape_to_show,
00189 RepresentationType.get_name(RepresentationType.SURFACE), 1, 0.8, 5.0)
00190 
00191 # Reset
00192 ##call_and_check(shape_to_show, "Shrinked", 0, "Shrinked")
00193 setShaded(my_view, 0)
00194 call_and_check(shape_to_show, "Shading", 0,)
00195 Render(my_view)
00196 call_and_check(shape_to_show, "Opacity", 1.0, 1, compare_prec)
00197 call_and_check(shape_to_show, "LineWidth", 1.0, 1, compare_prec)
00198 
00199 # Group 2 (WIREFRAME)
00200 hide_all(my_view)
00201 print "\nCheck in WIREFRAME:"
00202 scalar_map.Visibility = 1
00203 call_and_check(scalar_map, "Representation",
00204 RepresentationType.get_name(RepresentationType.WIREFRAME), "Representation")
00205 shrink_filter = Shrink(scalar_map.Input)
00206 shrink_filter.ShrinkFactor = 0.8
00207 shrink_filter.UpdatePipeline()
00208 shrinked_scalar_map = GetRepresentation(shrink_filter)
00209 shrinked_scalar_map.ColorAttributeType = EntityType.get_pvtype(EntityType.CELL)
00210 shrinked_scalar_map.ColorArrayName = field_name
00211 shrinked_scalar_map.Representation = scalar_map.Representation
00212 lookup_table = scalar_map.LookupTable
00213 shrinked_scalar_map.LookupTable = lookup_table
00214 scalar_map.Visibility = 0
00215 shrinked_scalar_map.Visibility = 1
00216 shape_to_show = shrinked_scalar_map
00217 
00218 setShaded(my_view, 1)
00219 call_and_check(shape_to_show, "Shading", 1)
00220 Render(my_view)
00221 call_and_check(shape_to_show, "Opacity", 0.8, 1, compare_prec)
00222 call_and_check(shape_to_show, "LineWidth", 5.0, 1, compare_prec)
00223 
00224 time.sleep(1)
00225 
00226 # save picture in file
00227 # Construct image file name
00228 pic_name = picturedir + "params_WIREFRAME_1." + pictureext
00229 # Show and record the presentation
00230 process_prs_for_test(shape_to_show, my_view, pic_name)
00231 
00232 
00233 call_and_check(shape_to_show, "Representation",
00234 RepresentationType.get_name(RepresentationType.SURFACE))
00235 call_and_check(shape_to_show, "Representation",
00236 RepresentationType.get_name(RepresentationType.WIREFRAME))
00237 
00238 time.sleep(1)
00239 # save picture in file
00240 # Construct image file name
00241 pic_name = picturedir + "params_WIREFRAME_2." + pictureext
00242 # Show and record the presentation
00243 process_prs_for_test(shape_to_show, my_view, pic_name)
00244 
00245 err = err + check_all_params(shape_to_show,
00246 RepresentationType.get_name(RepresentationType.WIREFRAME), 1, 0.8, 5.0)
00247 
00248 ##call_and_check(shape_to_show, "Shrinked", 0)
00249 ##call_and_check(shape_to_show, "Shrinked", 1)
00250 
00251 time.sleep(1)
00252 # save picture in file
00253 # Construct image file name
00254 pic_name = picturedir + "params_WIREFRAME_3." + pictureext
00255 # Show and record the presentation
00256 process_prs_for_test(shrinked_scalar_map, my_view, pic_name)
00257 
00258 err = err + check_all_params(shape_to_show,
00259 RepresentationType.get_name(RepresentationType.WIREFRAME), 1, 0.8, 5.0)
00260 
00261 call_and_check(shape_to_show, "Shading", 0)
00262 call_and_check(shape_to_show, "Shading", 1)
00263 
00264 time.sleep(1)
00265 # save picture in file
00266 # Construct image file name
00267 pic_name = picturedir + "params_WIREFRAME_4." + pictureext
00268 # Show and record the presentation
00269 process_prs_for_test(shape_to_show, my_view, pic_name)
00270 
00271 err = err + check_all_params(shape_to_show,
00272 RepresentationType.get_name(RepresentationType.WIREFRAME), 1, 0.8, 5.0)
00273 
00274 call_and_check(shape_to_show, "Opacity", 1.0, 1, compare_prec)
00275 call_and_check(shape_to_show, "Opacity", 0.8, 1, compare_prec)
00276 
00277 time.sleep(1)
00278 # save picture in file
00279 # Construct image file name
00280 pic_name = picturedir + "params_WIREFRAME_5." + pictureext
00281 # Show and record the presentation
00282 process_prs_for_test(shape_to_show, my_view, pic_name)
00283 
00284 err = err + check_all_params(shape_to_show,
00285 RepresentationType.get_name(RepresentationType.WIREFRAME), 1, 0.8, 5.0)
00286 
00287 if err:
00288     raise RuntimeError("Presentation parameters are not stable")