Salome HOME
Update copyright information
[modules/visu.git] / src / VISU_SWIG / VISU_Example_07.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23
24 # Manage view parameters of presentations:
25 # Representation Mode, Shrink, Shading, Opacity, Line Width
26 #
27 import salome
28
29 import VISU
30 import visu_gui
31
32 import os
33 import time
34
35 datadir = os.getenv("DATA_DIR") + "/MedFiles/"
36
37 myVisu = visu_gui.myVisu
38 myVisu.SetCurrentStudy(salome.myStudy)
39 myViewManager = myVisu.GetViewManager()
40 myView = myViewManager.Create3DView()
41
42 sleep_delay = 1
43
44 def AfterSet(error_string, method_name, old_value, new_value):
45     print method_name, "(): old_value = ", old_value, "new_value  = ", new_value
46     if error_string == "":
47         time.sleep(sleep_delay)
48     else:
49         print method_name, "() error = ", error_string
50         pass
51     pass
52
53 def ChangeRepresentation(scalarmap,repres,shrink,shading,opacity,linew):
54     if scalarmap is None : print "Error"
55     else : print "OK"
56
57     myView.DisplayOnly(scalarmap)
58     myView.FitAll()
59
60     time.sleep(sleep_delay)
61
62     # enum PresentationType{ POINT, WIREFRAME, SHADED, INSIDEFRAME, SURFACEFRAME, SHRINK }
63     old_prs_type = myView.GetPresentationType(scalarmap)
64     if old_prs_type != repres:
65         err_str = myView.SetPresentationType(scalarmap, repres)
66         AfterSet(err_str, "SetPresentationType", old_prs_type, repres)
67         pass
68
69     old_is_shrinked = myView.IsShrinked(scalarmap)
70     if old_is_shrinked != shrink:
71         err_str = myView.SetShrinked(scalarmap, shrink) # 1 - shrinked, 0 - not shrinked
72         AfterSet(err_str, "SetShrinked", old_is_shrinked, shrink)
73         pass
74
75     old_is_shaded = myView.IsShaded(scalarmap)
76     if old_is_shaded != shading:
77         err_str = myView.SetShaded(scalarmap, shading) # 1 - shaded, 0 - not shaded
78         AfterSet(err_str, "SetShaded", old_is_shaded, shading)
79         pass
80
81     old_opacity = myView.GetOpacity(scalarmap)
82     if old_opacity != opacity:
83         err_str = myView.SetOpacity(scalarmap, opacity) # double value [0, 1]
84         AfterSet(err_str, "SetOpacity", old_opacity, opacity)
85         pass
86
87     old_linew = myView.GetLineWidth(scalarmap)
88     if old_linew != linew:
89         err_str = myView.SetLineWidth(scalarmap, linew) # double value, recommended round [1, 10]
90         AfterSet(err_str, "SetLineWidth", old_linew, linew)
91         pass
92
93     print ""
94     pass
95
96 # ResOK_0000.med
97
98 print 'Import "ResOK_0000.med"...............',
99 medFile = datadir + "ResOK_0000.med"
100 myMeshName = 'dom'
101 myFieldName = 'vitesse'
102
103 myResult = myVisu.ImportFile(medFile)
104 if myResult is None : print "Error"
105 else : print "OK"
106
107 print "Creating Scalar Map.......",
108 scmap = myVisu.ScalarMapOnField(myResult,myMeshName,VISU.NODE,myFieldName,1);
109 ChangeRepresentation(scmap, VISU.INSIDEFRAME, 1, 0, 0.3, 5)
110
111 print "Creating Stream Lines.......",
112 scmap = myVisu.StreamLinesOnField(myResult,myMeshName,VISU.NODE,myFieldName,1);
113 ChangeRepresentation(scmap, VISU.WIREFRAME, 1, 1, 0.5, 3)
114
115 print "Creating Vectors..........",
116 scmap = myVisu.VectorsOnField(myResult,myMeshName,VISU.NODE,myFieldName,1);
117 ChangeRepresentation(scmap, VISU.WIREFRAME, 1, 1, 0.7, 2)
118
119 print "Creating Iso Surfaces.....",
120 scmap = myVisu.IsoSurfacesOnField(myResult,myMeshName,VISU.NODE,myFieldName,1);
121 ChangeRepresentation(scmap, VISU.SHADED, 1, 0, 0.4, 8)
122
123 print "Creating Cut Planes.......",
124 scmap = myVisu.CutPlanesOnField(myResult,myMeshName,VISU.NODE,myFieldName,1);
125 ChangeRepresentation(scmap, VISU.POINT, 0, 0, 0.6, 4)
126
127 # fra.med
128
129 print 'Import "fra.med"...............',
130 medFile = datadir + "fra.med"
131 myMeshName = 'LE VOLUME'
132 myFieldName = 'VITESSE'
133
134 myResult = myVisu.ImportFile(medFile)
135 if myResult is None : print "Error"
136 else : print "OK"
137
138 print "Creating Scalar Map.......",
139 scmap = myVisu.ScalarMapOnField(myResult,myMeshName,VISU.NODE,myFieldName,1);
140 ChangeRepresentation(scmap, VISU.WIREFRAME, 1, 1, 0.5, 3)
141
142 print "Creating Iso Surfaces.....",
143 scmap = myVisu.IsoSurfacesOnField(myResult,myMeshName,VISU.NODE,myFieldName,1);
144 ChangeRepresentation(scmap, VISU.WIREFRAME, 1, 1, 0.5, 3)
145
146 print "Creating Cut Planes.......",
147 scmap = myVisu.CutPlanesOnField(myResult,myMeshName,VISU.NODE,myFieldName,1);
148 ChangeRepresentation(scmap, VISU.SHADED, 1, 1, 0.5, 3)
149
150 print "Creating Scalar Map On Deformed Shape.......",
151 scmap = myVisu.DeformedShapeAndScalarMapOnField(myResult,myMeshName,VISU.NODE,myFieldName,1);
152 ChangeRepresentation(scmap, VISU.SHADED, 1, 1, 0.5, 3)
153
154 print "Creating Deformed Shape.......",
155 scmap = myVisu.DeformedShapeOnField(myResult,myMeshName,VISU.NODE,myFieldName,1)
156 scmap.ShowColored(1)
157 ChangeRepresentation(scmap, VISU.WIREFRAME, 1, 1, 0.5, 3)
158
159 print "Creating Cut Lines.......",
160 scmap = myVisu.CutLinesOnField(myResult,myMeshName,VISU.NODE,myFieldName,1)
161 ChangeRepresentation(scmap, VISU.WIREFRAME, 1, 1, 0.5, 3)
162
163 print "Creating Plot 3D.......",
164 scmap = myVisu.Plot3DOnField(myResult,myMeshName,VISU.NODE,myFieldName,1)
165 ChangeRepresentation(scmap, VISU.SHADED, 1, 1, 0.5, 3)