0024005: Intersecting a slightly off angle plane with a cylinder takes 7+ seconds
[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>
47#include <Visual3d_ClipPlane.hxx>
48#include <V3d_Static.hxx>
49#include <V3d.hxx>
50
51/*----------------------------------------------------------------------*/
52
53void V3d_View::SetLightOn( const Handle(V3d_Light)& TheLight ) {
54
55 if( !MyActiveLights.Contains(TheLight)){
56#ifdef GER61454
6942f04a 57 V3d_BadValue_Raise_if( MyActiveLights.Extent() >= MyView->LightLimit(),
7fd59977 58 "too many lights");
59#else
6942f04a 60// V3d_BadValue_Raise_if( MyActiveLights.Extent() >= Visual3d_Light::Limit(),
7fd59977 61// "too many lights");
62#endif
63 MyActiveLights.Append(TheLight) ;
64 MyViewContext.SetLightOn(TheLight->Light());
65 MyView->SetContext(MyViewContext);
66 }
67}
68
69void 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
78Standard_Boolean V3d_View::IsActiveLight(const Handle(V3d_Light)& aLight) const {
79 if( aLight.IsNull() ) return Standard_False;
80 return MyActiveLights.Contains(aLight);
81}
82
83void 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
95void 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
110void V3d_View::SetTransparency(const Standard_Boolean AnActivity) {
111
112 MyTransparencyFlag = AnActivity;
113 MyView->SetTransparency(AnActivity);
114}
115
116
117Standard_Boolean V3d_View::Transparency() const {
118
119 return MyTransparencyFlag;
120}
121
122void V3d_View::SetPlaneOn( const Handle(V3d_Plane)& ThePlane ) {
123
124#ifdef GER61454
125 if( !MyActivePlanes.Contains(ThePlane)) {
6942f04a 126 V3d_BadValue_Raise_if( MyActivePlanes.Extent() >= MyView->PlaneLimit(), "too many planes");
7fd59977 127 MyActivePlanes.Append(ThePlane) ;
128 }
129 MyViewContext.SetClipPlaneOn(ThePlane->Plane()) ;
130 MyView->SetContext(MyViewContext);
131#else //GER61454
132 if( !MyActivePlanes.Contains(ThePlane)) {
6942f04a 133 V3d_BadValue_Raise_if( MyActivePlanes.Extent() >= Visual3d_ClipPlane::Limit(), "too many planes");
7fd59977 134 MyActivePlanes.Append(ThePlane) ;
135 MyViewContext.SetClipPlaneOn(ThePlane->Plane()) ;
136
137 MyView->SetContext(MyViewContext);
138 }
139#endif //GER61454
140}
141
142void V3d_View::SetPlaneOff( const Handle(V3d_Plane)& ThePlane ) {
143
144 MyActivePlanes.Remove(ThePlane);
145 MyViewContext.SetClipPlaneOff(ThePlane->Plane()) ;
146 MyView->SetContext(MyViewContext) ;
147}
148
149Standard_Boolean V3d_View::IsActivePlane(const Handle(V3d_Plane)& aPlane) const {
150 if( aPlane.IsNull() ) return Standard_False;
151 return MyActivePlanes.Contains(aPlane);
152}
153
154void V3d_View::SetPlaneOn( ) {
155
156#ifdef GER61454
157 for(MyViewer->InitDefinedPlanes();MyViewer->MoreDefinedPlanes();MyViewer->NextDefinedPlanes()) {
158 if(!MyActivePlanes.Contains(MyViewer->DefinedPlane())) {
6942f04a 159 V3d_BadValue_Raise_if( MyActivePlanes.Extent() >= MyView->PlaneLimit(), "too many planes");
7fd59977 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())) {
6942f04a 168 V3d_BadValue_Raise_if( MyActivePlanes.Extent() >= Visual3d_ClipPlane::Limit(),
7fd59977 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
178void V3d_View::SetPlaneOff( ) {
179
180 for(InitActivePlanes();MoreActivePlanes();NextActivePlanes()) {
181 MyViewContext.SetClipPlaneOff(ActivePlane()->Plane());}
182 MyActivePlanes.Clear();
183 MyView->SetContext(MyViewContext) ;
184}
185
186void V3d_View::InitActiveLights() {
187myActiveLightsIterator.Initialize(MyActiveLights);
188}
189Standard_Boolean V3d_View::MoreActiveLights () const {
190 return myActiveLightsIterator.More();
191}
192void V3d_View::NextActiveLights () {
193 myActiveLightsIterator.Next();
194}
195Handle(V3d_Light) V3d_View::ActiveLight() const {
196 return (Handle(V3d_Light)&)(myActiveLightsIterator.Value());}
197
198
199void V3d_View::InitActivePlanes() {
200myActivePlanesIterator.Initialize(MyActivePlanes);
201}
202Standard_Boolean V3d_View::MoreActivePlanes () const {
203 return myActivePlanesIterator.More();
204}
205void V3d_View::NextActivePlanes () {
206 myActivePlanesIterator.Next();
207}
208
209Handle(V3d_Plane) V3d_View::ActivePlane() const {
210 return (Handle(V3d_Plane)&)(myActivePlanesIterator.Value());}
211
212Standard_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
222Standard_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}