Back to index

salome-paravis  6.5.0
A7.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/SWIG_scripts/A7 case
00021 
00022 import time
00023 
00024 from paravistest import datadir
00025 from presentations import *
00026 import paravis
00027 import pvsimple
00028 
00029 
00030 my_paravis = paravis.myParavis
00031 view = pvsimple.GetRenderView()
00032 reset_view(view)
00033 delay = 1
00034 
00035 
00036 def after_set(error_string, prop_name, old_value, new_value):
00037     print prop_name, ": old_value = ", old_value, "new_value  = ", new_value
00038     if error_string == "":
00039         time.sleep(delay)
00040     else:
00041         print prop_name, " error = ", error_string
00042         pass
00043     pass
00044 
00045 
00046 def change_representation(prs, repres, opacity, linew):
00047     if prs is None:
00048         print "FAILED"
00049         return
00050     else:
00051         print "OK"
00052 
00053     display_only(prs, view)
00054     view.ResetCamera()
00055 
00056     time.sleep(delay)
00057 
00058     old_prs_type = prs.Representation
00059     if old_prs_type != repres:
00060         err_str = ''
00061         try:
00062             prs.Representation = repres
00063         except:
00064             err_str = "Error"
00065         after_set(err_str, "Representation", old_prs_type, repres)
00066         pass
00067 
00068     old_opacity = prs.Opacity
00069     if old_opacity != opacity:
00070         err_str = ''
00071         try:
00072             prs.Opacity = opacity  # double value [0, 1]
00073         except:
00074             err_str = "Error"
00075         after_set(err_str, "Opacity", old_opacity, opacity)
00076         pass
00077 
00078     old_linew = prs.LineWidth
00079     if old_linew != linew:
00080         err_str = ''
00081         try:
00082             prs.LineWidth = linew  # double value, recommended round [1, 10]
00083         except:
00084             err_str = "Error"
00085         after_set(err_str, "LineWidth", old_linew, linew)
00086         pass
00087 
00088     print ""
00089     pass
00090 
00091 
00092 # ResOK_0000.med
00093 
00094 print 'Import "ResOK_0000.med"...............',
00095 file_path = datadir + "ResOK_0000.med"
00096 field_name = 'vitesse'
00097 node_entity = EntityType.NODE
00098 
00099 my_paravis.ImportFile(file_path)
00100 med_reader = pvsimple.GetActiveSource()
00101 
00102 if med_reader is None:
00103     print "FAILED"
00104 else:
00105     print "OK"
00106 
00107 print "Creating Scalar Map.......",
00108 scmap = ScalarMapOnField(med_reader, node_entity, field_name, 1)
00109 change_representation(scmap, 'Surface With Edges', 0.3, 5)
00110 
00111 print "Creating Stream Lines.......",
00112 slines = StreamLinesOnField(med_reader, node_entity, field_name, 1)
00113 change_representation(slines, 'Wireframe', 0.5, 3)
00114 
00115 print "Creating Vectors..........",
00116 vec = VectorsOnField(med_reader, node_entity, field_name, 1)
00117 change_representation(vec, 'Wireframe', 0.7, 2)
00118 
00119 print "Creating Iso Surfaces.....",
00120 iso = IsoSurfacesOnField(med_reader, node_entity, field_name, 1)
00121 change_representation(iso, 'Surface', 0.4, 8)
00122 
00123 print "Creating Cut Planes.......",
00124 clines = CutPlanesOnField(med_reader, node_entity, field_name, 1)
00125 change_representation(clines, 'Points', 0.6, 4)
00126 
00127 
00128 # fra.med
00129 
00130 print 'Import "fra.med"...............',
00131 file_path = datadir + "fra.med"
00132 field_name = 'VITESSE'
00133 
00134 pvsimple.SetActiveSource(None)
00135 my_paravis.ImportFile(file_path)
00136 med_reader = pvsimple.GetActiveSource()
00137 
00138 if med_reader is None:
00139     print "FAILED"
00140 else:
00141     print "OK"
00142 
00143 print "Creating Scalar Map.......",
00144 scmap = ScalarMapOnField(med_reader, node_entity, field_name, 1)
00145 change_representation(scmap, 'Wireframe', 0.5, 3)
00146 
00147 print "Creating Iso Surfaces.....",
00148 iso = IsoSurfacesOnField(med_reader, node_entity, field_name, 1)
00149 change_representation(iso, 'Wireframe', 0.5, 3)
00150 
00151 print "Creating Cut Planes.......",
00152 cplanes = CutPlanesOnField(med_reader, node_entity, field_name, 1)
00153 change_representation(cplanes, 'Surface', 0.5, 3)
00154 
00155 print "Creating Scalar Map On Deformed Shape.......",
00156 defmap = DeformedShapeAndScalarMapOnField(med_reader, node_entity,
00157                                           field_name, 1)
00158 change_representation(defmap, 'Surface', 0.5, 3)
00159 
00160 print "Creating Deformed Shape.......",
00161 defshape = DeformedShapeOnField(med_reader, node_entity, field_name, 1)
00162 defshape.ColorArrayName = field_name
00163 change_representation(defshape, 'Wireframe', 0.5, 3)
00164 
00165 print "Creating Cut Lines.......",
00166 clines = CutLinesOnField(med_reader, node_entity, field_name, 1)
00167 change_representation(clines, 'Wireframe', 0.5, 3)
00168 
00169 print "Creating Plot 3D.......",
00170 plot3d = Plot3DOnField(med_reader, node_entity, field_name, 1)
00171 change_representation(plot3d, 'Surface', 0.5, 3)
00172 change_representation(plot3d, 'Outline', 0.8, 2)