bbe98874597769229b551b11274c470237c400da
[occt.git] / src / V3d / V3d_View_1.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 /*     FUNCTION :
16      ----------
17         File V3d_View_1.cxx :     */
18 /*----------------------------------------------------------------------*/
19 /*
20  * Includes
21   */
22
23 #include <Aspect_GradientBackground.hxx>
24 #include <Aspect_Grid.hxx>
25 #include <Aspect_Window.hxx>
26 #include <Bnd_Box.hxx>
27 #include <gp_Ax3.hxx>
28 #include <gp_Dir.hxx>
29 #include <Graphic3d_Group.hxx>
30 #include <Graphic3d_Structure.hxx>
31 #include <Graphic3d_TextureEnv.hxx>
32 #include <Graphic3d_Vector.hxx>
33 #include <Quantity_Color.hxx>
34 #include <Standard_MultiplyDefined.hxx>
35 #include <Standard_TypeMismatch.hxx>
36 #include <V3d_BadValue.hxx>
37 #include <V3d_Light.hxx>
38 #include <V3d_UnMapped.hxx>
39 #include <V3d_View.hxx>
40 #include <V3d_Viewer.hxx>
41
42 //=============================================================================
43 //function : SetZClippingDepth
44 //purpose  :
45 //=============================================================================
46 void V3d_View::SetZClippingDepth (const Standard_Real theDepth)
47 {
48   Standard_Real aFront = 0., aBack = 0., aWidth = 0.;
49
50   aFront = myView->ZClippingFrontPlane();
51   aBack  = myView->ZClippingBackPlane();
52   aWidth = aFront - aBack;
53   aFront = theDepth + aWidth / 2.;
54   aBack  = theDepth - aWidth / 2.;
55   myView->SetZClippingBackPlane  (aBack);
56   myView->SetZClippingFrontPlane (aFront);
57 }
58
59 //=============================================================================
60 //function : SetZClippingWidth
61 //purpose  :
62 //=============================================================================
63 void V3d_View::SetZClippingWidth (const Standard_Real theWidth)
64 {
65   Standard_Real aFront = 0., aBack = 0., aDepth = 0.;
66   V3d_BadValue_Raise_if (theWidth <= 0., "V3d_View::SetZClippingWidth, bad width");
67
68   aFront = myView->ZClippingFrontPlane();
69   aBack  = myView->ZClippingBackPlane();
70   aDepth = (aFront + aBack)  / 2.;
71   aFront = aDepth + theWidth / 2.;
72   aBack  = aDepth - theWidth / 2.;
73   myView->SetZClippingBackPlane  (aBack);
74   myView->SetZClippingFrontPlane (aFront);
75 }
76
77 //=============================================================================
78 //function : SetZClippingType
79 //purpose  :
80 //=============================================================================
81 void V3d_View::SetZClippingType (const V3d_TypeOfZclipping theType)
82 {
83   switch (theType)
84   {
85     case V3d_OFF :
86     myView->SetFrontZClippingOn (Standard_False);
87     myView->SetBackZClippingOn  (Standard_False);
88     break;
89
90     case V3d_BACK :
91     myView->SetBackZClippingOn  (Standard_True);
92     myView->SetFrontZClippingOn (Standard_False);
93     break;
94
95     case V3d_FRONT :
96     myView->SetFrontZClippingOn (Standard_True);
97     myView->SetBackZClippingOn  (Standard_False);
98     break;
99
100     case V3d_SLICE :
101     myView->SetFrontZClippingOn (Standard_False);
102     myView->SetBackZClippingOn  (Standard_False);
103     break;
104   }
105 }
106
107 //=============================================================================
108 //function : ZClipping
109 //purpose  :
110 //=============================================================================
111 V3d_TypeOfZclipping V3d_View::ZClipping (Standard_Real& theDepth, Standard_Real& theWidth) const
112 {
113   V3d_TypeOfZclipping aType = V3d_OFF;
114
115   Standard_Real aBack        = myView->ZClippingBackPlane();
116   Standard_Real aFront       = myView->ZClippingFrontPlane();
117   Standard_Boolean isBackOn  = myView->BackZClippingIsOn();
118   Standard_Boolean isFrontOn = myView->FrontZClippingIsOn();
119
120   theWidth = aFront - aBack ;
121   theDepth = (aFront + aBack) / 2.0;
122   if (isBackOn)
123   {
124     if (isFrontOn)
125     {
126       aType = V3d_SLICE;
127     }
128     else
129     {
130       aType = V3d_BACK;
131     }
132   }
133   else if (isFrontOn)
134   {
135     aType = V3d_FRONT;
136   }
137
138   return aType;
139 }
140
141 //=============================================================================
142 //function : SetZCueingDepth
143 //purpose  :
144 //=============================================================================
145 void V3d_View::SetZCueingDepth (const Standard_Real theDepth)
146 {
147   Standard_Real aFront = myView->DepthCueingFrontPlane();
148   Standard_Real aBack  = myView->DepthCueingBackPlane();
149   Standard_Real aWidth = aFront - aBack;
150   aFront = theDepth + aWidth / 2.;
151   aBack  = theDepth - aWidth / 2.;
152   myView->SetDepthCueingBackPlane  (aBack);
153   myView->SetDepthCueingFrontPlane (aFront);
154 }
155
156 //=============================================================================
157 //function : SetZCueingWidth
158 //purpose  :
159 //=============================================================================
160 void V3d_View::SetZCueingWidth (const Standard_Real theWidth)
161 {
162   V3d_BadValue_Raise_if (theWidth <= 0., "V3d_View::SetZCueingWidth, bad width");
163
164   Standard_Real aFront = myView->DepthCueingFrontPlane();
165   Standard_Real aBack  = myView->DepthCueingBackPlane();
166   Standard_Real aDepth = (aFront + aBack) / 2.0;
167   aFront = aDepth + theWidth / 2.0;
168   aBack  = aDepth - theWidth / 2.0;
169   myView->SetDepthCueingBackPlane  (aBack);
170   myView->SetDepthCueingFrontPlane (aFront);
171 }
172
173 //=============================================================================
174 //function : SetZCueingOn
175 //purpose  :
176 //=============================================================================
177 void V3d_View::SetZCueingOn()
178 {
179   myView->SetDepthCueingOn (Standard_True);
180 }
181
182 //=============================================================================
183 //function : SetZCueingOff
184 //purpose  :
185 //=============================================================================
186 void V3d_View::SetZCueingOff()
187 {
188   myView->SetDepthCueingOn (Standard_False);
189 }
190
191 //=============================================================================
192 //function : ZCueing
193 //purpose  :
194 //=============================================================================
195 Standard_Boolean V3d_View::ZCueing (Standard_Real& theDepth, Standard_Real& theWidth) const
196 {
197   Standard_Boolean isOn = myView->DepthCueingIsOn();
198   Standard_Real aFront  = myView->DepthCueingFrontPlane();
199   Standard_Real aBack   = myView->DepthCueingBackPlane();
200
201   theWidth = aFront - aBack ;
202   theDepth = (aFront + aBack) / 2.;
203
204   return isOn;
205 }