]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_SWIG/VISU_Example_01.py
Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/visu.git] / src / VISU_SWIG / VISU_Example_01.py
1 #  Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 #
4 #  This library is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU Lesser General Public
6 #  License as published by the Free Software Foundation; either
7 #  version 2.1 of the License.
8 #
9 #  This library is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 #  Lesser General Public License for more details.
13 #
14 #  You should have received a copy of the GNU Lesser General Public
15 #  License along with this library; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # T 2.23, 28: Displaying fields (scalar and vectorial) on nodes, change presentation options.
21 # Uses MED files ResOK_0000.med and Fields_group3D.med
22
23 # This script is equivalent to non-regression test script 003/A1
24
25 import salome
26 import visu_gui
27 import SALOMEDS
28 import VISU
29 import os
30
31 datadir = os.getenv("DATA_DIR") + "/MedFiles/"
32
33 #%====================Stage1: Creating a new study====================%
34
35 print "**** Stage1: Creating a new study"
36
37 print "Creating a new study..................", 
38 myVisu = visu_gui.myVisu
39 myVisu.SetCurrentStudy(salome.myStudy)
40 myViewManager = myVisu.GetViewManager()
41 if myViewManager is None : print "Error"
42 else : print "OK"
43
44 #%====================Stage2: Importing MED file====================%
45
46 print "**** Stage2: Importing MED file"
47
48 print 'Import "ResOK_0000.med"...............',
49 medFile = datadir + "ResOK_0000.med"
50 myResult = myVisu.ImportFile(medFile)
51 if myResult is None : print "Error"
52 else : print "OK"
53
54 print 'Creating new View3D...................',
55 myView = myViewManager.Create3DView()
56 if myView is None : print "Error"
57 else : print "OK"
58
59 myMeshName = 'dom'
60 myCellEntity = VISU.CELL
61 myNodeEntity = VISU.NODE
62
63 #%====================Stage3: Displaying vector field====================%
64
65 print "**** Stage3: Displaying vector field"
66
67 print "Creating Scalar Map.......",
68 scalarmap = myVisu.ScalarMapOnField(myResult,myMeshName,myNodeEntity,'vitesse',1);
69 if scalarmap is None : print "Error"
70 else : print "OK"
71 scalarmap.SetSize(0.15, 0.8)
72 myView.DisplayOnly(scalarmap)
73 myView.FitAll()
74
75 print "Creating Stream Lines.....",
76 streamlines = myVisu.StreamLinesOnField(myResult,myMeshName,myNodeEntity,'vitesse',1);
77 if streamlines is None : print "Error"
78 else : print "OK"
79 myView.DisplayOnly(streamlines)
80
81 print "Creating Vectors..........",
82 vectors = myVisu.VectorsOnField(myResult,myMeshName,myNodeEntity,'vitesse',1);
83 if vectors is None : print "Error"
84 else : print "OK"
85 myView.DisplayOnly(vectors)
86
87
88 print "Creating Iso Surfaces.....",
89 isosurfaces = myVisu.IsoSurfacesOnField(myResult,myMeshName,myNodeEntity,'vitesse',1);
90 if isosurfaces is None : print "Error"
91 else : print "OK"
92 myView.DisplayOnly(isosurfaces)
93
94 print "Creating Cut Planes.......",
95 cutplanes = myVisu.CutPlanesOnField(myResult,myMeshName,myNodeEntity,'vitesse',1);
96 if cutplanes is None : print "Error"
97 else : print "OK"
98 cutplanes.SetNbPlanes(30)
99 cutplanes.SetOrientation(VISU.CutPlanes.YZ, 0, 0)
100 myView.DisplayOnly(cutplanes)
101
102 print "Creating Scalar Map On Deformed Shape.......",
103 scalarmapondefshape = myVisu.ScalarMapOnDeformedShapeOnField(myResult,myMeshName,myNodeEntity,'vitesse',1);
104 if scalarmapondefshape is None : print "Error"
105 else : print "OK"
106 scalarmapondefshape.SetScalarField(myMeshName,'pression',2,myCellEntity);
107 myView.DisplayOnly(scalarmapondefshape)
108
109 #%====================Stage4: Opening a new study and Med file import====================%
110
111 # Opening a new study tempoparily commented due to a problem
112 # with python initialization. To be restored after bug 10000 fixing.
113
114 #print "**** Stage4: Opening a new study and Med file import"
115 print "**** Stage4: Med file import"
116
117 #print "Creating a new study..................", 
118 #newStudy = salome.myStudyManager.NewStudy('newStudy')
119 newStudy = salome.myStudy # temporarily
120 #myVisu.SetCurrentStudy(newStudy)
121 myViewManager = myVisu.GetViewManager()
122 myView = myViewManager.Create3DView()
123 if myView is None : print "Error"
124 else : print "OK"
125
126 print 'Importing "Fields_group3D.med"........',
127 medFile = datadir + "Fields_group3D.med"
128 myResult1 = myVisu.ImportFile(medFile)
129 if myResult1 is None : print "Error"
130 myView1 = myViewManager.Create3DView()
131 if myView1 is None : print "Error"
132 else : print "OK"
133
134 #%====================Stage5: Displaying scalar field====================%
135
136 print "**** Stage5: Displaying scalar field"
137
138 myMeshName1 = 'mailles_MED'
139
140 print "Creating Scalar Map.......",
141 scalarmap1 = myVisu.ScalarMapOnField(myResult1,myMeshName1,myCellEntity,'scalar field',1);
142 if scalarmap1 is None : print "Error"
143 else : print "OK"
144 myView1.DisplayOnly(scalarmap1)
145 myView1.FitAll()
146
147 print "Creating Iso Surfaces.....",
148 isosurfaces1 = myVisu.IsoSurfacesOnField(myResult1,myMeshName1,myCellEntity,'scalar field',1);
149 if isosurfaces1 is None : print "Error"
150 else : print "OK"
151 myView1.DisplayOnly(isosurfaces1)
152
153 print "Creating Cut Planes.......",
154 cutplanes1 = myVisu.CutPlanesOnField(myResult1,myMeshName1,myCellEntity,'scalar field',1);
155 if cutplanes1 is None : print "Error"
156 else : print "OK"
157 cutplanes1.SetOrientation(VISU.CutPlanes.YZ, 0, 0)
158 myView1.DisplayOnly(cutplanes1)
159
160 print "Creating Scalar Map On Deformed Shape.......",
161 scalarmapondefshape1 = myVisu.ScalarMapOnDeformedShapeOnField(myResult1,myMeshName1,myCellEntity,'vectoriel field',1);
162 if scalarmapondefshape1 is None : print "Error"
163 else : print "OK"
164 myView1.DisplayOnly(scalarmapondefshape1)
165 #%====================Stage6: Object browser popup====================%
166
167 print "**** Stage6: Object browser popup"
168
169 print "Creating mesh.............",
170 mesh = myVisu.MeshOnEntity(myResult1,myMeshName1,myCellEntity);
171 if mesh is None : print "Error"
172 else : print "OK"
173 myView1.DisplayOnly(mesh)
174
175
176 print "Changing type of presentation of mesh:"
177 mesh.SetPresentationType(VISU.WIREFRAME)
178 PrsType = mesh.GetPresentationType()
179 print "Presentation type..", PrsType
180 myView1.DisplayOnly(mesh)
181
182 mesh.SetPresentationType(VISU.SHADED)
183 PrsType = mesh.GetPresentationType()
184 print "Presentation type.....", PrsType
185 myView1.DisplayOnly(mesh)
186
187 mesh.SetPresentationType(VISU.POINT)
188 PrsType = mesh.GetPresentationType()
189 print "Presentation type......", PrsType
190 myView1.DisplayOnly(mesh)
191 myView1.Update()
192
193 mesh.SetPresentationType(VISU.SHRINK)
194 PrsType = mesh.GetPresentationType()
195 print "Presentation type.....", PrsType
196 myView1.DisplayOnly(mesh)
197
198 print "Changing color of mesh....",
199 aColor = SALOMEDS.Color(0,0,1)
200 mesh.SetCellColor(aColor)
201 myView1.DisplayOnly(mesh)
202 print "OK"
203
204 print "Renaming ScalarMap........",
205 SObj = newStudy.FindObjectIOR(scalarmap1.GetID())
206 newName = 'Renamed Object'
207 SObj.Name = newName
208 print "OK"
209
210 print "Deleting Cut Planes.......",
211 SObj = newStudy.FindObjectIOR(cutplanes1.GetID())
212 myBuilder = newStudy.NewBuilder()
213 myBuilder.RemoveObject(SObj)
214 print "OK"
215
216 print "Changing first IsoSurfaces",
217 myVisu.SetCurrentStudy(salome.myStudy)
218 myView.DisplayOnly(isosurfaces)
219 isosurfaces.SetNbSurfaces(25)
220 print "OK"
221
222 myView.Maximize()
223 myView.DisplayOnly(isosurfaces)
224
225 print "Hide IsoSurfaces..........",
226 myView.Erase(isosurfaces)
227 print "OK"