Salome HOME
Synchronize adm files
[modules/paravis.git] / test / VisuPrs / dump_study / A6.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/dump_study/A6 case
21
22 from paravistest import datadir, delete_with_inputs
23 from presentations import *
24 import paravis
25 from pvsimple import *
26
27 my_paravis = paravis.myParavis
28
29 settings = {"Offset": [0.0001, 0.0002, 0], "ScalarMode": ("Component", 2), "Position": [0.1, 0.2], "Size": [0.15, 0.25], "Discretize": 1, "NbColors": 44, "NbLabels": 22, "Title": "My presentation", "UseLogScale": 1, "Orientation": 'Horizontal', "Scale": 0.12929}
30
31 # 1. TimeStamps.med import
32 file_path = datadir + "TimeStamps.med"
33 my_paravis.ImportFile(file_path)
34 med_reader = GetActiveSource()
35 if med_reader is None:
36     raise RuntimeError, "TimeStamps.med wasn't imported..."
37
38 # 2. ScalarMapOnDeformedShape creation
39 med_field = "vitesse"
40
41 prs = DeformedShapeAndScalarMapOnField(med_reader, EntityType.NODE, med_field, 1)
42
43 # apply settings
44 prs.Position = settings["Offset"]
45 prs.LookupTable.VectorMode = settings["ScalarMode"][0]
46 prs.LookupTable.VectorComponent =  settings["ScalarMode"][1]
47 prs.LookupTable.Discretize = settings["Discretize"]
48 prs.LookupTable.NumberOfTableValues = settings["NbColors"]
49 prs.LookupTable.UseLogScale = settings["UseLogScale"]
50
51 prs.Input.ScaleFactor = settings["Scale"]
52 range_min = prs.LookupTable.RGBPoints[0]
53 range_max = prs.LookupTable.RGBPoints[4]
54
55 bar = get_bar()
56 bar.Position = settings["Position"]
57 bar.Position2 = settings["Size"]
58 bar.NumberOfLabels = settings["NbLabels"]
59 bar.Title = settings["Title"]
60 bar.Orientation = settings["Orientation"]
61
62 # 3. Dump Study
63 path_to_save = os.path.join(os.getenv("HOME"), "ScalarMapOnDeformedShape.py")
64 SaveTrace( path_to_save )
65
66 # 4. Delete the created objects, recreate the view
67 delete_with_inputs(prs)
68 Delete(GetActiveView())
69 view = CreateRenderView()
70
71 # 5. Execution of the created script
72 execfile(path_to_save)
73
74 # 6. Checking of the settings done before dump
75 recreated_bar = view.Representations[0]
76 recreated_prs = view.Representations[1]
77
78 errors = 0
79 tolerance = 1e-05
80
81 # Offset
82 offset = recreated_prs.Position
83 for i in range(len(settings["Offset"])):
84     if abs(offset[i] - settings["Offset"][i]) > tolerance:
85         print "ERROR!!! Offset value with ", i, " index is incorrect: ", offset[i], " instead of ", settings["Offset"][i]
86         errors += 1
87
88 # Scalar mode
89 vector_mode = recreated_prs.LookupTable.VectorMode
90 vector_component = recreated_prs.LookupTable.VectorComponent
91
92 if vector_mode != settings["ScalarMode"][0]:
93     print "ERROR!!! Vector mode value is incorrect: ",  vector_mode, " instead of ", settings["ScalarMode"][0]
94     errors += 1
95 if vector_component != settings["ScalarMode"][1]:
96     print "ERROR!!! Vector component value is incorrect: ",  vector_component, " instead of ", settings["ScalarMode"][1]
97     errors += 1
98
99 # Position of scalar bar
100 pos_x = recreated_bar.Position[0]
101 pos_y = recreated_bar.Position[1]
102
103 if abs(pos_x - settings["Position"][0]) > tolerance:
104     print "ERROR!!! X coordinate of position of scalar bar is incorrect: ",  pos_x, " instead of ", settings["Position"][0]
105     errors += 1
106 if abs(pos_y - settings["Position"][1]) > tolerance:
107     print "ERROR!!! Y coordinate of position of scalar bar is incorrect: ",  pos_y, " instead of ", settings["Position"][1]
108     errors += 1
109
110 # Size of scalar bar
111 width  = recreated_bar.Position2[0]
112 height = recreated_bar.Position2[1]
113
114 if abs(width - settings["Size"][0]) > tolerance:
115     print "ERROR!!! Width of scalar bar is incorrect: ",  width, " instead of ", settings["Size"][0]
116     errors += 1
117 if abs(height - settings["Size"][1]) > tolerance:
118     print "ERROR!!! Height of scalar bar is incorrect: ",  height, " instead of ", settings["Size"][1]
119     errors += 1
120
121 # Discretize
122 discretize = recreated_prs.LookupTable.Discretize
123 if discretize != settings["Discretize"]:
124     print "ERROR!!! Discretize property is incorrect: ",  discretize, " instead of ", settings["Discretize"]
125     errors += 1
126
127 # Number of colors
128 nb_colors = recreated_prs.LookupTable.NumberOfTableValues
129 if nb_colors != settings["NbColors"]:
130     print "ERROR!!! Number of colors of scalar bar is incorrect: ",  nb_colors, " instead of ", settings["NbColors"]
131     errors += 1
132
133 # Number of labels
134 nb_labels = recreated_bar.NumberOfLabels
135 if nb_labels != settings["NbLabels"]:
136     print "ERROR!!! Number of labels of scalar bar is incorrect: ",  nb_labels, " instead of ", settings["NbLabels"]
137     errors += 1
138
139 # Title
140 title = recreated_bar.Title
141 if title != settings["Title"]:
142     print "ERROR!!! Title of presentation is incorrect: ",  title, " instead of ", settings["Title"]
143     errors += 1
144
145 # Scaling
146 use_log_scale = recreated_prs.LookupTable.UseLogScale
147 if use_log_scale != settings["UseLogScale"]:
148     print "ERROR!!! Scaling of presentation is incorrect: ",  use_log_scale, " instead of ", settings["UseLogScale"]
149     errors += 1
150
151 # Bar Orientation
152 orientation = recreated_bar.Orientation
153 if orientation != settings["Orientation"]:
154     print "ERROR!!! Orientation of scalar bar is incorrect: ",  orientation, " instead of ", settings["Orientation"]
155     errors += 1
156
157 # Range
158 cur_range_min = recreated_prs.LookupTable.RGBPoints[0]
159 cur_range_max = recreated_prs.LookupTable.RGBPoints[4]
160
161 if abs(cur_range_min - range_min) > tolerance:
162     print "ERROR!!! Minimum value of range of presentation is incorrect: ",  cur_range_min, " instead of ", range_min
163     errors += 1
164
165 if abs(cur_range_max - range_max) > tolerance:
166     print "ERROR!!! Maximum value of range of presentation is incorrect: ",  cur_range_max, " instead of ", range_max
167     errors += 1
168     
169 # Scale factor
170 scale = recreated_prs.Input.ScaleFactor
171 if abs(scale - settings["Scale"]) > tolerance:
172     print "ERROR!!! Scale of presentation is incorrect: ",  scale, " instead of ", settings["Scale"]
173     errors += 1
174
175 if errors > 0:
176     raise RuntimeError, "There is(are) some error(s) was(were) found... For more info see ERRORs above..."