Salome HOME
Update copyrights 2014.
[modules/paravis.git] / test / VisuPrs / SWIG_scripts / A7.py
1 # Copyright (C) 2010-2014  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/SWIG_scripts/A7 case
21
22 import time
23
24 from paravistest import datadir
25 from presentations import *
26 import paravis
27 import pvsimple
28
29
30 my_paravis = paravis.myParavis
31 view = pvsimple.GetRenderView()
32 reset_view(view)
33 delay = 1
34
35
36 def after_set(error_string, prop_name, old_value, new_value):
37     print prop_name, ": old_value = ", old_value, "new_value  = ", new_value
38     if error_string == "":
39         time.sleep(delay)
40     else:
41         print prop_name, " error = ", error_string
42         pass
43     pass
44
45
46 def change_representation(prs, repres, opacity, linew):
47     if prs is None:
48         print "FAILED"
49         return
50     else:
51         print "OK"
52
53     display_only(prs, view)
54     view.ResetCamera()
55
56     time.sleep(delay)
57
58     old_prs_type = prs.Representation
59     if old_prs_type != repres:
60         err_str = ''
61         try:
62             prs.Representation = repres
63         except:
64             err_str = "Error"
65         after_set(err_str, "Representation", old_prs_type, repres)
66         pass
67
68     old_opacity = prs.Opacity
69     if old_opacity != opacity:
70         err_str = ''
71         try:
72             prs.Opacity = opacity  # double value [0, 1]
73         except:
74             err_str = "Error"
75         after_set(err_str, "Opacity", old_opacity, opacity)
76         pass
77
78     old_linew = prs.LineWidth
79     if old_linew != linew:
80         err_str = ''
81         try:
82             prs.LineWidth = linew  # double value, recommended round [1, 10]
83         except:
84             err_str = "Error"
85         after_set(err_str, "LineWidth", old_linew, linew)
86         pass
87
88     print ""
89     pass
90
91
92 # ResOK_0000.med
93
94 print 'Import "ResOK_0000.med"...............',
95 file_path = datadir + "ResOK_0000.med"
96 field_name = 'vitesse'
97 node_entity = EntityType.NODE
98
99 my_paravis.ImportFile(file_path)
100 med_reader = pvsimple.GetActiveSource()
101
102 if med_reader is None:
103     print "FAILED"
104 else:
105     print "OK"
106
107 print "Creating Scalar Map.......",
108 scmap = ScalarMapOnField(med_reader, node_entity, field_name, 1)
109 change_representation(scmap, 'Surface With Edges', 0.3, 5)
110
111 print "Creating Stream Lines.......",
112 slines = StreamLinesOnField(med_reader, node_entity, field_name, 1)
113 change_representation(slines, 'Wireframe', 0.5, 3)
114
115 print "Creating Vectors..........",
116 vec = VectorsOnField(med_reader, node_entity, field_name, 1)
117 change_representation(vec, 'Wireframe', 0.7, 2)
118
119 print "Creating Iso Surfaces.....",
120 iso = IsoSurfacesOnField(med_reader, node_entity, field_name, 1)
121 change_representation(iso, 'Surface', 0.4, 8)
122
123 print "Creating Cut Planes.......",
124 clines = CutPlanesOnField(med_reader, node_entity, field_name, 1)
125 change_representation(clines, 'Points', 0.6, 4)
126
127
128 # fra.med
129
130 print 'Import "fra.med"...............',
131 file_path = datadir + "fra.med"
132 field_name = 'VITESSE'
133
134 pvsimple.SetActiveSource(None)
135 my_paravis.ImportFile(file_path)
136 med_reader = pvsimple.GetActiveSource()
137
138 if med_reader is None:
139     print "FAILED"
140 else:
141     print "OK"
142
143 print "Creating Scalar Map.......",
144 scmap = ScalarMapOnField(med_reader, node_entity, field_name, 1)
145 change_representation(scmap, 'Wireframe', 0.5, 3)
146
147 print "Creating Iso Surfaces.....",
148 iso = IsoSurfacesOnField(med_reader, node_entity, field_name, 1)
149 change_representation(iso, 'Wireframe', 0.5, 3)
150
151 print "Creating Cut Planes.......",
152 cplanes = CutPlanesOnField(med_reader, node_entity, field_name, 1)
153 change_representation(cplanes, 'Surface', 0.5, 3)
154
155 print "Creating Scalar Map On Deformed Shape.......",
156 defmap = DeformedShapeAndScalarMapOnField(med_reader, node_entity,
157                                           field_name, 1)
158 change_representation(defmap, 'Surface', 0.5, 3)
159
160 print "Creating Deformed Shape.......",
161 defshape = DeformedShapeOnField(med_reader, node_entity, field_name, 1)
162 defshape.ColorArrayName = field_name
163 change_representation(defshape, 'Wireframe', 0.5, 3)
164
165 print "Creating Cut Lines.......",
166 clines = CutLinesOnField(med_reader, node_entity, field_name, 1)
167 change_representation(clines, 'Wireframe', 0.5, 3)
168
169 print "Creating Plot 3D.......",
170 plot3d = Plot3DOnField(med_reader, node_entity, field_name, 1)
171 change_representation(plot3d, 'Surface', 0.5, 3)
172 change_representation(plot3d, 'Outline', 0.8, 2)