summaryrefslogtreecommitdiff
path: root/src/AIS/AIS_InteractiveObject.cxx
blob: 6217978299d756f200d6b9eeed4373c401bb40ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
// File:	AIS_InteractiveObject.cxx
// Created:	Wed Dec 18 14:44:37 1996
// Author:	Robert COUBLANC
//		<rob@robox.paris1.matra-dtv.fr>

// Modified :   22/03/04 ; SAN : OCC4895 High-level interface for controlling polygon offsets 

#define BUC60577        //GG_101099     Enable to compute correctly
//                      transparency with more than one object in the view.

#define GER61351	//GG_171199     Enable to set an object RGB color
//			instead a restricted object NameOfColor. 
//			Add SetCurrentFacingModel() method
//			

#define G003		//EUG/GG 260100 DEgenerate mode support
//			Add SetDegenerateModel() methods

#define IMP020200	//GG Add SetTransformation() method

#define IMP140200	//GG Add HasPresentation() and Presentation() methods
//			     Add SetAspect() method.

#define BUC60632	//GG 15/03/00 Add protection on SetDisplayMode()
//			method, compute only authorized presentation.

#define IMP220501	//GG CADPAK_V2 Update selection properly

#define OCC708          //SAV unsetting transformation correctly

#include <AIS_InteractiveObject.ixx>

#include <Aspect_PolygonOffsetMode.hxx>
#include <Prs3d_ShadingAspect.hxx>
#include <Prs3d_LineAspect.hxx>
#include <Prs3d_PointAspect.hxx>
#include <Prs3d_TextAspect.hxx>
#include <Prs3d_Presentation.hxx>
#include <Prs3d_Root.hxx>
#include <PrsMgr_ModedPresentation.hxx>
#include <PrsMgr_PresentationManager3d.hxx>
#include <TColStd_ListIteratorOfListOfInteger.hxx>
#include <AIS_GraphicTool.hxx>
#include <Graphic3d_AspectFillArea3d.hxx>
#include <Graphic3d_Group.hxx>
#include <Graphic3d_Structure.hxx>


//=======================================================================
//function : AIS_InteractiveObject
//purpose  : 
//=======================================================================

AIS_InteractiveObject::
AIS_InteractiveObject(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d):
SelectMgr_SelectableObject(aTypeOfPresentation3d),
myDrawer(new AIS_Drawer()),
myTransparency(0.),
myOwnColor(Quantity_NOC_WHITE),
myHilightMode(-1),
myOwnWidth(0.0),
myInfiniteState(Standard_False),
hasOwnColor(Standard_False),
hasOwnMaterial(Standard_False),
myRecomputeEveryPrs(Standard_True),
mySelPriority(-1),
myDisplayMode (-1),
mySelectionMode(0),
mystate(0)
{
  Handle (AIS_InteractiveContext) Bid;
  myCTXPtr = Bid.operator->();
#ifdef GER61351
  SetCurrentFacingModel();
#endif
}

//=======================================================================
//function : Redisplay
//purpose  : 
//=======================================================================

void AIS_InteractiveObject::Redisplay(const Standard_Boolean AllModes)
{
  Update(AllModes);
  UpdateSelection();
}

//=======================================================================
//function : Type
//purpose  : 
//=======================================================================

AIS_KindOfInteractive AIS_InteractiveObject::Type() const 
{return AIS_KOI_None;}

//=======================================================================
//function : Signature
//purpose  : 
//=======================================================================

Standard_Integer AIS_InteractiveObject::Signature() const 
{return -1;}

//=======================================================================
//function : RecomputeEveryPrs
//purpose  : 
//=======================================================================

