1 # Copyright (C) 2010-2016 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/A4 case
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
28 GetActiveViewOrCreate('RenderView')
30 config = smtrace.start_trace()
31 config.SetFullyTraceSupplementalProxies(True)
32 config.SetPropertiesToTraceOnCreate(config.RECORD_ALL_PROPERTIES)
35 settings = {"Offset": [0.0001, 0.0002, 0], "ScalarMode": ("Component", 1), "Position": [0.1, 0.2], "Size": [0.15, 0.25], "Discretize": 1, "NbColors": 44, "NbLabels": 22, "Title": "My presentation"}
37 # 1. TimeStamps.med import
38 file_path = datadir + "TimeStamps.med"
39 OpenDataFile(file_path)
40 med_reader = GetActiveSource()
41 if med_reader is None :
42 raise RuntimeError, "TimeStamps.med wasn't imported..."
44 # 2. GaussPoints creation
45 med_field = "pression"
47 gausspoints = GaussPointsOnField(med_reader, EntityType.CELL, med_field, 1)
48 gausspoints.Visibility = 1
49 gausspoints.SetScalarBarVisibility(GetActiveView(),1)
52 gausspoints.Position = settings["Offset"]
53 gausspoints.LookupTable.VectorMode = settings["ScalarMode"][0]
54 gausspoints.LookupTable.VectorComponent = settings["ScalarMode"][1]
55 gausspoints.LookupTable.Discretize = settings["Discretize"]
56 gausspoints.LookupTable.NumberOfTableValues = settings["NbColors"]
59 bar.Position = settings["Position"]
60 bar.Position2 = settings["Size"]
61 bar.NumberOfLabels = settings["NbLabels"]
62 bar.Title = settings["Title"]
65 text = smtrace.stop_trace()
66 path_to_save = os.path.join(os.getenv("HOME"), "GaussPoints.py")
67 save_trace( path_to_save, text )
69 # 4. Delete the created objects, recreate the view
70 delete_with_inputs(gausspoints)
71 Delete(GetActiveView())
72 view = CreateRenderView()
74 # 5. Execution of the created script
75 execfile(path_to_save)
77 # 6. Checking of the settings done before dump
78 recreated_bar = view.Representations[1]
79 recreated_gausspoints = view.Representations[0]
85 offset = recreated_gausspoints.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]
92 vector_mode = recreated_gausspoints.LookupTable.VectorMode
93 vector_component = recreated_gausspoints.LookupTable.VectorComponent
95 if vector_mode != settings["ScalarMode"][0]:
96 print "ERROR!!! Vector mode value is incorrect: ", vector_mode, " instead of ", settings["ScalarMode"][0]
98 if vector_component != settings["ScalarMode"][1]:
99 print "ERROR!!! Vector component value is incorrect: ", vector_component, " instead of ", settings["ScalarMode"][1]
102 # Position of scalar bar
103 pos_x = recreated_bar.Position[0]
104 pos_y = recreated_bar.Position[1]
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]
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]
114 width = recreated_bar.Position2[0]
115 height = recreated_bar.Position2[1]
117 if abs(width - settings["Size"][0]) > tolerance:
118 print "ERROR!!! Width of scalar bar is incorrect: ", width, " instead of ", settings["Size"][0]
120 if abs(height - settings["Size"][1]) > tolerance:
121 print "ERROR!!! Height of scalar bar is incorrect: ", height, " instead of ", settings["Size"][1]
125 discretize = recreated_gausspoints.LookupTable.Discretize
126 if discretize != settings["Discretize"]:
127 print "ERROR!!! Discretize property is incorrect: ", discretize, " instead of ", settings["Discretize"]
131 nb_colors = recreated_gausspoints.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"]
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"]
143 title = recreated_bar.Title
144 if title != settings["Title"]:
145 print "ERROR!!! Title of presentation is incorrect: ", title, " instead of ", settings["Title"]
149 raise RuntimeError, "There is(are) some error(s) was(were) found... For more info see ERRORs above..."