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