0024776: Visualization - inherit OpenGl_View from Graphic3d_CView
[occt.git] / src / V3d / V3d_View_3.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #include <Aspect_GradientBackground.hxx>
16 #include <Aspect_Grid.hxx>
17 #include <Aspect_Window.hxx>
18 #include <Bnd_Box.hxx>
19 #include <gp_Ax3.hxx>
20 #include <gp_Dir.hxx>
21 #include <Graphic3d_Group.hxx>
22 #include <Graphic3d_Structure.hxx>
23 #include <Graphic3d_TextureEnv.hxx>
24 #include <Graphic3d_Vector.hxx>
25 #include <Quantity_Color.hxx>
26 #include <Standard_MultiplyDefined.hxx>
27 #include <Standard_TypeMismatch.hxx>
28 #include <V3d_BadValue.hxx>
29 #include <V3d_Light.hxx>
30 #include <V3d_UnMapped.hxx>
31 #include <V3d_View.hxx>
32 #include <V3d_Viewer.hxx>
33
34 //=============================================================================
35 //function : Move
36 //purpose  :
37 //=============================================================================
38 void V3d_View::Move (const Standard_Real Dx,
39                      const Standard_Real Dy,
40                      const Standard_Real Dz,
41                      const Standard_Boolean Start)
42 {
43   Handle(Graphic3d_Camera) aCamera = Camera();
44
45   if( Start ) 
46   {
47     myCamStartOpEye = aCamera->Eye();
48
49     gp_Dir aReferencePlane (aCamera->Direction().Reversed());
50     gp_Dir anUp (aCamera->Up());
51     if (!ScreenAxis (aReferencePlane, anUp, myXscreenAxis, myYscreenAxis, myZscreenAxis))
52     {
53           V3d_BadValue::Raise ("V3d_View::Translate, alignment of Eye,At,Up");
54     }
55   }
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   aCamera->SetEye (myCamStartOpEye);
64
65   aCamera->SetEye (aCamera->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
71   AutoZFit();
72
73   ImmediateUpdate();
74 }
75
76 //=============================================================================
77 //function : Move
78 //purpose  :
79 //=============================================================================
80 void V3d_View::Move (const Standard_Real Length, const Standard_Boolean Start)
81 {
82   Handle(Graphic3d_Camera) aCamera = Camera();
83
84   if( Start )
85   {
86     myCamStartOpEye = aCamera->Eye();
87   }
88   aCamera->SetEye (myCamStartOpEye);
89
90   Standard_Real Vx, Vy, Vz;
91   MyDefaultViewAxis.Coord (Vx, Vy, Vz) ;
92
93   aCamera->SetEye (aCamera->Eye().XYZ() + Length * gp_Pnt (Vx, Vy, Vz).XYZ());
94
95   AutoZFit();
96
97   ImmediateUpdate();
98 }
99
100 //=============================================================================
101 //function : Move
102 //purpose  :
103 //=============================================================================
104 void V3d_View::Move (const V3d_TypeOfAxe Axe , const Standard_Real Length, const Standard_Boolean Start)
105 {
106   switch (Axe) {
107   case V3d_X :
108     Move(Length,0.,0.,Start);
109     break ;
110   case V3d_Y :
111     Move(0.,Length,0.,Start);
112     break ;
113   case V3d_Z :
114     Move(0.,0.,Length,Start);
115     break ;
116   }
117 }
118
119 //=============================================================================
120 //function : Translate
121 //purpose  :
122 //=============================================================================
123 void V3d_View::Translate (const Standard_Real Dx,
124                           const Standard_Real Dy,
125                           const Standard_Real Dz,
126                           const Standard_Boolean Start)
127 {
128   Handle(Graphic3d_Camera) aCamera = Camera();
129
130   if( Start )
131   {
132     myCamStartOpEye = aCamera->Eye();
133     myCamStartOpCenter = aCamera->Center();
134
135     gp_Dir aReferencePlane (aCamera->Direction().Reversed());
136     gp_Dir anUp (aCamera->Up());
137     if (!ScreenAxis (aReferencePlane, anUp,
138                   myXscreenAxis,myYscreenAxis,myZscreenAxis))
139               V3d_BadValue::Raise ("V3d_View::Translate, alignment of Eye,At,Up");
140   }
141
142   Standard_Real XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ;
143
144   myXscreenAxis.Coord (XX,XY,XZ);
145   myYscreenAxis.Coord (YX,YY,YZ);
146   myZscreenAxis.Coord (ZX,ZY,ZZ);
147
148   aCamera->SetEye (myCamStartOpEye);
149   aCamera->SetCenter (myCamStartOpCenter);
150
151   aCamera->SetCenter (aCamera->Center().XYZ()
152     - Dx * gp_Pnt (XX, XY, XZ).XYZ()
153     - Dy * gp_Pnt (YX, YY, YZ).XYZ()
154     - Dz * gp_Pnt (ZX, ZY, ZZ).XYZ()
155     );
156
157   aCamera->SetEye (aCamera->Eye().XYZ()
158     - Dx * gp_Pnt (XX, XY, XZ).XYZ()
159     - Dy * gp_Pnt (YX, YY, YZ).XYZ()
160     - Dz * gp_Pnt (ZX, ZY, ZZ).XYZ()
161     );
162
163   AutoZFit();
164
165   ImmediateUpdate();
166 }
167
168 //=============================================================================
169 //function : Translate
170 //purpose  :
171 //=============================================================================
172 void V3d_View::Translate(const V3d_TypeOfAxe Axe, const Standard_Real Length,const Standard_Boolean Start) {
173
174   switch (Axe) {
175   case V3d_X :
176     Translate(Length,0.,0., Start);
177     break ;
178   case V3d_Y :
179     Translate(0.,Length,0., Start);
180     break ;
181   case V3d_Z :
182     Translate(0.,0.,Length, Start);
183     break ;
184   }
185 }
186
187 //=======================================================================
188 //function : Place
189 //purpose  :
190 //=======================================================================
191 void V3d_View::Place (const Standard_Integer theXp,
192                       const Standard_Integer theYp,
193                       const Quantity_Factor theZoomFactor)
194 {
195   Standard_Integer aWinWidth  = 0;
196   Standard_Integer aWinHeight = 0;
197   View()->Window()->Size (aWinWidth, aWinHeight);
198
199   Standard_Integer aWinCXp = aWinWidth  / 2;
200   Standard_Integer aWinCYp = aWinHeight / 2;
201   Pan (aWinCXp - theXp, -(aWinCYp - theYp), theZoomFactor / Scale());
202 }
203
204 //=======================================================================
205 //function : Place
206 //purpose  :
207 //=======================================================================
208 void V3d_View::Translate (const Standard_Real theLength, const Standard_Boolean theStart)
209 {
210   Handle(Graphic3d_Camera) aCamera = Camera();
211
212   Standard_Real aVx, aVy, aVz;
213   if (theStart) 
214   {
215     myCamStartOpCenter = aCamera->Center() ;
216   }
217   MyDefaultViewAxis.Coord (aVx, aVy, aVz);
218   gp_Pnt aNewCenter (myCamStartOpCenter.XYZ() - gp_Pnt (aVx, aVy, aVz).XYZ() * theLength);
219   aCamera->SetCenter (aNewCenter);
220
221   AutoZFit();
222
223   ImmediateUpdate();
224 }