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