0024070: OpenGL capped object-level clipping planes
[occt.git] / src / Visual3d / Visual3d_ContextView.cxx
CommitLineData
b311480e 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
7fd59977 19/***********************************************************************
20
81bba717 21 FUNCTION :
7fd59977 22 ----------
81bba717 23 Class Visual3d_ContextView.cxx :
7fd59977 24
81bba717 25 Declaration of variables specific to view contexts.
7fd59977 26
81bba717 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
7fd59977 34
7fd59977 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
51Visual3d_ContextView::Visual3d_ContextView ():
52AliasingIsActive (Standard_False),
53ZcueingIsActive (Standard_False),
54FrontZclippingIsActive (Standard_False),
55BackZclippingIsActive (Standard_False),
56MyZclippingFrontPlane (Standard_ShortReal (1.0)),
57MyZclippingBackPlane (Standard_ShortReal (0.0)),
58MyDepthCueingFrontPlane (Standard_ShortReal (1.0)),
59MyDepthCueingBackPlane (Standard_ShortReal (0.0)),
60MyModel (Visual3d_TOM_NONE),
61MyVisual (Visual3d_TOV_WIREFRAME),
62MyLights (),
7fd59977 63MyTextureEnv(),
4269bd1b 64MySurfaceDetail(Visual3d_TOD_NONE),
65myClipPlanes()
7fd59977 66{
67}
68
69/*----------------------------------------------------------------------*/
70
71void Visual3d_ContextView::SetAliasingOn () {
72
73 AliasingIsActive = Standard_True;
74
75}
76
77void Visual3d_ContextView::SetAliasingOff () {
78
79 AliasingIsActive = Standard_False;
80
81}
82
83Standard_Boolean Visual3d_ContextView::AliasingIsOn () const {
84
85 return (AliasingIsActive);
86
87}
88
89void Visual3d_ContextView::SetZClippingOn () {
90
91 BackZclippingIsActive = Standard_True;
92 FrontZclippingIsActive = Standard_True;
93
94}
95
96void Visual3d_ContextView::SetZClippingOff () {
97
98 BackZclippingIsActive = Standard_False;
99 FrontZclippingIsActive = Standard_False;
100
101}
102
103Standard_Boolean Visual3d_ContextView::BackZClippingIsOn () const {
104
105 return (BackZclippingIsActive);
106
107}
108
109void Visual3d_ContextView::SetBackZClippingOn () {
110
111 BackZclippingIsActive = Standard_True;
112
113}
114
115void Visual3d_ContextView::SetBackZClippingOff () {
116
117 BackZclippingIsActive = Standard_False;
118
119}
120
121Standard_Boolean Visual3d_ContextView::FrontZClippingIsOn () const {
122
123 return (FrontZclippingIsActive);
124
125}
126
127void Visual3d_ContextView::SetFrontZClippingOn () {
128
129 FrontZclippingIsActive = Standard_True;
130
131}
132
133void Visual3d_ContextView::SetFrontZClippingOff () {
134
135 FrontZclippingIsActive = Standard_False;
136
137}
138
139void 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
152Standard_Real Visual3d_ContextView::ZClippingFrontPlane () const {
153
154 return (Standard_Real (MyZclippingFrontPlane));
155
156}
157
158void 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
170Standard_Real Visual3d_ContextView::DepthCueingFrontPlane () const {
171
172 return (Standard_Real (MyDepthCueingFrontPlane));
173
174}
175
176void 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
189Standard_Real Visual3d_ContextView::ZClippingBackPlane () const {
190
191 return (Standard_Real (MyZclippingBackPlane));
192
193}
194
195void 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
207Standard_Real Visual3d_ContextView::DepthCueingBackPlane () const {
208
209 return (Standard_Real (MyDepthCueingBackPlane));
210
211}
212
213void Visual3d_ContextView::SetDepthCueingOn () {
214
215 ZcueingIsActive = Standard_True;
216
217}
218
219void Visual3d_ContextView::SetDepthCueingOff () {
220
221 ZcueingIsActive = Standard_False;
222
223}
224
225Standard_Boolean Visual3d_ContextView::DepthCueingIsOn () const {
226
227 return (ZcueingIsActive);
228
229}
230
231void Visual3d_ContextView::SetModel (const Visual3d_TypeOfModel AModel) {
232
233 MyModel = AModel;
234
235}
236
237Visual3d_TypeOfModel Visual3d_ContextView::Model () const {
238
239 return (MyModel);
240
241}
242
243void Visual3d_ContextView::SetVisualization (const Visual3d_TypeOfVisualization AVisual) {
244
245 MyVisual = AVisual;
246
247}
248
249Visual3d_TypeOfVisualization Visual3d_ContextView::Visualization () const {
250
251 return (MyVisual);
252
253}
254
255void Visual3d_ContextView::SetLightOn (const Handle(Visual3d_Light)& ALight) {
256
257Standard_Integer LengthL = MyLights.Length ();
258Standard_Integer indexL = 0;
259
81bba717 260 // Find light <ALight> in
261 // the sequence of already active lights
7fd59977 262 for (Standard_Integer i=1; i<=LengthL && indexL==0; i++)
263 if ((void *) (MyLights.Value (i)) ==
264 (void *) (ALight.operator->())) indexL = i;
265
81bba717 266 // This is the activation of a new light
7fd59977 267 if (indexL == 0)
268 MyLights.Append ((void *) ALight.operator->());
269
270}
271
272void Visual3d_ContextView::SetLightOff (const Handle(Visual3d_Light)& ALight) {
273
274Standard_Integer LengthL = MyLights.Length ();
275Standard_Integer indexL = 0;
276
81bba717 277 // Find light <ALight> in
278 // the sequence of already active lights
7fd59977 279 for (Standard_Integer i=1; i<=LengthL && indexL==0; i++)
280 if ((void *) (MyLights.Value (i)) ==
281 (void *) (ALight.operator->())) indexL = i;
282
81bba717 283 // This is the activation of a new light
7fd59977 284 if (indexL != 0) MyLights.Remove (indexL);
285
286}
287
288Handle(Visual3d_HSetOfLight) Visual3d_ContextView::ActivatedLights () const {
289
290Handle(Visual3d_HSetOfLight) SG = new Visual3d_HSetOfLight ();
291Standard_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
300Standard_Integer Visual3d_ContextView::NumberOfActivatedLights () const {
301
302Standard_Integer Length = MyLights.Length ();
303
304 return (Length);
305
306}
307
308Handle(Visual3d_Light) Visual3d_ContextView::ActivatedLight (const Standard_Integer AnIndex) const {
309
310 return (Visual3d_Light *) (MyLights.Value (AnIndex));
311
312}
313
7fd59977 314void Visual3d_ContextView::SetSurfaceDetail(const Visual3d_TypeOfSurfaceDetail TOSD)
315{
316 MySurfaceDetail = TOSD;
317}
318
319
320void Visual3d_ContextView::SetTextureEnv(const Handle(Graphic3d_TextureEnv)& ATexture)
321{
322 MyTextureEnv = ATexture;
323}
324
325
326Handle_Graphic3d_TextureEnv Visual3d_ContextView::TextureEnv() const
327{
328 return MyTextureEnv;
329}
330
331
332Visual3d_TypeOfSurfaceDetail Visual3d_ContextView::SurfaceDetail() const
333{
334 return MySurfaceDetail;
335}
4269bd1b 336
337void Visual3d_ContextView::SetClipPlanes (const Graphic3d_SetOfHClipPlane& thePlanes)
338{
339 myClipPlanes = thePlanes;
340}
341
342const Graphic3d_SetOfHClipPlane& Visual3d_ContextView::GetClipPlanes() const
343{
344 return myClipPlanes;
345}