0030364: Visualization, TKOpenGl - allow initializing a Surface-less EGL context
[occt.git] / src / V3d / V3d_View_2.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      FONCTION :
16      ----------
17         Classe V3d_View_2.cxx :
18      HISTORIQUE DES MODIFICATIONS   :
19      --------------------------------
20       00-09-92 : GG  ; Creation.
21       24-12-97 : FMN ; Suppression de GEOMLITE
22       23-11-00 : GG  ; Add IsActiveLight() and IsActivePlane() methods
23 ************************************************************************/
24 /*
25  * Includes
26  */
27
28 #include <Aspect_GradientBackground.hxx>
29 #include <Aspect_Grid.hxx>
30 #include <Aspect_Window.hxx>
31 #include <Bnd_Box.hxx>
32 #include <gp_Ax3.hxx>
33 #include <gp_Dir.hxx>
34 #include <Graphic3d_Group.hxx>
35 #include <Graphic3d_GraphicDriver.hxx>
36 #include <Graphic3d_Structure.hxx>
37 #include <Graphic3d_TextureEnv.hxx>
38 #include <Quantity_Color.hxx>
39 #include <Standard_MultiplyDefined.hxx>
40 #include <Standard_TypeMismatch.hxx>
41 #include <V3d.hxx>
42 #include <V3d_BadValue.hxx>
43 #include <V3d_Light.hxx>
44 #include <V3d_UnMapped.hxx>
45 #include <V3d_View.hxx>
46 #include <V3d_Viewer.hxx>
47
48 //=============================================================================
49 //function : SetLightOn
50 //purpose  :
51 //=============================================================================
52 void V3d_View::SetLightOn (const Handle(V3d_Light)& theLight)
53 {
54   if (!myActiveLights.Contains (theLight))
55   {
56     myActiveLights.Append (theLight);
57     UpdateLights();
58   }
59 }
60
61 //=============================================================================
62 //function : SetLightOff
63 //purpose  :
64 //=============================================================================
65 void V3d_View::SetLightOff (const Handle(V3d_Light)& theLight)
66 {
67   if (MyViewer->IsGlobalLight (theLight))
68     throw Standard_TypeMismatch("V3d_View::SetLightOff, the light is global");
69   myActiveLights.Remove (theLight);
70   UpdateLights();
71 }
72
73 //=============================================================================
74 //function : IsActiveLight
75 //purpose  :
76 //=============================================================================
77 Standard_Boolean V3d_View::IsActiveLight (const Handle(V3d_Light)& theLight) const
78 {
79   return !theLight.IsNull()
80        && myActiveLights.Contains (theLight);
81 }
82
83 //=============================================================================
84 //function : SetLightOn
85 //purpose  :
86 //=============================================================================
87 void V3d_View::SetLightOn()
88 {
89   for (V3d_ListOfLightIterator aDefLightIter (MyViewer->DefinedLightIterator()); aDefLightIter.More(); aDefLightIter.Next())
90   {
91     if (!myActiveLights.Contains (aDefLightIter.Value()))
92     {
93       myActiveLights.Append (aDefLightIter.Value());
94     }
95   }
96   UpdateLights();
97 }
98
99 //=============================================================================
100 //function : SetLightOff
101 //purpose  :
102 //=============================================================================
103 void V3d_View::SetLightOff()
104 {
105   for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More();)
106   {
107     if (!MyViewer->IsGlobalLight (anActiveLightIter.Value()))
108     {
109       myActiveLights.Remove (anActiveLightIter);
110     }
111     else
112     {
113       anActiveLightIter.Next();
114     }
115   }
116   UpdateLights();
117 }
118
119 //=============================================================================
120 //function : IfMoreLights
121 //purpose  :
122 //=============================================================================
123 Standard_Boolean V3d_View::IfMoreLights() const
124 {
125   return myActiveLights.Extent() < LightLimit();
126 }
127
128 //=======================================================================
129 //function : LightLimit
130 //purpose  :
131 //=======================================================================
132 Standard_Integer V3d_View::LightLimit() const
133 {
134   return Viewer()->Driver()->InquireLightLimit();
135 }
136
137 //=======================================================================
138 //function : AddClipPlane
139 //purpose  :
140 //=======================================================================
141 void V3d_View::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
142 {
143   Handle(Graphic3d_SequenceOfHClipPlane) aSeqOfPlanes = ClipPlanes();
144   if (aSeqOfPlanes.IsNull())
145   {
146     aSeqOfPlanes = new Graphic3d_SequenceOfHClipPlane();
147   }
148   else
149   {
150     for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (*aSeqOfPlanes); aPlaneIt.More(); aPlaneIt.Next())
151     {
152       const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
153       if (aPlane == thePlane)
154       {
155         // plane is already defined in view
156         return;
157       }
158     }
159   }
160
161   aSeqOfPlanes->Append (thePlane);
162   SetClipPlanes (aSeqOfPlanes);
163 }
164
165 //=======================================================================
166 //function : RemoveClipPlane
167 //purpose  :
168 //=======================================================================
169 void V3d_View::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
170 {
171   Handle(Graphic3d_SequenceOfHClipPlane) aSeqOfPlanes = ClipPlanes();
172   if (aSeqOfPlanes.IsNull())
173   {
174     return;
175   }
176
177   for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt(*aSeqOfPlanes); aPlaneIt.More(); aPlaneIt.Next())
178   {
179     const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
180     if (aPlane != thePlane)
181       continue;
182
183     aSeqOfPlanes->Remove (aPlaneIt);
184     SetClipPlanes (aSeqOfPlanes);
185     return;
186   }
187 }
188
189 //=======================================================================
190 //function : SetClipPlanes
191 //purpose  :
192 //=======================================================================
193 void V3d_View::SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes)
194 {
195   myView->SetClipPlanes (thePlanes);
196 }
197
198 //=======================================================================
199 //function : ClipPlanes
200 //purpose  :
201 //=======================================================================
202 const Handle(Graphic3d_SequenceOfHClipPlane)& V3d_View::ClipPlanes() const
203 {
204   return myView->ClipPlanes();
205 }
206
207 //=======================================================================
208 //function : PlaneLimit
209 //purpose  :
210 //=======================================================================
211 Standard_Integer V3d_View::PlaneLimit() const
212 {
213   return Viewer()->Driver()->InquirePlaneLimit();
214 }