Salome HOME
Merge branch 'V7_main' of ssh://git.salome-platform.org/modules/paravis into V7_main
[modules/paravis.git] / test / VisuPrs / ScalarMap / G2.py
1 # Copyright (C) 2010-2013  CEA/DEN, EDF R&D
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 # This case corresponds to: /visu/ScalarMap/G2 case
21 # Create Scalar Map for field of the the given MED file for 10 timestamps%
22
23 import sys
24 import os
25 from paravistest import datadir, pictureext, get_picture_dir
26 import paravis
27 from pvsimple import GetActiveSource, GetRenderView, Render
28 from presentations import ScalarMapOnField, hide_all, EntityType, PrsTypeEnum,reset_view,process_prs_for_test
29
30
31 # Create presentations
32 myParavis = paravis.myParavis
33
34 picturedir = get_picture_dir("ScalarMap/G2")
35
36 theFileName = datadir +  "Bug829_resu_mode.med"
37 print " --------------------------------- "
38 print "file ", theFileName
39 print " --------------------------------- "
40     
41 """Build presentations of the given types for all fields of the given file."""
42 #print "Import %s..." % theFileName.split('/')[-1],
43 result = myParavis.ImportFile(theFileName)
44 proxy = GetActiveSource()
45 if proxy is None:
46         raise RuntimeError, "Error: can't import file."
47 else: print "OK"
48 # Get view
49 aView = GetRenderView()
50
51
52 field_names = proxy.PointArrays.GetData()
53 aTimeStamps = proxy.TimestepValues.GetData()
54 aFieldEntity = EntityType.NODE
55 aFieldName = "MODES_DEPL"
56 #create list to store picture files sizes
57 sizes=[]
58 #create Scalar Map presentations for 10 timestamps
59 for i in range(1,11):
60     hide_all(aView, True)
61     aPrs = ScalarMapOnField(proxy, aFieldEntity,aFieldName , i)
62     if aPrs is None:
63         raise RuntimeError, "Presentation is None!!!"
64     #display only current scalar map
65     aPrs.Visibility=1
66     reset_view(aView)
67     Render(aView)    
68     
69     # Add path separator to the end of picture path if necessery
70     if not picturedir.endswith(os.sep):
71             picturedir += os.sep
72     prs_type = PrsTypeEnum.SCALARMAP
73             
74     # Get name of presentation type
75     prs_name = PrsTypeEnum.get_name(prs_type)    
76     f_prs_type = prs_name.replace(' ', '').upper()
77     # Construct image file name
78     pic_name = picturedir + aFieldName + "_" + str(i) + "_" + f_prs_type + "." + pictureext
79     
80     # Show and record the presentation
81     process_prs_for_test(aPrs, aView, pic_name)
82     sizes.append(os.path.getsize(pic_name))
83
84 # check sizes of pictures       
85 if abs(max(sizes)-min(sizes)) > 0.01*max(sizes):
86     print "<b>WARNING!!! Pictures have different sizes!!!</b>"; 
87     for i in range(1,11):
88         picture_name = "time_stamp_"+str(i)+"."+pictureext
89         print "Picture: "+picture_name+"; size: "+str(sizes[i-1]) 
90     raise RuntimeError