Standard_Boolean  AIS_InteractiveObject::RecomputeEveryPrs() const 
{return myRecomputeEveryPrs;}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
Standard_Boolean AIS_InteractiveObject::HasInteractiveContext() const 
{
  Handle (AIS_InteractiveContext) aNull;
  return  (myCTXPtr != aNull.operator->());
}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
Handle(AIS_InteractiveContext) AIS_InteractiveObject::GetContext() const 
{
  return myCTXPtr;
}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
void AIS_InteractiveObject::SetContext(const Handle(AIS_InteractiveContext)& aCtx)
{
  myCTXPtr = aCtx.operator->();
  if (myDrawer.IsNull()) {
    myDrawer = new AIS_Drawer;
#ifdef DEB
    cout << "AIS_InteractiveObject::SetContext DRAWER NUL!" << endl;
#endif
  }
  myDrawer->Link(aCtx->DefaultDrawer());
}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
Standard_Boolean AIS_InteractiveObject::HasOwner() const 
{
  return (!myOwner.IsNull());
}



//=======================================================================
//function : 
//purpose  : 
//=======================================================================
void AIS_InteractiveObject::ClearOwner()
{
  myOwner.Nullify();
}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
Standard_Boolean AIS_InteractiveObject::HasUsers() const 
{
  return (!myUsers.IsEmpty());
}


//=======================================================================
//function : 
//purpose  : 
//=======================================================================
void AIS_InteractiveObject::AddUser(const Handle(Standard_Transient)& aUser)
{
  myUsers.Append(aUser);
}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
void AIS_InteractiveObject::ClearUsers()
{
  myUsers.Clear();
}


//=======================================================================
//function : 
//purpose  : 
//=======================================================================
void AIS_InteractiveObject::SetDisplayMode(const Standard_Integer aMode)
{
#ifdef BUC60632
  if( AcceptDisplayMode(aMode) )
#endif
    myDisplayMode = aMode;
}
  

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
void AIS_InteractiveObject::SetSelectionMode(const Standard_Integer aMode)
{
  mySelectionMode = aMode;
}



//=======================================================================
//function : 
//purpose  : 
//=======================================================================
#ifdef GER61351
void AIS_InteractiveObject::SetCurrentFacingModel(const Aspect_TypeOfFacingModel aModel) {
  myCurrentFacingModel = aModel;
}

//=======================================================================
//function : CurrentFacingModel
//purpose  : 
//=======================================================================

Aspect_TypeOfFacingModel AIS_InteractiveObject::CurrentFacingModel() const {
  return myCurrentFacingModel;
}
#endif

//=======================================================================
//function : SetColor
//purpose  : 
//=======================================================================

void AIS_InteractiveObject::SetColor(const Quantity_NameOfColor aColor)
#ifdef GER61351
{
  SetColor(Quantity_Color(aColor));
}

//=======================================================================
//function : SetColor
//purpose  : 
//=======================================================================

void AIS_InteractiveObject::SetColor(const Quantity_Color &aColor)
#endif
{
  myOwnColor = aColor;
  hasOwnColor = Standard_True;
}

//=======================================================================
//function : UnsetColor
//purpose  : 
//=======================================================================
void AIS_InteractiveObject::UnsetColor()
{
  hasOwnColor = Standard_False;
}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
void AIS_InteractiveObject::SetWidth(const Standard_Real aValue)
{
  myOwnWidth = aValue;
}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
void AIS_InteractiveObject::UnsetWidth()
{
  myOwnWidth = 0.;
}


//=======================================================================
//function : 
//purpose  : 
//=======================================================================
//POP pour K4L
void AIS_InteractiveObject::SetMaterial(const Graphic3d_NameOfMaterial aName)
//void AIS_InteractiveObject::SetMaterial(const Graphic3d_NameOfPhysicalMaterial aName)
{
  if( HasColor() || IsTransparent() || HasMaterial() )
    {
      myDrawer->ShadingAspect()->SetMaterial(aName);
    }
  else 
    {
      myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
      
      myDrawer->ShadingAspect()->SetMaterial(aName);
#ifndef BUC60577	//???
      myDrawer->ShadingAspect()->SetColor(AIS_GraphicTool::GetInteriorColor(myDrawer->Link()));
#endif
    }
  myOwnMaterial  = aName;
  hasOwnMaterial = Standard_True;
}
//=======================================================================
//function : SetMaterial
//purpose  : 
//=======================================================================

