Salome HOME
Copyrights update 2015.
[modules/paravis.git] / test / VisuPrs / dump_study / A4.py
1 # Copyright (C) 2010-2015  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/A4 case
21
22 from paravistest import datadir, delete_with_inputs
23 from presentations import *
24 import pvserver as paravis
25 from pvsimple import *
26
27 my_paravis = paravis.myParavis
28
29 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"}
30
31 # 1. TimeStamps.med import
32 file_path = datadir + "TimeStamps.med"
33 OpenDataFile(file_path)
34 med_reader = GetActiveSource()
35 if med_reader is None :
36     raise RuntimeError, "TimeStamps.med wasn't imported..."
37
38 # 2. GaussPoints creation
39 med_field = "pression"
40
41 gausspoints = GaussPointsOnField(med_reader, EntityType.CELL, med_field, 1)
42
43 # apply settings
44 gausspoints.Position = settings["Offset"]
45 gausspoints.LookupTable.VectorMode = settings["ScalarMode"][0]
46 gausspoints.LookupTable.VectorComponent =  settings["ScalarMode"][1]
47 gausspoints.LookupTable.Discretize = settings["Discretize"]
48 gausspoints.LookupTable.NumberOfTableValues = settings["NbColors"]
49
50 bar = get_bar()
51 bar.Position = settings["Position"]
52 bar.Position2 = settings["Size"]
53 bar.NumberOfLabels = settings["NbLabels"]
54 bar.Title = settings["Title"]
55
56 # 3. Dump Study
57 path_to_save = os.path.join(os.getenv("HOME"), "GaussPoints.py")
58 SaveTrace( path_to_save )
59
60 # 4. Delete the created objects, recreate the view
61 delete_with_inputs(gausspoints)
62 Delete(GetActiveView())
63 view = CreateRenderView()
64
65 # 5. Execution of the created script
66 execfile(path_to_save)
67
68 # 6. Checking of the settings done before dump
69 recreated_bar = view.Representations[0]
70 recreated_gausspoints = view.Representations[1]
71
72 errors = 0
73 tolerance = 1e-05
74
75 # Offset
76 offset = recreated_gausspoints.Position
77 for i in range(len(settings["Offset"])):
78     if abs(offset[i] - settings["Offset"][i]) > tolerance:
79         print "ERROR!!! Offset value with ", i, " index is incorrect: ", offset[i], " instead of ", settings["Offset"][i]
80         errors += 1
81
82 # Scalar mode
83 vector_mode = recreated_gausspoints.LookupTable.VectorMode
84 vector_component = recreated_gausspoints.LookupTable.VectorComponent
85
86 if vector_mode != settings["ScalarMode"][0]:
87     print "ERROR!!! Vector mode value is incorrect: ",  vector_mode, " instead of ", settings["ScalarMode"][0]
88     errors += 1
89 if vector_component != settings["ScalarMode"][1]:
90     print "ERROR!!! Vector component value is incorrect: ",  vector_component, " instead of ", settings["ScalarMode"][1]
91     errors += 1
92
93 # Position of scalar bar
94 pos_x = recreated_bar.Position[0]
95 pos_y = recreated_bar.Position[1]
96
97 if abs(pos_x - settings["Position"][0]) > tolerance:
98     print "ERROR!!! X coordinate of position of scalar bar is incorrect: ",  pos_x, " instead of ", settings["Position"][0]
99     errors += 1
100 if abs(pos_y - settings["Position"][1]) > tolerance:
101     print "ERROR!!! Y coordinate of position of scalar bar is incorrect: ",  pos_y, " instead of ", settings["Position"][1]
102     errors += 1
103
104 # Size of scalar bar
105 width  = recreated_bar.Position2[0]
106 height = recreated_bar.Position2[1]
107
108 if abs(width - settings["Size"][0]) > tolerance:
109     print "ERROR!!! Width of scalar bar is incorrect: ",  width, " instead of ", settings["Size"][0]
110     errors += 1
111 if abs(height - settings["Size"][1]) > tolerance:
112     print "ERROR!!! Height of scalar bar is incorrect: ",  height, " instead of ", settings["Size"][1]
113     errors += 1
114
115 # Discretize
116 discretize = recreated_gausspoints.LookupTable.Discretize
117 if discretize != settings["Discretize"]:
118     print "ERROR!!! Discretize property is incorrect: ",  discretize, " instead of ", settings["Discretize"]
119     errors += 1
120
121 # Number of colors
122 nb_colors = recreated_gausspoints.LookupTable.NumberOfTableValues
123 if nb_colors != settings["NbColors"]:
124     print "ERROR!!! Number of colors of scalar bar is incorrect: ",  nb_colors, " instead of ", settings["NbColors"]
125     errors += 1
126
127 # Number of labels
128 nb_labels = recreated_bar.NumberOfLabels
129 if nb_labels != settings["NbLabels"]:
130     print "ERROR!!! Number of labels of scalar bar is incorrect: ",  nb_labels, " instead of ", settings["NbLabels"]
131     errors += 1
132
133 # Title
134 title = recreated_bar.Title
135 if title != settings["Title"]:
136     print "ERROR!!! Title of presentation is incorrect: ",  title, " instead of ", settings["Title"]
137     errors += 1
138
139 if errors > 0:
140     raise RuntimeError, "There is(are) some error(s) was(were) found... For more info see ERRORs above..."