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