Back to index

salome-paravis  6.5.0
A6.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/A6 case
00021 # Create 3D Viewer and test set view properties for Scalar Map on
00022 # Deformed Shape presentation
00023 # Author:       POLYANSKIKH VERA
00024 from paravistest import *
00025 from presentations import *
00026 from pvsimple import *
00027 import sys
00028 import paravis
00029 import time
00030 
00031 # Directory for saving snapshots
00032 picturedir = get_picture_dir(sys.argv[1], "3D_viewer/A6")
00033 
00034 # Add path separator to the end of picture path if necessery
00035 if not picturedir.endswith(os.sep):
00036     picturedir += os.sep
00037 
00038 #import file
00039 my_paravis = paravis.myParavis
00040 
00041 # Get view
00042 my_view = GetRenderView()
00043 reset_view(my_view)
00044 Render(my_view)
00045 
00046 file_name = datadir + "cube_hexa8_quad4.med"
00047 print " --------------------------------- "
00048 print "file ", file_name
00049 print " --------------------------------- "
00050 
00051 my_paravis.ImportFile(file_name)
00052 proxy = GetActiveSource()
00053 if proxy is None:
00054     raise RuntimeError("Error: can't import file.")
00055 else:
00056     print "OK"
00057 
00058 represents = [RepresentationType.POINTS, RepresentationType.WIREFRAME,
00059 RepresentationType.SURFACE, RepresentationType.VOLUME]
00060 shrinks = [0, 1]
00061 shadings = [0, 1]
00062 opacities = [1.0, 0.5, 0.0]
00063 linewidths = [1.0, 3.0, 10.0]
00064 compare_prec = 0.00001
00065 shrink_filter = None
00066 shr_sm_on_ds = None
00067 
00068 field_name = 'fieldcelldouble'
00069 
00070 print "\nCreating scalar map on deformed shape.......",
00071 sm_on_ds = DeformedShapeAndScalarMapOnField(proxy, EntityType.CELL,
00072 field_name, 1, scale_factor=0.2)
00073 if sm_on_ds is None:
00074     raise RuntimeError("Error!!! Presentation wasn't created...")
00075 
00076 display_only(sm_on_ds, my_view)
00077 reset_view(my_view)
00078 Render(my_view)
00079 
00080 print "\nChange Presentation Parameters..."
00081 
00082 
00083 for reprCode in represents:
00084     repr = RepresentationType.get_name(reprCode)
00085     call_and_check(sm_on_ds, "Representation", repr, 1)
00086     for shr in shrinks:
00087         if shr > 0 and reprCode != RepresentationType.POINTS:
00088             if shr_sm_on_ds is None:
00089                 sm_on_ds.Visibility = 1
00090                 shrink_filter = Shrink(sm_on_ds.Input)
00091                 shrink_filter.ShrinkFactor = 0.8
00092                 shrink_filter.UpdatePipeline()
00093                 shr_sm_on_ds = GetRepresentation(shrink_filter)
00094                 shr_sm_on_ds.ColorArrayName = sm_on_ds.ColorArrayName
00095                 shr_sm_on_ds.LookupTable = sm_on_ds.LookupTable
00096                 shr_sm_on_ds.ColorAttributeType = sm_on_ds.ColorAttributeType
00097             sm_on_ds.Visibility = 0
00098             shr_sm_on_ds.Representation = sm_on_ds.Representation
00099             shape_to_show = shr_sm_on_ds
00100         else:
00101             if shr_sm_on_ds is not None:
00102                 shr_sm_on_ds.Visibility = 0
00103             shape_to_show = sm_on_ds
00104         shape_to_show.Visibility = 1
00105         Render(my_view)
00106 
00107         for sha in shadings:
00108             setShaded(my_view, sha)
00109             call_and_check(shape_to_show, "Shading", sha, 1)
00110             Render(my_view)
00111 
00112             for opa in opacities:
00113                 call_and_check(shape_to_show, "Opacity", opa, 1, compare_prec)
00114 
00115                 for lwi in linewidths:
00116                     call_and_check(shape_to_show, "LineWidth", lwi, 1,
00117                     compare_prec)
00118 
00119                     time.sleep(1)
00120                     # save picture in file
00121                     # Construct image file name
00122                     pic_name = picturedir + "params_" + repr.replace(' ', '_') + "_" + str(shr) + "_" +  \
00123                         str(sha) + "_" + str(opa) + "_" + str(lwi) + "." + pictureext
00124                     # Show and record the presentation
00125                     WriteImage(pic_name, view=my_view, Magnification=1)
00126                     pass
00127                 pass
00128             pass
00129         pass
00130     pass