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