Salome HOME
Update copyright information
[modules/visu.git] / src / VISU_SWIG / VISU_Example_01.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 # T 2.23, 28: Displaying fields (scalar and vectorial) on nodes, change presentation options.
25 # Uses MED files ResOK_0000.med and Fields_group3D.med
26 # This script is equivalent to non-regression test script 003/A1
27 #
28 import salome
29 import visu_gui
30 import SALOMEDS
31 import VISU
32 import os
33
34 datadir = os.getenv("DATA_DIR") + "/MedFiles/"
35
36 #%====================Stage1: Creating a new study====================%
37
38 print "**** Stage1: Creating a new study"
39
40 print "Creating a new study..................", 
41 myVisu = visu_gui.myVisu
42 myVisu.SetCurrentStudy(salome.myStudy)
43 myViewManager = myVisu.GetViewManager()
44 if myViewManager is None : print "Error"
45 else : print "OK"
46
47 #%====================Stage2: Importing MED file====================%
48
49 print "**** Stage2: Importing MED file"
50
51 print 'Import "ResOK_0000.med"...............',
52 medFile = datadir + "ResOK_0000.med"
53 myResult = myVisu.ImportFile(medFile)
54 if myResult is None : print "Error"
55 else : print "OK"
56
57 print 'Creating new View3D...................',
58 myView = myViewManager.Create3DView()
59 if myView is None : print "Error"
60 else : print "OK"
61
62 myMeshName = 'dom'
63 myCellEntity = VISU.CELL
64 myNodeEntity = VISU.NODE
65
66 #%====================Stage3: Displaying vector field====================%
67
68 print "**** Stage3: Displaying vector field"
69
70 print "Creating Scalar Map.......",
71 scalarmap = myVisu.ScalarMapOnField(myResult,myMeshName,myNodeEntity,'vitesse',1);
72 if scalarmap is None : print "Error"
73 else : print "OK"
74 scalarmap.SetSize(0.15, 0.8)
75 myView.DisplayOnly(scalarmap)
76 myView.FitAll()
77
78 print "Creating Stream Lines.....",
79 streamlines = myVisu.StreamLinesOnField(myResult,myMeshName,myNodeEntity,'vitesse',1);
80 if streamlines is None : print "Error"
81 else : print "OK"
82 myView.DisplayOnly(streamlines)
83
84 print "Creating Vectors..........",
85 vectors = myVisu.VectorsOnField(myResult,myMeshName,myNodeEntity,'vitesse',1);
86 if vectors is None : print "Error"
87 else : print "OK"
88 myView.DisplayOnly(vectors)
89
90
91 print "Creating Iso Surfaces.....",
92 isosurfaces = myVisu.IsoSurfacesOnField(myResult,myMeshName,myNodeEntity,'vitesse',1);
93 if isosurfaces is None : print "Error"
94 else : print "OK"
95 myView.DisplayOnly(isosurfaces)
96
97 print "Creating Cut Planes.......",
98 cutplanes = myVisu.CutPlanesOnField(myResult,myMeshName,myNodeEntity,'vitesse',1);
99 if cutplanes is None : print "Error"
100 else : print "OK"
101 cutplanes.SetNbPlanes(30)
102 cutplanes.SetOrientation(VISU.CutPlanes.YZ, 0, 0)
103 myView.DisplayOnly(cutplanes)
104
105 print "Creating Scalar Map On Deformed Shape.......",
106 scalarmapondefshape = myVisu.DeformedShapeAndScalarMapOnField(myResult,myMeshName,myNodeEntity,'vitesse',1);
107 if scalarmapondefshape is None : print "Error"
108 else : print "OK"
109 scalarmapondefshape.SetScalarField(myCellEntity,'pression',2);
110 myView.DisplayOnly(scalarmapondefshape)
111
112 #%====================Stage4: Opening a new study and Med file import====================%
113
114 # Opening a new study tempoparily commented due to a problem
115 # with python initialization. To be restored after bug 10000 fixing.
116
117 #print "**** Stage4: Opening a new study and Med file import"
118 print "**** Stage4: Med file import"
119
120 #print "Creating a new study..................", 
121 #newStudy = salome.myStudyManager.NewStudy('newStudy')
122 newStudy = salome.myStudy # temporarily
123 #myVisu.SetCurrentStudy(newStudy)
124 myViewManager = myVisu.GetViewManager()
125 myView = myViewManager.Create3DView()
126 if myView is None : print "Error"
127 else : print "OK"
128
129 print 'Importing "Fields_group3D.med"........',
130 medFile = datadir + "Fields_group3D.med"
131 myResult1 = myVisu.ImportFile(medFile)
132 if myResult1 is None : print "Error"
133 myView1 = myViewManager.Create3DView()
134 if myView1 is None : print "Error"
135 else : print "OK"
136
137 #%====================Stage5: Displaying scalar field====================%
138
139 print "**** Stage5: Displaying scalar field"
140
141 myMeshName1 = 'mailles_MED'
142
143 print "Creating Scalar Map.......",
144 scalarmap1 = myVisu.ScalarMapOnField(myResult1,myMeshName1,myCellEntity,'scalar field',1);
145 if scalarmap1 is None : print "Error"
146 else : print "OK"
147 myView1.DisplayOnly(scalarmap1)
148 myView1.FitAll()
149
150 print "Creating Iso Surfaces.....",
151 isosurfaces1 = myVisu.IsoSurfacesOnField(myResult1,myMeshName1,myCellEntity,'scalar field',1);
152 if isosurfaces1 is None : print "Error"
153 else : print "OK"
154 myView1.DisplayOnly(isosurfaces1)
155
156 print "Creating Cut Planes.......",
157 cutplanes1 = myVisu.CutPlanesOnField(myResult1,myMeshName1,myCellEntity,'scalar field',1);
158 if cutplanes1 is None : print "Error"
159 else : print "OK"
160 cutplanes1.SetOrientation(VISU.CutPlanes.YZ, 0, 0)
161 myView1.DisplayOnly(cutplanes1)
162
163 print "Creating Scalar Map On Deformed Shape.......",
164 scalarmapondefshape1 = myVisu.DeformedShapeAndScalarMapOnField(myResult1,myMeshName1,myCellEntity,'vectoriel field',1);
165 if scalarmapondefshape1 is None : print "Error"
166 else : print "OK"
167 myView1.DisplayOnly(scalarmapondefshape1)
168 #%====================Stage6: Object browser popup====================%
169
170 print "**** Stage6: Object browser popup"
171
172 print "Creating mesh.............",
173 mesh = myVisu.MeshOnEntity(myResult1,myMeshName1,myCellEntity);
174 if mesh is None : print "Error"
175 else : print "OK"
176 myView1.DisplayOnly(mesh)
177
178
179 print "Changing type of presentation of mesh:"
180 mesh.SetPresentationType(VISU.WIREFRAME)
181 PrsType = mesh.GetPresentationType()
182 print "Presentation type..", PrsType
183 myView1.DisplayOnly(mesh)
184
185 mesh.SetPresentationType(VISU.SHADED)
186 PrsType = mesh.GetPresentationType()
187 print "Presentation type.....", PrsType
188 myView1.DisplayOnly(mesh)
189
190 mesh.SetPresentationType(VISU.POINT)
191 PrsType = mesh.GetPresentationType()
192 print "Presentation type......", PrsType
193 myView1.DisplayOnly(mesh)
194 myView1.Update()
195
196 mesh.SetPresentationType(VISU.SHRINK)
197 PrsType = mesh.GetPresentationType()
198 print "Presentation type.....", PrsType
199 myView1.DisplayOnly(mesh)
200
201 print "Changing color of mesh....",
202 aColor = SALOMEDS.Color(0,0,1)
203 mesh.SetCellColor(aColor)
204 myView1.DisplayOnly(mesh)
205 print "OK"
206
207 print "Renaming ScalarMap........",
208 SObj = newStudy.FindObjectIOR(scalarmap1.GetID())
209 newName = 'Renamed Object'
210 SObj.Name = newName
211 print "OK"
212
213 print "Deleting Cut Planes.......",
214 SObj = newStudy.FindObjectIOR(cutplanes1.GetID())
215 myBuilder = newStudy.NewBuilder()
216 myBuilder.RemoveObject(SObj)
217 print "OK"
218
219 print "Changing first IsoSurfaces",
220 myVisu.SetCurrentStudy(salome.myStudy)
221 myView.DisplayOnly(isosurfaces)
222 isosurfaces.SetNbSurfaces(25)
223 print "OK"
224
225 myView.Maximize()
226 myView.DisplayOnly(isosurfaces)
227
228 print "Hide IsoSurfaces..........",
229 myView.Erase(isosurfaces)
230 print "OK"