1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 # T 2.24: Save/retrieve view parameters.
25 # Uses MED file fra.med from ${DATA_DIR}/MedFiles directory.
26 # This script is equivalent to non-regression test script 003/A3
35 medFile = os.getenv("DATA_DIR") + "/MedFiles/fra.med"
37 #%====================Stage1: Creating a new study====================%
39 print "**** Stage1: Creating a new study "
41 print "Creating a new study..................",
42 myVisu = visu_gui.myVisu
43 myVisu.SetCurrentStudy(salome.myStudy)
44 myViewManager = myVisu.GetViewManager()
45 if myViewManager is None : print "Error"
48 #%====================Stage2: Saving view parameters before import====================%
50 print "**** Stage2: Saving view parameters before import "
52 myView = myViewManager.Create3DView()
54 print "Zooming trihedron.....................",
55 aScale = myView.GetParallelScale()
56 myView.SetParallelScale(aScale*4)
59 print "Rotating trihedron....................",
60 aPoint = (100,100,100)
61 myView.SetPointOfView(aPoint)
64 print "Saving view parameters................",
65 aViewParamsName1 = 'ViewParams:1'
66 aSaveRes = myView.SaveViewParams(aViewParamsName1)
67 if aSaveRes != 1 : print "Error"
70 #%====================Stage3: Import MED file====================%
72 print "**** Stage3: Import MED file"
74 print 'Importing "fra.med"...................',
75 myResult = myVisu.ImportFile(medFile)
76 if myResult is None : print "Error"
79 print "Creating mesh.........................",
80 myMeshName = 'LE VOLUME'
81 myCellEntity = VISU.CELL
82 mesh = myVisu.MeshOnEntity(myResult,myMeshName,myCellEntity);
83 if mesh is None : print "Error"
90 #%====================Stage4: Saving view parameters after import====================%
92 print "**** Stage4: Saving view parameters after import"
94 print "Creating Scalar Map...................",
95 myFieldName = 'TAUX_DE_VIDE'
96 myNodeEntity = VISU.NODE
97 scalarmap = myVisu.ScalarMapOnField(myResult,myMeshName,myNodeEntity,myFieldName,1);
98 if scalarmap is None : print "Error"
100 myView.DisplayOnly(scalarmap)
102 print "Zooming 3D view.......................",
103 aScale = myView.GetParallelScale()
104 myView.SetParallelScale(aScale*2)
107 print "Setting view point(LEFT)..............",
108 myView.SetView((VISU.View3D.LEFT))
111 print "Saving view parameters................",
112 aViewParamsName2 = 'ViewParams:2'
113 aSaveRes = myView.SaveViewParams(aViewParamsName2)
114 if aSaveRes != 1 : print "Error"
117 print "Creating Cut Planes...................",
118 cutplanes = myVisu.CutPlanesOnField(myResult,myMeshName,myNodeEntity,myFieldName,1);
119 if cutplanes is None : print "Error"
121 cutplanes.SetNbPlanes(4)
122 myView.DisplayOnly(cutplanes)
124 print "Setting scaling.......................",
126 #Define parameters of scaling:
131 myXAxis = VISU.View3D.XAxis
132 myYAxis = VISU.View3D.YAxis
133 myZAxis = VISU.View3D.ZAxis
135 myView.ScaleView(myXAxis,myXParam)
136 myView.ScaleView(myYAxis,myYParam)
137 myView.ScaleView(myZAxis,myZParam)
140 print "Rotating 3d view......................",
142 myView.SetPointOfView(aPoint)
145 print "Fit All...............................",
149 print "Saving view parameters................",
150 aViewParamsName3 = 'ViewParams:3'
151 aSaveRes = myView.SaveViewParams(aViewParamsName3)
152 if aSaveRes != 1 : print "Error"
155 #%====================Stage5: Restoring view parameters====================%
157 print "**** Stage5: Restoring view parameters"
159 print "Restoring first view parameters.......",
160 aRestoreRes = myView.RestoreViewParams(aViewParamsName1)
161 if aRestoreRes != 1 : print "Error"
164 print "Restoring second view parameters......",
165 aRestoreRes = myView.RestoreViewParams(aViewParamsName2)
166 if aRestoreRes != 1 : print "Error"
169 print "Displaing only Scalar Map.............",
170 myView.DisplayOnly(scalarmap)
173 print "Displaing only Cut Planes.............",
174 myView.DisplayOnly(cutplanes)
177 print "Restoring third view parameters.......",
178 aRestoreRes = myView.RestoreViewParams(aViewParamsName3)
179 if aRestoreRes != 1 : print "Error"
182 print "Displaing only Mesh...................",
183 myView.DisplayOnly(mesh)
186 print "Displaing only Scalar Map.............",
187 myView.DisplayOnly(scalarmap)
190 print "Displaing only Cut Planes.............",
191 myView.DisplayOnly(cutplanes)
194 #%====================Stage6: Changing of view parameters====================%
196 print "**** Stage6: Changing of view parameters"
198 print "Remove scaling........................",
202 print "Fit All...............................",
206 print "Rotating 3d view......................",
208 myView.SetPointOfView(aPoint)
211 print "Resaving first view parameters........",
212 aSaveRes = myView.SaveViewParams(aViewParamsName1)
213 if aSaveRes != 1 : print "Error"
216 print "Restoring third view parameters.......",
217 aRestoreRes = myView.RestoreViewParams(aViewParamsName3)
218 if aRestoreRes != 1 : print "Error"
221 print "Restoring first view parameters.......",
222 aRestoreRes = myView.RestoreViewParams(aViewParamsName1)
223 if aRestoreRes != 1 : print "Error"
226 print "Displaying only Mesh..................",
227 myView.DisplayOnly(mesh)
230 print "Displaying only Scalar Map............",
231 myView.DisplayOnly(scalarmap)
234 #%====================Stage7: Saving of created view parameters====================%
236 print "**** Stage7: Saving of created view parameters"
238 print "Saving study..........................",
240 str = os.getenv("TmpDir")
244 file = str+'/VISU_005.hdf'
246 salome.myStudyManager.SaveAs(file, salome.myStudy, 0)
247 study_id = salome.myStudy._get_StudyId()
250 file_new = str+'/VISU_005_new.hdf'
252 if not sys.platform == "win32":
253 command = "mv " + file + " " + file_new
255 command = "move /Y " + file + " " + file_new
260 # Opening a study tempoparily commented due to a problem
261 # with python initialization. To be restored after bug 10000 fixing.
263 #print "Opening just saved study..............",
265 #openedStudy = salome.myStudyManager.Open(file)]
266 openedStudy = salome.myStudy # temporarily
267 #myVisu.SetCurrentStudy(openedStudy)
268 myViewManager = myVisu.GetViewManager()
269 myView1 = myViewManager.Create3DView()
270 if myView1 is None : print "Error"
276 print "Restoring first view parameters.......",
277 aRestoreRes = myView1.RestoreViewParams(aViewParamsName1)
278 if aRestoreRes != 1 : print "Error"
281 Builder = openedStudy.NewBuilder()
282 #SCom = openedStudy.FindComponent("VISU")
283 #Builder.LoadWith(SCom ,myVisu)
285 print "Displaying Scalar Map.................",
286 SObj = openedStudy.FindObject('ScalarMap')
287 scalarmap1 = visu_gui.visu.SObjectToObject(SObj)
288 if scalarmap1 is None : print "Error"
290 myView1.DisplayOnly(scalarmap1)
292 print "Displaying Cut Planes.................",
293 SObj = openedStudy.FindObject('CutPlanes')
294 cutplanes1 = visu_gui.visu.SObjectToObject(SObj)
295 if cutplanes1 is None : print "Error"
297 myView1.DisplayOnly(cutplanes1)
299 print "Restoring second view parameters......",
300 aRestoreRes = myView1.RestoreViewParams(aViewParamsName2)
301 if aRestoreRes != 1 : print "Error"
304 print "Displaying Scalar Map.................",
305 myView1.DisplayOnly(scalarmap1)
308 print "Restoring third view parameters.......",
309 aRestoreRes = myView1.RestoreViewParams(aViewParamsName3)
310 if aRestoreRes != 1 : print "Error"
313 print "Displaying Cut Planes.................",
314 myView1.DisplayOnly(cutplanes1)
317 #%====================Stage8: Changing of saved session====================%
319 print "**** Stage8: Changing of saved session"
321 print "Deleting ViewParams:3,1,2.............",
322 SObj = openedStudy.FindObject(aViewParamsName3)
323 Builder.RemoveObject(SObj)
324 SObj = openedStudy.FindObject(aViewParamsName1)
325 Builder.RemoveObject(SObj)
326 SObj = openedStudy.FindObject(aViewParamsName2)
327 Builder.RemoveObject(SObj)
330 SObjList2 = openedStudy.FindObjectByName(aViewParamsName1, "VISU")
331 print "FindObjectByName(aViewParamsName1, VISU) returned ", len(SObjList2), " objects"
333 print "Zooming trihedron.....................",
334 aScale = myView.GetParallelScale()
335 myView1.SetParallelScale(aScale*2)
339 print "Rotating trihedron....................",
340 aPoint = (200,40,-40)
341 myView1.SetPointOfView(aPoint)
344 print "Saving view parameters................",
345 aSaveRes = myView1.SaveViewParams(aViewParamsName1)
346 if aSaveRes != 1 : print "Error"
349 print "Renaming ViewParams:1.................",
350 SObj = openedStudy.FindObject(aViewParamsName1)
351 SObj.Name = "New_view"
354 print "Setting scaling.......................",
355 #Define parameters of scaling:
360 myXAxis = VISU.View3D.XAxis
361 myYAxis = VISU.View3D.YAxis
362 myZAxis = VISU.View3D.ZAxis
364 myView1.ScaleView(myXAxis,myXParam)
365 myView1.ScaleView(myYAxis,myYParam)
366 myView1.ScaleView(myZAxis,myZParam)
371 print "Saving view parameters................",
372 aSaveRes = myView1.SaveViewParams(aViewParamsName2)
373 if aSaveRes != 1 : print "Error"
376 print "Restoring first view parameters.......",
377 aRestoreRes = myView1.RestoreViewParams(aViewParamsName1)
378 if aSaveRes != 1 : print "Error"
381 print "Restoring second view parameters......",
382 aRestoreRes = myView1.RestoreViewParams(aViewParamsName2)
383 if aRestoreRes != 1 : print "Error"
386 # Remove the study file
387 if not sys.platform == "win32":
388 command = "rm -r " + file
390 command = "del /F " + file