0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / V3d / V3d_View_3.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18/***********************************************************************
19
20 FONCTION :
21 ----------
22 Classe V3d_View_3.cxx :
23
24 HISTORIQUE DES MODIFICATIONS :
25 --------------------------------
26 00-09-92 : GG ; Creation.
27 24-12-97 : FMN ; Suppression de GEOMLITE
28 13-06-98 : FMN ; PRO14896: Correction sur la gestion de la perspective (cf Programming Guide)
29 22-12-98 : FMN ; Rename CSF_WALKTHROW en CSF_WALKTHROUGH
30 IMP240100: GG -> Activates WalkThrough model.
31
32************************************************************************/
33
34#define IMP020300 //GG Don't use ZFitAll in during Rotation
35// for perf improvment
36
37/*----------------------------------------------------------------------*/
38/*
39 * Includes
40 */
41
42#include <V3d_View.jxx>
43#include <V3d_Static.hxx>
44
45#define Zmargin 1.
46
47/*----------------------------------------------------------------------*/
48
49void V3d_View::Move(const Standard_Real Dx, const Standard_Real Dy, const Standard_Real Dz, const Standard_Boolean Start) {
50
51 Graphic3d_Vertex Prp ;
52 Graphic3d_Vector Vpn ;
53 Standard_Real XX,XY,XZ,YX,YY,YZ,ZX,ZY,ZZ ;
54 Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xeye,Yeye,Zeye ;
55
56 if( Start ) {
57 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
58 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
59 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
60 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
61 if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
62 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
6942f04a 63 V3d_BadValue::Raise ("V3d_View::Move, alignment of Eye,At,Up");
7fd59977 64 }
65 MyXscreenAxis.Coord(XX,XY,XZ) ;
66 MyYscreenAxis.Coord(YX,YY,YZ) ;
67 MyZscreenAxis.Coord(ZX,ZY,ZZ) ;
68 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
69 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
70 Xeye = Zrp*Xpn + Dx*XX + Dy*YX + Dz*ZX ;
71 Yeye = Zrp*Ypn + Dx*XY + Dy*YY + Dz*ZY ;
72 Zeye = Zrp*Zpn + Dx*XZ + Dy*YZ + Dz*ZZ ;
73 Zrp = sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ;
6942f04a 74 V3d_BadValue_Raise_if( Zrp <= 0. ,"V3d_View::Move:: Eye,At are Confused");
302f96fb 75
7fd59977 76 Prp.SetCoord(Xrp,Yrp,Zrp) ;
77 MyViewMapping.SetProjectionReferencePoint(Prp) ;
78 Xpn = Xeye / Zrp ; Ypn = Yeye / Zrp ; Zpn = Zeye / Zrp ;
79 Vpn.SetCoord(Xpn,Ypn,Zpn) ;
80 MyViewOrientation.SetViewReferencePlane(Vpn) ;
81 MyView->SetViewOrientation(MyViewOrientation) ;
82
83 // Check ZClipping planes
7fd59977 84 MyView->SetViewMapping(MyViewMapping) ;
85 SetZSize(0.);
7fd59977 86 ImmediateUpdate();
87}
88
89void V3d_View::Move(const Standard_Real Length, const Standard_Boolean Start) {
90 Graphic3d_Vertex Prp ;
91 Graphic3d_Vector Vpn ;
92 Standard_Real Vx,Vy,Vz ;
93 Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xeye,Yeye,Zeye ;
94 if( Start ) {
95 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
96 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
97 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
98 }
99 MyDefaultViewAxis.Coord(Vx,Vy,Vz) ;
100 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
101 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
102 Xeye = Zrp*Xpn + Vx*Length ;
103 Yeye = Zrp*Ypn + Vy*Length ;
104 Zeye = Zrp*Zpn + Vz*Length ;
105 Zrp = sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ;
6942f04a 106 V3d_BadValue_Raise_if( Zrp <= 0. ,"V3d_View::Move:: Eye,At are Confused");
7fd59977 107
7fd59977 108 Prp.SetCoord(Xrp,Yrp,Zrp) ;
109 MyViewMapping.SetProjectionReferencePoint(Prp) ;
110 Xpn = Xeye / Zrp ; Ypn = Yeye / Zrp ; Zpn = Zeye / Zrp ;
111 Vpn.SetCoord(Xpn,Ypn,Zpn) ;
112 MyViewOrientation.SetViewReferencePlane(Vpn) ;
113 MyView->SetViewOrientation(MyViewOrientation) ;
114
115#ifdef IMP020300
116 MyView->SetViewMapping(MyViewMapping) ;
117 SetZSize(0.);
118#else
119 // Check ZClipping planes
120 Standard_Real Zmax,Xat,Yat,Zat ;
121 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
122 Xeye += Xat ; Yeye += Yat ; Zeye += Zat ;
123 Zmax = sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ;
124 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
125 MyProjModel == V3d_TPM_SCREEN ) {
126 SetZSize(2.*Zmax+Zmax*Zmargin) ;
127 } else {
128 if( MyType == V3d_PERSPECTIVE ) {
129 SetFocale(focale) ;
130 }
131 MyView->SetViewMapping(MyViewMapping) ;
132 }
133#endif
134 ImmediateUpdate();
135}
136
137void V3d_View::Move(const V3d_TypeOfAxe Axe , const Standard_Real Length, const Standard_Boolean Start) {
138
139
140 switch (Axe) {
141 case V3d_X :
142 Move(Length,0.,0.,Start);
143 break ;
144 case V3d_Y :
145 Move(0.,Length,0.,Start);
146 break ;
147 case V3d_Z :
148 Move(0.,0.,Length,Start);
149 break ;
150 }
151}
152
153void V3d_View::Translate(const Standard_Real Dx, const Standard_Real Dy, const Standard_Real Dz, const Standard_Boolean Start) {
154
155 Graphic3d_Vertex Vrp ;
156 Standard_Real XX,XY,XZ,YX,YY,YZ,ZX,ZY,ZZ ;
157 Standard_Real Xat,Yat,Zat ;
158 if( Start ) {
159 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
160 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
161 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
162 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
163 if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
164 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
6942f04a 165 V3d_BadValue::Raise ("V3d_View::Translate, alignment of Eye,At,Up");
7fd59977 166 }
167 MyXscreenAxis.Coord(XX,XY,XZ) ;
168 MyYscreenAxis.Coord(YX,YY,YZ) ;
169 MyZscreenAxis.Coord(ZX,ZY,ZZ) ;
170 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
171 Xat -= Dx*XX + Dy*YX + Dz*ZX ;
172 Yat -= Dx*XY + Dy*YY + Dz*ZY ;
173 Zat -= Dx*XZ + Dy*YZ + Dz*ZZ ;
174 Vrp.SetCoord(Xat,Yat,Zat) ;
175 MyViewOrientation.SetViewReferencePoint(Vrp) ;
176 MyView->SetViewOrientation(MyViewOrientation) ;
177#ifdef IMP020300
178 SetZSize(0.);
179#else
180 // Check ZClipping planes
181 Standard_Real Xpn,Ypn,Zpn,Xrp,Yrp,Zrp,Xeye,Yeye,Zeye,Zmax ;
182 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
183 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
184 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
185 Zmax = Max(sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ,
186 sqrt( Xat*Xat + Yat*Yat + Zat*Zat )) ;
187 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
188 MyProjModel == V3d_TPM_SCREEN ) {
189 SetZSize(2.*Zmax+Zmax*Zmargin) ;
190 }
191#endif
192 ImmediateUpdate();
193}
194
195void V3d_View::Translate(const V3d_TypeOfAxe Axe, const Standard_Real Length,const Standard_Boolean Start) {
196
197 switch (Axe) {
198 case V3d_X :
199 Translate(Length,0.,0., Start);
200 break ;
201 case V3d_Y :
202 Translate(0.,Length,0., Start);
203 break ;
204 case V3d_Z :
205 Translate(0.,0.,Length, Start);
206 break ;
207 }
208}
209void V3d_View::Place (const Standard_Integer ix, const Standard_Integer iy,
210 const Quantity_Factor aZoomFactor) {
211 Standard_Real xpos,ypos;
212 Standard_Integer xc,yc;
213 Center(xpos,ypos);
214 Convert(xpos,ypos,xc,yc);
215 Pan(xc-ix,iy-yc,aZoomFactor/Scale());
216}
217void V3d_View::Translate(const Standard_Real Length,const Standard_Boolean Start) {
218 Graphic3d_Vertex Vrp ;
219 Standard_Real Xat,Yat,Zat,Vx,Vy,Vz ;
220 if( Start ) {
221 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
222 }
223 MyDefaultViewAxis.Coord(Vx,Vy,Vz) ;
224 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
225 Xat -= Vx*Length ; Yat -= Vy*Length ; Zat -= Vz*Length ;
226 Vrp.SetCoord(Xat,Yat,Zat) ;
227 MyViewOrientation.SetViewReferencePoint(Vrp) ;
228 MyView->SetViewOrientation(MyViewOrientation) ;
229
230#ifdef IMP020300
231 SetZSize(0.);
232#else
233 // Check ZClipping planes
234 Standard_Real Xpn,Ypn,Zpn,Xrp,Yrp,Zrp,Xeye,Yeye,Zeye,Zmax ;
235 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
236 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
237 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
238 Zmax = Max(sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ,
239 sqrt( Xat*Xat + Yat*Yat + Zat*Zat )) ;
240 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
241 MyProjModel == V3d_TPM_SCREEN ) {
242 SetZSize(2.*Zmax+Zmax*Zmargin) ;
243 }
244#endif
245 ImmediateUpdate();
246}