0025785: Visualization - introduce AIS_ColorScale presentation for Color Scale
[occt.git] / src / V3d / V3d_View_2.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 /***********************************************************************
15      FONCTION :
16      ----------
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 /*----------------------------------------------------------------------*/
27 /*
28  * Includes
29  */
30
31 #include <Aspect_GradientBackground.hxx>
32 #include <Aspect_Grid.hxx>
33 #include <Aspect_Window.hxx>
34 #include <Bnd_Box.hxx>
35 #include <gp_Ax3.hxx>
36 #include <gp_Dir.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>
44 #include <V3d.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>
53
54 /*----------------------------------------------------------------------*/
55 void V3d_View::SetLightOn( const Handle(V3d_Light)& TheLight ) {
56
57   if( !MyActiveLights.Contains(TheLight)){
58     V3d_BadValue_Raise_if( MyActiveLights.Extent() >= MyView->LightLimit(),
59                           "too many lights");
60     MyActiveLights.Append(TheLight) ;
61     MyViewContext.SetLightOn(TheLight->Light());
62     MyView->SetContext(MyViewContext);
63   }
64 }
65
66 void V3d_View::SetLightOff( const Handle(V3d_Light)& TheLight ) {
67
68   Standard_TypeMismatch_Raise_if(MyViewer->IsGlobalLight(TheLight),"the light is global");
69   
70   MyActiveLights.Remove(TheLight);
71   MyViewContext.SetLightOff(TheLight->Light()) ;
72   MyView->SetContext(MyViewContext) ;
73 }
74
75 Standard_Boolean V3d_View::IsActiveLight(const Handle(V3d_Light)& aLight) const {
76   if( aLight.IsNull() ) return Standard_False;
77   return  MyActiveLights.Contains(aLight);
78 }
79
80 void V3d_View::SetLightOn( ) {
81
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());
86     }
87   }
88   MyView->SetContext(MyViewContext) ;
89   
90 }
91
92 void V3d_View::SetLightOff( ) {
93   
94   InitActiveLights();
95   while(MoreActiveLights()) {
96     if (!MyViewer->IsGlobalLight(ActiveLight())) {
97       MyActiveLights.Remove(ActiveLight());
98       MyViewContext.SetLightOff(ActiveLight()->Light());
99     }
100     else
101       NextActiveLights();
102   }
103   MyView->SetContext(MyViewContext) ;
104
105 }
106
107 void V3d_View::InitActiveLights() {
108 myActiveLightsIterator.Initialize(MyActiveLights);
109 }
110 Standard_Boolean V3d_View::MoreActiveLights () const {
111   return myActiveLightsIterator.More();
112 }
113 void V3d_View::NextActiveLights () {
114   myActiveLightsIterator.Next();
115 }
116 Handle(V3d_Light) V3d_View::ActiveLight() const {
117   return (Handle(V3d_Light)&)(myActiveLightsIterator.Value());}
118
119 Standard_Boolean V3d_View::IfMoreLights() const {
120
121         return MyActiveLights.Extent() < MyView->LightLimit();
122 }
123
124 //=======================================================================
125 //function : AddClipPlane
126 //purpose  :
127 //=======================================================================
128 void V3d_View::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
129 {
130   MyViewContext.ChangeClipPlanes().Append (thePlane);
131   MyView->SetContext (MyViewContext);
132 }
133
134 //=======================================================================
135 //function : RemoveClipPlane
136 //purpose  :
137 //=======================================================================
138 void V3d_View::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
139 {
140   Graphic3d_SequenceOfHClipPlane& aSeqOfPlanes = MyViewContext.ChangeClipPlanes();
141   Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (aSeqOfPlanes);
142   for (; aPlaneIt.More(); aPlaneIt.Next())
143   {
144     const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
145     if (aPlane != thePlane)
146       continue;
147
148     aSeqOfPlanes.Remove (aPlaneIt);
149     MyView->SetContext (MyViewContext);
150     return;
151   }
152 }
153
154 //=======================================================================
155 //function : SetClipPlanes
156 //purpose  :
157 //=======================================================================
158 void V3d_View::SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes)
159 {
160   MyViewContext.ChangeClipPlanes() = thePlanes;
161   MyView->SetContext (MyViewContext);
162 }
163
164 //=======================================================================
165 //function : GetClipPlanes
166 //purpose  :
167 //=======================================================================
168 const Graphic3d_SequenceOfHClipPlane& V3d_View::GetClipPlanes() const
169 {
170   return MyViewContext.ClipPlanes();
171 }