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