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/A5 case
22 from paravistest import datadir, delete_with_inputs
23 from presentations import *
24 import pvserver as paravis
25 from pvsimple import *
27 my_paravis = paravis.myParavis
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', "ScaleFactor": 0.25, "NbContours": 4}
31 # 1. TimeStamps.med import
32 file_path = datadir + "fra.med"
33 OpenDataFile(file_path)
34 med_reader = GetActiveSource()
35 if med_reader is None :
36 raise RuntimeError, "TimeStamps.med wasn't imported..."
41 plot3d = Plot3DOnField(med_reader, EntityType.NODE, med_field, 1, is_contour=True)
44 plot3d.Position = settings["Offset"]
45 plot3d.LookupTable.VectorMode = settings["ScalarMode"][0]
46 plot3d.LookupTable.VectorComponent = settings["ScalarMode"][1]
47 plot3d.LookupTable.Discretize = settings["Discretize"]
48 plot3d.LookupTable.NumberOfTableValues = settings["NbColors"]
49 plot3d.LookupTable.UseLogScale = settings["UseLogScale"]
51 slice_filter = plot3d.Input.Input.Input.Input
52 normal = get_normal_by_orientation(Orientation.ZX, radians(22), radians(33))
53 bounds = get_bounds(med_reader)
54 pos = get_positions(1, normal, bounds, 0.11)
55 slice_filter.SliceType.Normal = normal
56 slice_filter.SliceOffsetValues = pos
58 plot3d.Input.Input.ScaleFactor = settings["ScaleFactor"]
60 contour_filter = plot3d.Input
61 rgb_points = plot3d.LookupTable.RGBPoints
62 scalar_range = [rgb_points[0], rgb_points[4]]
63 surfaces = get_contours(scalar_range, settings["NbContours"])
64 contour_filter.Isosurfaces = surfaces
67 bar.Position = settings["Position"]
68 bar.Position2 = settings["Size"]
69 bar.NumberOfLabels = settings["NbLabels"]
70 bar.Title = settings["Title"]
71 bar.Orientation = settings["Orientation"]
74 path_to_save = os.path.join(os.getenv("HOME"), "Plot3D.py")
75 SaveTrace( path_to_save )
77 # 4. Delete the created objects, recreate the view
78 delete_with_inputs(plot3d)
79 Delete(GetActiveView())
80 view = CreateRenderView()
82 # 5. Execution of the created script
83 execfile(path_to_save)
85 # 6. Checking of the settings done before dump
86 recreated_bar = view.Representations[0]
87 recreated_plot3d = view.Representations[1]
93 offset = recreated_plot3d.Position
94 for i in range(len(settings["Offset"])):
95 if abs(offset[i] - settings["Offset"][i]) > tolerance:
96 print "ERROR!!! Offset value with ", i, " index is incorrect: ", offset[i], " instead of ", settings["Offset"][i]
100 vector_mode = recreated_plot3d.LookupTable.VectorMode
101 vector_component = recreated_plot3d.LookupTable.VectorComponent
103 if vector_mode != settings["ScalarMode"][0]:
104 print "ERROR!!! Vector mode value is incorrect: ", vector_mode, " instead of ", settings["ScalarMode"][0]
106 if vector_component != settings["ScalarMode"][1]:
107 print "ERROR!!! Vector component value is incorrect: ", vector_component, " instead of ", settings["ScalarMode"][1]
110 # Position of scalar bar
111 pos_x = recreated_bar.Position[0]
112 pos_y = recreated_bar.Position[1]
114 if abs(pos_x - settings["Position"][0]) > tolerance:
115 print "ERROR!!! X coordinate of position of scalar bar is incorrect: ", pos_x, " instead of ", settings["Position"][0]
117 if abs(pos_y - settings["Position"][1]) > tolerance:
118 print "ERROR!!! Y coordinate of position of scalar bar is incorrect: ", pos_y, " instead of ", settings["Position"][1]
122 width = recreated_bar.Position2[0]
123 height = recreated_bar.Position2[1]
125 if abs(width - settings["Size"][0]) > tolerance:
126 print "ERROR!!! Width of scalar bar is incorrect: ", width, " instead of ", settings["Size"][0]
128 if abs(height - settings["Size"][1]) > tolerance:
129 print "ERROR!!! Height of scalar bar is incorrect: ", height, " instead of ", settings["Size"][1]
133 discretize = recreated_plot3d.LookupTable.Discretize
134 if discretize != settings["Discretize"]:
135 print "ERROR!!! Discretize property is incorrect: ", discretize, " instead of ", settings["Discretize"]
139 nb_colors = recreated_plot3d.LookupTable.NumberOfTableValues
140 if nb_colors != settings["NbColors"]:
141 print "ERROR!!! Number of colors of scalar bar is incorrect: ", nb_colors, " instead of ", settings["NbColors"]
145 nb_labels = recreated_bar.NumberOfLabels
146 if nb_labels != settings["NbLabels"]:
147 print "ERROR!!! Number of labels of scalar bar is incorrect: ", nb_labels, " instead of ", settings["NbLabels"]
151 title = recreated_bar.Title
152 if title != settings["Title"]:
153 print "ERROR!!! Title of presentation is incorrect: ", title, " instead of ", settings["Title"]
157 use_log_scale = recreated_plot3d.LookupTable.UseLogScale
158 if use_log_scale != settings["UseLogScale"]:
159 print "ERROR!!! Scaling of presentation is incorrect: ", use_log_scale, " instead of ", settings["UseLogScale"]
163 orientation = recreated_bar.Orientation
164 if orientation != settings["Orientation"]:
165 print "ERROR!!! Orientation of scalar bar is incorrect: ", orientation, " instead of ", settings["Orientation"]
169 scale_factor = recreated_plot3d.Input.Input.ScaleFactor
170 if abs(scale_factor - settings["ScaleFactor"]) > tolerance:
171 print "ERROR!!! Scale factor of presentation is incorrect: ", scale_factor, " instead of ", settings["ScaleFactor"]
175 cur_slice_filter = recreated_plot3d.Input.Input.Input.Input
177 cur_normal = list(cur_slice_filter.SliceType.Normal)
178 if cur_normal != normal:
179 print "ERROR!!! Normal of the cutting plane is incorrect: ", cur_normal, " instead of ", normal
182 cur_pos = list(cur_slice_filter.SliceOffsetValues)
184 print "ERROR!!! Position of the cuttting plane is incorrect: ", cur_pos, " instead of ", pos
188 cur_surfaces = list(recreated_plot3d.Input.Isosurfaces)
189 if cur_surfaces != surfaces:
190 print "ERROR!!! Contours is incorrect: ", cur_surfaces, " instead of ", surfaces
194 raise RuntimeError, "There is(are) some error(s) was(were) found... For more info see ERRORs above..."