Back to index

salome-paravis  6.5.0
G2.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/ScalarMap/G2 case
00021 # Create Scalar Map for field of the the given MED file for 10 timestamps%
00022 
00023 import sys
00024 import os
00025 from paravistest import datadir, pictureext, get_picture_dir
00026 import paravis
00027 from pvsimple import GetActiveSource, GetRenderView, Render
00028 from presentations import ScalarMapOnField, hide_all, EntityType, PrsTypeEnum,reset_view,process_prs_for_test
00029 
00030 
00031 # Create presentations
00032 myParavis = paravis.myParavis
00033 
00034 picturedir = get_picture_dir(sys.argv[1], "ScalarMap/G2")
00035 
00036 theFileName = datadir +  "Bug829_resu_mode.med"
00037 print " --------------------------------- "
00038 print "file ", theFileName
00039 print " --------------------------------- "
00040     
00041 """Build presentations of the given types for all fields of the given file."""
00042 #print "Import %s..." % theFileName.split('/')[-1],
00043 result = myParavis.ImportFile(theFileName)
00044 proxy = GetActiveSource()
00045 if proxy is None:
00046        raise RuntimeError, "Error: can't import file."
00047 else: print "OK"
00048 # Get view
00049 aView = GetRenderView()
00050 
00051 
00052 field_names = proxy.PointArrays.GetData()
00053 aTimeStamps = proxy.TimestepValues.GetData()
00054 aFieldEntity = EntityType.NODE
00055 aFieldName = "MODES_DEPL"
00056 #create list to store picture files sizes
00057 sizes=[]
00058 #create Scalar Map presentations for 10 timestamps
00059 for i in range(1,11):
00060     hide_all(aView, True)
00061     aPrs = ScalarMapOnField(proxy, aFieldEntity,aFieldName , i)
00062     if aPrs is None:
00063         raise RuntimeError, "Presentation is None!!!"
00064     #display only current scalar map
00065     aPrs.Visibility=1
00066     reset_view(aView)
00067     Render(aView)    
00068     
00069     # Add path separator to the end of picture path if necessery
00070     if not picturedir.endswith(os.sep):
00071             picturedir += os.sep
00072     prs_type = PrsTypeEnum.SCALARMAP
00073             
00074     # Get name of presentation type
00075     prs_name = PrsTypeEnum.get_name(prs_type)    
00076     f_prs_type = prs_name.replace(' ', '').upper()
00077     # Construct image file name
00078     pic_name = picturedir + aFieldName + "_" + str(i) + "_" + f_prs_type + "." + pictureext
00079     
00080     # Show and record the presentation
00081     process_prs_for_test(aPrs, aView, pic_name)
00082     sizes.append(os.path.getsize(pic_name))
00083 
00084 # check sizes of pictures   
00085 if abs(max(sizes)-min(sizes)) > 0.01*max(sizes):
00086     print "<b>WARNING!!! Pictures have different sizes!!!</b>"; 
00087     for i in range(1,11):
00088         picture_name = "time_stamp_"+str(i)+"."+pictureext
00089         print "Picture: "+picture_name+"; size: "+str(sizes[i-1]) 
00090     raise RuntimeError