Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / VISU_SWIG / visu_view3d_parameters.py
1 #  -*- coding: iso-8859-1 -*-
2 #  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
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
21 #  VISU VISU_SWIG : binding of C++ implementation and Python
22 #  File   : visu_view3d.py
23 #  Module : VISU
24 #
25 import salome
26 import visu_gui
27 import VISU
28 import os
29 import time
30
31 medFile = os.getenv("DATA_DIR") + "/MedFiles/fra.med"
32
33 #%====================Stage1: Creating a study====================%
34
35 print "Creating a new study... "
36 myVisu.SetCurrentStudy(salome.myStudy)
37
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 myView = myViewManager.Create3DView()
45
46 #%====================Stage2: Import MED file====================%
47
48 print "Importing Med file... "
49 myResult = myVisu.ImportFile(medFile)
50 if myResult is None : print "Error"
51 else : print "OK"
52
53 print "Creating mesh... "
54 myMeshName = 'LE VOLUME'
55 myCellEntity = VISU.CELL
56 mesh = myVisu.MeshOnEntity(myResult,myMeshName,myCellEntity);
57 if mesh is None : print "Error"
58 else : print "OK"
59
60 myView.Display(mesh)
61
62 #%====================Stage3: Changing of view parameters====================%
63
64 myView.FitAll()
65
66 aDelay=0.02
67
68 print "Rotating X..."
69 for i in range(0,100) :
70     aPoint = (i,60,150)
71     myView.SetPointOfView(aPoint) 
72     myView.Update();
73     time.sleep(aDelay)
74     
75 print "OK"
76
77 print "Zooming out...",
78 aScale = myView.GetParallelScale()
79 print "Zooming 3D view..."
80 for i in range(0,50) :
81     aScale = aScale + 0.05
82     myView.SetParallelScale(aScale)
83     myView.Update();
84     time.sleep(aDelay)
85 print "OK"
86
87 print "Change Focal Point..."
88 aFocalPoint = myView.GetFocalPoint()
89 for i in range(0,61) :
90     if i <= 30 :
91       aFocalPoint[0] = aFocalPoint[0] - 0.1;
92     else :
93       aFocalPoint[0] = aFocalPoint[0] + 0.1;
94     myView.SetFocalPoint(aFocalPoint) 
95     myView.Update();
96     time.sleep(aDelay)
97 for i in range(0,61) :
98     if i <= 30 :
99       aFocalPoint[1] = aFocalPoint[1] - 0.1;
100     else :
101       aFocalPoint[1] = aFocalPoint[1] + 0.1;
102     myView.SetFocalPoint(aFocalPoint) 
103     myView.Update();
104     time.sleep(aDelay)
105 print "OK"
106
107 print "Change View Up..."
108 aViewUp = myView.GetViewUp();
109 for i in range(0,40) :
110     aViewUp[0] = aViewUp[0] + 0.1;
111     myView.SetViewUp(aViewUp) 
112     myView.Update();
113     time.sleep(aDelay*2)
114 print "OK"
115
116 #create second viewer
117
118 myView1 = myViewManager.Create3DView()
119 myView1.SplitRight()
120 myView1.Display(mesh)
121 myView1.FitAll()
122 time.sleep(1)
123
124 # Get properties from the First viewer and apply it to the New viewer
125 aP = myView.GetPointOfView()
126 myView1.SetPointOfView(aP)
127
128 aFP = myView.GetFocalPoint()
129 myView1.SetFocalPoint(aFP)
130
131 aVU = myView.GetViewUp()
132 myView1.SetViewUp(aVU)
133
134 aScale = myView.GetParallelScale()
135 myView1.SetParallelScale( aScale )
136
137 myView.Update();
138 myView1.Update();
139 time.sleep(1)
140
141 # Change Parameters in both viewers
142
143 print "Zooming...",
144 aScale = myView.GetParallelScale()
145 for i in range(0,70) :
146     aScale = aScale - 0.08
147     myView.SetParallelScale(aScale)
148     myView.Update();
149     myView1.SetParallelScale(aScale)
150     myView1.Update();
151     time.sleep(aDelay)
152 print "OK"
153
154 print "Rotating Y..."
155 aPoint = myView1.GetPointOfView();
156 for i in range(0,150) :
157     aPoint[1] = aPoint[1] + 1;
158     myView1.SetPointOfView(aPoint) 
159     myView1.Update();
160     myView.SetPointOfView(aPoint) 
161     myView.Update();
162 print "OK"
163
164 print "Zooming back...",
165 for i in range(0,40) :
166     aScale = aScale + 0.08
167     myView.SetParallelScale(aScale)
168     myView.Update();
169     myView1.SetParallelScale(aScale)
170     myView1.Update();
171     time.sleep(aDelay)
172 print "OK"