void AIS_InteractiveObject::SetMaterial(const Graphic3d_MaterialAspect& aMat)
{
#ifdef BUC60577
  if( HasColor() || IsTransparent() || HasMaterial() )
#else
  if(hasOwnColor ||(myTransparency==0.0) || hasOwnMaterial )
#endif
    {
      myDrawer->ShadingAspect()->SetMaterial(aMat);
    }
  else 
    {
      myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
      myDrawer->ShadingAspect()->SetMaterial(aMat);
    }
  hasOwnMaterial = Standard_True;
  
}
//=======================================================================
//function : 
//purpose  : 
//=======================================================================
void AIS_InteractiveObject::UnsetMaterial()
{
#ifdef BUC60577
  if( !HasMaterial() ) return;
  if( HasColor() || IsTransparent()) {
    myDrawer->ShadingAspect()->SetMaterial(
		AIS_GraphicTool::GetMaterial(myDrawer->Link()));
    if( HasColor() ) SetColor(myOwnColor);
    if( IsTransparent() ) SetTransparency(myTransparency);
  }
#else
  if(!hasOwnMaterial) return;
  if(hasOwnColor ||(myTransparency==0.0))
    {
      myDrawer->ShadingAspect()->SetMaterial(AIS_GraphicTool::GetMaterial(myDrawer->Link()));
    }
#endif
  else{
    Handle(Prs3d_ShadingAspect) SA;
    myDrawer->SetShadingAspect(SA);
  }
  hasOwnMaterial = Standard_False;
}

//=======================================================================
//function : SetTransparency
//purpose  : 
//=======================================================================
void AIS_InteractiveObject::SetTransparency(const Standard_Real aValue)
{

#ifdef BUC60577                     // Back & Front material can be different !

  if(!HasColor() && !IsTransparent() && !HasMaterial() ) {
        myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
      if(!myDrawer->Link().IsNull())
        myDrawer->ShadingAspect()->SetMaterial(AIS_GraphicTool::GetMaterial(myDrawer->Link()));
  }
  Graphic3d_MaterialAspect FMat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
  Graphic3d_MaterialAspect BMat = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
  FMat.SetTransparency(aValue); BMat.SetTransparency(aValue);
  myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(FMat);
  myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(BMat);
#else
  if(aValue<0.0 || aValue>1.0) return;
  
  if(aValue<=0.05) 
    {
      UnsetTransparency();
      return;
    }
  

  if(hasOwnColor || hasOwnMaterial || myTransparency> 0.0)
    {
      Graphic3d_MaterialAspect Mat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
      Mat.SetTransparency(aValue);
      myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(Mat);
      myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(Mat);
    }
  else
    {
      myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
      if(!myDrawer->Link().IsNull())
	myDrawer->ShadingAspect()->SetMaterial(AIS_GraphicTool::GetMaterial(myDrawer->Link()));
      Graphic3d_MaterialAspect Mat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
      Mat.SetTransparency(aValue);
      myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(Mat);
      myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(Mat);
    }
#endif
  myTransparency = aValue;
}

//=======================================================================
//function : UnsetTransparency
//purpose  : 
//=======================================================================
void AIS_InteractiveObject::UnsetTransparency()
{
#ifdef BUC60577                     // Back & Front material can be different !
    if(HasColor() || HasMaterial() )
    {
      Graphic3d_MaterialAspect FMat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
      Graphic3d_MaterialAspect BMat = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
      FMat.SetTransparency(0.); BMat.SetTransparency(0.);
      myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(FMat);
      myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(BMat);
    }
#else
    if(hasOwnColor || hasOwnMaterial )
    {
      Graphic3d_MaterialAspect Mat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
      Mat.SetTransparency(0.0);
//      myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(Mat);
//      myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(Mat);
       myDrawer->ShadingAspect()->SetMaterial(Mat);
    }
#endif
  else{
    Handle (Prs3d_ShadingAspect) SA;
    myDrawer->SetShadingAspect(SA);
  }
  myTransparency =0.0;
}
//=======================================================================
//function : Transparency
//purpose  : 
//=======================================================================
Standard_Real AIS_InteractiveObject::Transparency() const 
{
  return (myTransparency<=0.05 ? 0 : myTransparency);
// Graphic3d_MaterialAspect Mat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
// return Mat.Transparency();
}

