Salome HOME
Update ParaVis non-regression test base in the following ways:
[modules/paravis.git] / test / VisuPrs / dump_study / A1.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/A1 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', "NbSurfaces": 444}
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. IsoSurfaces creation
36 med_field = "vitesse"
37
38 isosurfaces = IsoSurfacesOnField(med_reader, EntityType.NODE, med_field, 1)
39
40 # apply settings
41 isosurfaces.Position = settings["Offset"]
42 isosurfaces.LookupTable.VectorMode = settings["ScalarMode"][0]
43 isosurfaces.LookupTable.VectorComponent =  settings["ScalarMode"][1]
44 isosurfaces.LookupTable.Discretize = settings["Discretize"]
45 isosurfaces.LookupTable.NumberOfTableValues = settings["NbColors"]
46 isosurfaces.LookupTable.UseLogScale = settings["UseLogScale"]
47
48 contour_filter = isosurfaces.Input
49 rgb_points = isosurfaces.LookupTable.RGBPoints
50 scalar_range = [rgb_points[0], rgb_points[4]]
51 surfaces = get_contours(scalar_range, settings["NbSurfaces"])
52 contour_filter.Isosurfaces = surfaces
53
54 bar = get_bar()
55 bar.Position = settings["Position"]
56 bar.Position2 = settings["Size"]
57 bar.NumberOfLabels = settings["NbLabels"]
58 bar.Title = settings["Title"]
59 bar.Orientation = settings["Orientation"]
60
61 # 3. Dump Study
62 path_to_save = os.path.join(os.getenv("HOME"), "IsoSurfaces.py")
63 SaveTrace( path_to_save )
64
65 # 4. Delete the created objects, recreate the view
66 delete_with_inputs(isosurfaces)
67 Delete(GetActiveView())
68 view = CreateRenderView()
69
70 # 5. Execution of the created script
71 execfile(path_to_save)
72
73 # 6. Checking of the settings done before dump
74 recreated_bar = view.Representations[0]
75 recreated_isosurfaces = view.Representations[1]
76
77 errors = 0
78 tolerance = 1e-05
79
80 # Offset
81 offset = recreated_isosurfaces.Position
82 for i in range(len(settings["Offset"])):
83     if abs(offset[i] - settings["Offset"][i]) > tolerance:
84         print "ERROR!!! Offset value with ", i, " index is incorrect: ", offset[i], " instead of ", settings["Offset"][i]
85         errors += 1
86
87 # Scalar mode
88 vector_mode = recreated_isosurfaces.LookupTable.VectorMode
89 vector_component = recreated_isosurfaces.LookupTable.VectorComponent
90
91 if vector_mode != settings["ScalarMode"][0]:
92     print "ERROR!!! Vector mode value is incorrect: ",  vector_mode, " instead of ", settings["ScalarMode"][0]
93     errors += 1
94 if vector_component != settings["ScalarMode"][1]:
95     print "ERROR!!! Vector component value is incorrect: ",  vector_component, " instead of ", settings["ScalarMode"][1]
96     errors += 1
97
98 # Position of scalar bar
99 pos_x = recreated_bar.Position[0]
100 pos_y = recreated_bar.Position[1]
101
102 if abs(pos_x - settings["Position"][0]) > tolerance:
103     print "ERROR!!! X coordinate of position of scalar bar is incorrect: ",  pos_x, " instead of ", settings["Position"][0]
104     errors += 1
105 if abs(pos_y - settings["Position"][1]) > tolerance:
106     print "ERROR!!! Y coordinate of position of scalar bar is incorrect: ",  pos_y, " instead of ", settings["Position"][1]
107     errors += 1
108
109 # Size of scalar bar
110 width  = recreated_bar.Position2[0]
111 height = recreated_bar.Position2[1]
112
113 if abs(width - settings["Size"][0]) > tolerance:
114     print "ERROR!!! Width of scalar bar is incorrect: ",  width, " instead of ", settings["Size"][0]
115     errors += 1
116 if abs(height - settings["Size"][1]) > tolerance:
117     print "ERROR!!! Height of scalar bar is incorrect: ",  height, " instead of ", settings["Size"][1]
118     errors += 1
119
120 # Discretize
121 discretize = recreated_isosurfaces.LookupTable.Discretize
122 if discretize != settings["Discretize"]:
123     print "ERROR!!! Discretize property is incorrect: ",  discretize, " instead of ", settings["Discretize"]
124     errors += 1
125
126 # Number of colors
127 nb_colors = recreated_isosurfaces.LookupTable.NumberOfTableValues
128 if nb_colors != settings["NbColors"]:
129     print "ERROR!!! Number of colors of scalar bar is incorrect: ",  nb_colors, " instead of ", settings["NbColors"]
130     errors += 1
131
132 # Number of labels
133 nb_labels = recreated_bar.NumberOfLabels
134 if nb_labels != settings["NbLabels"]:
135     print "ERROR!!! Number of labels of scalar bar is incorrect: ",  nb_labels, " instead of ", settings["NbLabels"]
136     errors += 1
137
138 # Title
139 title = recreated_bar.Title
140 if title != settings["Title"]:
141     print "ERROR!!! Title of presentation is incorrect: ",  title, " instead of ", settings["Title"]
142     errors += 1
143
144 # Scaling
145 use_log_scale = recreated_isosurfaces.LookupTable.UseLogScale
146 if use_log_scale != settings["UseLogScale"]:
147     print "ERROR!!! Scaling of presentation is incorrect: ",  use_log_scale, " instead of ", settings["UseLogScale"]
148     errors += 1
149
150 # Bar Orientation
151 orientation = recreated_bar.Orientation
152 if orientation != settings["Orientation"]:
153     print "ERROR!!! Orientation of scalar bar is incorrect: ",  orientation, " instead of ", settings["Orientation"]
154     errors += 1
155
156 # NbSurfaces
157 nb_surfaces = len(recreated_isosurfaces.Input.Isosurfaces)
158 if nb_surfaces != settings["NbSurfaces"]:
159     print "ERROR!!! Number of surfaces of presentation is incorrect: ", nb_surfaces, " instead of ", settings["NbSurfaces"]
160     errors += 1
161
162 if errors > 0:
163     raise RuntimeError, "There is(are) some error(s) was(were) found... For more info see ERRORs above..."