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