0022627: Change OCCT memory management defaults
[occt.git] / src / V3d / V3d_View_3.cxx
CommitLineData
7fd59977 1/***********************************************************************
2
3 FONCTION :
4 ----------
5 Classe V3d_View_3.cxx :
6
7 HISTORIQUE DES MODIFICATIONS :
8 --------------------------------
9 00-09-92 : GG ; Creation.
10 24-12-97 : FMN ; Suppression de GEOMLITE
11 13-06-98 : FMN ; PRO14896: Correction sur la gestion de la perspective (cf Programming Guide)
12 22-12-98 : FMN ; Rename CSF_WALKTHROW en CSF_WALKTHROUGH
13 IMP240100: GG -> Activates WalkThrough model.
14
15************************************************************************/
16
17#define IMP020300 //GG Don't use ZFitAll in during Rotation
18// for perf improvment
19
20/*----------------------------------------------------------------------*/
21/*
22 * Includes
23 */
24
25#include <V3d_View.jxx>
26#include <V3d_Static.hxx>
27
28#define Zmargin 1.
29
30/*----------------------------------------------------------------------*/
31
32void V3d_View::Move(const Standard_Real Dx, const Standard_Real Dy, const Standard_Real Dz, const Standard_Boolean Start) {
33
34 Graphic3d_Vertex Prp ;
35 Graphic3d_Vector Vpn ;
36 Standard_Real XX,XY,XZ,YX,YY,YZ,ZX,ZY,ZZ ;
37 Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xeye,Yeye,Zeye ;
38
39 if( Start ) {
40 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
41 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
42 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
43 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
44 if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
45 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
46 Viewer_BadValue::Raise ("V3d_View::Move, alignment of Eye,At,Up");
47 }
48 MyXscreenAxis.Coord(XX,XY,XZ) ;
49 MyYscreenAxis.Coord(YX,YY,YZ) ;
50 MyZscreenAxis.Coord(ZX,ZY,ZZ) ;
51 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
52 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
53 Xeye = Zrp*Xpn + Dx*XX + Dy*YX + Dz*ZX ;
54 Yeye = Zrp*Ypn + Dx*XY + Dy*YY + Dz*ZY ;
55 Zeye = Zrp*Zpn + Dx*XZ + Dy*YZ + Dz*ZZ ;
56 Zrp = sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ;
57 Viewer_BadValue_Raise_if( Zrp <= 0. ,"V3d_View::Move:: Eye,At are Confused");
58#ifdef DEB
59 Standard_Real focale =
60#endif
61 Focale();
62 Prp.SetCoord(Xrp,Yrp,Zrp) ;
63 MyViewMapping.SetProjectionReferencePoint(Prp) ;
64 Xpn = Xeye / Zrp ; Ypn = Yeye / Zrp ; Zpn = Zeye / Zrp ;
65 Vpn.SetCoord(Xpn,Ypn,Zpn) ;
66 MyViewOrientation.SetViewReferencePlane(Vpn) ;
67 MyView->SetViewOrientation(MyViewOrientation) ;
68
69 // Check ZClipping planes
70#ifdef IMP020300
71 MyView->SetViewMapping(MyViewMapping) ;
72 SetZSize(0.);
73#else
74 Standard_Real Zmax,Xat,Yat,Zat ;
75 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
76 Xeye += Xat ; Yeye += Yat ; Zeye += Zat ;
77 Zmax = sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ;
78 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
79 MyProjModel == V3d_TPM_SCREEN ) {
80 SetZSize(2.*Zmax+Zmax*Zmargin) ;
81 } else {
82 if( MyType == V3d_PERSPECTIVE ) {
83 SetFocale(focale) ;
84 }
85 MyView->SetViewMapping(MyViewMapping) ;
86 }
87#endif
88 ImmediateUpdate();
89}
90
91void V3d_View::Move(const Standard_Real Length, const Standard_Boolean Start) {
92 Graphic3d_Vertex Prp ;
93 Graphic3d_Vector Vpn ;
94 Standard_Real Vx,Vy,Vz ;
95 Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xeye,Yeye,Zeye ;
96 if( Start ) {
97 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
98 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
99 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
100 }
101 MyDefaultViewAxis.Coord(Vx,Vy,Vz) ;
102 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
103 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
104 Xeye = Zrp*Xpn + Vx*Length ;
105 Yeye = Zrp*Ypn + Vy*Length ;
106 Zeye = Zrp*Zpn + Vz*Length ;
107 Zrp = sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ;
108 Viewer_BadValue_Raise_if( Zrp <= 0. ,"V3d_View::Move:: Eye,At are Confused");
109
110#ifdef DEB
111 Standard_Real focale =
112#endif
113 Focale();
114 Prp.SetCoord(Xrp,Yrp,Zrp) ;
115 MyViewMapping.SetProjectionReferencePoint(Prp) ;
116 Xpn = Xeye / Zrp ; Ypn = Yeye / Zrp ; Zpn = Zeye / Zrp ;
117 Vpn.SetCoord(Xpn,Ypn,Zpn) ;
118 MyViewOrientation.SetViewReferencePlane(Vpn) ;
119 MyView->SetViewOrientation(MyViewOrientation) ;
120
121#ifdef IMP020300
122 MyView->SetViewMapping(MyViewMapping) ;
123 SetZSize(0.);
124#else
125 // Check ZClipping planes
126 Standard_Real Zmax,Xat,Yat,Zat ;
127 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
128 Xeye += Xat ; Yeye += Yat ; Zeye += Zat ;
129 Zmax = sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ;
130 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
131 MyProjModel == V3d_TPM_SCREEN ) {
132 SetZSize(2.*Zmax+Zmax*Zmargin) ;
133 } else {
134 if( MyType == V3d_PERSPECTIVE ) {
135 SetFocale(focale) ;
136 }
137 MyView->SetViewMapping(MyViewMapping) ;
138 }
139#endif
140 ImmediateUpdate();
141}
142
143void V3d_View::Move(const V3d_TypeOfAxe Axe , const Standard_Real Length, const Standard_Boolean Start) {
144
145
146 switch (Axe) {
147 case V3d_X :
148 Move(Length,0.,0.,Start);
149 break ;
150 case V3d_Y :
151 Move(0.,Length,0.,Start);
152 break ;
153 case V3d_Z :
154 Move(0.,0.,Length,Start);
155 break ;
156 }
157}
158
159void V3d_View::Translate(const Standard_Real Dx, const Standard_Real Dy, const Standard_Real Dz, const Standard_Boolean Start) {
160
161 Graphic3d_Vertex Vrp ;
162 Standard_Real XX,XY,XZ,YX,YY,YZ,ZX,ZY,ZZ ;
163 Standard_Real Xat,Yat,Zat ;
164 if( Start ) {
165 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
166 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
167 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
168 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
169 if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
170 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
171 Viewer_BadValue::Raise ("V3d_View::Translate, alignment of Eye,At,Up");
172 }
173 MyXscreenAxis.Coord(XX,XY,XZ) ;
174 MyYscreenAxis.Coord(YX,YY,YZ) ;
175 MyZscreenAxis.Coord(ZX,ZY,ZZ) ;
176 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
177 Xat -= Dx*XX + Dy*YX + Dz*ZX ;
178 Yat -= Dx*XY + Dy*YY + Dz*ZY ;
179 Zat -= Dx*XZ + Dy*YZ + Dz*ZZ ;
180 Vrp.SetCoord(Xat,Yat,Zat) ;
181 MyViewOrientation.SetViewReferencePoint(Vrp) ;
182 MyView->SetViewOrientation(MyViewOrientation) ;
183#ifdef IMP020300
184 SetZSize(0.);
185#else
186 // Check ZClipping planes
187 Standard_Real Xpn,Ypn,Zpn,Xrp,Yrp,Zrp,Xeye,Yeye,Zeye,Zmax ;
188 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
189 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
190 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
191 Zmax = Max(sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ,
192 sqrt( Xat*Xat + Yat*Yat + Zat*Zat )) ;
193 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
194 MyProjModel == V3d_TPM_SCREEN ) {
195 SetZSize(2.*Zmax+Zmax*Zmargin) ;
196 }
197#endif
198 ImmediateUpdate();
199}
200
201void V3d_View::Translate(const V3d_TypeOfAxe Axe, const Standard_Real Length,const Standard_Boolean Start) {
202
203 switch (Axe) {
204 case V3d_X :
205 Translate(Length,0.,0., Start);
206 break ;
207 case V3d_Y :
208 Translate(0.,Length,0., Start);
209 break ;
210 case V3d_Z :
211 Translate(0.,0.,Length, Start);
212 break ;
213 }
214}
215void V3d_View::Place (const Standard_Integer ix, const Standard_Integer iy,
216 const Quantity_Factor aZoomFactor) {
217 Standard_Real xpos,ypos;
218 Standard_Integer xc,yc;
219 Center(xpos,ypos);
220 Convert(xpos,ypos,xc,yc);
221 Pan(xc-ix,iy-yc,aZoomFactor/Scale());
222}
223void V3d_View::Translate(const Standard_Real Length,const Standard_Boolean Start) {
224 Graphic3d_Vertex Vrp ;
225 Standard_Real Xat,Yat,Zat,Vx,Vy,Vz ;
226 if( Start ) {
227 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
228 }
229 MyDefaultViewAxis.Coord(Vx,Vy,Vz) ;
230 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
231 Xat -= Vx*Length ; Yat -= Vy*Length ; Zat -= Vz*Length ;
232 Vrp.SetCoord(Xat,Yat,Zat) ;
233 MyViewOrientation.SetViewReferencePoint(Vrp) ;
234 MyView->SetViewOrientation(MyViewOrientation) ;
235
236#ifdef IMP020300
237 SetZSize(0.);
238#else
239 // Check ZClipping planes
240 Standard_Real Xpn,Ypn,Zpn,Xrp,Yrp,Zrp,Xeye,Yeye,Zeye,Zmax ;
241 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
242 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
243 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
244 Zmax = Max(sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ,
245 sqrt( Xat*Xat + Yat*Yat + Zat*Zat )) ;
246 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
247 MyProjModel == V3d_TPM_SCREEN ) {
248 SetZSize(2.*Zmax+Zmax*Zmargin) ;
249 }
250#endif
251 ImmediateUpdate();
252}