]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_SWIG/VISU_Example_02.py
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / VISU_SWIG / VISU_Example_02.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.24: Save/retrieve view parameters.
21 # Uses MED file fra.med from ${DATA_DIR}/MedFiles directory.
22
23 # This script is equivalent to non-regression test script 003/A3
24
25 import salome
26 import visu_gui
27 import SALOMEDS
28 import VISU
29 import os
30 import sys
31
32 medFile = os.getenv("DATA_DIR") + "/MedFiles/fra.med"
33
34 #%====================Stage1: Creating a new study====================%
35
36 print "**** Stage1: Creating a new study "
37
38 print "Creating a new study..................", 
39 myVisu = visu_gui.myVisu
40 myVisu.SetCurrentStudy(salome.myStudy)
41 myViewManager = myVisu.GetViewManager()
42 if myViewManager is None : print "Error"
43 else : print "OK"
44
45 #%====================Stage2: Saving view parameters before import====================%
46
47 print "**** Stage2: Saving view parameters before import "
48
49 myView = myViewManager.Create3DView()
50
51 print "Zooming trihedron.....................",
52 aScale = myView.GetParallelScale()
53 myView.SetParallelScale(aScale*4)
54 print "OK"
55
56 print "Rotating trihedron....................",
57 aPoint = (100,100,100)
58 myView.SetPointOfView(aPoint) 
59 print "OK"
60
61 print "Saving view parameters................",
62 aViewParamsName1 = 'ViewParams:1'
63 aSaveRes = myView.SaveViewParams(aViewParamsName1)
64 if aSaveRes != 1 : print "Error"
65 else : print "OK"
66
67 #%====================Stage3: Import MED file====================%
68
69 print "**** Stage3: Import MED file"
70
71 print 'Importing "fra.med"...................',
72 myResult = myVisu.ImportFile(medFile)
73 if myResult is None : print "Error"
74 else : print "OK"
75
76 print "Creating mesh.........................",
77 myMeshName = 'LE VOLUME'
78 myCellEntity = VISU.CELL
79 mesh = myVisu.MeshOnEntity(myResult,myMeshName,myCellEntity);
80 if mesh is None : print "Error"
81 else : print "OK"
82
83 myView.Maximize()
84 myView.Display(mesh)
85 myView.FitAll()
86
87 #%====================Stage4: Saving view parameters after import====================%
88
89 print "**** Stage4:  Saving view parameters after import"
90
91 print "Creating Scalar Map...................",
92 myFieldName = 'TAUX_DE_VIDE'
93 myNodeEntity = VISU.NODE
94 scalarmap = myVisu.ScalarMapOnField(myResult,myMeshName,myNodeEntity,myFieldName,1);
95 if scalarmap is None : print "Error"
96 else : print "OK"
97 myView.DisplayOnly(scalarmap)
98
99 print "Zooming 3D view.......................",
100 aScale = myView.GetParallelScale()
101 myView.SetParallelScale(aScale*2)
102 print "OK"
103
104 print "Setting view point(LEFT)..............",
105 myView.SetView((VISU.View3D.LEFT))
106 print "OK"
107
108 print "Saving view parameters................",
109 aViewParamsName2 = 'ViewParams:2'
110 aSaveRes = myView.SaveViewParams(aViewParamsName2)
111 if aSaveRes != 1 : print "Error"
112 else : print "OK"
113
114 print "Creating Cut Planes...................",
115 cutplanes = myVisu.CutPlanesOnField(myResult,myMeshName,myNodeEntity,myFieldName,1);
116 if cutplanes is None : print "Error"
117 else : print "OK"
118 cutplanes.SetNbPlanes(4)
119 myView.DisplayOnly(cutplanes)
120
121 print "Setting scaling.......................",
122
123 #Define parameters of scaling:
124 myXParam = 5
125 myYParam = 5
126 myZParam = 1
127
128 myXAxis = VISU.View3D.XAxis
129 myYAxis = VISU.View3D.YAxis
130 myZAxis = VISU.View3D.ZAxis
131
132 myView.ScaleView(myXAxis,myXParam)
133 myView.ScaleView(myYAxis,myYParam)
134 myView.ScaleView(myZAxis,myZParam)
135 print "OK"
136
137 print "Rotating 3d view......................",
138 aPoint = (100,40,0)
139 myView.SetPointOfView(aPoint) 
140 print "OK"
141
142 print "Fit All...............................",
143 myView.FitAll()
144 print "OK"
145
146 print "Saving view parameters................",
147 aViewParamsName3 = 'ViewParams:3'
148 aSaveRes = myView.SaveViewParams(aViewParamsName3)
149 if aSaveRes != 1 : print "Error"
150 else : print "OK"
151
152 #%====================Stage5: Restoring view parameters====================%
153
154 print "**** Stage5: Restoring view parameters"
155
156 print "Restoring first view parameters.......",
157 aRestoreRes = myView.RestoreViewParams(aViewParamsName1)
158 if aRestoreRes != 1 : print "Error"
159 else : print "OK"
160
161 print "Restoring second view parameters......",
162 aRestoreRes = myView.RestoreViewParams(aViewParamsName2)
163 if aRestoreRes != 1 : print "Error"
164 else : print "OK"
165
166 print "Displaing only Scalar Map.............",
167 myView.DisplayOnly(scalarmap)
168 print "OK"
169
170 print "Displaing only Cut Planes.............",
171 myView.DisplayOnly(cutplanes)
172 print "OK"
173
174 print "Restoring third view parameters.......",
175 aRestoreRes = myView.RestoreViewParams(aViewParamsName3)
176 if aRestoreRes != 1 : print "Error"
177 else : print "OK"
178
179 print "Displaing only Mesh...................",
180 myView.DisplayOnly(mesh)
181 print "OK"
182
183 print "Displaing only Scalar Map.............",
184 myView.DisplayOnly(scalarmap)
185 print "OK"
186
187 print "Displaing only Cut Planes.............",
188 myView.DisplayOnly(cutplanes)
189 print "OK"
190
191 #%====================Stage6: Changing of view parameters====================%
192
193 print "**** Stage6: Changing of view parameters"
194
195 print "Remove scaling........................",
196 myView.RemoveScale()
197 print "OK"
198
199 print "Fit All...............................",
200 myView.FitAll()
201 print "OK"
202
203 print "Rotating 3d view......................",
204 aPoint = (0,60,150)
205 myView.SetPointOfView(aPoint) 
206 print "OK"
207
208 print "Resaving first view parameters........",
209 aSaveRes = myView.SaveViewParams(aViewParamsName1)
210 if aSaveRes != 1 : print "Error"
211 else : print "OK"
212
213 print "Restoring third view parameters.......",
214 aRestoreRes = myView.RestoreViewParams(aViewParamsName3)
215 if aRestoreRes != 1 : print "Error"
216 else : print "OK"
217
218 print "Restoring first view parameters.......",
219 aRestoreRes = myView.RestoreViewParams(aViewParamsName1)
220 if aRestoreRes != 1 : print "Error"
221 else : print "OK"
222
223 print "Displaying only Mesh..................",
224 myView.DisplayOnly(mesh)
225 print "OK"
226
227 print "Displaying only Scalar Map............",
228 myView.DisplayOnly(scalarmap)
229 print "OK"
230
231 #%====================Stage7: Saving of created view parameters====================%
232
233 print "**** Stage7: Saving of created view parameters"
234
235 print "Saving study..........................",
236
237 str = os.getenv("TmpDir")
238 if str == None:
239         str = "/tmp"
240
241 file = str+'/VISU_005.hdf'
242
243 salome.myStudyManager.SaveAs(file, salome.myStudy, 0)
244 study_id = salome.myStudy._get_StudyId()
245 print "OK"
246
247 file_new = str+'/VISU_005_new.hdf'
248
249 if not sys.platform == "win32":
250   command = "mv " + file + " " + file_new
251 else:
252   command = "move /Y " + file + " " + file_new
253   
254 os.system(command)
255 file = file_new
256
257 # Opening a study tempoparily commented due to a problem
258 # with python initialization. To be restored after bug 10000 fixing.
259
260 #print "Opening just saved study..............",
261 #
262 #openedStudy = salome.myStudyManager.Open(file)]
263 openedStudy = salome.myStudy # temporarily
264 #myVisu.SetCurrentStudy(openedStudy)
265 myViewManager = myVisu.GetViewManager()
266 myView1 = myViewManager.Create3DView()
267 if myView1 is None : print "Error"
268 else : print "OK"
269
270 import time
271 time.sleep(1)
272
273 print "Restoring first view parameters.......",
274 aRestoreRes = myView1.RestoreViewParams(aViewParamsName1)
275 if aRestoreRes != 1 : print "Error"
276 else : print "OK"
277
278 Builder = openedStudy.NewBuilder()
279 #SCom = openedStudy.FindComponent("VISU")
280 #Builder.LoadWith(SCom ,myVisu)
281
282 print "Displaying Scalar Map.................",
283 SObj = openedStudy.FindObject('ScalarMap')
284 scalarmap1 = visu_gui.visu.SObjectToObject(SObj)
285 if scalarmap1 is None : print "Error"
286 else : print "OK"
287 myView1.DisplayOnly(scalarmap1)
288
289 print "Displaying Cut Planes.................",
290 SObj = openedStudy.FindObject('CutPlanes')
291 cutplanes1 = visu_gui.visu.SObjectToObject(SObj)
292 if cutplanes1 is None : print "Error"
293 else : print "OK"
294 myView1.DisplayOnly(cutplanes1)
295
296 print "Restoring second view parameters......",
297 aRestoreRes = myView1.RestoreViewParams(aViewParamsName2)
298 if aRestoreRes != 1 : print "Error"
299 else : print "OK"
300
301 print "Displaying Scalar Map.................",
302 myView1.DisplayOnly(scalarmap1)
303 print "OK"
304
305 print "Restoring third view parameters.......",
306 aRestoreRes = myView1.RestoreViewParams(aViewParamsName3)
307 if aRestoreRes != 1 : print "Error"
308 else : print "OK"
309
310 print "Displaying Cut Planes.................",
311 myView1.DisplayOnly(cutplanes1)
312 print "OK"
313
314 #%====================Stage8: Changing of saved session====================%
315
316 print "**** Stage8: Changing of saved session"
317
318 print "Deleting ViewParams:3,1,2.............",
319 SObj = openedStudy.FindObject(aViewParamsName3)
320 Builder.RemoveObject(SObj)
321 SObj = openedStudy.FindObject(aViewParamsName1)
322 Builder.RemoveObject(SObj)
323 SObj = openedStudy.FindObject(aViewParamsName2)
324 Builder.RemoveObject(SObj)
325 print "OK"
326
327 SObjList2 = openedStudy.FindObjectByName(aViewParamsName1, "VISU")
328 print "FindObjectByName(aViewParamsName1, VISU) returned ", len(SObjList2), " objects"
329
330 print "Zooming trihedron.....................",
331 aScale = myView.GetParallelScale()
332 myView1.SetParallelScale(aScale*2)
333 myView1.Update()
334 print "OK"
335
336 print "Rotating trihedron....................",
337 aPoint = (200,40,-40)
338 myView1.SetPointOfView(aPoint) 
339 print "OK"
340
341 print "Saving view parameters................",
342 aSaveRes = myView1.SaveViewParams(aViewParamsName1)
343 if aSaveRes != 1 : print "Error"
344 else : print "OK"
345
346 print "Renaming ViewParams:1.................",
347 SObj = openedStudy.FindObject(aViewParamsName1)
348 SObj.Name = "New_view"
349 print "OK"
350
351 print "Setting scaling.......................",
352 #Define parameters of scaling:
353 myXParam = 4
354 myYParam = 4
355 myZParam = 8
356
357 myXAxis = VISU.View3D.XAxis
358 myYAxis = VISU.View3D.YAxis
359 myZAxis = VISU.View3D.ZAxis
360
361 myView1.ScaleView(myXAxis,myXParam)
362 myView1.ScaleView(myYAxis,myYParam)
363 myView1.ScaleView(myZAxis,myZParam)
364 print "OK"
365
366 myView1.FitAll()
367
368 print "Saving view parameters................",
369 aSaveRes = myView1.SaveViewParams(aViewParamsName2)
370 if aSaveRes != 1 : print "Error"
371 else : print "OK"
372
373 print "Restoring first view parameters.......",
374 aRestoreRes = myView1.RestoreViewParams(aViewParamsName1)
375 if aSaveRes != 1 : print "Error"
376 else : print "OK"
377
378 print "Restoring second view parameters......",
379 aRestoreRes = myView1.RestoreViewParams(aViewParamsName2)
380 if aRestoreRes != 1 : print "Error"
381 else : print "OK"
382
383 # Remove the study file
384 if not sys.platform == "win32":
385   command = "rm -r " + file
386 else:
387   command = "del /F " + file
388 os.system(command)