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 /***********************************************************************
18 Classe V3d_View_2.cxx :
20 HISTORIQUE DES MODIFICATIONS :
21 --------------------------------
22 00-09-92 : GG ; Creation.
23 24-12-97 : FMN ; Suppression de GEOMLITE
24 23-11-00 : GG ; Add IsActiveLight() and IsActivePlane() methods
26 ************************************************************************/
28 #define GER61454 //GG 13-09-99 Activates model clipping planes
29 // Use myView->PlaneLimit() instead Visual3d_ClipPlane::Limit()
30 // Use myView->LightLimit() instead Visual3d_Light::Limit()
34 /*----------------------------------------------------------------------*/
39 #include <V3d_View.jxx>
40 #include <Visual3d_View.hxx>
41 #include <Visual3d_Light.hxx>
42 #include <V3d_Static.hxx>
45 /*----------------------------------------------------------------------*/
47 void V3d_View::SetLightOn( const Handle(V3d_Light)& TheLight ) {
49 if( !MyActiveLights.Contains(TheLight)){
51 V3d_BadValue_Raise_if( MyActiveLights.Extent() >= MyView->LightLimit(),
54 // V3d_BadValue_Raise_if( MyActiveLights.Extent() >= Visual3d_Light::Limit(),
55 // "too many lights");
57 MyActiveLights.Append(TheLight) ;
58 MyViewContext.SetLightOn(TheLight->Light());
59 MyView->SetContext(MyViewContext);
63 void V3d_View::SetLightOff( const Handle(V3d_Light)& TheLight ) {
65 Standard_TypeMismatch_Raise_if(MyViewer->IsGlobalLight(TheLight),"the light is global");
67 MyActiveLights.Remove(TheLight);
68 MyViewContext.SetLightOff(TheLight->Light()) ;
69 MyView->SetContext(MyViewContext) ;
72 Standard_Boolean V3d_View::IsActiveLight(const Handle(V3d_Light)& aLight) const {
73 if( aLight.IsNull() ) return Standard_False;
74 return MyActiveLights.Contains(aLight);
77 void V3d_View::SetLightOn( ) {
79 for(MyViewer->InitDefinedLights();MyViewer->MoreDefinedLights();MyViewer->NextDefinedLights()){
80 if(!MyActiveLights.Contains(MyViewer->DefinedLight())){
81 MyActiveLights.Append(MyViewer->DefinedLight()) ;
82 MyViewContext.SetLightOn(MyViewer->DefinedLight()->Light());
85 MyView->SetContext(MyViewContext) ;
89 void V3d_View::SetLightOff( ) {
92 while(MoreActiveLights()) {
93 if (!MyViewer->IsGlobalLight(ActiveLight())) {
94 MyActiveLights.Remove(ActiveLight());
95 MyViewContext.SetLightOff(ActiveLight()->Light());
100 MyView->SetContext(MyViewContext) ;
104 void V3d_View::InitActiveLights() {
105 myActiveLightsIterator.Initialize(MyActiveLights);
107 Standard_Boolean V3d_View::MoreActiveLights () const {
108 return myActiveLightsIterator.More();
110 void V3d_View::NextActiveLights () {
111 myActiveLightsIterator.Next();
113 Handle(V3d_Light) V3d_View::ActiveLight() const {
114 return (Handle(V3d_Light)&)(myActiveLightsIterator.Value());}
116 Standard_Boolean V3d_View::IfMoreLights() const {
119 return MyActiveLights.Extent() < MyView->LightLimit();
121 // return MyActiveLights.Extent() < Visual3d_Light::Limit();
122 return MyActiveLights.Extent();
126 //=======================================================================
127 //function : AddClipPlane
129 //=======================================================================
130 void V3d_View::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
132 MyViewContext.ChangeClipPlanes().Append (thePlane);
133 MyView->SetContext (MyViewContext);
136 //=======================================================================
137 //function : RemoveClipPlane
139 //=======================================================================
140 void V3d_View::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
142 Graphic3d_SequenceOfHClipPlane& aSeqOfPlanes = MyViewContext.ChangeClipPlanes();
143 Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (aSeqOfPlanes);
144 for (; aPlaneIt.More(); aPlaneIt.Next())
146 const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
147 if (aPlane != thePlane)
150 aSeqOfPlanes.Remove (aPlaneIt);
151 MyView->SetContext (MyViewContext);
156 //=======================================================================
157 //function : SetClipPlanes
159 //=======================================================================
160 void V3d_View::SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes)
162 MyViewContext.ChangeClipPlanes() = thePlanes;
163 MyView->SetContext (MyViewContext);
166 //=======================================================================
167 //function : GetClipPlanes
169 //=======================================================================
170 const Graphic3d_SequenceOfHClipPlane& V3d_View::GetClipPlanes() const
172 return MyViewContext.ClipPlanes();