]> SALOME platform Git repositories - modules/paravis.git/blob - test/VisuPrs/dump_study/A3.py
Salome HOME
Merge branch 'V7_dev'
[modules/paravis.git] / test / VisuPrs / dump_study / A3.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 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, "ColorArray": "", "ColorComponents": [0.111, 0.222, 0.333]}
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. DeformedShape creation
44 med_field = "vitesse"
45
46 deformedshape = DeformedShapeOnField(med_reader, EntityType.NODE, med_field, 1, None, True)
47 deformedshape.Visibility = 1
48 deformedshape.SetScalarBarVisibility(GetActiveView(),1)
49
50 # apply settings
51 deformedshape.Position = settings["Offset"]
52 deformedshape.LookupTable.VectorMode = settings["ScalarMode"][0]
53 deformedshape.LookupTable.VectorComponent =  settings["ScalarMode"][1]
54 deformedshape.LookupTable.Discretize = settings["Discretize"]
55 deformedshape.LookupTable.NumberOfTableValues = settings["NbColors"]
56 deformedshape.LookupTable.UseLogScale = settings["UseLogScale"]
57
58 deformedshape.Input.ScaleFactor = settings["Scale"]
59 deformedshape.ColorArrayName = (None, '')
60 deformedshape.AmbientColor = settings["ColorComponents"]
61
62 bar = get_bar()
63 bar.Position = settings["Position"]
64 bar.Position2 = settings["Size"]
65 bar.NumberOfLabels = settings["NbLabels"]
66 bar.Title = settings["Title"]
67 bar.Orientation = settings["Orientation"]
68
69 # 3. Dump Study
70 text  = smtrace.stop_trace()
71 path_to_save = os.path.join(os.getenv("HOME"), "DeformedShape.py")
72 save_trace( path_to_save, text )
73
74 # 4. Delete the created objects, recreate the view
75 delete_with_inputs(deformedshape)
76 Delete(GetActiveView())
77 view = CreateRenderView()
78
79 # 5. Execution of the created script
80 execfile(path_to_save)
81
82 # 6. Checking of the settings done before dump
83 recreated_bar = view.Representations[1]
84 recreated_deformedshape = view.Representations[0]
85
86 errors = 0
87 tolerance = 1e-05
88
89 # Offset
90 offset = recreated_deformedshape.Position
91 for i in range(len(settings["Offset"])):
92     if abs(offset[i] - settings["Offset"][i]) > tolerance:
93         print "ERROR!!! Offset value with ", i, " index is incorrect: ", offset[i], " instead of ", settings["Offset"][i]
94         errors += 1
95
96 # Scalar mode
97 vector_mode = recreated_deformedshape.LookupTable.VectorMode
98 vector_component = recreated_deformedshape.LookupTable.VectorComponent
99
100 if vector_mode != settings["ScalarMode"][0]:
101     print "ERROR!!! Vector mode value is incorrect: ",  vector_mode, " instead of ", settings["ScalarMode"][0]
102     errors += 1
103 if vector_component != settings["ScalarMode"][1]:
104     print "ERROR!!! Vector component value is incorrect: ",  vector_component, " instead of ", settings["ScalarMode"][1]
105     errors += 1
106
107 # Position of scalar bar
108 pos_x = recreated_bar.Position[0]
109 pos_y = recreated_bar.Position[1]
110
111 if abs(pos_x - settings["Position"][0]) > tolerance:
112     print "ERROR!!! X coordinate of position of scalar bar is incorrect: ",  pos_x, " instead of ", settings["Position"][0]
113     errors += 1
114 if abs(pos_y - settings["Position"][1]) > tolerance:
115     print "ERROR!!! Y coordinate of position of scalar bar is incorrect: ",  pos_y, " instead of ", settings["Position"][1]
116     errors += 1
117
118 # Size of scalar bar
119 width  = recreated_bar.Position2[0]
120 height = recreated_bar.Position2[1]
121
122 if abs(width - settings["Size"][0]) > tolerance:
123     print "ERROR!!! Width of scalar bar is incorrect: ",  width, " instead of ", settings["Size"][0]
124     errors += 1
125 if abs(height - settings["Size"][1]) > tolerance:
126     print "ERROR!!! Height of scalar bar is incorrect: ",  height, " instead of ", settings["Size"][1]
127     errors += 1
128
129 # Discretize
130 discretize = recreated_deformedshape.LookupTable.Discretize
131 if discretize != settings["Discretize"]:
132     print "ERROR!!! Discretize property is incorrect: ",  discretize, " instead of ", settings["Discretize"]
133     errors += 1
134
135 # Number of colors
136 nb_colors = recreated_deformedshape.LookupTable.NumberOfTableValues
137 if nb_colors != settings["NbColors"]:
138     print "ERROR!!! Number of colors of scalar bar is incorrect: ",  nb_colors, " instead of ", settings["NbColors"]
139     errors += 1
140
141 # Number of labels
142 nb_labels = recreated_bar.NumberOfLabels
143 if nb_labels != settings["NbLabels"]:
144     print "ERROR!!! Number of labels of scalar bar is incorrect: ",  nb_labels, " instead of ", settings["NbLabels"]
145     errors += 1
146
147 # Title
148 title = recreated_bar.Title
149 if title != settings["Title"]:
150     print "ERROR!!! Title of presentation is incorrect: ",  title, " instead of ", settings["Title"]
151     errors += 1
152
153 # Scaling
154 use_log_scale = recreated_deformedshape.LookupTable.UseLogScale
155 if use_log_scale != settings["UseLogScale"]:
156     print "ERROR!!! Scaling of presentation is incorrect: ",  use_log_scale, " instead of ", settings["UseLogScale"]
157     errors += 1
158
159 # Bar Orientation
160 orientation = recreated_bar.Orientation
161 if orientation != settings["Orientation"]:
162     print "ERROR!!! Orientation of scalar bar is incorrect: ",  orientation, " instead of ", settings["Orientation"]
163     errors += 1
164
165 # Scale factor
166 scale = recreated_deformedshape.Input.ScaleFactor
167 if abs(scale - settings["Scale"]) > tolerance:
168     print "ERROR!!! Scale of presentation is incorrect: ",  scale, " instead of ", settings["Scale"]
169     errors += 1
170
171 # Color array name
172 array_name = recreated_deformedshape.ColorArrayName[1]
173 if array_name != med_field:
174     print "ERROR!!! Color array name of presentation is incorrect: ",  array_name , " instead of ", med_field
175     errors += 1
176
177 # Color
178 color = list(recreated_deformedshape.AmbientColor)
179 if color != settings["ColorComponents"]:
180     print "ERROR!!! Color of presentation is incorrect: ",  color, " instead of ", settings["ColorComponents"]
181     errors += 1
182
183 if errors > 0:
184     raise RuntimeError, "There is(are) some error(s) was(were) found... For more info see ERRORs above..."