1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
18 /***********************************************************************
22 Classe V3d_View_2.cxx :
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
31 ************************************************************************/
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()
39 /*----------------------------------------------------------------------*/
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>
51 /*----------------------------------------------------------------------*/
53 void V3d_View::SetLightOn( const Handle(V3d_Light)& TheLight ) {
55 if( !MyActiveLights.Contains(TheLight)){
57 Viewer_BadValue_Raise_if( MyActiveLights.Extent() >= MyView->LightLimit(),
60 // Viewer_BadValue_Raise_if( MyActiveLights.Extent() >= Visual3d_Light::Limit(),
61 // "too many lights");
63 MyActiveLights.Append(TheLight) ;
64 MyViewContext.SetLightOn(TheLight->Light());
65 MyView->SetContext(MyViewContext);
69 void V3d_View::SetLightOff( const Handle(V3d_Light)& TheLight ) {
71 Standard_TypeMismatch_Raise_if(MyViewer->IsGlobalLight(TheLight),"the light is global");
73 MyActiveLights.Remove(TheLight);
74 MyViewContext.SetLightOff(TheLight->Light()) ;
75 MyView->SetContext(MyViewContext) ;
78 Standard_Boolean V3d_View::IsActiveLight(const Handle(V3d_Light)& aLight) const {
79 if( aLight.IsNull() ) return Standard_False;
80 return MyActiveLights.Contains(aLight);
83 void V3d_View::SetLightOn( ) {
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());
91 MyView->SetContext(MyViewContext) ;
95 void V3d_View::SetLightOff( ) {
98 while(MoreActiveLights()) {
99 if (!MyViewer->IsGlobalLight(ActiveLight())) {
100 MyActiveLights.Remove(ActiveLight());
101 MyViewContext.SetLightOff(ActiveLight()->Light());
106 MyView->SetContext(MyViewContext) ;
110 void V3d_View::SetTransparency(const Standard_Boolean AnActivity) {
112 MyTransparencyFlag = AnActivity;
113 MyView->SetTransparency(AnActivity);
117 Standard_Boolean V3d_View::Transparency() const {
119 return MyTransparencyFlag;
122 void V3d_View::SetPlaneOn( const Handle(V3d_Plane)& ThePlane ) {
125 if( !MyActivePlanes.Contains(ThePlane)) {
126 Viewer_BadValue_Raise_if( MyActivePlanes.Extent() >= MyView->PlaneLimit(), "too many planes");
127 MyActivePlanes.Append(ThePlane) ;
129 MyViewContext.SetClipPlaneOn(ThePlane->Plane()) ;
130 MyView->SetContext(MyViewContext);
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()) ;
137 MyView->SetContext(MyViewContext);
142 void V3d_View::SetPlaneOff( const Handle(V3d_Plane)& ThePlane ) {
144 MyActivePlanes.Remove(ThePlane);
145 MyViewContext.SetClipPlaneOff(ThePlane->Plane()) ;
146 MyView->SetContext(MyViewContext) ;
149 Standard_Boolean V3d_View::IsActivePlane(const Handle(V3d_Plane)& aPlane) const {
150 if( aPlane.IsNull() ) return Standard_False;
151 return MyActivePlanes.Contains(aPlane);
154 void V3d_View::SetPlaneOn( ) {
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());
162 MyViewContext.SetClipPlaneOn(MyViewer->DefinedPlane()->Plane());
164 MyView->SetContext(MyViewContext) ;
166 for(MyViewer->InitDefinedPlanes();MyViewer->MoreDefinedPlanes();MyViewer->NextDefinedPlanes()) {
167 if(!MyActivePlanes.Contains(MyViewer->DefinedPlane())) {
168 Viewer_BadValue_Raise_if( MyActivePlanes.Extent() >= Visual3d_ClipPlane::Limit(),
170 MyActivePlanes.Append(MyViewer->DefinedPlane());
171 MyViewContext.SetClipPlaneOn(MyViewer->DefinedPlane()->Plane());
172 MyView->SetContext(MyViewContext) ;
178 void V3d_View::SetPlaneOff( ) {
180 for(InitActivePlanes();MoreActivePlanes();NextActivePlanes()) {
181 MyViewContext.SetClipPlaneOff(ActivePlane()->Plane());}
182 MyActivePlanes.Clear();
183 MyView->SetContext(MyViewContext) ;
186 void V3d_View::InitActiveLights() {
187 myActiveLightsIterator.Initialize(MyActiveLights);
189 Standard_Boolean V3d_View::MoreActiveLights () const {
190 return myActiveLightsIterator.More();
192 void V3d_View::NextActiveLights () {
193 myActiveLightsIterator.Next();
195 Handle(V3d_Light) V3d_View::ActiveLight() const {
196 return (Handle(V3d_Light)&)(myActiveLightsIterator.Value());}
199 void V3d_View::InitActivePlanes() {
200 myActivePlanesIterator.Initialize(MyActivePlanes);
202 Standard_Boolean V3d_View::MoreActivePlanes () const {
203 return myActivePlanesIterator.More();
205 void V3d_View::NextActivePlanes () {
206 myActivePlanesIterator.Next();
209 Handle(V3d_Plane) V3d_View::ActivePlane() const {
210 return (Handle(V3d_Plane)&)(myActivePlanesIterator.Value());}
212 Standard_Boolean V3d_View::IfMorePlanes() const {
215 return MyActivePlanes.Extent() < MyView->PlaneLimit();
217 return MyActivePlanes.Extent() < Visual3d_ClipPlane::Limit();
222 Standard_Boolean V3d_View::IfMoreLights() const {
225 return MyActiveLights.Extent() < MyView->LightLimit();
227 // return MyActiveLights.Extent() < Visual3d_Light::Limit();
228 return MyActiveLights.Extent();