1 # Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # T 2.24: Save/retrieve view parameters.
21 # Uses MED file fra.med from ${DATA_DIR}/MedFiles directory.
23 # This script is equivalent to non-regression test script 003/A3
32 medFile = os.getenv("DATA_DIR") + "/MedFiles/fra.med"
34 #%====================Stage1: Creating a new study====================%
36 print "**** Stage1: Creating a new study "
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"
45 #%====================Stage2: Saving view parameters before import====================%
47 print "**** Stage2: Saving view parameters before import "
49 myView = myViewManager.Create3DView()
51 print "Zooming trihedron.....................",
52 aScale = myView.GetParallelScale()
53 myView.SetParallelScale(aScale*4)
56 print "Rotating trihedron....................",
57 aPoint = (100,100,100)
58 myView.SetPointOfView(aPoint)
61 print "Saving view parameters................",
62 aViewParamsName1 = 'ViewParams:1'
63 aSaveRes = myView.SaveViewParams(aViewParamsName1)
64 if aSaveRes != 1 : print "Error"
67 #%====================Stage3: Import MED file====================%
69 print "**** Stage3: Import MED file"
71 print 'Importing "fra.med"...................',
72 myResult = myVisu.ImportFile(medFile)
73 if myResult is None : print "Error"
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"
87 #%====================Stage4: Saving view parameters after import====================%
89 print "**** Stage4: Saving view parameters after import"
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"
97 myView.DisplayOnly(scalarmap)
99 print "Zooming 3D view.......................",
100 aScale = myView.GetParallelScale()
101 myView.SetParallelScale(aScale*2)
104 print "Setting view point(LEFT)..............",
105 myView.SetView((VISU.View3D.LEFT))
108 print "Saving view parameters................",
109 aViewParamsName2 = 'ViewParams:2'
110 aSaveRes = myView.SaveViewParams(aViewParamsName2)
111 if aSaveRes != 1 : print "Error"
114 print "Creating Cut Planes...................",
115 cutplanes = myVisu.CutPlanesOnField(myResult,myMeshName,myNodeEntity,myFieldName,1);
116 if cutplanes is None : print "Error"
118 cutplanes.SetNbPlanes(4)
119 myView.DisplayOnly(cutplanes)
121 print "Setting scaling.......................",
123 #Define parameters of scaling:
128 myXAxis = VISU.View3D.XAxis
129 myYAxis = VISU.View3D.YAxis
130 myZAxis = VISU.View3D.ZAxis
132 myView.ScaleView(myXAxis,myXParam)
133 myView.ScaleView(myYAxis,myYParam)
134 myView.ScaleView(myZAxis,myZParam)
137 print "Rotating 3d view......................",
139 myView.SetPointOfView(aPoint)
142 print "Fit All...............................",
146 print "Saving view parameters................",
147 aViewParamsName3 = 'ViewParams:3'
148 aSaveRes = myView.SaveViewParams(aViewParamsName3)
149 if aSaveRes != 1 : print "Error"
152 #%====================Stage5: Restoring view parameters====================%
154 print "**** Stage5: Restoring view parameters"
156 print "Restoring first view parameters.......",
157 aRestoreRes = myView.RestoreViewParams(aViewParamsName1)
158 if aRestoreRes != 1 : print "Error"
161 print "Restoring second view parameters......",
162 aRestoreRes = myView.RestoreViewParams(aViewParamsName2)
163 if aRestoreRes != 1 : print "Error"
166 print "Displaing only Scalar Map.............",
167 myView.DisplayOnly(scalarmap)
170 print "Displaing only Cut Planes.............",
171 myView.DisplayOnly(cutplanes)
174 print "Restoring third view parameters.......",
175 aRestoreRes = myView.RestoreViewParams(aViewParamsName3)
176 if aRestoreRes != 1 : print "Error"
179 print "Displaing only Mesh...................",
180 myView.DisplayOnly(mesh)
183 print "Displaing only Scalar Map.............",
184 myView.DisplayOnly(scalarmap)
187 print "Displaing only Cut Planes.............",
188 myView.DisplayOnly(cutplanes)
191 #%====================Stage6: Changing of view parameters====================%
193 print "**** Stage6: Changing of view parameters"
195 print "Remove scaling........................",
199 print "Fit All...............................",
203 print "Rotating 3d view......................",
205 myView.SetPointOfView(aPoint)
208 print "Resaving first view parameters........",
209 aSaveRes = myView.SaveViewParams(aViewParamsName1)
210 if aSaveRes != 1 : print "Error"
213 print "Restoring third view parameters.......",
214 aRestoreRes = myView.RestoreViewParams(aViewParamsName3)
215 if aRestoreRes != 1 : print "Error"
218 print "Restoring first view parameters.......",
219 aRestoreRes = myView.RestoreViewParams(aViewParamsName1)
220 if aRestoreRes != 1 : print "Error"
223 print "Displaying only Mesh..................",
224 myView.DisplayOnly(mesh)
227 print "Displaying only Scalar Map............",
228 myView.DisplayOnly(scalarmap)
231 #%====================Stage7: Saving of created view parameters====================%
233 print "**** Stage7: Saving of created view parameters"
235 print "Saving study..........................",
237 str = os.getenv("TmpDir")
241 file = str+'/VISU_005.hdf'
243 salome.myStudyManager.SaveAs(file, salome.myStudy, 0)
244 study_id = salome.myStudy._get_StudyId()
247 file_new = str+'/VISU_005_new.hdf'
249 if not sys.platform == "win32":
250 command = "mv " + file + " " + file_new
252 command = "move /Y " + file + " " + file_new
257 # Opening a study tempoparily commented due to a problem
258 # with python initialization. To be restored after bug 10000 fixing.
260 #print "Opening just saved study..............",
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"
273 print "Restoring first view parameters.......",
274 aRestoreRes = myView1.RestoreViewParams(aViewParamsName1)
275 if aRestoreRes != 1 : print "Error"
278 Builder = openedStudy.NewBuilder()
279 #SCom = openedStudy.FindComponent("VISU")
280 #Builder.LoadWith(SCom ,myVisu)
282 print "Displaying Scalar Map.................",
283 SObj = openedStudy.FindObject('ScalarMap')
284 scalarmap1 = visu_gui.visu.SObjectToObject(SObj)
285 if scalarmap1 is None : print "Error"
287 myView1.DisplayOnly(scalarmap1)
289 print "Displaying Cut Planes.................",
290 SObj = openedStudy.FindObject('CutPlanes')
291 cutplanes1 = visu_gui.visu.SObjectToObject(SObj)
292 if cutplanes1 is None : print "Error"
294 myView1.DisplayOnly(cutplanes1)
296 print "Restoring second view parameters......",
297 aRestoreRes = myView1.RestoreViewParams(aViewParamsName2)
298 if aRestoreRes != 1 : print "Error"
301 print "Displaying Scalar Map.................",
302 myView1.DisplayOnly(scalarmap1)
305 print "Restoring third view parameters.......",
306 aRestoreRes = myView1.RestoreViewParams(aViewParamsName3)
307 if aRestoreRes != 1 : print "Error"
310 print "Displaying Cut Planes.................",
311 myView1.DisplayOnly(cutplanes1)
314 #%====================Stage8: Changing of saved session====================%
316 print "**** Stage8: Changing of saved session"
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)
327 SObjList2 = openedStudy.FindObjectByName(aViewParamsName1, "VISU")
328 print "FindObjectByName(aViewParamsName1, VISU) returned ", len(SObjList2), " objects"
330 print "Zooming trihedron.....................",
331 aScale = myView.GetParallelScale()
332 myView1.SetParallelScale(aScale*2)
336 print "Rotating trihedron....................",
337 aPoint = (200,40,-40)
338 myView1.SetPointOfView(aPoint)
341 print "Saving view parameters................",
342 aSaveRes = myView1.SaveViewParams(aViewParamsName1)
343 if aSaveRes != 1 : print "Error"
346 print "Renaming ViewParams:1.................",
347 SObj = openedStudy.FindObject(aViewParamsName1)
348 SObj.Name = "New_view"
351 print "Setting scaling.......................",
352 #Define parameters of scaling:
357 myXAxis = VISU.View3D.XAxis
358 myYAxis = VISU.View3D.YAxis
359 myZAxis = VISU.View3D.ZAxis
361 myView1.ScaleView(myXAxis,myXParam)
362 myView1.ScaleView(myYAxis,myYParam)
363 myView1.ScaleView(myZAxis,myZParam)
368 print "Saving view parameters................",
369 aSaveRes = myView1.SaveViewParams(aViewParamsName2)
370 if aSaveRes != 1 : print "Error"
373 print "Restoring first view parameters.......",
374 aRestoreRes = myView1.RestoreViewParams(aViewParamsName1)
375 if aSaveRes != 1 : print "Error"
378 print "Restoring second view parameters......",
379 aRestoreRes = myView1.RestoreViewParams(aViewParamsName2)
380 if aRestoreRes != 1 : print "Error"
383 # Remove the study file
384 if not sys.platform == "win32":
385 command = "rm -r " + file
387 command = "del /F " + file