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 ************************************************************************/
24 // Use myView->PlaneLimit() instead Visual3d_ClipPlane::Limit()
25 // Use myView->LightLimit() instead Visual3d_Light::Limit()
26 /*----------------------------------------------------------------------*/
31 #include <Aspect_GradientBackground.hxx>
32 #include <Aspect_Grid.hxx>
33 #include <Aspect_Window.hxx>
34 #include <Bnd_Box.hxx>
37 #include <Graphic3d_Group.hxx>
38 #include <Graphic3d_Structure.hxx>
39 #include <Graphic3d_TextureEnv.hxx>
40 #include <Graphic3d_Vector.hxx>
41 #include <Quantity_Color.hxx>
42 #include <Standard_MultiplyDefined.hxx>
43 #include <Standard_TypeMismatch.hxx>
45 #include <V3d_BadValue.hxx>
46 #include <V3d_LayerMgr.hxx>
47 #include <V3d_Light.hxx>
48 #include <V3d_UnMapped.hxx>
49 #include <V3d_View.hxx>
50 #include <V3d_Viewer.hxx>
51 #include <Visual3d_Light.hxx>
52 #include <Visual3d_View.hxx>
54 /*----------------------------------------------------------------------*/
55 void V3d_View::SetLightOn( const Handle(V3d_Light)& TheLight ) {
57 if( !MyActiveLights.Contains(TheLight)){
58 V3d_BadValue_Raise_if( MyActiveLights.Extent() >= MyView->LightLimit(),
60 MyActiveLights.Append(TheLight) ;
61 MyViewContext.SetLightOn(TheLight->Light());
62 MyView->SetContext(MyViewContext);
66 void V3d_View::SetLightOff( const Handle(V3d_Light)& TheLight ) {
68 Standard_TypeMismatch_Raise_if(MyViewer->IsGlobalLight(TheLight),"the light is global");
70 MyActiveLights.Remove(TheLight);
71 MyViewContext.SetLightOff(TheLight->Light()) ;
72 MyView->SetContext(MyViewContext) ;
75 Standard_Boolean V3d_View::IsActiveLight(const Handle(V3d_Light)& aLight) const {
76 if( aLight.IsNull() ) return Standard_False;
77 return MyActiveLights.Contains(aLight);
80 void V3d_View::SetLightOn( ) {
82 for(MyViewer->InitDefinedLights();MyViewer->MoreDefinedLights();MyViewer->NextDefinedLights()){
83 if(!MyActiveLights.Contains(MyViewer->DefinedLight())){
84 MyActiveLights.Append(MyViewer->DefinedLight()) ;
85 MyViewContext.SetLightOn(MyViewer->DefinedLight()->Light());
88 MyView->SetContext(MyViewContext) ;
92 void V3d_View::SetLightOff( ) {
95 while(MoreActiveLights()) {
96 if (!MyViewer->IsGlobalLight(ActiveLight())) {
97 MyActiveLights.Remove(ActiveLight());
98 MyViewContext.SetLightOff(ActiveLight()->Light());
103 MyView->SetContext(MyViewContext) ;
107 void V3d_View::InitActiveLights() {
108 myActiveLightsIterator.Initialize(MyActiveLights);
110 Standard_Boolean V3d_View::MoreActiveLights () const {
111 return myActiveLightsIterator.More();
113 void V3d_View::NextActiveLights () {
114 myActiveLightsIterator.Next();
116 Handle(V3d_Light) V3d_View::ActiveLight() const {
117 return (Handle(V3d_Light)&)(myActiveLightsIterator.Value());}
119 Standard_Boolean V3d_View::IfMoreLights() const {
121 return MyActiveLights.Extent() < MyView->LightLimit();
124 //=======================================================================
125 //function : AddClipPlane
127 //=======================================================================
128 void V3d_View::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
130 MyViewContext.ChangeClipPlanes().Append (thePlane);
131 MyView->SetContext (MyViewContext);
134 //=======================================================================
135 //function : RemoveClipPlane
137 //=======================================================================
138 void V3d_View::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
140 Graphic3d_SequenceOfHClipPlane& aSeqOfPlanes = MyViewContext.ChangeClipPlanes();
141 Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (aSeqOfPlanes);
142 for (; aPlaneIt.More(); aPlaneIt.Next())
144 const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
145 if (aPlane != thePlane)
148 aSeqOfPlanes.Remove (aPlaneIt);
149 MyView->SetContext (MyViewContext);
154 //=======================================================================
155 //function : SetClipPlanes
157 //=======================================================================
158 void V3d_View::SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes)
160 MyViewContext.ChangeClipPlanes() = thePlanes;
161 MyView->SetContext (MyViewContext);
164 //=======================================================================
165 //function : GetClipPlanes
167 //=======================================================================
168 const Graphic3d_SequenceOfHClipPlane& V3d_View::GetClipPlanes() const
170 return MyViewContext.ClipPlanes();