0023663: Removing 2D viewer library
[occt.git] / src / AIS / AIS_InteractiveObject.cxx
1 // Created on: 1996-12-18
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 // Modified :   22/03/04 ; SAN : OCC4895 High-level interface for controlling polygon offsets 
23
24 #define BUC60577        //GG_101099     Enable to compute correctly
25 //                      transparency with more than one object in the view.
26
27 #define GER61351        //GG_171199     Enable to set an object RGB color
28 //                      instead a restricted object NameOfColor. 
29 //                      Add SetCurrentFacingModel() method
30
31 #define G003            //EUG/GG 260100 DEgenerate mode support
32 //                      Add SetDegenerateModel() methods
33
34 #define IMP020200       //GG Add SetTransformation() method
35
36 #define IMP140200       //GG Add HasPresentation() and Presentation() methods
37 //                           Add SetAspect() method.
38
39 #define BUC60632        //GG 15/03/00 Add protection on SetDisplayMode()
40 //                      method, compute only authorized presentation.
41
42 #define IMP220501       //GG CADPAK_V2 Update selection properly
43
44 #define OCC708          //SAV unsetting transformation correctly
45
46 #include <AIS_InteractiveObject.ixx>
47
48 #include <Aspect_PolygonOffsetMode.hxx>
49 #include <Prs3d_ShadingAspect.hxx>
50 #include <Prs3d_LineAspect.hxx>
51 #include <Prs3d_PointAspect.hxx>
52 #include <Prs3d_TextAspect.hxx>
53 #include <Prs3d_Presentation.hxx>
54 #include <Prs3d_Root.hxx>
55 #include <PrsMgr_ModedPresentation.hxx>
56 #include <PrsMgr_PresentationManager3d.hxx>
57 #include <TColStd_ListIteratorOfListOfInteger.hxx>
58 #include <AIS_GraphicTool.hxx>
59 #include <Graphic3d_AspectFillArea3d.hxx>
60 #include <Graphic3d_AspectLine3d.hxx>
61 #include <Graphic3d_AspectMarker3d.hxx>
62 #include <Graphic3d_AspectText3d.hxx>
63 #include <Graphic3d_Group.hxx>
64 #include <Graphic3d_Structure.hxx>
65
66
67 //=======================================================================
68 //function : AIS_InteractiveObject
69 //purpose  : 
70 //=======================================================================
71
72 AIS_InteractiveObject::
73 AIS_InteractiveObject(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d):
74 SelectMgr_SelectableObject(aTypeOfPresentation3d),
75 myDrawer(new AIS_Drawer()),
76 myTransparency(0.),
77 myOwnColor(Quantity_NOC_WHITE),
78 myOwnMaterial(Graphic3d_NOM_DEFAULT),
79 myHilightMode(-1),
80 myOwnWidth(0.0),
81 myInfiniteState(Standard_False),
82 hasOwnColor(Standard_False),
83 hasOwnMaterial(Standard_False),
84 myCurrentFacingModel(Aspect_TOFM_BOTH_SIDE),
85 myRecomputeEveryPrs(Standard_True),
86 myCTXPtr(NULL),
87 mySelPriority(-1),
88 myDisplayMode (-1),
89 mySelectionMode(0),
90 mystate(0),
91 myHasTransformation(Standard_False)
92 {
93   Handle (AIS_InteractiveContext) Bid;
94   myCTXPtr = Bid.operator->();
95 #ifdef GER61351
96   SetCurrentFacingModel();
97 #endif
98 }
99
100 //=======================================================================
101 //function : Redisplay
102 //purpose  : 
103 //=======================================================================
104
105 void AIS_InteractiveObject::Redisplay(const Standard_Boolean AllModes)
106 {
107   Update(AllModes);
108   UpdateSelection();
109 }
110
111 //=======================================================================
112 //function : Type
113 //purpose  : 
114 //=======================================================================
115
116 AIS_KindOfInteractive AIS_InteractiveObject::Type() const 
117 {return AIS_KOI_None;}
118
119 //=======================================================================
120 //function : Signature
121 //purpose  : 
122 //=======================================================================
123
124 Standard_Integer AIS_InteractiveObject::Signature() const 
125 {return -1;}
126
127 //=======================================================================
128 //function : RecomputeEveryPrs
129 //purpose  : 
130 //=======================================================================
131
132 Standard_Boolean  AIS_InteractiveObject::RecomputeEveryPrs() const 
133 {return myRecomputeEveryPrs;}
134
135 //=======================================================================
136 //function : 
137 //purpose  : 
138 //=======================================================================
139 Standard_Boolean AIS_InteractiveObject::HasInteractiveContext() const 
140 {
141   Handle (AIS_InteractiveContext) aNull;
142   return  (myCTXPtr != aNull.operator->());
143 }
144
145 //=======================================================================
146 //function : 
147 //purpose  : 
148 //=======================================================================
149 Handle(AIS_InteractiveContext) AIS_InteractiveObject::GetContext() const 
150 {
151   return myCTXPtr;
152 }
153
154 //=======================================================================
155 //function : 
156 //purpose  : 
157 //=======================================================================
158 void AIS_InteractiveObject::SetContext(const Handle(AIS_InteractiveContext)& aCtx)
159 {
160   myCTXPtr = aCtx.operator->();
161   if (myDrawer.IsNull()) {
162     myDrawer = new AIS_Drawer;
163 #ifdef DEB
164     cout << "AIS_InteractiveObject::SetContext DRAWER NUL!" << endl;
165 #endif
166   }
167   myDrawer->Link(aCtx->DefaultDrawer());
168 }
169
170 //=======================================================================
171 //function : 
172 //purpose  : 
173 //=======================================================================
174 Standard_Boolean AIS_InteractiveObject::HasOwner() const 
175 {
176   return (!myOwner.IsNull());
177 }
178
179
180
181 //=======================================================================
182 //function : 
183 //purpose  : 
184 //=======================================================================
185 void AIS_InteractiveObject::ClearOwner()
186 {
187   myOwner.Nullify();
188 }
189
190 //=======================================================================
191 //function : 
192 //purpose  : 
193 //=======================================================================
194 Standard_Boolean AIS_InteractiveObject::HasUsers() const 
195 {
196   return (!myUsers.IsEmpty());
197 }
198
199
200 //=======================================================================
201 //function : 
202 //purpose  : 
203 //=======================================================================
204 void AIS_InteractiveObject::AddUser(const Handle(Standard_Transient)& aUser)
205 {
206   myUsers.Append(aUser);
207 }
208
209 //=======================================================================
210 //function : 
211 //purpose  : 
212 //=======================================================================
213 void AIS_InteractiveObject::ClearUsers()
214 {
215   myUsers.Clear();
216 }
217
218
219 //=======================================================================
220 //function : 
221 //purpose  : 
222 //=======================================================================
223 void AIS_InteractiveObject::SetDisplayMode(const Standard_Integer aMode)
224 {
225 #ifdef BUC60632
226   if( AcceptDisplayMode(aMode) )
227 #endif
228     myDisplayMode = aMode;
229 }
230   
231
232 //=======================================================================
233 //function : 
234 //purpose  : 
235 //=======================================================================
236 void AIS_InteractiveObject::SetSelectionMode(const Standard_Integer aMode)
237 {
238   mySelectionMode = aMode;
239 }
240
241
242
243 //=======================================================================
244 //function : 
245 //purpose  : 
246 //=======================================================================
247 #ifdef GER61351
248 void AIS_InteractiveObject::SetCurrentFacingModel(const Aspect_TypeOfFacingModel aModel) {
249   myCurrentFacingModel = aModel;
250 }
251
252 //=======================================================================
253 //function : CurrentFacingModel
254 //purpose  : 
255 //=======================================================================
256
257 Aspect_TypeOfFacingModel AIS_InteractiveObject::CurrentFacingModel() const {
258   return myCurrentFacingModel;
259 }
260 #endif
261
262 //=======================================================================
263 //function : SetColor
264 //purpose  : 
265 //=======================================================================
266
267 void AIS_InteractiveObject::SetColor(const Quantity_NameOfColor aColor)
268 #ifdef GER61351
269 {
270   SetColor(Quantity_Color(aColor));
271 }
272
273 //=======================================================================
274 //function : SetColor
275 //purpose  : 
276 //=======================================================================
277
278 void AIS_InteractiveObject::SetColor(const Quantity_Color &aColor)
279 #endif
280 {
281   myOwnColor = aColor;
282   hasOwnColor = Standard_True;
283 }
284
285 //=======================================================================
286 //function : UnsetColor
287 //purpose  : 
288 //=======================================================================
289 void AIS_InteractiveObject::UnsetColor()
290 {
291   hasOwnColor = Standard_False;
292 }
293
294 //=======================================================================
295 //function : 
296 //purpose  : 
297 //=======================================================================
298 void AIS_InteractiveObject::SetWidth(const Standard_Real aValue)
299 {
300   myOwnWidth = aValue;
301 }
302
303 //=======================================================================
304 //function : 
305 //purpose  : 
306 //=======================================================================
307 void AIS_InteractiveObject::UnsetWidth()
308 {
309   myOwnWidth = 0.;
310 }
311
312
313 //=======================================================================
314 //function : 
315 //purpose  : 
316 //=======================================================================
317 //POP pour K4L
318 void AIS_InteractiveObject::SetMaterial(const Graphic3d_NameOfMaterial aName)
319 //void AIS_InteractiveObject::SetMaterial(const Graphic3d_NameOfPhysicalMaterial aName)
320 {
321   if( HasColor() || IsTransparent() || HasMaterial() )
322     {
323       myDrawer->ShadingAspect()->SetMaterial(aName);
324     }
325   else 
326     {
327       myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
328       
329       myDrawer->ShadingAspect()->SetMaterial(aName);
330 #ifndef BUC60577        //???
331       myDrawer->ShadingAspect()->SetColor(AIS_GraphicTool::GetInteriorColor(myDrawer->Link()));
332 #endif
333     }
334   myOwnMaterial  = aName;
335   hasOwnMaterial = Standard_True;
336 }
337 //=======================================================================
338 //function : SetMaterial
339 //purpose  : 
340 //=======================================================================
341
342 void AIS_InteractiveObject::SetMaterial(const Graphic3d_MaterialAspect& aMat)
343 {
344 #ifdef BUC60577
345   if( HasColor() || IsTransparent() || HasMaterial() )
346 #else
347   if(hasOwnColor ||(myTransparency==0.0) || hasOwnMaterial )
348 #endif
349     {
350       myDrawer->ShadingAspect()->SetMaterial(aMat);
351     }
352   else 
353     {
354       myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
355       myDrawer->ShadingAspect()->SetMaterial(aMat);
356     }
357   hasOwnMaterial = Standard_True;
358   
359 }
360 //=======================================================================
361 //function : 
362 //purpose  : 
363 //=======================================================================
364 void AIS_InteractiveObject::UnsetMaterial()
365 {
366 #ifdef BUC60577
367   if( !HasMaterial() ) return;
368   if( HasColor() || IsTransparent()) {
369     myDrawer->ShadingAspect()->SetMaterial(
370                 AIS_GraphicTool::GetMaterial(myDrawer->Link()));
371     if( HasColor() ) SetColor(myOwnColor);
372     if( IsTransparent() ) SetTransparency(myTransparency);
373   }
374 #else
375   if(!hasOwnMaterial) return;
376   if(hasOwnColor ||(myTransparency==0.0))
377     {
378       myDrawer->ShadingAspect()->SetMaterial(AIS_GraphicTool::GetMaterial(myDrawer->Link()));
379     }
380 #endif
381   else{
382     Handle(Prs3d_ShadingAspect) SA;
383     myDrawer->SetShadingAspect(SA);
384   }
385   hasOwnMaterial = Standard_False;
386 }
387
388 //=======================================================================
389 //function : SetTransparency
390 //purpose  : 
391 //=======================================================================
392 void AIS_InteractiveObject::SetTransparency(const Standard_Real aValue)
393 {
394
395 #ifdef BUC60577                     // Back & Front material can be different !
396
397   if(!HasColor() && !IsTransparent() && !HasMaterial() ) {
398         myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
399       if(!myDrawer->Link().IsNull())
400         myDrawer->ShadingAspect()->SetMaterial(AIS_GraphicTool::GetMaterial(myDrawer->Link()));
401   }
402   Graphic3d_MaterialAspect FMat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
403   Graphic3d_MaterialAspect BMat = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
404   FMat.SetTransparency(aValue); BMat.SetTransparency(aValue);
405   myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(FMat);
406   myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(BMat);
407 #else
408   if(aValue<0.0 || aValue>1.0) return;
409   
410   if(aValue<=0.05) 
411     {
412       UnsetTransparency();
413       return;
414     }
415   
416
417   if(hasOwnColor || hasOwnMaterial || myTransparency> 0.0)
418     {
419       Graphic3d_MaterialAspect Mat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
420       Mat.SetTransparency(aValue);
421       myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(Mat);
422       myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(Mat);
423     }
424   else
425     {
426       myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
427       if(!myDrawer->Link().IsNull())
428         myDrawer->ShadingAspect()->SetMaterial(AIS_GraphicTool::GetMaterial(myDrawer->Link()));
429       Graphic3d_MaterialAspect Mat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
430       Mat.SetTransparency(aValue);
431       myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(Mat);
432       myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(Mat);
433     }
434 #endif
435   myTransparency = aValue;
436 }
437
438 //=======================================================================
439 //function : UnsetTransparency
440 //purpose  : 
441 //=======================================================================
442 void AIS_InteractiveObject::UnsetTransparency()
443 {
444 #ifdef BUC60577                     // Back & Front material can be different !
445     if(HasColor() || HasMaterial() )
446     {
447       Graphic3d_MaterialAspect FMat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
448       Graphic3d_MaterialAspect BMat = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
449       FMat.SetTransparency(0.); BMat.SetTransparency(0.);
450       myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(FMat);
451       myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(BMat);
452     }
453 #else
454     if(hasOwnColor || hasOwnMaterial )
455     {
456       Graphic3d_MaterialAspect Mat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
457       Mat.SetTransparency(0.0);
458 //      myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(Mat);
459 //      myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(Mat);
460        myDrawer->ShadingAspect()->SetMaterial(Mat);
461     }
462 #endif
463   else{
464     Handle (Prs3d_ShadingAspect) SA;
465     myDrawer->SetShadingAspect(SA);
466   }
467   myTransparency =0.0;
468 }
469 //=======================================================================
470 //function : Transparency
471 //purpose  : 
472 //=======================================================================
473 Standard_Real AIS_InteractiveObject::Transparency() const 
474 {
475   return (myTransparency<=0.05 ? 0 : myTransparency);
476 // Graphic3d_MaterialAspect Mat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
477 // return Mat.Transparency();
478 }
479
480 //=======================================================================
481 //function : SetAttributes
482 //purpose  : 
483 //=======================================================================
484
485 void AIS_InteractiveObject::SetAttributes(const Handle(AIS_Drawer)& aDrawer)
486 {myDrawer = aDrawer;}
487
488
489 //=======================================================================
490 //function : UnsetAttributes
491 //purpose  : 
492 //=======================================================================
493 void AIS_InteractiveObject::UnsetAttributes()
494 {
495   Handle(AIS_Drawer) dr = new AIS_Drawer();
496   if(myDrawer->HasLink())
497     dr->Link(myDrawer->Link());
498   myDrawer       = dr;
499   hasOwnColor    = Standard_False;
500   hasOwnMaterial = Standard_False;
501   myOwnWidth     = 0.0;
502   myTransparency = 0.0;
503 }
504
505 //=======================================================================
506 //function : 
507 //purpose  : 
508 //=======================================================================
509 void AIS_InteractiveObject::MustRecomputePrs(const Standard_Integer ) const 
510 {}
511
512 //=======================================================================
513 //function : 
514 //purpose  : 
515 //=======================================================================
516 const TColStd_ListOfInteger& AIS_InteractiveObject::ListOfRecomputeModes() const 
517 {return myToRecomputeModes;}
518
519 //=======================================================================
520 //function : 
521 //purpose  : 
522 //=======================================================================
523 void AIS_InteractiveObject::SetRecomputeOk()
524 {myToRecomputeModes.Clear();}
525
526
527 //=======================================================================
528 //function : AcceptDisplayMode
529 //purpose  : 
530 //=======================================================================
531
532 Standard_Boolean  AIS_InteractiveObject::AcceptDisplayMode(const Standard_Integer ) const
533 {return Standard_True;}
534
535 //=======================================================================
536 //function : DefaultDisplayMode
537 //purpose  : 
538 //=======================================================================
539
540 Standard_Integer AIS_InteractiveObject::DefaultDisplayMode() const
541 {return 0;}
542
543
544 //=======================================================================
545 //function : SetInfiniteState
546 //purpose  : 
547 //=======================================================================
548 void AIS_InteractiveObject::SetInfiniteState(const Standard_Boolean aFlag)
549 {
550   myInfiniteState = aFlag;
551   Handle(Prs3d_Presentation) P;
552
553   for(Standard_Integer i =1; i<=myPresentations.Length();i++){
554     P = Handle(Prs3d_Presentation)::DownCast(myPresentations(i).Presentation());
555     if(!P.IsNull())
556       P->SetInfiniteState(myInfiniteState);}
557 }
558
559 #ifdef G003
560 //=======================================================================
561 //function : SetDegenerateModel
562 //purpose  : 
563 //=======================================================================
564 void AIS_InteractiveObject::SetDegenerateModel(
565                 const Aspect_TypeOfDegenerateModel aModel,
566                 const Quantity_Ratio aRatio ) {
567   if( !HasColor() && !IsTransparent() && !HasMaterial() ) {
568     myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
569   }
570
571   myDrawer->ShadingAspect()->Aspect()->SetDegenerateModel(aModel,aRatio);
572
573   if(!GetContext().IsNull()){
574     if( GetContext()->MainPrsMgr()->HasPresentation(this,1)){
575       Handle(Prs3d_Presentation) P = 
576         GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
577       Handle(Graphic3d_AspectFillArea3d) a4bis = 
578                                 myDrawer->ShadingAspect()->Aspect();
579       P->SetPrimitivesAspect(a4bis);
580     }
581   }
582 }
583
584 //=======================================================================
585 //function : DegenerateModel
586 //purpose  : 
587 //=======================================================================
588
589 Aspect_TypeOfDegenerateModel AIS_InteractiveObject::DegenerateModel( 
590                         Quantity_Ratio& aRatio) const
591 {
592   return myDrawer->ShadingAspect()->Aspect()->DegenerateModel(aRatio);
593 }
594 #endif
595
596 #ifdef IMP020200
597 //=======================================================================
598 //function : SetTransformation
599 //purpose  : 
600 //=======================================================================
601 void AIS_InteractiveObject::SetTransformation(const Handle(Geom_Transformation)& aTrsf, const Standard_Boolean postConcatenate, const Standard_Boolean updateSelection) {
602
603   if(!GetContext().IsNull()){
604     const PrsMgr_Presentations& prs = Presentations(); 
605     Handle(Prs3d_Presentation) P;
606     Standard_Integer mode;
607     myHasTransformation = Standard_True;
608     for( Standard_Integer i=1 ; i<=prs.Length() ; i++ ) {
609       mode = prs(i).Mode();
610       P = GetContext()->MainPrsMgr()->CastPresentation(this,mode)->Presentation();
611       if( postConcatenate ) P->Multiply(aTrsf);
612       else                  P->Transform(aTrsf);
613       if( updateSelection ) {
614 #ifdef IMP220501
615         myCTXPtr->ClearSelected(Standard_True);
616         myCTXPtr->RecomputeSelectionOnly(this);
617 #else
618         if( HasSelection(mode) ) {
619           UpdateSelection(mode);      
620         }
621 #endif
622       }
623     }
624   }
625 }
626
627 //=======================================================================
628 //function : SetTransformation
629 //purpose  : 
630 //=======================================================================
631 void AIS_InteractiveObject::UnsetTransformation() {
632 #ifdef OCC708
633   static Handle(Geom_Transformation) trsf = new Geom_Transformation( gp_Trsf() );
634 #else
635 Handle(Geom_Transformation) trsf;
636 #endif
637
638     SetTransformation(trsf);    // Set identity transformation
639     myHasTransformation = Standard_False;
640 }
641
642 //=======================================================================
643 //function : Transformation
644 //purpose  : 
645 //=======================================================================
646 Handle(Geom_Transformation) AIS_InteractiveObject::Transformation() {
647 Handle(Geom_Transformation) trsf; 
648
649   if(!GetContext().IsNull() ) {
650     const PrsMgr_Presentations& prs = Presentations(); 
651     if( prs.Length() > 0 ) {
652       Handle(Prs3d_Presentation) P = 
653           GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
654       trsf = P->Transformation();
655     }
656   }
657
658   return trsf;
659 }
660
661 //=======================================================================
662 //function : HasTransformation
663 //purpose  : 
664 //=======================================================================
665 Standard_Boolean AIS_InteractiveObject::HasTransformation() const {
666
667   return myHasTransformation;
668 }
669 #endif
670
671 #ifdef IMP140200
672 //=======================================================================
673 //function : HasPresentation
674 //purpose  : 
675 //=======================================================================
676 Standard_Boolean AIS_InteractiveObject::HasPresentation() const {
677
678   if( !GetContext().IsNull() && 
679         GetContext()->MainPrsMgr()->HasPresentation(this,myDisplayMode) ) {
680     return Standard_True;
681   }
682
683   return Standard_False;
684 }
685
686 //=======================================================================
687 //function : Presentation
688 //purpose  : 
689 //=======================================================================
690 Handle(Prs3d_Presentation) AIS_InteractiveObject::Presentation() const {
691 Handle(Prs3d_Presentation) prs;
692
693   if( HasPresentation() ) {
694     prs = GetContext()->MainPrsMgr()->
695                 CastPresentation(this,myDisplayMode)->Presentation();
696   }
697
698   return prs;
699 }
700
701 //=======================================================================
702 //function : SetAspect 
703 //purpose  : 
704 //=======================================================================
705 void AIS_InteractiveObject::SetAspect(const Handle(Prs3d_BasicAspect)& anAspect,
706                                       const Standard_Boolean globalChange) {
707
708   if( HasPresentation() ) {
709     Handle(Prs3d_Presentation) prs = Presentation();
710     { Handle(Prs3d_ShadingAspect) aspect =
711                         Handle(Prs3d_ShadingAspect)::DownCast(anAspect);
712       if( !aspect.IsNull() ) {
713         if( globalChange ) prs->SetPrimitivesAspect(aspect->Aspect());
714         Prs3d_Root::CurrentGroup(prs)->SetGroupPrimitivesAspect(aspect->Aspect());
715         return;
716       }
717     }
718     { Handle(Prs3d_LineAspect) aspect =
719                         Handle(Prs3d_LineAspect)::DownCast(anAspect);
720       if( !aspect.IsNull() ) {
721         if( globalChange ) prs->SetPrimitivesAspect(aspect->Aspect());
722         Prs3d_Root::CurrentGroup(prs)->SetGroupPrimitivesAspect(aspect->Aspect());
723         return;
724       }
725     }
726     { Handle(Prs3d_PointAspect) aspect =
727                         Handle(Prs3d_PointAspect)::DownCast(anAspect);
728       if( !aspect.IsNull() ) {
729         if( globalChange ) prs->SetPrimitivesAspect(aspect->Aspect());
730         Prs3d_Root::CurrentGroup(prs)->SetGroupPrimitivesAspect(aspect->Aspect());
731         return;
732       }
733     }
734     { Handle(Prs3d_TextAspect) aspect =
735                         Handle(Prs3d_TextAspect)::DownCast(anAspect);
736       if( !aspect.IsNull() ) {
737         if( globalChange ) prs->SetPrimitivesAspect(aspect->Aspect());
738         Prs3d_Root::CurrentGroup(prs)->SetGroupPrimitivesAspect(aspect->Aspect());
739         return;
740       }
741     }
742   }
743 }
744 #endif
745
746 // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
747
748 //=======================================================================
749 //function : SetPolygonOffsets 
750 //purpose  : 
751 //======================================================================= 
752 void AIS_InteractiveObject::SetPolygonOffsets(const Standard_Integer    aMode,
753                                               const Standard_ShortReal  aFactor,
754                                               const Standard_ShortReal  aUnits) 
755 {
756   if ( !HasPolygonOffsets() )
757     myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
758
759   myDrawer->ShadingAspect()->Aspect()->SetPolygonOffsets( aMode, aFactor, aUnits );
760
761   // Modify existing presentations 
762   Handle(Graphic3d_Structure) aStruct;
763   for( Standard_Integer i = 1, n = myPresentations.Length(); i <= n; i++ ) {
764     Handle(PrsMgr_Presentation3d) aPrs3d =
765       Handle(PrsMgr_Presentation3d)::DownCast( myPresentations(i).Presentation() );
766     if ( !aPrs3d.IsNull() ) {
767       aStruct = Handle(Graphic3d_Structure)::DownCast( aPrs3d->Presentation() );
768       if( !aStruct.IsNull() ) {
769         aStruct->SetPrimitivesAspect( myDrawer->ShadingAspect()->Aspect() );
770         // Workaround for issue 23115: Need to update also groups, because their
771         // face aspect ALWAYS overrides the structure's.
772         const Graphic3d_SequenceOfGroup& aGroups = aStruct->Groups();
773         Standard_Integer aGroupIndex = 1, aGroupNb = aGroups.Length();
774         for ( ; aGroupIndex <= aGroupNb; aGroupIndex++ ) {
775           Handle(Graphic3d_Group) aGrp = aGroups.Value(aGroupIndex);
776           if ( !aGrp.IsNull() && aGrp->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA) ) {
777             Handle(Graphic3d_AspectFillArea3d) aFaceAsp = new Graphic3d_AspectFillArea3d();
778             Handle(Graphic3d_AspectLine3d) aLineAsp = new Graphic3d_AspectLine3d();
779             Handle(Graphic3d_AspectMarker3d) aPntAsp = new Graphic3d_AspectMarker3d();
780             Handle(Graphic3d_AspectText3d) aTextAsp = new Graphic3d_AspectText3d();
781             // TODO: Add methods for retrieving individual aspects from Graphic3d_Group
782             aGrp->GroupPrimitivesAspect(aLineAsp, aTextAsp, aPntAsp, aFaceAsp);
783             aFaceAsp->SetPolygonOffsets(aMode, aFactor, aUnits);
784             // TODO: Issue 23118 - This line kills texture data in the group...
785             aGrp->SetGroupPrimitivesAspect(aFaceAsp);
786           }
787         }
788       }
789     }
790   }
791 }
792
793
794 //=======================================================================
795 //function : HasPolygonOffsets 
796 //purpose  : 
797 //=======================================================================
798 Standard_Boolean AIS_InteractiveObject::HasPolygonOffsets() const
799 {
800   return !( myDrawer->ShadingAspect().IsNull() || 
801           ( !myDrawer->Link().IsNull() && 
802           myDrawer->ShadingAspect() == myDrawer->Link()->ShadingAspect() ) );
803 }
804
805 //=======================================================================
806 //function : PolygonOffsets 
807 //purpose  : 
808 //=======================================================================
809 void AIS_InteractiveObject::PolygonOffsets(Standard_Integer&    aMode,
810                                            Standard_ShortReal&  aFactor,
811                                            Standard_ShortReal&  aUnits) const 
812 {
813   if( HasPolygonOffsets() )
814     myDrawer->ShadingAspect()->Aspect()->PolygonOffsets( aMode, aFactor, aUnits );
815 }
816 // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets