0026937: Eliminate NO_CXX_EXCEPTION macro support
[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 <Graphic3d_Vector.hxx>
39 #include <Quantity_Color.hxx>
40 #include <Standard_MultiplyDefined.hxx>
41 #include <Standard_TypeMismatch.hxx>
42 #include <V3d.hxx>
43 #include <V3d_BadValue.hxx>
44 #include <V3d_Light.hxx>
45 #include <V3d_UnMapped.hxx>
46 #include <V3d_View.hxx>
47 #include <V3d_Viewer.hxx>
48
49 //=============================================================================
50 //function : SetLightOn
51 //purpose  :
52 //=============================================================================
53 void V3d_View::SetLightOn (const Handle(V3d_Light)& theLight)
54 {
55   if (!myActiveLights.Contains (theLight))
56   {
57     if (myActiveLights.Extent() >= LightLimit())
58       throw V3d_BadValue("V3d_View::SetLightOn, too many lights");
59     myActiveLights.Append (theLight);
60     UpdateLights();
61   }
62 }
63
64 //=============================================================================
65 //function : SetLightOff
66 //purpose  :
67 //=============================================================================
68 void V3d_View::SetLightOff (const Handle(V3d_Light)& theLight)
69 {
70   if (MyViewer->IsGlobalLight (theLight))
71     throw Standard_TypeMismatch("V3d_View::SetLightOff, the light is global");
72   myActiveLights.Remove (theLight);
73   UpdateLights();
74 }
75
76 //=============================================================================
77 //function : IsActiveLight
78 //purpose  :
79 //=============================================================================
80 Standard_Boolean V3d_View::IsActiveLight (const Handle(V3d_Light)& theLight) const
81 {
82   return !theLight.IsNull()
83        && myActiveLights.Contains (theLight);
84 }
85
86 //=============================================================================
87 //function : SetLightOn
88 //purpose  :
89 //=============================================================================
90 void V3d_View::SetLightOn()
91 {
92   for (V3d_ListOfLightIterator aDefLightIter (MyViewer->DefinedLightIterator()); aDefLightIter.More(); aDefLightIter.Next())
93   {
94     if (!myActiveLights.Contains (aDefLightIter.Value()))
95     {
96       myActiveLights.Append (aDefLightIter.Value());
97     }
98   }
99   UpdateLights();
100 }
101
102 //=============================================================================
103 //function : SetLightOff
104 //purpose  :
105 //=============================================================================
106 void V3d_View::SetLightOff()
107 {
108   for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More();)
109   {
110     if (!MyViewer->IsGlobalLight (anActiveLightIter.Value()))
111     {
112       myActiveLights.Remove (anActiveLightIter);
113     }
114     else
115     {
116       anActiveLightIter.Next();
117     }
118   }
119   UpdateLights();
120 }
121
122 //=============================================================================
123 //function : IfMoreLights
124 //purpose  :
125 //=============================================================================
126 Standard_Boolean V3d_View::IfMoreLights() const
127 {
128   return myActiveLights.Extent() < LightLimit();
129 }
130
131 //=======================================================================
132 //function : LightLimit
133 //purpose  :
134 //=======================================================================
135 Standard_Integer V3d_View::LightLimit() const
136 {
137   return Viewer()->Driver()->InquireLightLimit();
138 }
139
140 //=======================================================================
141 //function : AddClipPlane
142 //purpose  :
143 //=======================================================================
144 void V3d_View::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
145 {
146   Handle(Graphic3d_SequenceOfHClipPlane) aSeqOfPlanes = ClipPlanes();
147   if (aSeqOfPlanes.IsNull())
148   {
149     aSeqOfPlanes = new Graphic3d_SequenceOfHClipPlane();
150   }
151   else
152   {
153     for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (*aSeqOfPlanes); aPlaneIt.More(); aPlaneIt.Next())
154     {
155       const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
156       if (aPlane == thePlane)
157       {
158         // plane is already defined in view
159         return;
160       }
161     }
162   }
163
164   aSeqOfPlanes->Append (thePlane);
165   SetClipPlanes (aSeqOfPlanes);
166 }
167
168 //=======================================================================
169 //function : RemoveClipPlane
170 //purpose  :
171 //=======================================================================
172 void V3d_View::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
173 {
174   Handle(Graphic3d_SequenceOfHClipPlane) aSeqOfPlanes = ClipPlanes();
175   if (aSeqOfPlanes.IsNull())
176   {
177     return;
178   }
179
180   for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt(*aSeqOfPlanes); aPlaneIt.More(); aPlaneIt.Next())
181   {
182     const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
183     if (aPlane != thePlane)
184       continue;
185
186     aSeqOfPlanes->Remove (aPlaneIt);
187     SetClipPlanes (aSeqOfPlanes);
188     return;
189   }
190 }
191
192 //=======================================================================
193 //function : SetClipPlanes
194 //purpose  :
195 //=======================================================================
196 void V3d_View::SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes)
197 {
198   myView->SetClipPlanes (thePlanes);
199 }
200
201 //=======================================================================
202 //function : ClipPlanes
203 //purpose  :
204 //=======================================================================
205 const Handle(Graphic3d_SequenceOfHClipPlane)& V3d_View::ClipPlanes() const
206 {
207   return myView->ClipPlanes();
208 }
209
210 //=======================================================================
211 //function : PlaneLimit
212 //purpose  :
213 //=======================================================================
214 Standard_Integer V3d_View::PlaneLimit() const
215 {
216   return Viewer()->Driver()->InquirePlaneLimit();
217 }