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