62218b6cd7baa827b85c3e4cdfeb6bf90a8cdccb
[occt.git] / src / V3d / V3d_View_2.cxx
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
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>
47 #include <Visual3d_ClipPlane.hxx>
48 #include <V3d_Static.hxx>
49 #include <V3d.hxx>
50
51 /*----------------------------------------------------------------------*/
52
53 void V3d_View::SetLightOn( const Handle(V3d_Light)& TheLight ) {
54
55   if( !MyActiveLights.Contains(TheLight)){
56 #ifdef GER61454
57     Viewer_BadValue_Raise_if( MyActiveLights.Extent() >= MyView->LightLimit(),
58                           "too many lights");
59 #else
60 //    Viewer_BadValue_Raise_if( MyActiveLights.Extent() >= Visual3d_Light::Limit(),
61 //                        "too many lights");
62 #endif
63     MyActiveLights.Append(TheLight) ;
64     MyViewContext.SetLightOn(TheLight->Light());
65     MyView->SetContext(MyViewContext);
66   }
67 }
68
69 void V3d_View::SetLightOff( const Handle(V3d_Light)& TheLight ) {
70
71   Standard_TypeMismatch_Raise_if(MyViewer->IsGlobalLight(TheLight),"the light is global");
72   
73   MyActiveLights.Remove(TheLight);
74   MyViewContext.SetLightOff(TheLight->Light()) ;
75   MyView->SetContext(MyViewContext) ;
76 }
77
78 Standard_Boolean V3d_View::IsActiveLight(const Handle(V3d_Light)& aLight) const {
79   if( aLight.IsNull() ) return Standard_False;
80   return  MyActiveLights.Contains(aLight);
81 }
82
83 void V3d_View::SetLightOn( ) {
84
85   for(MyViewer->InitDefinedLights();MyViewer->MoreDefinedLights();MyViewer->NextDefinedLights()){
86     if(!MyActiveLights.Contains(MyViewer->DefinedLight())){
87       MyActiveLights.Append(MyViewer->DefinedLight()) ;
88       MyViewContext.SetLightOn(MyViewer->DefinedLight()->Light());
89     }
90   }
91   MyView->SetContext(MyViewContext) ;
92   
93 }
94
95 void V3d_View::SetLightOff( ) {
96   
97   InitActiveLights();
98   while(MoreActiveLights()) {
99     if (!MyViewer->IsGlobalLight(ActiveLight())) {
100       MyActiveLights.Remove(ActiveLight());
101       MyViewContext.SetLightOff(ActiveLight()->Light());
102     }
103     else
104       NextActiveLights();
105   }
106   MyView->SetContext(MyViewContext) ;
107
108 }
109
110 void V3d_View::SetTransparency(const Standard_Boolean AnActivity) {
111
112   MyTransparencyFlag = AnActivity;
113   MyView->SetTransparency(AnActivity);
114 }
115
116
117 Standard_Boolean V3d_View::Transparency() const {
118
119   return MyTransparencyFlag;
120 }
121
122 void V3d_View::SetPlaneOn( const Handle(V3d_Plane)& ThePlane ) {
123
124 #ifdef GER61454
125   if( !MyActivePlanes.Contains(ThePlane)) {
126     Viewer_BadValue_Raise_if( MyActivePlanes.Extent() >= MyView->PlaneLimit(), "too many planes");
127     MyActivePlanes.Append(ThePlane) ;
128   }
129   MyViewContext.SetClipPlaneOn(ThePlane->Plane()) ;
130   MyView->SetContext(MyViewContext);
131 #else   //GER61454
132   if( !MyActivePlanes.Contains(ThePlane)) {
133     Viewer_BadValue_Raise_if( MyActivePlanes.Extent() >= Visual3d_ClipPlane::Limit(), "too many planes");
134     MyActivePlanes.Append(ThePlane) ;
135     MyViewContext.SetClipPlaneOn(ThePlane->Plane()) ;
136     
137     MyView->SetContext(MyViewContext);
138   }
139 #endif  //GER61454
140 }
141
142 void V3d_View::SetPlaneOff( const Handle(V3d_Plane)& ThePlane ) {
143
144   MyActivePlanes.Remove(ThePlane);
145   MyViewContext.SetClipPlaneOff(ThePlane->Plane()) ;
146   MyView->SetContext(MyViewContext) ;
147 }
148
149 Standard_Boolean V3d_View::IsActivePlane(const Handle(V3d_Plane)& aPlane) const {
150   if( aPlane.IsNull() ) return Standard_False;
151   return  MyActivePlanes.Contains(aPlane);
152 }
153
154 void V3d_View::SetPlaneOn( ) {
155
156 #ifdef GER61454
157   for(MyViewer->InitDefinedPlanes();MyViewer->MoreDefinedPlanes();MyViewer->NextDefinedPlanes()) {
158     if(!MyActivePlanes.Contains(MyViewer->DefinedPlane())) {
159       Viewer_BadValue_Raise_if( MyActivePlanes.Extent() >= MyView->PlaneLimit(), "too many planes");
160       MyActivePlanes.Append(MyViewer->DefinedPlane());
161     }
162     MyViewContext.SetClipPlaneOn(MyViewer->DefinedPlane()->Plane());
163   }
164   MyView->SetContext(MyViewContext) ;
165 #else   //GER61454
166   for(MyViewer->InitDefinedPlanes();MyViewer->MoreDefinedPlanes();MyViewer->NextDefinedPlanes()) {
167     if(!MyActivePlanes.Contains(MyViewer->DefinedPlane())) {
168       Viewer_BadValue_Raise_if( MyActivePlanes.Extent() >=  Visual3d_ClipPlane::Limit(),
169                             "too many planes");
170       MyActivePlanes.Append(MyViewer->DefinedPlane());
171       MyViewContext.SetClipPlaneOn(MyViewer->DefinedPlane()->Plane());
172       MyView->SetContext(MyViewContext) ;
173     }
174   }
175 #endif  //GER61454
176 }
177
178 void V3d_View::SetPlaneOff( ) {
179
180   for(InitActivePlanes();MoreActivePlanes();NextActivePlanes()) {
181     MyViewContext.SetClipPlaneOff(ActivePlane()->Plane());}
182   MyActivePlanes.Clear();
183   MyView->SetContext(MyViewContext) ;
184 }
185
186 void V3d_View::InitActiveLights() {
187 myActiveLightsIterator.Initialize(MyActiveLights);
188 }
189 Standard_Boolean V3d_View::MoreActiveLights () const {
190   return myActiveLightsIterator.More();
191 }
192 void V3d_View::NextActiveLights () {
193   myActiveLightsIterator.Next();
194 }
195 Handle(V3d_Light) V3d_View::ActiveLight() const {
196   return (Handle(V3d_Light)&)(myActiveLightsIterator.Value());}
197
198
199 void V3d_View::InitActivePlanes() {
200 myActivePlanesIterator.Initialize(MyActivePlanes);
201 }
202 Standard_Boolean V3d_View::MoreActivePlanes () const {
203   return myActivePlanesIterator.More();
204 }
205 void V3d_View::NextActivePlanes () {
206   myActivePlanesIterator.Next();
207 }
208
209 Handle(V3d_Plane) V3d_View::ActivePlane() const {
210   return (Handle(V3d_Plane)&)(myActivePlanesIterator.Value());}
211
212 Standard_Boolean V3d_View::IfMorePlanes() const {
213
214 #ifdef GER61454
215         return MyActivePlanes.Extent() < MyView->PlaneLimit();
216 #else
217         return MyActivePlanes.Extent() < Visual3d_ClipPlane::Limit();
218 #endif
219
220 }
221
222 Standard_Boolean V3d_View::IfMoreLights() const {
223
224 #ifdef GER61454
225         return MyActiveLights.Extent() < MyView->LightLimit();
226 #else
227 //      return MyActiveLights.Extent() < Visual3d_Light::Limit();
228         return MyActiveLights.Extent();
229 #endif
230 }