1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 /***********************************************************************
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 ************************************************************************/
28 #include <Aspect_GradientBackground.hxx>
29 #include <Aspect_Grid.hxx>
30 #include <Aspect_Window.hxx>
31 #include <Bnd_Box.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>
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>
49 //=============================================================================
50 //function : SetLightOn
52 //=============================================================================
53 void V3d_View::SetLightOn (const Handle(V3d_Light)& theLight)
55 if (!myActiveLights.Contains (theLight))
57 V3d_BadValue_Raise_if (myActiveLights.Extent() >= LightLimit(),
58 "V3d_View::SetLightOn, "
60 myActiveLights.Append (theLight);
65 //=============================================================================
66 //function : SetLightOff
68 //=============================================================================
69 void V3d_View::SetLightOff (const Handle(V3d_Light)& theLight)
71 Standard_TypeMismatch_Raise_if (MyViewer->IsGlobalLight (theLight),
72 "V3d_View::SetLightOff, "
73 "the light is global");
74 myActiveLights.Remove (theLight);
78 //=============================================================================
79 //function : IsActiveLight
81 //=============================================================================
82 Standard_Boolean V3d_View::IsActiveLight (const Handle(V3d_Light)& theLight) const
84 return !theLight.IsNull()
85 && myActiveLights.Contains (theLight);
88 //=============================================================================
89 //function : SetLightOn
91 //=============================================================================
92 void V3d_View::SetLightOn()
94 for (V3d_ListOfLightIterator aDefLightIter (MyViewer->DefinedLightIterator()); aDefLightIter.More(); aDefLightIter.Next())
96 if (!myActiveLights.Contains (aDefLightIter.Value()))
98 myActiveLights.Append (aDefLightIter.Value());
104 //=============================================================================
105 //function : SetLightOff
107 //=============================================================================
108 void V3d_View::SetLightOff()
110 for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More();)
112 if (!MyViewer->IsGlobalLight (anActiveLightIter.Value()))
114 myActiveLights.Remove (anActiveLightIter);
118 anActiveLightIter.Next();
124 //=============================================================================
125 //function : IfMoreLights
127 //=============================================================================
128 Standard_Boolean V3d_View::IfMoreLights() const
130 return myActiveLights.Extent() < LightLimit();
133 //=======================================================================
134 //function : LightLimit
136 //=======================================================================
137 Standard_Integer V3d_View::LightLimit() const
139 return Viewer()->Driver()->InquireLightLimit();
142 //=======================================================================
143 //function : AddClipPlane
145 //=======================================================================
146 void V3d_View::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
148 Handle(Graphic3d_SequenceOfHClipPlane) aSeqOfPlanes = ClipPlanes();
149 if (aSeqOfPlanes.IsNull())
151 aSeqOfPlanes = new Graphic3d_SequenceOfHClipPlane();
154 aSeqOfPlanes->Append (thePlane);
155 SetClipPlanes (aSeqOfPlanes);
158 //=======================================================================
159 //function : RemoveClipPlane
161 //=======================================================================
162 void V3d_View::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
164 Handle(Graphic3d_SequenceOfHClipPlane) aSeqOfPlanes = ClipPlanes();
165 if (aSeqOfPlanes.IsNull())
170 for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt(*aSeqOfPlanes); aPlaneIt.More(); aPlaneIt.Next())
172 const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
173 if (aPlane != thePlane)
176 aSeqOfPlanes->Remove (aPlaneIt);
177 SetClipPlanes (aSeqOfPlanes);
182 //=======================================================================
183 //function : SetClipPlanes
185 //=======================================================================
186 void V3d_View::SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes)
188 myView->SetClipPlanes (thePlanes);
191 //=======================================================================
192 //function : ClipPlanes
194 //=======================================================================
195 const Handle(Graphic3d_SequenceOfHClipPlane)& V3d_View::ClipPlanes() const
197 return myView->ClipPlanes();
200 //=======================================================================
201 //function : PlaneLimit
203 //=======================================================================
204 Standard_Integer V3d_View::PlaneLimit() const
206 return Viewer()->Driver()->InquirePlaneLimit();