0028889: Visualization, V3d_View - View specific Graphic3d_Structure should be remove...
[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
42cf5bc1 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>
42cf5bc1 29#include <V3d_Light.hxx>
30#include <V3d_UnMapped.hxx>
31#include <V3d_View.hxx>
32#include <V3d_Viewer.hxx>
7fd59977 33
c357e426 34//=============================================================================
35//function : Move
36//purpose :
37//=============================================================================
38void 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
b5ac8292 45 if( Start )
46 {
c357e426 47 myCamStartOpEye = aCamera->Eye();
b5ac8292 48
c357e426 49 gp_Dir aReferencePlane (aCamera->Direction().Reversed());
50 gp_Dir anUp (aCamera->Up());
d0607a76 51 if (!ScreenAxis (aReferencePlane, anUp, myXscreenAxis, myYscreenAxis, myZscreenAxis))
b5ac8292 52 {
9775fa61 53 throw V3d_BadValue("V3d_View::Translate, alignment of Eye,At,Up");
b5ac8292 54 }
7fd59977 55 }
b5ac8292 56
57 Standard_Real XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ;
58
d0607a76 59 myXscreenAxis.Coord (XX,XY,XZ);
60 myYscreenAxis.Coord (YX,YY,YZ);
61 myZscreenAxis.Coord (ZX,ZY,ZZ);
b5ac8292 62
c357e426 63 aCamera->SetEye (myCamStartOpEye);
b5ac8292 64
c357e426 65 aCamera->SetEye (aCamera->Eye().XYZ()
b5ac8292 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
c357e426 71 AutoZFit();
b5ac8292 72
7fd59977 73 ImmediateUpdate();
74}
75
c357e426 76//=============================================================================
77//function : Move
78//purpose :
79//=============================================================================
80void V3d_View::Move (const Standard_Real Length, const Standard_Boolean Start)
81{
82 Handle(Graphic3d_Camera) aCamera = Camera();
b5ac8292 83
c357e426 84 if( Start )
b5ac8292 85 {
c357e426 86 myCamStartOpEye = aCamera->Eye();
7fd59977 87 }
c357e426 88 aCamera->SetEye (myCamStartOpEye);
b5ac8292 89
90 Standard_Real Vx, Vy, Vz;
91 MyDefaultViewAxis.Coord (Vx, Vy, Vz) ;
92
c357e426 93 aCamera->SetEye (aCamera->Eye().XYZ() + Length * gp_Pnt (Vx, Vy, Vz).XYZ());
b5ac8292 94
c357e426 95 AutoZFit();
b5ac8292 96
7fd59977 97 ImmediateUpdate();
98}
99
c357e426 100//=============================================================================
101//function : Move
102//purpose :
103//=============================================================================
104void V3d_View::Move (const V3d_TypeOfAxe Axe , const Standard_Real Length, const Standard_Boolean Start)
105{
7fd59977 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
c357e426 119//=============================================================================
120//function : Translate
121//purpose :
122//=============================================================================
123void 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();
7fd59977 129
c357e426 130 if( Start )
b5ac8292 131 {
c357e426 132 myCamStartOpEye = aCamera->Eye();
133 myCamStartOpCenter = aCamera->Center();
b5ac8292 134
c357e426 135 gp_Dir aReferencePlane (aCamera->Direction().Reversed());
136 gp_Dir anUp (aCamera->Up());
b5ac8292 137 if (!ScreenAxis (aReferencePlane, anUp,
d0607a76 138 myXscreenAxis,myYscreenAxis,myZscreenAxis))
9775fa61 139 throw V3d_BadValue("V3d_View::Translate, alignment of Eye,At,Up");
7fd59977 140 }
b5ac8292 141
142 Standard_Real XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ;
143
d0607a76 144 myXscreenAxis.Coord (XX,XY,XZ);
145 myYscreenAxis.Coord (YX,YY,YZ);
146 myZscreenAxis.Coord (ZX,ZY,ZZ);
b5ac8292 147
c357e426 148 aCamera->SetEye (myCamStartOpEye);
149 aCamera->SetCenter (myCamStartOpCenter);
b5ac8292 150
c357e426 151 aCamera->SetCenter (aCamera->Center().XYZ()
b5ac8292 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
c357e426 157 aCamera->SetEye (aCamera->Eye().XYZ()
b5ac8292 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
c357e426 163 AutoZFit();
b5ac8292 164
7fd59977 165 ImmediateUpdate();
166}
167
c357e426 168//=============================================================================
169//function : Translate
170//purpose :
171//=============================================================================
7fd59977 172void 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}
197ac94e 186
187//=======================================================================
188//function : Place
189//purpose :
190//=======================================================================
191void V3d_View::Place (const Standard_Integer theXp,
192 const Standard_Integer theYp,
ee2be2a8 193 const Standard_Real theZoomFactor)
197ac94e 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;
49e1a5c7 201 Pan (aWinCXp - theXp, -(aWinCYp - theYp), theZoomFactor / Scale());
7fd59977 202}
b5ac8292 203
c357e426 204//=======================================================================
205//function : Place
206//purpose :
207//=======================================================================
208void V3d_View::Translate (const Standard_Real theLength, const Standard_Boolean theStart)
209{
210 Handle(Graphic3d_Camera) aCamera = Camera();
b5ac8292 211
c357e426 212 Standard_Real aVx, aVy, aVz;
b5ac8292 213 if (theStart)
214 {
c357e426 215 myCamStartOpCenter = aCamera->Center() ;
7fd59977 216 }
b5ac8292 217 MyDefaultViewAxis.Coord (aVx, aVy, aVz);
218 gp_Pnt aNewCenter (myCamStartOpCenter.XYZ() - gp_Pnt (aVx, aVy, aVz).XYZ() * theLength);
c357e426 219 aCamera->SetCenter (aNewCenter);
b5ac8292 220
c357e426 221 AutoZFit();
b5ac8292 222
7fd59977 223 ImmediateUpdate();
224}