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 if (myActiveLights.Extent() >= LightLimit())
58 throw V3d_BadValue("V3d_View::SetLightOn, too many lights");
59 myActiveLights.Append (theLight);
64 //=============================================================================
65 //function : SetLightOff
67 //=============================================================================
68 void V3d_View::SetLightOff (const Handle(V3d_Light)& theLight)
70 if (MyViewer->IsGlobalLight (theLight))
71 throw Standard_TypeMismatch("V3d_View::SetLightOff, the light is global");
72 myActiveLights.Remove (theLight);
76 //=============================================================================
77 //function : IsActiveLight
79 //=============================================================================
80 Standard_Boolean V3d_View::IsActiveLight (const Handle(V3d_Light)& theLight) const
82 return !theLight.IsNull()
83 && myActiveLights.Contains (theLight);
86 //=============================================================================
87 //function : SetLightOn
89 //=============================================================================
90 void V3d_View::SetLightOn()
92 for (V3d_ListOfLightIterator aDefLightIter (MyViewer->DefinedLightIterator()); aDefLightIter.More(); aDefLightIter.Next())
94 if (!myActiveLights.Contains (aDefLightIter.Value()))
96 myActiveLights.Append (aDefLightIter.Value());
102 //=============================================================================
103 //function : SetLightOff
105 //=============================================================================
106 void V3d_View::SetLightOff()
108 for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More();)
110 if (!MyViewer->IsGlobalLight (anActiveLightIter.Value()))
112 myActiveLights.Remove (anActiveLightIter);
116 anActiveLightIter.Next();
122 //=============================================================================
123 //function : IfMoreLights
125 //=============================================================================
126 Standard_Boolean V3d_View::IfMoreLights() const
128 return myActiveLights.Extent() < LightLimit();
131 //=======================================================================
132 //function : LightLimit
134 //=======================================================================
135 Standard_Integer V3d_View::LightLimit() const
137 return Viewer()->Driver()->InquireLightLimit();
140 //=======================================================================
141 //function : AddClipPlane
143 //=======================================================================
144 void V3d_View::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
146 Handle(Graphic3d_SequenceOfHClipPlane) aSeqOfPlanes = ClipPlanes();
147 if (aSeqOfPlanes.IsNull())
149 aSeqOfPlanes = new Graphic3d_SequenceOfHClipPlane();
153 for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (*aSeqOfPlanes); aPlaneIt.More(); aPlaneIt.Next())
155 const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
156 if (aPlane == thePlane)
158 // plane is already defined in view
164 aSeqOfPlanes->Append (thePlane);
165 SetClipPlanes (aSeqOfPlanes);
168 //=======================================================================
169 //function : RemoveClipPlane
171 //=======================================================================
172 void V3d_View::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
174 Handle(Graphic3d_SequenceOfHClipPlane) aSeqOfPlanes = ClipPlanes();
175 if (aSeqOfPlanes.IsNull())
180 for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt(*aSeqOfPlanes); aPlaneIt.More(); aPlaneIt.Next())
182 const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
183 if (aPlane != thePlane)
186 aSeqOfPlanes->Remove (aPlaneIt);
187 SetClipPlanes (aSeqOfPlanes);
192 //=======================================================================
193 //function : SetClipPlanes
195 //=======================================================================
196 void V3d_View::SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes)
198 myView->SetClipPlanes (thePlanes);
201 //=======================================================================
202 //function : ClipPlanes
204 //=======================================================================
205 const Handle(Graphic3d_SequenceOfHClipPlane)& V3d_View::ClipPlanes() const
207 return myView->ClipPlanes();
210 //=======================================================================
211 //function : PlaneLimit
213 //=======================================================================
214 Standard_Integer V3d_View::PlaneLimit() const
216 return Viewer()->Driver()->InquirePlaneLimit();