1 # Copyright (C) 2010-2015 CEA/DEN, EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # This case corresponds to: /visu/dump_study/A0 case
22 from paravistest import datadir, delete_with_inputs
23 from presentations import *
24 from pvsimple import *
26 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'}
28 # 1. TimeStamps.med import
29 file_path = datadir + "TimeStamps.med"
30 OpenDataFile(file_path)
31 med_reader = GetActiveSource()
32 if med_reader is None :
33 raise RuntimeError, "TimeStamps.med wasn't imported..."
35 # 2. ScalarMap creation
38 scalarmap = ScalarMapOnField(med_reader, EntityType.NODE, med_field, 1)
41 scalarmap.Position = settings["Offset"]
42 scalarmap.LookupTable.VectorMode = settings["ScalarMode"][0]
43 scalarmap.LookupTable.VectorComponent = settings["ScalarMode"][1]
44 scalarmap.LookupTable.Discretize = settings["Discretize"]
45 scalarmap.LookupTable.NumberOfTableValues = settings["NbColors"]
46 scalarmap.LookupTable.UseLogScale = settings["UseLogScale"]
49 bar.Position = settings["Position"]
50 bar.Position2 = settings["Size"]
51 bar.NumberOfLabels = settings["NbLabels"]
52 bar.Title = settings["Title"]
53 bar.Orientation = settings["Orientation"]
56 path_to_save = os.path.join(os.getenv("HOME"), "ScalarMap.py")
57 SaveTrace( path_to_save )
59 # 4. Delete the created objects, recreate the view
60 delete_with_inputs(scalarmap)
61 Delete(GetActiveView())
62 view = CreateRenderView()
64 # 5. Execution of the created script
65 execfile(path_to_save)
67 # 6. Checking of the settings done before dump
68 recreated_bar = view.Representations[0]
69 recreated_scalarmap = view.Representations[1]
75 offset = recreated_scalarmap.Position
76 for i in range(len(settings["Offset"])):
77 if abs(offset[i] - settings["Offset"][i]) > tolerance:
78 print "ERROR!!! Offset value with ", i, " index is incorrect: ", offset[i], " instead of ", settings["Offset"][i]
82 vector_mode = recreated_scalarmap.LookupTable.VectorMode
83 vector_component = recreated_scalarmap.LookupTable.VectorComponent
85 if vector_mode != settings["ScalarMode"][0]:
86 print "ERROR!!! Vector mode value is incorrect: ", vector_mode, " instead of ", settings["ScalarMode"][0]
88 if vector_component != settings["ScalarMode"][1]:
89 print "ERROR!!! Vector component value is incorrect: ", vector_component, " instead of ", settings["ScalarMode"][1]
92 # Position of scalar bar
93 pos_x = recreated_bar.Position[0]
94 pos_y = recreated_bar.Position[1]
96 if abs(pos_x - settings["Position"][0]) > tolerance:
97 print "ERROR!!! X coordinate of position of scalar bar is incorrect: ", pos_x, " instead of ", settings["Position"][0]
99 if abs(pos_y - settings["Position"][1]) > tolerance:
100 print "ERROR!!! Y coordinate of position of scalar bar is incorrect: ", pos_y, " instead of ", settings["Position"][1]
104 width = recreated_bar.Position2[0]
105 height = recreated_bar.Position2[1]
107 if abs(width - settings["Size"][0]) > tolerance:
108 print "ERROR!!! Width of scalar bar is incorrect: ", width, " instead of ", settings["Size"][0]
110 if abs(height - settings["Size"][1]) > tolerance:
111 print "ERROR!!! Height of scalar bar is incorrect: ", height, " instead of ", settings["Size"][1]
115 discretize = recreated_scalarmap.LookupTable.Discretize
116 if discretize != settings["Discretize"]:
117 print "ERROR!!! Discretize property is incorrect: ", discretize, " instead of ", settings["Discretize"]
121 nb_colors = recreated_scalarmap.LookupTable.NumberOfTableValues
122 if nb_colors != settings["NbColors"]:
123 print "ERROR!!! Number of colors of scalar bar is incorrect: ", nb_colors, " instead of ", settings["NbColors"]
127 nb_labels = recreated_bar.NumberOfLabels
128 if nb_labels != settings["NbLabels"]:
129 print "ERROR!!! Number of labels of scalar bar is incorrect: ", nb_labels, " instead of ", settings["NbLabels"]
133 title = recreated_bar.Title
134 if title != settings["Title"]:
135 print "ERROR!!! Title of presentation is incorrect: ", title, " instead of ", settings["Title"]
139 use_log_scale = recreated_scalarmap.LookupTable.UseLogScale
140 if use_log_scale != settings["UseLogScale"]:
141 print "ERROR!!! Scaling of presentation is incorrect: ", use_log_scale, " instead of ", settings["UseLogScale"]
145 orientation = recreated_bar.Orientation
146 if orientation != settings["Orientation"]:
147 print "ERROR!!! Orientation of scalar bar is incorrect: ", orientation, " instead of ", settings["Orientation"]
151 raise RuntimeError, "There is(are) some error(s) was(were) found... For more info see ERRORs above..."