Salome HOME
Merge branch 'akl/tests_update'
[modules/paravis.git] / test / VisuPrs / imps / A1.py
1 # Copyright (C) 2010-2014  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, or (at your option) any later version.
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/imps/A1 case
21
22 import sys
23 import os
24 from paravistest import datadir, pictureext, get_picture_dir
25 from presentations import *
26 import paravis
27 import pvsimple
28
29 my_paravis = paravis.myParavis
30 os.environ["PARAVIS_TEST_PICS"] = sys.argv[1]
31 picturedir = get_picture_dir("imps/A1")
32
33
34 def set_prs_colored(prs, proxy, entity, field_name, vector_mode, timestamp_nb):
35     # Get time value
36     time_value = get_time(proxy, timestamp_nb)
37     
38     # Check vector mode
39     nb_components = get_nb_components(proxy, entity, field_name)
40     check_vector_mode(vector_mode, nb_components)
41
42     # Get lookup table
43     lookup_table = get_lookup_table(field_name, nb_components, vector_mode)
44
45     # Set field range
46     data_range = get_data_range(proxy, entity,
47                                 field_name, vector_mode)
48     lookup_table.LockScalarRange = 1
49     lookup_table.RGBPoints = [data_range[0], 0, 0, 1, data_range[1], 1, 0, 0]
50
51     # Set properties
52     prs.ColorAttributeType = EntityType.get_pvtype(entity)
53     prs.ColorArrayName = field_name
54     prs.LookupTable = lookup_table
55
56     # Add scalar bar
57     add_scalar_bar(field_name, nb_components,
58                    vector_mode, lookup_table, time_value)
59     
60
61 # 1. Import of the "Penta6.med" file
62 print 'Import "Penta6.med" file........',
63 file_path = datadir + "Penta6.med"
64 my_paravis.ImportFile(file_path)
65 med_reader = pvsimple.GetActiveSource()
66 if med_reader is None:
67     raise RuntimeError, "Penta6.med was not imported!!!"
68 else:
69     print "OK"
70
71 view = pvsimple.GetRenderView()
72
73 # 2. Creation of "CutPlanes" presentation, based on time stamp of "scalar field" field
74 print 'Creation of "CutPlanes" presentation, based on time stamp of "scalar field" field....'
75 cutplanes = CutPlanesOnField(med_reader, EntityType.CELL, "scalar_field", 1)
76 if cutplanes is None : 
77     raise RuntimeError, "Presentation is None!!!"
78 else:
79     print "OK"
80
81 print "Setting of deformation:"
82 warp_vector = pvsimple.WarpByVector(cutplanes.Input)
83 warp_vector.Vectors = ["vectoriel_field"]
84 warp_vector.ScaleFactor = 5.0
85
86 print "Got scale     : ", warp_vector.ScaleFactor
87 print "Got field name: ", warp_vector.Vectors
88
89 presentation = pvsimple.GetRepresentation(warp_vector)
90 set_prs_colored(presentation, med_reader, EntityType.CELL, "scalar_field", 'Magnitude', 1)
91
92 pic_path = os.path.join(picturedir, "deformed_cut_planes_scalar" + "." + pictureext)
93 process_prs_for_test(presentation, view, pic_path)
94
95 # 3. Creation of "CutPlanes" presentation, based on time stamp of "vectoriel field" field
96 print 'Creation of "CutPlanes" presentation, based on time stamp of "vectoriel field" field....'
97 cutplanes = CutPlanesOnField(med_reader, EntityType.CELL, "vectoriel_field", 1)
98
99 if cutplanes is None : 
100     raise RuntimeError, "Presentation is None!!!"
101 else:
102     print "OK"
103
104 print "Setting of deformation:"
105 warp_vector = pvsimple.WarpByVector(cutplanes.Input)
106 warp_vector.Vectors = ["vectoriel_field"]
107 warp_vector.ScaleFactor = 5.0
108
109 print "Got scale     : ", warp_vector.ScaleFactor
110 print "Got field name: ", warp_vector.Vectors
111
112 presentation = pvsimple.GetRepresentation(warp_vector)
113 set_prs_colored(presentation, med_reader, EntityType.CELL, "vectoriel_field", 'Magnitude', 1)
114
115 pic_path = os.path.join(picturedir, "deformed_cut_planes_vectorial" + "." + pictureext)
116 process_prs_for_test(presentation, view, pic_path)