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