0024321: Use List collection instead of NCollection_Set for collection of Handle...
[occt.git] / src / Visual3d / Visual3d_ContextView.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 //
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
8 //
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 //
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
18
19 /***********************************************************************
20
21      FUNCTION :
22      ----------
23         Class Visual3d_ContextView.cxx :
24
25         Declaration of variables specific to view contexts.
26
27         A view context is defined by :
28                 - the activity of aliasing
29                 - the activity of depth-cueing
30                 - the activity of Z clipping
31                 - the activity of defined light sources
32                 - the required type of visualization
33                 - the model of shading if required
34
35
36 ************************************************************************/
37
38 #define BUC60572        //GG 03-08-99 Move Zcueing and Zclipping front & back planes
39 //                  coherence checking in Visual3d_View::SetContext()
40
41
42 /*----------------------------------------------------------------------*/
43 /*
44  * Includes
45  */
46
47 #include <Visual3d_ContextView.ixx>
48
49 /*----------------------------------------------------------------------*/
50
51 Visual3d_ContextView::Visual3d_ContextView ():
52 AliasingIsActive (Standard_False),
53 ZcueingIsActive (Standard_False),
54 FrontZclippingIsActive (Standard_False),
55 BackZclippingIsActive (Standard_False),
56 MyZclippingFrontPlane (Standard_ShortReal (1.0)),
57 MyZclippingBackPlane (Standard_ShortReal (0.0)),
58 MyDepthCueingFrontPlane (Standard_ShortReal (1.0)),
59 MyDepthCueingBackPlane (Standard_ShortReal (0.0)),
60 MyModel (Visual3d_TOM_NONE),
61 MyVisual (Visual3d_TOV_WIREFRAME),
62 MyLights (),
63 MyTextureEnv(),
64 MySurfaceDetail(Visual3d_TOD_NONE),
65 myClipPlanes()
66 {
67 }
68
69 /*----------------------------------------------------------------------*/
70
71 void Visual3d_ContextView::SetAliasingOn () {
72
73         AliasingIsActive        = Standard_True;
74
75 }
76
77 void Visual3d_ContextView::SetAliasingOff () {
78
79         AliasingIsActive        = Standard_False;
80
81 }
82
83 Standard_Boolean Visual3d_ContextView::AliasingIsOn () const {
84
85         return (AliasingIsActive);
86
87 }
88
89 void Visual3d_ContextView::SetZClippingOn () {
90
91         BackZclippingIsActive   = Standard_True;
92         FrontZclippingIsActive  = Standard_True;
93
94 }
95
96 void Visual3d_ContextView::SetZClippingOff () {
97
98         BackZclippingIsActive   = Standard_False;
99         FrontZclippingIsActive  = Standard_False;
100
101 }
102
103 Standard_Boolean Visual3d_ContextView::BackZClippingIsOn () const {
104
105         return (BackZclippingIsActive);
106
107 }
108
109 void Visual3d_ContextView::SetBackZClippingOn () {
110
111         BackZclippingIsActive   = Standard_True;
112
113 }
114
115 void Visual3d_ContextView::SetBackZClippingOff () {
116
117         BackZclippingIsActive   = Standard_False;
118
119 }
120
121 Standard_Boolean Visual3d_ContextView::FrontZClippingIsOn () const {
122
123         return (FrontZclippingIsActive);
124
125 }
126
127 void Visual3d_ContextView::SetFrontZClippingOn () {
128
129         FrontZclippingIsActive  = Standard_True;
130
131 }
132
133 void Visual3d_ContextView::SetFrontZClippingOff () {
134
135         FrontZclippingIsActive  = Standard_False;
136
137 }
138
139 void Visual3d_ContextView::SetZClippingFrontPlane (const Standard_Real AFront) {
140
141 #ifndef BUC60572
142         if ( (FrontZclippingIsActive) && (BackZclippingIsActive) &&
143                                         (MyZclippingBackPlane >= AFront) )
144                 Visual3d_ZClippingDefinitionError::Raise
145                         ("Bad value for ZClippingFrontPlane");
146 #endif
147
148         MyZclippingFrontPlane   = Standard_ShortReal (AFront);
149
150 }
151
152 Standard_Real Visual3d_ContextView::ZClippingFrontPlane () const {
153
154         return (Standard_Real (MyZclippingFrontPlane));
155
156 }
157
158 void Visual3d_ContextView::SetDepthCueingFrontPlane (const Standard_Real AFront) {
159
160 #ifndef BUC60572
161         if ( (ZcueingIsActive) && (MyDepthCueingBackPlane >= AFront) )
162                 Visual3d_DepthCueingDefinitionError::Raise
163                         ("Bad value for DepthCueingFrontPlane");
164 #endif
165
166         MyDepthCueingFrontPlane = Standard_ShortReal (AFront);
167
168 }
169
170 Standard_Real Visual3d_ContextView::DepthCueingFrontPlane () const {
171
172         return (Standard_Real (MyDepthCueingFrontPlane));
173
174 }
175
176 void Visual3d_ContextView::SetZClippingBackPlane (const Standard_Real ABack) {
177
178 #ifndef BUC60572
179         if ( (FrontZclippingIsActive) && (FrontZclippingIsActive) &&
180                                         (MyZclippingFrontPlane <= ABack) )
181                 Visual3d_ZClippingDefinitionError::Raise
182                         ("Bad value for ZClippingBackPlane");
183 #endif
184
185         MyZclippingBackPlane    = Standard_ShortReal (ABack);
186
187 }
188
189 Standard_Real Visual3d_ContextView::ZClippingBackPlane () const {
190
191         return (Standard_Real (MyZclippingBackPlane));
192
193 }
194
195 void Visual3d_ContextView::SetDepthCueingBackPlane (const Standard_Real ABack) {
196
197 #ifndef BUC60572
198         if ( (ZcueingIsActive) && (MyDepthCueingFrontPlane <= ABack) )
199                 Visual3d_DepthCueingDefinitionError::Raise
200                         ("Bad value for DepthCueingBackPlane");
201 #endif
202
203         MyDepthCueingBackPlane  = Standard_ShortReal (ABack);
204
205 }
206
207 Standard_Real Visual3d_ContextView::DepthCueingBackPlane () const {
208
209         return (Standard_Real (MyDepthCueingBackPlane));
210
211 }
212
213 void Visual3d_ContextView::SetDepthCueingOn () {
214
215         ZcueingIsActive = Standard_True;
216
217 }
218
219 void Visual3d_ContextView::SetDepthCueingOff () {
220
221         ZcueingIsActive = Standard_False;
222
223 }
224
225 Standard_Boolean Visual3d_ContextView::DepthCueingIsOn () const {
226
227         return (ZcueingIsActive);
228
229 }
230
231 void Visual3d_ContextView::SetModel (const Visual3d_TypeOfModel AModel) {
232
233         MyModel = AModel;
234
235 }
236
237 Visual3d_TypeOfModel Visual3d_ContextView::Model () const {
238
239         return (MyModel);
240
241 }
242
243 void Visual3d_ContextView::SetVisualization (const Visual3d_TypeOfVisualization AVisual) {
244
245         MyVisual        = AVisual;
246
247 }
248
249 Visual3d_TypeOfVisualization Visual3d_ContextView::Visualization () const {
250
251         return (MyVisual);
252
253 }
254
255 void Visual3d_ContextView::SetLightOn (const Handle(Visual3d_Light)& ALight) {
256
257 Standard_Integer LengthL        = MyLights.Length ();
258 Standard_Integer indexL = 0;
259
260         // Find light <ALight> in 
261         // the sequence of already active lights
262         for (Standard_Integer i=1; i<=LengthL && indexL==0; i++)
263                 if ((void *) (MyLights.Value (i)) ==
264                     (void *) (ALight.operator->())) indexL = i;
265
266         // This is the activation of a new light
267         if (indexL == 0)
268                 MyLights.Append ((void *) ALight.operator->());
269
270 }
271
272 void Visual3d_ContextView::SetLightOff (const Handle(Visual3d_Light)& ALight) {
273
274 Standard_Integer LengthL        = MyLights.Length ();
275 Standard_Integer indexL = 0;
276
277         // Find light <ALight> in 
278         // the sequence of already active lights
279         for (Standard_Integer i=1; i<=LengthL && indexL==0; i++)
280                 if ((void *) (MyLights.Value (i)) ==
281                     (void *) (ALight.operator->())) indexL = i;
282
283         // This is the activation of a new light
284         if (indexL != 0) MyLights.Remove (indexL);
285
286 }
287
288 Handle(Visual3d_HSetOfLight) Visual3d_ContextView::ActivatedLights () const {
289
290 Handle(Visual3d_HSetOfLight) SG = new Visual3d_HSetOfLight ();
291 Standard_Integer Length = MyLights.Length ();
292
293         for (Standard_Integer i=1; i<=Length; i++)
294                 SG->Add ((Visual3d_Light *) (MyLights.Value (i)));
295
296         return (SG);
297
298 }
299
300 Standard_Integer Visual3d_ContextView::NumberOfActivatedLights () const {
301
302 Standard_Integer Length = MyLights.Length ();
303
304         return (Length);
305
306 }
307
308 Handle(Visual3d_Light) Visual3d_ContextView::ActivatedLight (const Standard_Integer AnIndex) const {
309
310         return (Visual3d_Light *) (MyLights.Value (AnIndex));
311
312 }
313
314 void Visual3d_ContextView::SetSurfaceDetail(const Visual3d_TypeOfSurfaceDetail TOSD)
315 {
316   MySurfaceDetail = TOSD;
317 }
318
319
320 void Visual3d_ContextView::SetTextureEnv(const Handle(Graphic3d_TextureEnv)& ATexture)
321 {
322   MyTextureEnv = ATexture;
323 }
324
325
326 Handle_Graphic3d_TextureEnv Visual3d_ContextView::TextureEnv() const
327 {
328   return MyTextureEnv;
329 }
330
331
332 Visual3d_TypeOfSurfaceDetail Visual3d_ContextView::SurfaceDetail() const
333 {
334   return MySurfaceDetail;
335 }
336
337 //=======================================================================
338 //function : ClipPlanes
339 //purpose  :
340 //=======================================================================
341 const Graphic3d_SequenceOfHClipPlane& Visual3d_ContextView::ClipPlanes() const
342 {
343   return myClipPlanes;
344 }
345
346 //=======================================================================
347 //function : ChangeClipPlanes
348 //purpose  :
349 //=======================================================================
350 Graphic3d_SequenceOfHClipPlane& Visual3d_ContextView::ChangeClipPlanes()
351 {
352   return myClipPlanes;
353 }