Salome HOME
Renamed paravis into pvserver in tests.
[modules/paravis.git] / test / VisuPrs / dump_study / A8.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/A3 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', "Scale": 0.333, "ColorArray": "", "ColorComponents": [0.111, 0.222, 0.333],  "LineWidth": 2, "GlyphType": 'Cone', "GlyphPos": [-0.5, 0.0, 0.0]}
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. Vectors creation
39 med_field = "vitesse"
40
41 vectors = VectorsOnField(med_reader, EntityType.NODE, med_field, 1)
42
43 # apply settings
44 vectors.Position = settings["Offset"]
45 vectors.LookupTable.VectorMode = settings["ScalarMode"][0]
46 vectors.LookupTable.VectorComponent =  settings["ScalarMode"][1]
47 vectors.LookupTable.Discretize = settings["Discretize"]
48 vectors.LookupTable.NumberOfTableValues = settings["NbColors"]
49 vectors.LookupTable.UseLogScale = settings["UseLogScale"]
50
51 vectors.Input.SetScaleFactor = settings["Scale"]
52 vectors.ColorArrayName = ''
53 vectors.AmbientColor = settings["ColorComponents"]
54
55 vectors.LineWidth = settings["LineWidth"]
56 vectors.Input.GlyphType = settings["GlyphType"]
57 vectors.Input.GlyphType.Center = settings["GlyphPos"]
58
59 bar = get_bar()
60 bar.Position = settings["Position"]
61 bar.Position2 = settings["Size"]
62 bar.NumberOfLabels = settings["NbLabels"]
63 bar.Title = settings["Title"]
64 bar.Orientation = settings["Orientation"]
65
66 cone_glyth_type = type(vectors.Input.GlyphType)
67
68 # 3. Dump Study
69 path_to_save = os.path.join(os.getenv("HOME"), "Vectors.py")
70 SaveTrace( path_to_save )
71
72 # 4. Delete the created objects, recreate the view
73 delete_with_inputs(vectors)
74 Delete(GetActiveView())
75 view = CreateRenderView()
76
77 # 5. Execution of the created script
78 execfile(path_to_save)
79
80 # 6. Checking of the settings done before dump
81 recreated_bar = view.Representations[0]
82 recreated_vectors = view.Representations[1]
83
84 errors = 0
85 tolerance = 1e-05
86
87 # Offset
88 offset = recreated_vectors.Position
89 for i in range(len(settings["Offset"])):
90     if abs(offset[i] - settings["Offset"][i]) > tolerance:
91         print "ERROR!!! Offset value with ", i, " index is incorrect: ", offset[i], " instead of ", settings["Offset"][i]
92         errors += 1
93
94 # Scalar mode
95 vector_mode = recreated_vectors.LookupTable.VectorMode
96 vector_component = recreated_vectors.LookupTable.VectorComponent
97
98 if vector_mode != settings["ScalarMode"][0]:
99     print "ERROR!!! Vector mode value is incorrect: ",  vector_mode, " instead of ", settings["ScalarMode"][0]
100     errors += 1
101 if vector_component != settings["ScalarMode"][1]:
102     print "ERROR!!! Vector component value is incorrect: ",  vector_component, " instead of ", settings["ScalarMode"][1]
103     errors += 1
104
105 # Position of scalar bar
106 pos_x = recreated_bar.Position[0]
107 pos_y = recreated_bar.Position[1]
108
109 if abs(pos_x - settings["Position"][0]) > tolerance:
110     print "ERROR!!! X coordinate of position of scalar bar is incorrect: ",  pos_x, " instead of ", settings["Position"][0]
111     errors += 1
112 if abs(pos_y - settings["Position"][1]) > tolerance:
113     print "ERROR!!! Y coordinate of position of scalar bar is incorrect: ",  pos_y, " instead of ", settings["Position"][1]
114     errors += 1
115
116 # Size of scalar bar
117 width  = recreated_bar.Position2[0]
118 height = recreated_bar.Position2[1]
119
120 if abs(width - settings["Size"][0]) > tolerance:
121     print "ERROR!!! Width of scalar bar is incorrect: ",  width, " instead of ", settings["Size"][0]
122     errors += 1
123 if abs(height - settings["Size"][1]) > tolerance:
124     print "ERROR!!! Height of scalar bar is incorrect: ",  height, " instead of ", settings["Size"][1]
125     errors += 1
126
127 # Discretize
128 discretize = recreated_vectors.LookupTable.Discretize
129 if discretize != settings["Discretize"]:
130     print "ERROR!!! Discretize property is incorrect: ",  discretize, " instead of ", settings["Discretize"]
131     errors += 1
132
133 # Number of colors
134 nb_colors = recreated_vectors.LookupTable.NumberOfTableValues
135 if nb_colors != settings["NbColors"]:
136     print "ERROR!!! Number of colors of scalar bar is incorrect: ",  nb_colors, " instead of ", settings["NbColors"]
137     errors += 1
138
139 # Number of labels
140 nb_labels = recreated_bar.NumberOfLabels
141 if nb_labels != settings["NbLabels"]:
142     print "ERROR!!! Number of labels of scalar bar is incorrect: ",  nb_labels, " instead of ", settings["NbLabels"]
143     errors += 1
144
145 # Title
146 title = recreated_bar.Title
147 if title != settings["Title"]:
148     print "ERROR!!! Title of presentation is incorrect: ",  title, " instead of ", settings["Title"]
149     errors += 1
150
151 # Scaling
152 use_log_scale = recreated_vectors.LookupTable.UseLogScale
153 if use_log_scale != settings["UseLogScale"]:
154     print "ERROR!!! Scaling of presentation is incorrect: ",  use_log_scale, " instead of ", settings["UseLogScale"]
155     errors += 1
156
157 # Bar Orientation
158 orientation = recreated_bar.Orientation
159 if orientation != settings["Orientation"]:
160     print "ERROR!!! Orientation of scalar bar is incorrect: ",  orientation, " instead of ", settings["Orientation"]
161     errors += 1
162
163 # Scale factor
164 scale = recreated_vectors.Input.SetScaleFactor
165 if abs(scale - settings["Scale"]) > tolerance:
166     print "ERROR!!! Scale of presentation is incorrect: ",  scale, " instead of ", settings["Scale"]
167     errors += 1
168
169 # Color array name
170 array_name = recreated_vectors.ColorArrayName
171 if array_name != settings["ColorArray"]:
172     print "ERROR!!! Color array name of presentation is incorrect: ",  array_name, " instead of ", settings["arrayName"]
173     errors += 1
174
175 # Color
176 color = list(recreated_vectors.AmbientColor)
177 if color != settings["ColorComponents"]:
178     print "ERROR!!! Color of presentation is incorrect: ",  color, " instead of ", settings["ColorComponents"]
179     errors += 1
180
181 # Line width
182 line_width = recreated_vectors.LineWidth
183 if abs(line_width - settings["LineWidth"]) > tolerance:
184     print "ERROR!!! Line width of presentation is incorrect: ",  line_width, " instead of ", settings["LineWidth"]
185     errors += 1
186
187 # Glyph type
188 glyph_type = type(recreated_vectors.Input.GlyphType)
189 if glyph_type != cone_glyth_type:
190     print "ERROR!!! Glyph type is incorrect: ", glyph_type, " instead of ", cone_glyth_type
191     errors += 1
192
193 # Glyph position
194 glyph_position = list(recreated_vectors.Input.GlyphType.Center)
195 if glyph_position != settings["GlyphPos"]:
196     print "ERROR!!! Glyph position is incorrect: ", glyph_position, " instead of ", settings["GlyphPos"]
197     errors += 1
198
199 if errors > 0:
200     raise RuntimeError, "There is(are) some error(s) was(were) found... For more info see ERRORs above..."