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