1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
19 /***********************************************************************
23 Class Visual3d_ContextView.cxx :
25 Declaration of variables specific to view contexts.
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
36 ************************************************************************/
38 #define BUC60572 //GG 03-08-99 Move Zcueing and Zclipping front & back planes
39 // coherence checking in Visual3d_View::SetContext()
42 /*----------------------------------------------------------------------*/
47 #include <Visual3d_ContextView.ixx>
49 /*----------------------------------------------------------------------*/
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),
64 MySurfaceDetail(Visual3d_TOD_NONE),
69 /*----------------------------------------------------------------------*/
71 void Visual3d_ContextView::SetAliasingOn () {
73 AliasingIsActive = Standard_True;
77 void Visual3d_ContextView::SetAliasingOff () {
79 AliasingIsActive = Standard_False;
83 Standard_Boolean Visual3d_ContextView::AliasingIsOn () const {
85 return (AliasingIsActive);
89 void Visual3d_ContextView::SetZClippingOn () {
91 BackZclippingIsActive = Standard_True;
92 FrontZclippingIsActive = Standard_True;
96 void Visual3d_ContextView::SetZClippingOff () {
98 BackZclippingIsActive = Standard_False;
99 FrontZclippingIsActive = Standard_False;
103 Standard_Boolean Visual3d_ContextView::BackZClippingIsOn () const {
105 return (BackZclippingIsActive);
109 void Visual3d_ContextView::SetBackZClippingOn () {
111 BackZclippingIsActive = Standard_True;
115 void Visual3d_ContextView::SetBackZClippingOff () {
117 BackZclippingIsActive = Standard_False;
121 Standard_Boolean Visual3d_ContextView::FrontZClippingIsOn () const {
123 return (FrontZclippingIsActive);
127 void Visual3d_ContextView::SetFrontZClippingOn () {
129 FrontZclippingIsActive = Standard_True;
133 void Visual3d_ContextView::SetFrontZClippingOff () {
135 FrontZclippingIsActive = Standard_False;
139 void Visual3d_ContextView::SetZClippingFrontPlane (const Standard_Real AFront) {
142 if ( (FrontZclippingIsActive) && (BackZclippingIsActive) &&
143 (MyZclippingBackPlane >= AFront) )
144 Visual3d_ZClippingDefinitionError::Raise
145 ("Bad value for ZClippingFrontPlane");
148 MyZclippingFrontPlane = Standard_ShortReal (AFront);
152 Standard_Real Visual3d_ContextView::ZClippingFrontPlane () const {
154 return (Standard_Real (MyZclippingFrontPlane));
158 void Visual3d_ContextView::SetDepthCueingFrontPlane (const Standard_Real AFront) {
161 if ( (ZcueingIsActive) && (MyDepthCueingBackPlane >= AFront) )
162 Visual3d_DepthCueingDefinitionError::Raise
163 ("Bad value for DepthCueingFrontPlane");
166 MyDepthCueingFrontPlane = Standard_ShortReal (AFront);
170 Standard_Real Visual3d_ContextView::DepthCueingFrontPlane () const {
172 return (Standard_Real (MyDepthCueingFrontPlane));
176 void Visual3d_ContextView::SetZClippingBackPlane (const Standard_Real ABack) {
179 if ( (FrontZclippingIsActive) && (FrontZclippingIsActive) &&
180 (MyZclippingFrontPlane <= ABack) )
181 Visual3d_ZClippingDefinitionError::Raise
182 ("Bad value for ZClippingBackPlane");
185 MyZclippingBackPlane = Standard_ShortReal (ABack);
189 Standard_Real Visual3d_ContextView::ZClippingBackPlane () const {
191 return (Standard_Real (MyZclippingBackPlane));
195 void Visual3d_ContextView::SetDepthCueingBackPlane (const Standard_Real ABack) {
198 if ( (ZcueingIsActive) && (MyDepthCueingFrontPlane <= ABack) )
199 Visual3d_DepthCueingDefinitionError::Raise
200 ("Bad value for DepthCueingBackPlane");
203 MyDepthCueingBackPlane = Standard_ShortReal (ABack);
207 Standard_Real Visual3d_ContextView::DepthCueingBackPlane () const {
209 return (Standard_Real (MyDepthCueingBackPlane));
213 void Visual3d_ContextView::SetDepthCueingOn () {
215 ZcueingIsActive = Standard_True;
219 void Visual3d_ContextView::SetDepthCueingOff () {
221 ZcueingIsActive = Standard_False;
225 Standard_Boolean Visual3d_ContextView::DepthCueingIsOn () const {
227 return (ZcueingIsActive);
231 void Visual3d_ContextView::SetModel (const Visual3d_TypeOfModel AModel) {
237 Visual3d_TypeOfModel Visual3d_ContextView::Model () const {
243 void Visual3d_ContextView::SetVisualization (const Visual3d_TypeOfVisualization AVisual) {
249 Visual3d_TypeOfVisualization Visual3d_ContextView::Visualization () const {
255 void Visual3d_ContextView::SetLightOn (const Handle(Visual3d_Light)& ALight) {
257 Standard_Integer LengthL = MyLights.Length ();
258 Standard_Integer indexL = 0;
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;
266 // This is the activation of a new light
268 MyLights.Append ((void *) ALight.operator->());
272 void Visual3d_ContextView::SetLightOff (const Handle(Visual3d_Light)& ALight) {
274 Standard_Integer LengthL = MyLights.Length ();
275 Standard_Integer indexL = 0;
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;
283 // This is the activation of a new light
284 if (indexL != 0) MyLights.Remove (indexL);
288 Handle(Visual3d_HSetOfLight) Visual3d_ContextView::ActivatedLights () const {
290 Handle(Visual3d_HSetOfLight) SG = new Visual3d_HSetOfLight ();
291 Standard_Integer Length = MyLights.Length ();
293 for (Standard_Integer i=1; i<=Length; i++)
294 SG->Add ((Visual3d_Light *) (MyLights.Value (i)));
300 Standard_Integer Visual3d_ContextView::NumberOfActivatedLights () const {
302 Standard_Integer Length = MyLights.Length ();
308 Handle(Visual3d_Light) Visual3d_ContextView::ActivatedLight (const Standard_Integer AnIndex) const {
310 return (Visual3d_Light *) (MyLights.Value (AnIndex));
314 void Visual3d_ContextView::SetSurfaceDetail(const Visual3d_TypeOfSurfaceDetail TOSD)
316 MySurfaceDetail = TOSD;
320 void Visual3d_ContextView::SetTextureEnv(const Handle(Graphic3d_TextureEnv)& ATexture)
322 MyTextureEnv = ATexture;
326 Handle_Graphic3d_TextureEnv Visual3d_ContextView::TextureEnv() const
332 Visual3d_TypeOfSurfaceDetail Visual3d_ContextView::SurfaceDetail() const
334 return MySurfaceDetail;
337 //=======================================================================
338 //function : ClipPlanes
340 //=======================================================================
341 const Graphic3d_SequenceOfHClipPlane& Visual3d_ContextView::ClipPlanes() const
346 //=======================================================================
347 //function : ChangeClipPlanes
349 //=======================================================================
350 Graphic3d_SequenceOfHClipPlane& Visual3d_ContextView::ChangeClipPlanes()