Salome HOME
66d855e2598492a7dd380f30a63d776195b96368
[modules/paravis.git] / test / VisuPrs / dump_study / A2.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/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'}
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. CutPlanes creation
39 med_field = "vitesse"
40
41 cutplanes = CutPlanesOnField(med_reader, EntityType.NODE, med_field, 1)
42
43 # apply settings
44 cutplanes.Position = settings["Offset"]
45 cutplanes.LookupTable.VectorMode = settings["ScalarMode"][0]
46 cutplanes.LookupTable.VectorComponent =  settings["ScalarMode"][1]
47 cutplanes.LookupTable.Discretize = settings["Discretize"]
48 cutplanes.LookupTable.NumberOfTableValues = settings["NbColors"]
49 cutplanes.LookupTable.UseLogScale = settings["UseLogScale"]
50
51 normal = get_normal_by_orientation(Orientation.YZ, radians(33), radians(44))
52 bounds = get_bounds(med_reader)
53 pos = get_positions(2, normal, bounds, 0.1)
54 pos[1] = 0.5
55 cutplanes.Input.SliceType.Normal = normal
56 cutplanes.Input.SliceOffsetValues = pos
57
58 bar = get_bar()
59 bar.Position = settings["Position"]
60 bar.Position2 = settings["Size"]
61 bar.NumberOfLabels = settings["NbLabels"]
62 bar.Title = settings["Title"]
63 bar.Orientation = settings["Orientation"]
64
65 # 3. Dump Study
66 path_to_save = os.path.join(os.getenv("HOME"), "CutPlanes.py")
67 SaveTrace( path_to_save )
68
69 # 4. Delete the created objects, recreate the view
70 delete_with_inputs(cutplanes)
71 Delete(GetActiveView())
72 view = CreateRenderView()
73
74 # 5. Execution of the created script
75 execfile(path_to_save)
76
77 # 6. Checking of the settings done before dump
78 recreated_bar = view.Representations[0]
79 recreated_cutplanes = view.Representations[1]
80
81 errors = 0
82 tolerance = 1e-05
83
84 # Offset
85 offset = recreated_cutplanes.Position
86 for i in range(len(settings["Offset"])):
87     if abs(offset[i] - settings["Offset"][i]) > tolerance:
88         print "ERROR!!! Offset value with ", i, " index is incorrect: ", offset[i], " instead of ", settings["Offset"][i]
89         errors += 1
90
91 # Scalar mode
92 vector_mode = recreated_cutplanes.LookupTable.VectorMode
93 vector_component = recreated_cutplanes.LookupTable.VectorComponent
94
95 if vector_mode != settings["ScalarMode"][0]:
96     print "ERROR!!! Vector mode value is incorrect: ",  vector_mode, " instead of ", settings["ScalarMode"][0]
97     errors += 1
98 if vector_component != settings["ScalarMode"][1]:
99     print "ERROR!!! Vector component value is incorrect: ",  vector_component, " instead of ", settings["ScalarMode"][1]
100     errors += 1
101
102 # Position of scalar bar
103 pos_x = recreated_bar.Position[0]
104 pos_y = recreated_bar.Position[1]
105
106 if abs(pos_x - settings["Position"][0]) > tolerance:
107     print "ERROR!!! X coordinate of position of scalar bar is incorrect: ",  pos_x, " instead of ", settings["Position"][0]
108     errors += 1
109 if abs(pos_y - settings["Position"][1]) > tolerance:
110     print "ERROR!!! Y coordinate of position of scalar bar is incorrect: ",  pos_y, " instead of ", settings["Position"][1]
111     errors += 1
112
113 # Size of scalar bar
114 width  = recreated_bar.Position2[0]
115 height = recreated_bar.Position2[1]
116
117 if abs(width - settings["Size"][0]) > tolerance:
118     print "ERROR!!! Width of scalar bar is incorrect: ",  width, " instead of ", settings["Size"][0]
119     errors += 1
120 if abs(height - settings["Size"][1]) > tolerance:
121     print "ERROR!!! Height of scalar bar is incorrect: ",  height, " instead of ", settings["Size"][1]
122     errors += 1
123
124 # Discretize
125 discretize = recreated_cutplanes.LookupTable.Discretize
126 if discretize != settings["Discretize"]:
127     print "ERROR!!! Discretize property is incorrect: ",  discretize, " instead of ", settings["Discretize"]
128     errors += 1
129
130 # Number of colors
131 nb_colors = recreated_cutplanes.LookupTable.NumberOfTableValues
132 if nb_colors != settings["NbColors"]:
133     print "ERROR!!! Number of colors of scalar bar is incorrect: ",  nb_colors, " instead of ", settings["NbColors"]
134     errors += 1
135
136 # Number of labels
137 nb_labels = recreated_bar.NumberOfLabels
138 if nb_labels != settings["NbLabels"]:
139     print "ERROR!!! Number of labels of scalar bar is incorrect: ",  nb_labels, " instead of ", settings["NbLabels"]
140     errors += 1
141
142 # Title
143 title = recreated_bar.Title
144 if title != settings["Title"]:
145     print "ERROR!!! Title of presentation is incorrect: ",  title, " instead of ", settings["Title"]
146     errors += 1
147
148 # Scaling
149 use_log_scale = recreated_cutplanes.LookupTable.UseLogScale
150 if use_log_scale != settings["UseLogScale"]:
151     print "ERROR!!! Scaling of presentation is incorrect: ",  use_log_scale, " instead of ", settings["UseLogScale"]
152     errors += 1
153
154 # Bar Orientation
155 orientation = recreated_bar.Orientation
156 if orientation != settings["Orientation"]:
157     print "ERROR!!! Orientation of scalar bar is incorrect: ",  orientation, " instead of ", settings["Orientation"]
158     errors += 1
159
160 # Normal
161 cur_normal = list(recreated_cutplanes.Input.SliceType.Normal)
162 if cur_normal != normal:
163     print "ERROR!!! Normal of cut planes is incorrect: ",  cur_normal, " instead of ", normal
164     errors += 1
165
166 # Position
167 cur_pos = list(recreated_cutplanes.Input.SliceOffsetValues)
168 if cur_pos != pos:
169     print "ERROR!!! Positions of cut planes is incorrect: ",  cur_pos, " instead of ", pos
170     errors += 1
171
172 if errors > 0:
173     raise RuntimeError, "There is(are) some error(s) was(were) found... For more info see ERRORs above..."