0025507: Visualization - the method V3d_View::Place() is incorrect
[occt.git] / src / V3d / V3d_View_3.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14/***********************************************************************
15
16 FONCTION :
17 ----------
18 Classe V3d_View_3.cxx :
19
20 HISTORIQUE DES MODIFICATIONS :
21 --------------------------------
22 00-09-92 : GG ; Creation.
23 24-12-97 : FMN ; Suppression de GEOMLITE
24 13-06-98 : FMN ; PRO14896: Correction sur la gestion de la perspective (cf Programming Guide)
7fd59977 25
26************************************************************************/
27
28#define IMP020300 //GG Don't use ZFitAll in during Rotation
29// for perf improvment
30
31/*----------------------------------------------------------------------*/
32/*
33 * Includes
34 */
35
36#include <V3d_View.jxx>
37#include <V3d_Static.hxx>
38
39#define Zmargin 1.
40
41/*----------------------------------------------------------------------*/
42
43void V3d_View::Move(const Standard_Real Dx, const Standard_Real Dy, const Standard_Real Dz, const Standard_Boolean Start) {
7fd59977 44
b5ac8292 45 if( Start )
46 {
47 myCamStartOpEye = myCamera->Eye();
48
49 gp_Dir aReferencePlane (myCamera->Direction().Reversed());
50 gp_Dir anUp (myCamera->Up());
51 if (!ScreenAxis (aReferencePlane, anUp, MyXscreenAxis, MyYscreenAxis, MyZscreenAxis))
52 {
53 V3d_BadValue::Raise ("V3d_View::Translate, alignment of Eye,At,Up");
54 }
7fd59977 55 }
b5ac8292 56
57 Standard_Real XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ;
58
59 MyXscreenAxis.Coord (XX,XY,XZ);
60 MyYscreenAxis.Coord (YX,YY,YZ);
61 MyZscreenAxis.Coord (ZX,ZY,ZZ);
62
63 myCamera->SetEye (myCamStartOpEye);
64
65 myCamera->SetEye (myCamera->Eye().XYZ()
66 + Dx * gp_Pnt (XX, XY, XZ).XYZ()
67 + Dy * gp_Pnt (YX, YY, YZ).XYZ()
68 + Dz * gp_Pnt (ZX, ZY, ZZ).XYZ()
69 );
70
6bc6a6fc 71 View()->AutoZFit();
b5ac8292 72
7fd59977 73 ImmediateUpdate();
74}
75
76void V3d_View::Move(const Standard_Real Length, const Standard_Boolean Start) {
b5ac8292 77
78 if( Start )
79 {
80 myCamStartOpEye = myCamera->Eye();
7fd59977 81 }
b5ac8292 82 myCamera->SetEye (myCamStartOpEye);
83
84 Standard_Real Vx, Vy, Vz;
85 MyDefaultViewAxis.Coord (Vx, Vy, Vz) ;
86
87 myCamera->SetEye (myCamera->Eye().XYZ() + Length * gp_Pnt (Vx, Vy, Vz).XYZ());
88
6bc6a6fc 89 View()->AutoZFit();
b5ac8292 90
7fd59977 91 ImmediateUpdate();
92}
93
94void V3d_View::Move(const V3d_TypeOfAxe Axe , const Standard_Real Length, const Standard_Boolean Start) {
95
96
97 switch (Axe) {
98 case V3d_X :
99 Move(Length,0.,0.,Start);
100 break ;
101 case V3d_Y :
102 Move(0.,Length,0.,Start);
103 break ;
104 case V3d_Z :
105 Move(0.,0.,Length,Start);
106 break ;
107 }
108}
109
110void V3d_View::Translate(const Standard_Real Dx, const Standard_Real Dy, const Standard_Real Dz, const Standard_Boolean Start) {
111
b5ac8292 112 if( Start )
113 {
114 myCamStartOpEye = myCamera->Eye();
115 myCamStartOpCenter = myCamera->Center();
116
117 gp_Dir aReferencePlane (myCamera->Direction().Reversed());
118 gp_Dir anUp (myCamera->Up());
119 if (!ScreenAxis (aReferencePlane, anUp,
120 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
121 V3d_BadValue::Raise ("V3d_View::Translate, alignment of Eye,At,Up");
7fd59977 122 }
b5ac8292 123
124 Standard_Real XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ;
125
126 MyXscreenAxis.Coord (XX,XY,XZ);
127 MyYscreenAxis.Coord (YX,YY,YZ);
128 MyZscreenAxis.Coord (ZX,ZY,ZZ);
129
130 myCamera->SetEye (myCamStartOpEye);
131 myCamera->SetCenter (myCamStartOpCenter);
132
133 myCamera->SetCenter (myCamera->Center().XYZ()
134 - Dx * gp_Pnt (XX, XY, XZ).XYZ()
135 - Dy * gp_Pnt (YX, YY, YZ).XYZ()
136 - Dz * gp_Pnt (ZX, ZY, ZZ).XYZ()
137 );
138
139 myCamera->SetEye (myCamera->Eye().XYZ()
140 - Dx * gp_Pnt (XX, XY, XZ).XYZ()
141 - Dy * gp_Pnt (YX, YY, YZ).XYZ()
142 - Dz * gp_Pnt (ZX, ZY, ZZ).XYZ()
143 );
144
6bc6a6fc 145 View()->AutoZFit();
b5ac8292 146
7fd59977 147 ImmediateUpdate();
148}
149
150void V3d_View::Translate(const V3d_TypeOfAxe Axe, const Standard_Real Length,const Standard_Boolean Start) {
151
152 switch (Axe) {
153 case V3d_X :
154 Translate(Length,0.,0., Start);
155 break ;
156 case V3d_Y :
157 Translate(0.,Length,0., Start);
158 break ;
159 case V3d_Z :
160 Translate(0.,0.,Length, Start);
161 break ;
162 }
163}
197ac94e 164
165//=======================================================================
166//function : Place
167//purpose :
168//=======================================================================
169void V3d_View::Place (const Standard_Integer theXp,
170 const Standard_Integer theYp,
171 const Quantity_Factor theZoomFactor)
172{
173 Standard_Integer aWinWidth = 0;
174 Standard_Integer aWinHeight = 0;
175 View()->Window()->Size (aWinWidth, aWinHeight);
176
177 Standard_Integer aWinCXp = aWinWidth / 2;
178 Standard_Integer aWinCYp = aWinHeight / 2;
49e1a5c7 179 Pan (aWinCXp - theXp, -(aWinCYp - theYp), theZoomFactor / Scale());
7fd59977 180}
b5ac8292 181
182void V3d_View::Translate(const Standard_Real theLength, const Standard_Boolean theStart) {
183
184 Standard_Real aVx, aVy, aVz ;
185 if (theStart)
186 {
187 myCamStartOpCenter = myCamera->Center() ;
7fd59977 188 }
b5ac8292 189 MyDefaultViewAxis.Coord (aVx, aVy, aVz);
190 gp_Pnt aNewCenter (myCamStartOpCenter.XYZ() - gp_Pnt (aVx, aVy, aVz).XYZ() * theLength);
191 myCamera->SetCenter (aNewCenter);
192
6bc6a6fc 193 View()->AutoZFit();
b5ac8292 194
7fd59977 195 ImmediateUpdate();
196}