//=======================================================================
//function : SetAttributes
//purpose  : 
//=======================================================================

void AIS_InteractiveObject::SetAttributes(const Handle(AIS_Drawer)& aDrawer)
{myDrawer = aDrawer;}


//=======================================================================
//function : UnsetAttributes
//purpose  : 
//=======================================================================
void AIS_InteractiveObject::UnsetAttributes()
{
  Handle(AIS_Drawer) dr = new AIS_Drawer();
  if(myDrawer->HasLink())
    dr->Link(myDrawer->Link());
  myDrawer       = dr;
  hasOwnColor    = Standard_False;
  hasOwnMaterial = Standard_False;
  myOwnWidth     = 0.0;
  myTransparency = 0.0;
}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
void AIS_InteractiveObject::MustRecomputePrs(const Standard_Integer ) const 
{}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
const TColStd_ListOfInteger& AIS_InteractiveObject::ListOfRecomputeModes() const 
{return myToRecomputeModes;}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
void AIS_InteractiveObject::SetRecomputeOk()
{myToRecomputeModes.Clear();}


//=======================================================================
//function : AcceptDisplayMode
//purpose  : 
//=======================================================================

Standard_Boolean  AIS_InteractiveObject::AcceptDisplayMode(const Standard_Integer ) const
{return Standard_True;}

//=======================================================================
//function : DefaultDisplayMode
//purpose  : 
//=======================================================================

Standard_Integer AIS_InteractiveObject::DefaultDisplayMode() const
{return 0;}


//=======================================================================
//function : SetInfiniteState
//purpose  : 
//=======================================================================
void AIS_InteractiveObject::SetInfiniteState(const Standard_Boolean aFlag)
{
  myInfiniteState = aFlag;
  Handle(Prs3d_Presentation) P;

  for(Standard_Integer i =1; i<=myPresentations.Length();i++){
    P = Handle(Prs3d_Presentation)::DownCast(myPresentations(i).Presentation());
    if(!P.IsNull())
      P->SetInfiniteState(myInfiniteState);}
}

#ifdef G003
//=======================================================================
//function : SetDegenerateModel
//purpose  : 
//=======================================================================
void AIS_InteractiveObject::SetDegenerateModel(
		const Aspect_TypeOfDegenerateModel aModel,
		const Quantity_Ratio aRatio ) {
  if( !HasColor() && !IsTransparent() && !HasMaterial() ) {
    myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
  }

  myDrawer->ShadingAspect()->Aspect()->SetDegenerateModel(aModel,aRatio);

  if(!GetContext().IsNull()){
    if( GetContext()->MainPrsMgr()->HasPresentation(this,1)){
      Handle(Prs3d_Presentation) P = 
	GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
      Handle(Graphic3d_AspectFillArea3d) a4bis = 
				myDrawer->ShadingAspect()->Aspect();
      P->SetPrimitivesAspect(a4bis);
    }
  }
}

//=======================================================================
//function : DegenerateModel
//purpose  : 
//=======================================================================

Aspect_TypeOfDegenerateModel AIS_InteractiveObject::DegenerateModel( 
			Quantity_Ratio& aRatio) const
{
  return myDrawer->ShadingAspect()->Aspect()->DegenerateModel(aRatio);
}
#endif

#ifdef IMP020200
//=======================================================================
//function : SetTransformation
//purpose  : 
//=======================================================================
void AIS_InteractiveObject::SetTransformation(const Handle(Geom_Transformation)& aTrsf, const Standard_Boolean postConcatenate, const Standard_Boolean updateSelection) {

  if(!GetContext().IsNull()){
    const PrsMgr_Presentations& prs = Presentations(); 
    Handle(Prs3d_Presentation) P;
    Standard_Integer mode;
    myHasTransformation = Standard_True;
    for( Standard_Integer i=1 ; i<=prs.Length() ; i++ ) {
      mode = prs(i).Mode();
      P = GetContext()->MainPrsMgr()->CastPresentation(this,mode)->Presentation();
      if( postConcatenate ) P->Multiply(aTrsf);
      else     	            P->Transform(aTrsf);
      if( updateSelection ) {
#ifdef IMP220501
        myCTXPtr->ClearSelected(Standard_True);
	myCTXPtr->RecomputeSelectionOnly(this);
#else
        if( HasSelection(mode) ) {
          UpdateSelection(mode);      
        }
#endif
      }
    }
  }
}

