0024070: OpenGL capped object-level clipping planes
[occt.git] / src / V3d / V3d_View_2.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18/***********************************************************************
19
20 FONCTION :
21 ----------
22 Classe V3d_View_2.cxx :
23
24 HISTORIQUE DES MODIFICATIONS :
25 --------------------------------
26 00-09-92 : GG ; Creation.
27 24-12-97 : FMN ; Suppression de GEOMLITE
28 21-02-00 : GG ; Add Transparency() method
29 23-11-00 : GG ; Add IsActiveLight() and IsActivePlane() methods
30
31************************************************************************/
32
33#define GER61454 //GG 13-09-99 Activates model clipping planes
34// Use myView->PlaneLimit() instead Visual3d_ClipPlane::Limit()
35// Use myView->LightLimit() instead Visual3d_Light::Limit()
36
37
38
39/*----------------------------------------------------------------------*/
40/*
41 * Includes
42 */
43
44#include <V3d_View.jxx>
45#include <Visual3d_View.hxx>
46#include <Visual3d_Light.hxx>
7fd59977 47#include <V3d_Static.hxx>
48#include <V3d.hxx>
49
50/*----------------------------------------------------------------------*/
51
52void V3d_View::SetLightOn( const Handle(V3d_Light)& TheLight ) {
53
54 if( !MyActiveLights.Contains(TheLight)){
55#ifdef GER61454
6942f04a 56 V3d_BadValue_Raise_if( MyActiveLights.Extent() >= MyView->LightLimit(),
7fd59977 57 "too many lights");
58#else
6942f04a 59// V3d_BadValue_Raise_if( MyActiveLights.Extent() >= Visual3d_Light::Limit(),
7fd59977 60// "too many lights");
61#endif
62 MyActiveLights.Append(TheLight) ;
63 MyViewContext.SetLightOn(TheLight->Light());
64 MyView->SetContext(MyViewContext);
65 }
66}
67
68void V3d_View::SetLightOff( const Handle(V3d_Light)& TheLight ) {
69
70 Standard_TypeMismatch_Raise_if(MyViewer->IsGlobalLight(TheLight),"the light is global");
71
72 MyActiveLights.Remove(TheLight);
73 MyViewContext.SetLightOff(TheLight->Light()) ;
74 MyView->SetContext(MyViewContext) ;
75}
76
77Standard_Boolean V3d_View::IsActiveLight(const Handle(V3d_Light)& aLight) const {
78 if( aLight.IsNull() ) return Standard_False;
79 return MyActiveLights.Contains(aLight);
80}
81
82void V3d_View::SetLightOn( ) {
83
84 for(MyViewer->InitDefinedLights();MyViewer->MoreDefinedLights();MyViewer->NextDefinedLights()){
85 if(!MyActiveLights.Contains(MyViewer->DefinedLight())){
86 MyActiveLights.Append(MyViewer->DefinedLight()) ;
87 MyViewContext.SetLightOn(MyViewer->DefinedLight()->Light());
88 }
89 }
90 MyView->SetContext(MyViewContext) ;
91
92}
93
94void V3d_View::SetLightOff( ) {
95
96 InitActiveLights();
97 while(MoreActiveLights()) {
98 if (!MyViewer->IsGlobalLight(ActiveLight())) {
99 MyActiveLights.Remove(ActiveLight());
100 MyViewContext.SetLightOff(ActiveLight()->Light());
101 }
102 else
103 NextActiveLights();
104 }
105 MyView->SetContext(MyViewContext) ;
106
107}
108
109void V3d_View::SetTransparency(const Standard_Boolean AnActivity) {
110
111 MyTransparencyFlag = AnActivity;
112 MyView->SetTransparency(AnActivity);
113}
114
115
116Standard_Boolean V3d_View::Transparency() const {
117
118 return MyTransparencyFlag;
119}
120
7fd59977 121void V3d_View::InitActiveLights() {
122myActiveLightsIterator.Initialize(MyActiveLights);
123}
124Standard_Boolean V3d_View::MoreActiveLights () const {
125 return myActiveLightsIterator.More();
126}
127void V3d_View::NextActiveLights () {
128 myActiveLightsIterator.Next();
129}
130Handle(V3d_Light) V3d_View::ActiveLight() const {
131 return (Handle(V3d_Light)&)(myActiveLightsIterator.Value());}
132
7fd59977 133Standard_Boolean V3d_View::IfMoreLights() const {
134
135#ifdef GER61454
136 return MyActiveLights.Extent() < MyView->LightLimit();
137#else
138// return MyActiveLights.Extent() < Visual3d_Light::Limit();
139 return MyActiveLights.Extent();
140#endif
141}
4269bd1b 142
143//=======================================================================
144//function : AddClipPlane
145//purpose :
146//=======================================================================
147void V3d_View::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
148{
149 Graphic3d_SetOfHClipPlane aCurrPlanes = MyViewContext.GetClipPlanes();
150 if (!aCurrPlanes.Add (thePlane))
151 return;
152
153 MyViewContext.SetClipPlanes (aCurrPlanes);
154 MyView->SetContext (MyViewContext) ;
155}
156
157//=======================================================================
158//function : RemoveClipPlane
159//purpose :
160//=======================================================================
161void V3d_View::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
162{
163 Graphic3d_SetOfHClipPlane aCurrPlanes = MyViewContext.GetClipPlanes();
164 if (!aCurrPlanes.Remove (thePlane))
165 return;
166
167 MyViewContext.SetClipPlanes (aCurrPlanes);
168 MyView->SetContext (MyViewContext) ;
169}
170
171//=======================================================================
172//function : SetClipPlanes
173//purpose :
174//=======================================================================
175void V3d_View::SetClipPlanes (const Graphic3d_SetOfHClipPlane& thePlanes)
176{
177 MyViewContext.SetClipPlanes (thePlanes);
178 MyView->SetContext (MyViewContext) ;
179}
180
181//=======================================================================
182//function : GetClipPlanes
183//purpose :
184//=======================================================================
185const Graphic3d_SetOfHClipPlane& V3d_View::GetClipPlanes() const
186{
187 return MyViewContext.GetClipPlanes();
188}