0025511: Visualization - drop redundant viewer option V3d_View::Transparency()
[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  
16      FONCTION :
17      ----------
18         Classe V3d_View_2.cxx :
19  
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
25
26 ************************************************************************/
27
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()
31
32
33
34 /*----------------------------------------------------------------------*/
35 /*
36  * Includes
37  */
38
39 #include <V3d_View.jxx>
40 #include <Visual3d_View.hxx>
41 #include <Visual3d_Light.hxx>
42 #include <V3d_Static.hxx>
43 #include <V3d.hxx>
44
45 /*----------------------------------------------------------------------*/
46
47 void V3d_View::SetLightOn( const Handle(V3d_Light)& TheLight ) {
48
49   if( !MyActiveLights.Contains(TheLight)){
50 #ifdef GER61454
51     V3d_BadValue_Raise_if( MyActiveLights.Extent() >= MyView->LightLimit(),
52                           "too many lights");
53 #else
54 //    V3d_BadValue_Raise_if( MyActiveLights.Extent() >= Visual3d_Light::Limit(),
55 //                        "too many lights");
56 #endif
57     MyActiveLights.Append(TheLight) ;
58     MyViewContext.SetLightOn(TheLight->Light());
59     MyView->SetContext(MyViewContext);
60   }
61 }
62
63 void V3d_View::SetLightOff( const Handle(V3d_Light)& TheLight ) {
64
65   Standard_TypeMismatch_Raise_if(MyViewer->IsGlobalLight(TheLight),"the light is global");
66   
67   MyActiveLights.Remove(TheLight);
68   MyViewContext.SetLightOff(TheLight->Light()) ;
69   MyView->SetContext(MyViewContext) ;
70 }
71
72 Standard_Boolean V3d_View::IsActiveLight(const Handle(V3d_Light)& aLight) const {
73   if( aLight.IsNull() ) return Standard_False;
74   return  MyActiveLights.Contains(aLight);
75 }
76
77 void V3d_View::SetLightOn( ) {
78
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());
83     }
84   }
85   MyView->SetContext(MyViewContext) ;
86   
87 }
88
89 void V3d_View::SetLightOff( ) {
90   
91   InitActiveLights();
92   while(MoreActiveLights()) {
93     if (!MyViewer->IsGlobalLight(ActiveLight())) {
94       MyActiveLights.Remove(ActiveLight());
95       MyViewContext.SetLightOff(ActiveLight()->Light());
96     }
97     else
98       NextActiveLights();
99   }
100   MyView->SetContext(MyViewContext) ;
101
102 }
103
104 void V3d_View::InitActiveLights() {
105 myActiveLightsIterator.Initialize(MyActiveLights);
106 }
107 Standard_Boolean V3d_View::MoreActiveLights () const {
108   return myActiveLightsIterator.More();
109 }
110 void V3d_View::NextActiveLights () {
111   myActiveLightsIterator.Next();
112 }
113 Handle(V3d_Light) V3d_View::ActiveLight() const {
114   return (Handle(V3d_Light)&)(myActiveLightsIterator.Value());}
115
116 Standard_Boolean V3d_View::IfMoreLights() const {
117
118 #ifdef GER61454
119         return MyActiveLights.Extent() < MyView->LightLimit();
120 #else
121 //      return MyActiveLights.Extent() < Visual3d_Light::Limit();
122         return MyActiveLights.Extent();
123 #endif
124 }
125
126 //=======================================================================
127 //function : AddClipPlane
128 //purpose  :
129 //=======================================================================
130 void V3d_View::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
131 {
132   MyViewContext.ChangeClipPlanes().Append (thePlane);
133   MyView->SetContext (MyViewContext);
134 }
135
136 //=======================================================================
137 //function : RemoveClipPlane
138 //purpose  :
139 //=======================================================================
140 void V3d_View::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
141 {
142   Graphic3d_SequenceOfHClipPlane& aSeqOfPlanes = MyViewContext.ChangeClipPlanes();
143   Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (aSeqOfPlanes);
144   for (; aPlaneIt.More(); aPlaneIt.Next())
145   {
146     const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
147     if (aPlane != thePlane)
148       continue;
149
150     aSeqOfPlanes.Remove (aPlaneIt);
151     MyView->SetContext (MyViewContext);
152     return;
153   }
154 }
155
156 //=======================================================================
157 //function : SetClipPlanes
158 //purpose  :
159 //=======================================================================
160 void V3d_View::SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes)
161 {
162   MyViewContext.ChangeClipPlanes() = thePlanes;
163   MyView->SetContext (MyViewContext);
164 }
165
166 //=======================================================================
167 //function : GetClipPlanes
168 //purpose  :
169 //=======================================================================
170 const Graphic3d_SequenceOfHClipPlane& V3d_View::GetClipPlanes() const
171 {
172   return MyViewContext.ClipPlanes();
173 }