]> SALOME platform Git repositories - modules/paravis.git/blob - test/VisuPrs/dump_study/A5.py
Salome HOME
Merge branch 'V7_dev'
[modules/paravis.git] / test / VisuPrs / dump_study / A5.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/A5 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 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', "ScaleFactor": 0.25, "NbContours": 4}
35
36 # 1. TimeStamps.med import
37 file_path = datadir + "fra.med"
38 OpenDataFile(file_path)
39 med_reader = GetActiveSource()
40 if med_reader is None :
41     raise RuntimeError, "TimeStamps.med wasn't imported..."
42
43 # 2. Plot3D creation
44 med_field = "VITESSE"
45
46 plot3d = Plot3DOnField(med_reader, EntityType.NODE, med_field, 1, is_contour=True)
47 plot3d.Visibility = 1
48 plot3d.SetScalarBarVisibility(GetActiveView(),1)
49
50 # apply settings
51 plot3d.Position = settings["Offset"]
52 plot3d.LookupTable.VectorMode = settings["ScalarMode"][0]
53 plot3d.LookupTable.VectorComponent =  settings["ScalarMode"][1]
54 plot3d.LookupTable.Discretize = settings["Discretize"]
55 plot3d.LookupTable.NumberOfTableValues = settings["NbColors"]
56 plot3d.LookupTable.UseLogScale = settings["UseLogScale"]
57
58 slice_filter = plot3d.Input.Input.Input.Input
59 normal = get_normal_by_orientation(Orientation.ZX, radians(22), radians(33))
60 bounds = get_bounds(med_reader)
61 pos = get_positions(1, normal, bounds, 0.11)
62 slice_filter.SliceType.Normal = normal
63 slice_filter.SliceOffsetValues = pos
64
65 plot3d.Input.Input.ScaleFactor = settings["ScaleFactor"]
66
67 contour_filter = plot3d.Input
68 rgb_points = plot3d.LookupTable.RGBPoints
69 scalar_range = [rgb_points[0], rgb_points[4]]
70 surfaces = get_contours(scalar_range, settings["NbContours"])
71 contour_filter.Isosurfaces = surfaces
72
73 bar = get_bar()
74 bar.Position = settings["Position"]
75 bar.Position2 = settings["Size"]
76 bar.NumberOfLabels = settings["NbLabels"]
77 bar.Title = settings["Title"]
78 bar.Orientation = settings["Orientation"]
79
80 # 3. Dump Study
81 text  = smtrace.stop_trace()
82 path_to_save = os.path.join(os.getenv("HOME"), "Plot3D.py")
83 save_trace( path_to_save, text )
84
85 # 4. Delete the created objects, recreate the view
86 delete_with_inputs(plot3d)
87 Delete(GetActiveView())
88 view = CreateRenderView()
89
90 # 5. Execution of the created script
91 execfile(path_to_save)
92
93 # 6. Checking of the settings done before dump
94 recreated_bar = view.Representations[1]
95 recreated_plot3d = view.Representations[0]
96
97 errors = 0
98 tolerance = 1e-05
99
100 # Offset
101 offset = recreated_plot3d.Position
102 for i in range(len(settings["Offset"])):
103     if abs(offset[i] - settings["Offset"][i]) > tolerance:
104         print "ERROR!!! Offset value with ", i, " index is incorrect: ", offset[i], " instead of ", settings["Offset"][i]
105         errors += 1
106
107 # Scalar mode
108 vector_mode = recreated_plot3d.LookupTable.VectorMode
109 vector_component = recreated_plot3d.LookupTable.VectorComponent
110
111 if vector_mode != settings["ScalarMode"][0]:
112     print "ERROR!!! Vector mode value is incorrect: ",  vector_mode, " instead of ", settings["ScalarMode"][0]
113     errors += 1
114 if vector_component != settings["ScalarMode"][1]:
115     print "ERROR!!! Vector component value is incorrect: ",  vector_component, " instead of ", settings["ScalarMode"][1]
116     errors += 1
117
118 # Position of scalar bar
119 pos_x = recreated_bar.Position[0]
120 pos_y = recreated_bar.Position[1]
121
122 if abs(pos_x - settings["Position"][0]) > tolerance:
123     print "ERROR!!! X coordinate of position of scalar bar is incorrect: ",  pos_x, " instead of ", settings["Position"][0]
124     errors += 1
125 if abs(pos_y - settings["Position"][1]) > tolerance:
126     print "ERROR!!! Y coordinate of position of scalar bar is incorrect: ",  pos_y, " instead of ", settings["Position"][1]
127     errors += 1
128
129 # Size of scalar bar
130 width  = recreated_bar.Position2[0]
131 height = recreated_bar.Position2[1]
132
133 if abs(width - settings["Size"][0]) > tolerance:
134     print "ERROR!!! Width of scalar bar is incorrect: ",  width, " instead of ", settings["Size"][0]
135     errors += 1
136 if abs(height - settings["Size"][1]) > tolerance:
137     print "ERROR!!! Height of scalar bar is incorrect: ",  height, " instead of ", settings["Size"][1]
138     errors += 1
139
140 # Discretize
141 discretize = recreated_plot3d.LookupTable.Discretize
142 if discretize != settings["Discretize"]:
143     print "ERROR!!! Discretize property is incorrect: ",  discretize, " instead of ", settings["Discretize"]
144     errors += 1
145
146 # Number of colors
147 nb_colors = recreated_plot3d.LookupTable.NumberOfTableValues
148 if nb_colors != settings["NbColors"]:
149     print "ERROR!!! Number of colors of scalar bar is incorrect: ",  nb_colors, " instead of ", settings["NbColors"]
150     errors += 1
151
152 # Number of labels
153 nb_labels = recreated_bar.NumberOfLabels
154 if nb_labels != settings["NbLabels"]:
155     print "ERROR!!! Number of labels of scalar bar is incorrect: ",  nb_labels, " instead of ", settings["NbLabels"]
156     errors += 1
157
158 # Title
159 title = recreated_bar.Title
160 if title != settings["Title"]:
161     print "ERROR!!! Title of presentation is incorrect: ",  title, " instead of ", settings["Title"]
162     errors += 1
163
164 # Scaling
165 use_log_scale = recreated_plot3d.LookupTable.UseLogScale
166 if use_log_scale != settings["UseLogScale"]:
167     print "ERROR!!! Scaling of presentation is incorrect: ",  use_log_scale, " instead of ", settings["UseLogScale"]
168     errors += 1
169
170 # Bar Orientation
171 orientation = recreated_bar.Orientation
172 if orientation != settings["Orientation"]:
173     print "ERROR!!! Orientation of scalar bar is incorrect: ",  orientation, " instead of ", settings["Orientation"]
174     errors += 1
175
176 # Scale Factor
177 scale_factor = recreated_plot3d.Input.Input.ScaleFactor
178 if abs(scale_factor - settings["ScaleFactor"]) > tolerance:
179     print "ERROR!!! Scale factor of presentation is incorrect: ",  scale_factor, " instead of ", settings["ScaleFactor"]
180     errors += 1
181
182 # Cutting plane
183 cur_slice_filter = recreated_plot3d.Input.Input.Input.Input
184
185 cur_normal = list(cur_slice_filter.SliceType.Normal)
186 if cur_normal != normal:
187     print "ERROR!!! Normal of the cutting plane is incorrect: ",  cur_normal, " instead of ", normal
188     errors += 1
189
190 cur_pos = list(cur_slice_filter.SliceOffsetValues)
191 if cur_pos != pos:
192     print "ERROR!!! Position of the cuttting plane is incorrect: ",  cur_pos, " instead of ", pos
193     errors += 1
194
195 # Contours
196 cur_surfaces = list(recreated_plot3d.Input.Isosurfaces)
197 if cur_surfaces != surfaces:
198     print "ERROR!!! Contours is incorrect: ",  cur_surfaces, " instead of ", surfaces
199     errors += 1
200
201 if errors > 0:
202     raise RuntimeError, "There is(are) some error(s) was(were) found... For more info see ERRORs above..."