//=======================================================================
//function : SetTransformation
//purpose  : 
//=======================================================================
void AIS_InteractiveObject::UnsetTransformation() {
#ifdef OCC708
  static Handle(Geom_Transformation) trsf = new Geom_Transformation( gp_Trsf() );
#else
Handle(Geom_Transformation) trsf;
#endif

    SetTransformation(trsf);	// Set identity transformation
    myHasTransformation = Standard_False;
}

//=======================================================================
//function : Transformation
//purpose  : 
//=======================================================================
Handle(Geom_Transformation) AIS_InteractiveObject::Transformation() {
Handle(Geom_Transformation) trsf; 

  if(!GetContext().IsNull() ) {
    const PrsMgr_Presentations& prs = Presentations(); 
    if( prs.Length() > 0 ) {
      Handle(Prs3d_Presentation) P = 
	  GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
      trsf = P->Transformation();
    }
  }

  return trsf;
}

//=======================================================================
//function : HasTransformation
//purpose  : 
//=======================================================================
Standard_Boolean AIS_InteractiveObject::HasTransformation() const {

  return myHasTransformation;
}
#endif

#ifdef IMP140200
//=======================================================================
//function : HasPresentation
//purpose  : 
//=======================================================================
Standard_Boolean AIS_InteractiveObject::HasPresentation() const {

  if( !GetContext().IsNull() && 
	GetContext()->MainPrsMgr()->HasPresentation(this,myDisplayMode) ) {
    return Standard_True;
  }

  return Standard_False;
}

//=======================================================================
//function : Presentation
//purpose  : 
//=======================================================================
Handle(Prs3d_Presentation) AIS_InteractiveObject::Presentation() const {
Handle(Prs3d_Presentation) prs;

  if( HasPresentation() ) {
    prs = GetContext()->MainPrsMgr()->
		CastPresentation(this,myDisplayMode)->Presentation();
  }

  return prs;
}

//=======================================================================
//function : SetAspect 
//purpose  : 
//=======================================================================
void AIS_InteractiveObject::SetAspect(const Handle(Prs3d_BasicAspect)& anAspect,
				      const Standard_Boolean globalChange) {

  if( HasPresentation() ) {
    Handle(Prs3d_Presentation) prs = Presentation();
    { Handle(Prs3d_ShadingAspect) aspect =
			Handle(Prs3d_ShadingAspect)::DownCast(anAspect);
      if( !aspect.IsNull() ) {
        if( globalChange ) prs->SetPrimitivesAspect(aspect->Aspect());
        Prs3d_Root::CurrentGroup(prs)->SetGroupPrimitivesAspect(aspect->Aspect());
        return;
      }
    }
    { Handle(Prs3d_LineAspect) aspect =
			Handle(Prs3d_LineAspect)::DownCast(anAspect);
      if( !aspect.IsNull() ) {
        if( globalChange ) prs->SetPrimitivesAspect(aspect->Aspect());
        Prs3d_Root::CurrentGroup(prs)->SetGroupPrimitivesAspect(aspect->Aspect());
        return;
      }
    }
    { Handle(Prs3d_PointAspect) aspect =
			Handle(Prs3d_PointAspect)::DownCast(anAspect);
      if( !aspect.IsNull() ) {
        if( globalChange ) prs->SetPrimitivesAspect(aspect->Aspect());
        Prs3d_Root::CurrentGroup(prs)->SetGroupPrimitivesAspect(aspect->Aspect());
        return;
      }
    }
    { Handle(Prs3d_TextAspect) aspect =
			Handle(Prs3d_TextAspect)::DownCast(anAspect);
      if( !aspect.IsNull() ) {
        if( globalChange ) prs->SetPrimitivesAspect(aspect->Aspect());
        Prs3d_Root::CurrentGroup(prs)->SetGroupPrimitivesAspect(aspect->Aspect());
        return;
      }
    }
  }
}
#endif

// OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets

//=======================================================================
//function : SetPolygonOffsets 
//purpose  : 
//======================================================================= 
void AIS_InteractiveObject::SetPolygonOffsets(const Standard_Integer aMode,
                                              const Standard_Real    aFactor,
                                              const Standard_Real    aUnits) 
{
  if ( !HasPolygonOffsets() )
    myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());

  myDrawer->ShadingAspect()->Aspect()->SetPolygonOffsets( aMode, aFactor, aUnits );

  // Modify existing presentations 
  Handle(Graphic3d_Structure) aStruct;
  for( Standard_Integer i = 1, n = myPresentations.Length(); i <= n; i++ ) {
    Handle(PrsMgr_Presentation3d) aPrs3d =
      Handle(PrsMgr_Presentation3d)::DownCast( myPresentations(i).Presentation() );
    if ( !aPrs3d.IsNull() ) {
      aStruct = Handle(Graphic3d_Structure)::DownCast( aPrs3d->Presentation() );
      if( !aStruct.IsNull() )
        aStruct->SetPrimitivesAspect( myDrawer->ShadingAspect()->Aspect() );
    }
  }
}


//=======================================================================
//function : HasPolygonOffsets 
//purpose  : 
//=======================================================================
Standard_Boolean AIS_InteractiveObject::HasPolygonOffsets() const
{
  return !( myDrawer->ShadingAspect().IsNull() || 
          ( !myDrawer->Link().IsNull() && 
          myDrawer->ShadingAspect() == myDrawer->Link()->ShadingAspect() ) );
}

//=======================================================================
//function : PolygonOffsets 
//purpose  : 
//=======================================================================
void AIS_InteractiveObject::PolygonOffsets(Standard_Integer& aMode,
                                           Standard_Real&    aFactor,
                                           Standard_Real&    aUnits) const 
{
  if( HasPolygonOffsets() )
    myDrawer->ShadingAspect()->Aspect()->PolygonOffsets( aMode, aFactor, aUnits );
}

void AIS_InteractiveObject::Fill(const Handle(PrsMgr_PresentationManager)& aPresentationManager,
                                 const Handle(PrsMgr_Presentation)& aPresentation,
                                 const Standard_Integer aMode)
{
  PrsMgr_PresentableObject::Fill(aPresentationManager, aPresentation, aMode);

  // Update polygon offsets for <aPresentation> using <myDrawer> data
  if ( !myDrawer->ShadingAspect().IsNull() )
  {
    Standard_Integer aMode1 = Aspect_POM_Fill;
    Standard_Real aFactor = 1., aUnits = 0.;
    myDrawer->ShadingAspect()->Aspect()->PolygonOffsets( aMode1, aFactor, aUnits );

    // Here we force this object to have default polygon offsets , if they are not 
    // turned on for this object explicitly
    if ( ( aMode1 & Aspect_POM_None ) == Aspect_POM_None )
    {
      aMode1 = Aspect_POM_Fill;
      aFactor = 1.;
      aUnits = 0.;
      myDrawer->ShadingAspect()->Aspect()->SetPolygonOffsets( aMode1, aFactor, aUnits );
    }
  }

  Handle(PrsMgr_Presentation3d) aPrs3d =
    Handle(PrsMgr_Presentation3d)::DownCast( aPresentation );
  if ( !aPrs3d.IsNull() ) {
    Handle(Graphic3d_Structure) aStruct = 
      Handle(Graphic3d_Structure)::DownCast( aPrs3d->Presentation() );
    if( !aStruct.IsNull() )
      aStruct->SetPrimitivesAspect( myDrawer->ShadingAspect()->Aspect() );
  }
}
// OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets