Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/visu.git] / src / VISU_SWIG / VISU_Example_04.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/
19 #
20 # Show some results presentations in different 3D and 2D viewers
21 # with different options (view parameters and display modes).
22 # Uses MED files fra.med and TimeStamps.med from ${DATA_DIR}/MedFiles directory.
23
24 # Pay attention to a viewer title to know its purpose.
25
26 # This script is equivalent to script VISU_SWIG/visu_view3d.py
27
28 import os
29 import time
30 import math
31 import VISU
32 import SALOMEDS
33 from visu_gui import *
34
35 aDelay = 1
36
37 myViewManager = myVisu.GetViewManager();
38
39 myView = myViewManager.Create3DView();
40 myView.SetTitle("The window will be soon destroyed!")
41 print "myViewManager.Create3DView()"
42 time.sleep(aDelay)
43
44 myView.Maximize()
45 print "myView.Maximize()"
46 time.sleep(aDelay)
47
48 myView.Restore()
49 print "myView.Restore()"
50 time.sleep(aDelay)
51
52 myView.Minimize()
53 print "myView.Minimize()"
54 time.sleep(aDelay)
55
56 myViewManager.Destroy(myView)
57 print "myViewManager.Destroy(myView)"
58 time.sleep(aDelay)
59
60
61 medFile = "fra.med"
62 myFieldName = "VITESSE";
63
64 aMeshName ="LE VOLUME"
65 anEntity = VISU.NODE
66 aTimeStampId = 1
67
68 medFile = os.getenv('DATA_DIR') + '/MedFiles/' + medFile
69 myResult = myVisu.ImportFile(medFile)
70
71 myView = myViewManager.Create3DView();
72
73 print "myView.SetBackground(...)"
74 aColor = SALOMEDS.Color(0.0,0.3,1.0)
75 myView.SetBackground(aColor);
76
77 myView.SetTitle("The viewer will display ScalarMap")
78 print "myViewManager.Create3DView()"
79
80 aScalarMap = myVisu.ScalarMapOnField(myResult,aMeshName,anEntity,myFieldName,aTimeStampId)
81
82 myView.Display(aScalarMap);
83 print "myView.Display(aScalarMap)"
84 myView.SetFocalPoint([0,0,0]);
85 print "myView.SetFocalPoint(...)"
86 myView.SetParallelScale(2);
87 print "myView.SetParallelScale(...)"
88 myView.FitAll();
89
90 aMax = aScalarMap.GetMax()
91 aMin = aScalarMap.GetMin()
92 aDelta = (aMax - aMin)/2.0
93 aNbColors = aScalarMap.GetNbColors()
94 aNbColors = 64
95 for i in range(2,aNbColors) :
96     aScalarMap.SetNbColors(i)
97     aX = aMin + aDelta*i/aNbColors
98     aY = aMax - aDelta*i/aNbColors
99     aScalarMap.SetRange(aX,aY)
100     myView.Update();
101     time.sleep(aDelay)
102
103 aScalarMap.SetRange(aMin,aMax)
104
105 print "myView.Update()"
106 myView.Update();
107 print "myView.FitAll()"
108 myView.FitAll();
109
110
111 myView = myViewManager.Create3DView();
112 myView.SetTitle("Here we will display CutPlanes")
113
114 print "myView.SetBackground(...)"
115 aColor = SALOMEDS.Color(0.0,0.7,0.0)
116 myView.SetBackground(aColor);
117
118 aCutPlanes = myVisu.CutPlanesOnField(myResult,aMeshName,anEntity,myFieldName,aTimeStampId)
119 print "myVisu.CutPlanesOnField(...)"
120
121 myView.DisplayOnly(aCutPlanes);
122 print "myView.DisplayOnly(aCutPlanes)"
123
124 aPoint = myView.GetPointOfView();
125 aPoint[0] = aPoint[0] + 10;
126 myView.SetPointOfView(aPoint);
127 print "myView.SetPointOfView(...)"
128 myView.ScaleView(VISU.View3D.YAxis,10.0);
129 myView.ScaleView(VISU.View3D.XAxis,3.0);
130 print "myView.ScaleView(...)"
131 time.sleep(aDelay)
132
133 myView.FitAll();
134
135 aNbPlanes = aCutPlanes.GetNbPlanes()
136 aNbPlanes = 30
137 aXAngle = aCutPlanes.GetRotateX()
138 aYAngle = aCutPlanes.GetRotateY()
139 anOrientation = aCutPlanes.GetOrientationType()
140 for i in range(aNbPlanes,1,-1) :
141     aCutPlanes.SetNbPlanes(i)
142     aX = math.pi/2.0*(aNbPlanes-i)/aNbPlanes
143     aY = math.pi/2.0*(aNbPlanes-i)/aNbPlanes
144     aCutPlanes.SetOrientation(anOrientation,aX,aY)
145     myView.Update();
146     time.sleep(aDelay)
147
148 aNbPlanes = 10
149 aCutPlanes.SetOrientation(VISU.CutPlanes.ZX,0,0)
150 for i in range(1,aNbPlanes) :
151     aCutPlanes.SetNbPlanes(i)
152     myView.Update();
153     time.sleep(aDelay)
154
155 myView.SaveViewParams('AAA')
156 print "myView.SaveViewParams('AAA')"
157 time.sleep(aDelay)
158
159 aCutPlanes.SetOrientation(VISU.CutPlanes.XY,0,0)
160 myView.RemoveScale();
161
162 print "myView.Update()"
163 myView.Update();
164 print "myView.FitAll()"
165 myView.FitAll();
166
167
168 myView = myViewManager.Create3DView();
169 print "myViewManager.Create3DView()"
170
171 myView.SetTitle("IsoSurface's viewer")
172
173 print "myView.SetBackground(...)"
174 aColor = SALOMEDS.Color(1.0,0.7,0.0)
175 myView.SetBackground(aColor);
176 time.sleep(aDelay)
177
178 aIsoSurfaces = myVisu.IsoSurfacesOnField(myResult, aMeshName, anEntity, myFieldName, aTimeStampId)
179
180 myView.DisplayOnly(aIsoSurfaces);
181 myView.FitAll();
182 print "myView.DisplayOnly(aCutPlanes)"
183 time.sleep(aDelay)
184
185 aNbSurfaces = aIsoSurfaces.GetNbSurfaces()
186 aNbSurfaces = 32
187 for i in range(2,aNbSurfaces) :
188     aIsoSurfaces.SetNbSurfaces(i)
189     myView.Update();
190     time.sleep(aDelay)
191
192 aIsoSurfaces.SetNbSurfaces(10)
193
194 print "myView.Update()"
195 myView.Update();
196 print "myView.FitAll()"
197 myView.FitAll();
198
199
200 myView = myViewManager.Create3DView();
201 myView.SetTitle("The viewer for CutLines")
202 print "myViewManager.Create3DView()"
203 time.sleep(aDelay)
204
205 print "myView.SetBackground(...)"
206 aColor = SALOMEDS.Color(0.7,0.7,0.7)
207 myView.SetBackground(aColor);
208 time.sleep(aDelay)
209
210 aCutLines = myVisu.CutLinesOnField(myResult, aMeshName, anEntity, myFieldName, aTimeStampId)
211 aCutLines.SetOrientation(VISU.CutPlanes.ZX,0,0)
212 aCutLines.SetOrientation2(VISU.CutPlanes.YZ,0,0)
213
214 myView.DisplayOnly(aCutLines);
215 myView.FitAll();
216 print "myView.DisplayOnly(aCutLines)"
217 time.sleep(aDelay)
218
219 aSObj = myStudy.FindObjectIOR(aCutLines.GetID())
220 aTable = myVisu.CreateTable( aSObj.GetID() )
221 print "myVisu.CreateTable(...)"
222
223 aTableView = myViewManager.CreateTableView(aTable)
224 aTableView.SetTitle('Changed Title')
225
226 aContainer = myVisu.CreateContainer()
227 print "myVisu.CreateContainer(...)"
228
229 aNbCurve = aTable.GetNbRows() - 1
230 for i in range(2,aNbCurve):
231    aCurve = myVisu.CreateCurve( aTable, 1, i )
232    print i, aCurve
233    aContainer.AddCurve(aCurve)
234
235
236 myView = myViewManager.CreateXYPlot();
237 myView.SetTitle("The viewer for Curves from CutLines")
238 print "myViewManager.CreateXYPlot()"
239 time.sleep(aDelay)
240
241 myView.Display(aContainer)
242
243
244 myView = myViewManager.Create3DView();
245 myView.SetTitle("The viewer for Animation")
246 print "myViewManager.Create3DView()"
247 time.sleep(aDelay)
248
249 medFile = "TimeStamps.med"
250 myFieldName = "vitesse";
251
252 medFile = os.getenv('DATA_DIR') + '/MedFiles/' + medFile
253 myResult = myVisu.ImportFile(medFile)
254
255 anAnim = myVisu.CreateAnimation(myView);
256 aSObj = myStudy.FindObjectIOR(myResult.GetID())
257 aSObj = aSObj.FindSubObject(1)[1]
258 aSObj = aSObj.FindSubObject(3)[1]
259 aSObj = aSObj.FindSubObject(2)[1]
260 anAnim.addField(aSObj)
261 anAnim.setPresentationType(0,VISU.TISOSURFACE)
262 print "Generate presentations"
263 anAnim.generatePresentations(0)
264 print "Generate frames"
265 anAnim.generateFrames()
266 print "Start Animation"
267 anAnim.setSpeed(99)
268 anAnim.startAnimation()
269 myView.FitAll()
270 while 1:
271     time.sleep(1+aDelay)
272     if not anAnim.isRunning():
273         anAnim.stopAnimation()
274         break