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 <Quantity_Color.hxx>
39 #include <Standard_MultiplyDefined.hxx>
40 #include <Standard_TypeMismatch.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>
48 //=============================================================================
49 //function : SetLightOn
51 //=============================================================================
52 void V3d_View::SetLightOn (const Handle(V3d_Light)& theLight)
54 if (!myActiveLights.Contains (theLight))
56 myActiveLights.Append (theLight);
61 //=============================================================================
62 //function : SetLightOff
64 //=============================================================================
65 void V3d_View::SetLightOff (const Handle(V3d_Light)& theLight)
67 if (MyViewer->IsGlobalLight (theLight))
68 throw Standard_TypeMismatch("V3d_View::SetLightOff, the light is global");
69 myActiveLights.Remove (theLight);
73 //=============================================================================
74 //function : IsActiveLight
76 //=============================================================================
77 Standard_Boolean V3d_View::IsActiveLight (const Handle(V3d_Light)& theLight) const
79 return !theLight.IsNull()
80 && myActiveLights.Contains (theLight);
83 //=============================================================================
84 //function : SetLightOn
86 //=============================================================================
87 void V3d_View::SetLightOn()
89 for (V3d_ListOfLightIterator aDefLightIter (MyViewer->DefinedLightIterator()); aDefLightIter.More(); aDefLightIter.Next())
91 if (!myActiveLights.Contains (aDefLightIter.Value()))
93 myActiveLights.Append (aDefLightIter.Value());
99 //=============================================================================
100 //function : SetLightOff
102 //=============================================================================
103 void V3d_View::SetLightOff()
105 for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More();)
107 if (!MyViewer->IsGlobalLight (anActiveLightIter.Value()))
109 myActiveLights.Remove (anActiveLightIter);
113 anActiveLightIter.Next();
119 //=============================================================================
120 //function : IfMoreLights
122 //=============================================================================
123 Standard_Boolean V3d_View::IfMoreLights() const
125 return myActiveLights.Extent() < LightLimit();
128 //=======================================================================
129 //function : LightLimit
131 //=======================================================================
132 Standard_Integer V3d_View::LightLimit() const
134 return Viewer()->Driver()->InquireLightLimit();
137 //=======================================================================
138 //function : AddClipPlane
140 //=======================================================================
141 void V3d_View::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
143 Handle(Graphic3d_SequenceOfHClipPlane) aSeqOfPlanes = ClipPlanes();
144 if (aSeqOfPlanes.IsNull())
146 aSeqOfPlanes = new Graphic3d_SequenceOfHClipPlane();
150 for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (*aSeqOfPlanes); aPlaneIt.More(); aPlaneIt.Next())
152 const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
153 if (aPlane == thePlane)
155 // plane is already defined in view
161 aSeqOfPlanes->Append (thePlane);
162 SetClipPlanes (aSeqOfPlanes);
165 //=======================================================================
166 //function : RemoveClipPlane
168 //=======================================================================
169 void V3d_View::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
171 Handle(Graphic3d_SequenceOfHClipPlane) aSeqOfPlanes = ClipPlanes();
172 if (aSeqOfPlanes.IsNull())
177 for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt(*aSeqOfPlanes); aPlaneIt.More(); aPlaneIt.Next())
179 const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
180 if (aPlane != thePlane)
183 aSeqOfPlanes->Remove (aPlaneIt);
184 SetClipPlanes (aSeqOfPlanes);
189 //=======================================================================
190 //function : SetClipPlanes
192 //=======================================================================
193 void V3d_View::SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes)
195 myView->SetClipPlanes (thePlanes);
198 //=======================================================================
199 //function : ClipPlanes
201 //=======================================================================
202 const Handle(Graphic3d_SequenceOfHClipPlane)& V3d_View::ClipPlanes() const
204 return myView->ClipPlanes();
207 //=======================================================================
208 //function : PlaneLimit
210 //=======================================================================
211 Standard_Integer V3d_View::PlaneLimit() const
213 return Viewer()->Driver()->InquirePlaneLimit();