0022627: Change OCCT memory management defaults
[occt.git] / src / TPrsStd / TPrsStd_AISPresentation.cxx
1 // Created:     Wed Sep 30 08:50:34 1998
2 // Author:      Sergey RUIN
3 //              <srn@popox.nnov.matra-dtv.fr>
4
5
6
7 // Lastly modified by :
8 // +---------------------------------------------------------------------------+
9 // !      ivan ! SetMode                                 ! 5-04-2001! 3.0-00-1!
10 // +---------------------------------------------------------------------------+
11 #include <TPrsStd_AISPresentation.ixx>
12
13 #include <TDF_DefaultDeltaOnRemoval.hxx>
14 #include <TDF_DefaultDeltaOnModification.hxx>
15 #include <TDF_DeltaOnAddition.hxx>
16 #include <TDF_Tool.hxx>
17 #include <TCollection_ExtendedString.hxx>
18 #include <TPrsStd_AISViewer.hxx>
19 #include <AIS_InteractiveContext.hxx>
20 #include <AIS_InteractiveObject.hxx>
21 #include <TPrsStd_Driver.hxx>
22 #include <TPrsStd_DriverTable.hxx>
23
24
25 #define BUC60917
26 #define BUC61050
27
28 #define OCC1029
29 #define OCC1030
30 #define OCC1031
31 #define OCC1032
32 #define OCC1033
33 #define OCC1034
34
35 //=======================================================================
36 //function : Set
37 //purpose  : 
38 //=======================================================================
39 Handle(TPrsStd_AISPresentation) TPrsStd_AISPresentation::Set(const TDF_Label& L,const Standard_GUID& driver) 
40 {   
41
42   Handle(TPrsStd_AISPresentation) P; 
43
44   if (!L.FindAttribute(TPrsStd_AISPresentation::GetID(),P)) { 
45     P = new TPrsStd_AISPresentation ();  
46     L.AddAttribute(P);
47   }
48   P->SetDriverGUID(driver);   
49   return P;
50 }
51
52
53 //=======================================================================
54 //function : Unset
55 //purpose  : 
56 //=======================================================================
57 void TPrsStd_AISPresentation::Unset (const TDF_Label& L)
58 {   
59   Handle(TPrsStd_AISPresentation) P;  
60
61   if (L.FindAttribute(TPrsStd_AISPresentation::GetID(),P)) { 
62     L.ForgetAttribute(P);
63   }
64 }
65
66
67 //=======================================================================
68 //function : Set
69 //purpose  : 
70 //=======================================================================
71 Handle(TPrsStd_AISPresentation) TPrsStd_AISPresentation::Set (const Handle(TDF_Attribute)& master) 
72 {  
73   Handle(TPrsStd_AISPresentation) P;  
74
75   if (!master->Label().FindAttribute(TPrsStd_AISPresentation::GetID(),P)) { 
76     P = new TPrsStd_AISPresentation ();  
77     master->Label().AddAttribute(P);
78   }   
79
80   P->SetDriverGUID( master->ID() );
81
82   return P;
83 }
84
85
86
87
88 //=======================================================================
89 //function : GetID
90 //purpose  : 
91 //=======================================================================
92 const Standard_GUID& TPrsStd_AISPresentation::GetID() 
93 {
94   static Standard_GUID TPrsStd_AISPresentationID("04fb4d00-5690-11d1-8940-080009dc3333");
95   return TPrsStd_AISPresentationID;
96 }
97
98
99 //=======================================================================
100 //function : TPrsStd_AISPresentation
101 //purpose  : 
102 //=======================================================================
103 TPrsStd_AISPresentation::TPrsStd_AISPresentation () : 
104 myDriverGUID("00000000-0000-0000-0000-000000000000"),
105 myTransparency(0.),
106 myColor(Quantity_NOC_WHITE),
107 myMaterial(Graphic3d_NOM_BRASS),
108 myWidth(0.),
109 #ifdef BUC61050
110 myMode(0),
111 mySelectionMode(0),
112 #endif
113 isDisplayed(Standard_False),
114 hasOwnColor(Standard_False),
115 hasOwnMaterial(Standard_False),
116 hasOwnTransparency(Standard_False),
117 hasOwnWidth(Standard_False)
118 #ifdef BUC61050
119 ,hasOwnMode(Standard_False),
120 hasOwnSelectionMode(Standard_False)
121 #endif
122 {}
123
124
125 //=======================================================================
126 //function : Display
127 //purpose  : 
128 //=======================================================================
129 void TPrsStd_AISPresentation::Display (const Standard_Boolean update)
130 {
131    
132   if( update || myAIS.IsNull() ) {
133     AISUpdate();
134   }
135   AISDisplay();     
136 }
137
138
139 //=======================================================================
140 //function : Erase
141 //purpose  : 
142 //=======================================================================
143 void TPrsStd_AISPresentation::Erase (const Standard_Boolean remove)
144 {  
145   if( isDisplayed ) AISErase(remove);   
146 }
147
148 //=======================================================================
149 //function : Update
150 //purpose  : 
151 //=======================================================================
152 void  TPrsStd_AISPresentation::Update ()
153 {  
154   AISUpdate();
155 }
156
157
158 //=======================================================================
159 //function : IsDisplayed
160 //purpose  : 
161 //=======================================================================
162 Standard_Boolean TPrsStd_AISPresentation::IsDisplayed () const
163 {
164   return isDisplayed;
165 }
166
167
168 //=======================================================================
169 //function :SetDriverGUID
170 //purpose  : 
171 //=======================================================================
172 void TPrsStd_AISPresentation::SetDriverGUID(const Standard_GUID& guid) 
173 {
174   // OCC2932 correction
175   if(myDriverGUID == guid) return;
176
177   Backup(); 
178   myDriverGUID = guid;
179 }
180
181
182 //=======================================================================
183 //function :GetDriverGUID
184 //purpose  : 
185 //=======================================================================
186 Standard_GUID TPrsStd_AISPresentation::GetDriverGUID() const
187 {
188   return myDriverGUID;
189 }
190
191
192 //=======================================================================
193 //function :Material
194 //purpose  : 
195 //=======================================================================
196 Graphic3d_NameOfMaterial TPrsStd_AISPresentation::Material() const
197 {
198   return myMaterial; 
199 }
200
201 //=======================================================================
202 //function :HasMaterial
203 //purpose  : 
204 //=======================================================================
205 Standard_Boolean TPrsStd_AISPresentation::HasOwnMaterial() const
206 {
207   return hasOwnMaterial;
208 }
209
210 //=======================================================================
211 //function :UnsetMaterial
212 //purpose  : 
213 //=======================================================================
214 void TPrsStd_AISPresentation::UnsetMaterial()
215 {
216   // OCC2932 correction
217   if(hasOwnMaterial == Standard_False && !myAIS.IsNull()) {
218       if(!myAIS->HasMaterial())
219         return;
220   }
221     
222   Backup();
223   hasOwnMaterial = Standard_False;
224   if( myAIS.IsNull() ) AISUpdate();
225   if( !myAIS.IsNull() &&  myAIS->HasMaterial() ) {
226     Handle(AIS_InteractiveContext) ctx;
227     Handle(TPrsStd_AISViewer) viewer;
228     if( TPrsStd_AISViewer::Find(Label(), viewer) ) ctx = viewer->GetInteractiveContext(); 
229     if( !ctx.IsNull() )   
230       ctx->UnsetMaterial(myAIS, Standard_False);
231     else  
232       myAIS->UnsetMaterial();
233   }
234 }
235
236 //=======================================================================
237 //function :SetMaterial
238 //purpose  : 
239 //=======================================================================
240 void TPrsStd_AISPresentation::SetMaterial(const Graphic3d_NameOfMaterial aName) 
241 {
242   // OCC2932 correction
243   if(myMaterial == aName && hasOwnMaterial == Standard_True && !myAIS.IsNull()) {
244       if(myAIS->HasMaterial() && myAIS->Material() == aName)
245         return;
246   }
247
248   Backup();
249   myMaterial = aName;
250   hasOwnMaterial = Standard_True;
251   if( myAIS.IsNull() ) AISUpdate();
252   if( !myAIS.IsNull() ) { 
253     if( myAIS->HasMaterial() && myAIS->Material() == aName ) return;   // AIS has already had that material     
254     Handle(AIS_InteractiveContext) ctx;
255     Handle(TPrsStd_AISViewer) viewer;
256     if( TPrsStd_AISViewer::Find(Label(), viewer) ) ctx = viewer->GetInteractiveContext(); 
257     if( !ctx.IsNull() )   
258       ctx->SetMaterial(myAIS, aName,  Standard_False);
259     else  
260       myAIS->SetMaterial(aName);
261   }
262 }
263
264
265 //=======================================================================
266 //function :SetTransparency
267 //purpose  : 
268 //=======================================================================
269 void TPrsStd_AISPresentation::SetTransparency(const Standard_Real aValue) 
270 {
271   // OCC2932 correction
272   if(hasOwnTransparency == Standard_True && myTransparency == aValue && !myAIS.IsNull())
273       if(myAIS->Transparency() == aValue)
274         return;
275
276   Backup();
277   myTransparency = aValue;
278   hasOwnTransparency = Standard_True;
279   if( myAIS.IsNull() ) AISUpdate(); 
280   if( !myAIS.IsNull() ) { 
281     if( myAIS->Transparency() == aValue ) return;   // AIS has already had that transparency 
282     Handle(AIS_InteractiveContext) ctx;
283     Handle(TPrsStd_AISViewer) viewer;
284     if( TPrsStd_AISViewer::Find(Label(), viewer) ) ctx = viewer->GetInteractiveContext();
285     if( !ctx.IsNull() )  
286       ctx->SetTransparency(myAIS, aValue, Standard_False);
287     else 
288       myAIS->SetTransparency(aValue);
289   }
290 }
291
292
293 //=======================================================================
294 //function :Transparency
295 //purpose  : 
296 //=======================================================================
297 Standard_Real TPrsStd_AISPresentation::Transparency() const
298 {
299   return myTransparency;
300 }
301
302 //=======================================================================
303 //function :UnsetTransparency
304 //purpose  : 
305 //=======================================================================
306 void TPrsStd_AISPresentation::UnsetTransparency()
307 {
308   // OCC2932 correction
309   if(!hasOwnTransparency)
310     return;
311
312   Backup(); 
313   hasOwnTransparency = Standard_False;
314   if( myAIS.IsNull() ) AISUpdate();
315   if( !myAIS.IsNull() ) {
316     Handle(AIS_InteractiveContext) ctx;
317     Handle(TPrsStd_AISViewer) viewer;
318     if( TPrsStd_AISViewer::Find(Label(), viewer) ) ctx = viewer->GetInteractiveContext(); 
319     if( !ctx.IsNull() )   
320       ctx->UnsetTransparency(myAIS, Standard_False);
321     else  
322       myAIS->UnsetTransparency();
323   }
324 }
325
326 //=======================================================================
327 //function :HasTransparency
328 //purpose  : 
329 //=======================================================================
330 Standard_Boolean TPrsStd_AISPresentation::HasOwnTransparency() const
331 {
332   return hasOwnTransparency;
333 }
334
335 //=======================================================================
336 //function :Color
337 //purpose  : 
338 //=======================================================================
339 Quantity_NameOfColor TPrsStd_AISPresentation::Color() const
340 {
341   return myColor;
342 }
343
344 //=======================================================================
345 //function :HasColor
346 //purpose  : 
347 //=======================================================================
348 Standard_Boolean TPrsStd_AISPresentation::HasOwnColor() const
349 {
350   return hasOwnColor;
351 }
352
353 //=======================================================================
354 //function :UnsetColor
355 //purpose  : 
356 //=======================================================================
357 void TPrsStd_AISPresentation::UnsetColor()
358 {
359   // OCC2932 correction
360   if(!hasOwnColor && !myAIS.IsNull()) 
361       if(!myAIS->HasColor())
362         return;
363   
364   Backup();
365   hasOwnColor = Standard_False;
366   if( myAIS.IsNull() ) AISUpdate();
367   if( !myAIS.IsNull() &&  myAIS->HasColor() ) {
368     Handle(AIS_InteractiveContext) ctx;
369     Handle(TPrsStd_AISViewer) viewer;
370     if( TPrsStd_AISViewer::Find(Label(), viewer) ) ctx = viewer->GetInteractiveContext(); 
371     if( !ctx.IsNull() )   
372       ctx->UnsetColor(myAIS, Standard_False);
373     else  
374       myAIS->UnsetColor();
375   }
376 }
377
378 //=======================================================================
379 //function :SetColor
380 //purpose  : 
381 //=======================================================================
382 void TPrsStd_AISPresentation::SetColor(const Quantity_NameOfColor aColor) 
383 {
384   // OCC2932 correction
385   if(hasOwnColor && myColor == aColor && ! myAIS.IsNull()) 
386     if(myAIS->HasColor() && myAIS->Color() == aColor ) 
387       return;
388   
389   Backup();
390   myColor = aColor;
391   hasOwnColor = Standard_True;
392   if( myAIS.IsNull() ) AISUpdate();
393   if( !myAIS.IsNull() ) {
394     if( myAIS->HasColor() && myAIS->Color() == aColor ) return;   // AIS has already had that color     
395     Handle(AIS_InteractiveContext) ctx;
396     Handle(TPrsStd_AISViewer) viewer;
397     if( TPrsStd_AISViewer::Find(Label(), viewer) ) ctx = viewer->GetInteractiveContext();
398     if( !ctx.IsNull() )  
399       ctx->SetColor(myAIS, aColor, Standard_False);
400     else 
401       myAIS->SetColor(aColor);
402   }
403 }
404
405
406 //=======================================================================
407 //function :Width
408 //purpose  : 
409 //=======================================================================
410 Standard_Real TPrsStd_AISPresentation::Width() const
411 {
412    return myWidth;
413 }
414
415 //=======================================================================
416 //function :HasWidth
417 //purpose  : 
418 //=======================================================================
419 Standard_Boolean TPrsStd_AISPresentation::HasOwnWidth() const
420 {
421   return hasOwnWidth;
422 }
423
424 //=======================================================================
425 //function :SetWidth
426 //purpose  : 
427 //=======================================================================
428 void TPrsStd_AISPresentation::SetWidth(const Standard_Real aWidth) 
429 {
430   // OCC2932 correction
431   if(hasOwnWidth && myWidth == aWidth && myAIS.IsNull()) 
432     if(myAIS->HasWidth() && myAIS->Width() == aWidth ) 
433       return;
434
435   Backup();
436   myWidth = aWidth;
437   hasOwnWidth = Standard_True;
438   if( myAIS.IsNull() ) AISUpdate();
439   if( !myAIS.IsNull() ) {
440     if( myAIS->HasWidth() && myAIS->Width() == aWidth ) return;   // AIS has already had that width     
441     Handle(AIS_InteractiveContext) ctx;
442     Handle(TPrsStd_AISViewer) viewer;
443     if( TPrsStd_AISViewer::Find(Label(), viewer) ) ctx = viewer->GetInteractiveContext();
444     if( !ctx.IsNull() )  
445       ctx->SetWidth(myAIS, aWidth, Standard_False);
446     else 
447       myAIS->SetWidth(aWidth);
448   }
449 }
450
451 //=======================================================================
452 //function :UnsetWidth
453 //purpose  : 
454 //=======================================================================
455 void TPrsStd_AISPresentation::UnsetWidth()
456 {
457   // OCC2932 correction
458   if(!hasOwnWidth && !myAIS.IsNull())
459     if(!myAIS->HasWidth())
460       return;
461
462   Backup();
463   hasOwnWidth = Standard_False;
464   if( myAIS.IsNull() ) AISUpdate();
465   if( !myAIS.IsNull() &&  myAIS->HasWidth() ) {
466     Handle(AIS_InteractiveContext) ctx;
467     Handle(TPrsStd_AISViewer) viewer;
468     if( TPrsStd_AISViewer::Find(Label(), viewer) ) ctx = viewer->GetInteractiveContext(); 
469     if( !ctx.IsNull() )   
470       ctx->UnsetWidth(myAIS, Standard_False);
471     else  
472       myAIS->UnsetWidth();
473   }
474 }
475
476
477
478 //=======================================================================
479 //function : Mode
480 //purpose  : 
481 //=======================================================================
482
483 Standard_Integer TPrsStd_AISPresentation::Mode() const
484 {
485    return myMode;
486 }
487
488 //=======================================================================
489 //function :HasOwnMode
490 //purpose  : 
491 //=======================================================================
492 Standard_Boolean TPrsStd_AISPresentation::HasOwnMode() const
493 {
494   return hasOwnMode;
495 }
496
497 //=======================================================================
498 //function :SetMode
499 //purpose  : 
500 //=======================================================================
501 void TPrsStd_AISPresentation::SetMode(const Standard_Integer theMode) 
502 {
503   // OCC2932 correction
504   if(hasOwnMode && myMode == theMode && !myAIS.IsNull()) 
505     if(myAIS->DisplayMode() == theMode ) 
506       return;
507
508   Backup();
509   myMode = theMode;
510   hasOwnMode = Standard_True;
511   if( myAIS.IsNull() ) AISUpdate();
512   if( !myAIS.IsNull() ) {
513     if(  myAIS->DisplayMode() == theMode ) return;   // AIS has already had that mode    
514     Handle(AIS_InteractiveContext) ctx;
515     Handle(TPrsStd_AISViewer) viewer;
516     if( TPrsStd_AISViewer::Find(Label(), viewer) )
517       ctx = viewer->GetInteractiveContext();
518     if( !ctx.IsNull() )  
519       ctx->SetDisplayMode(myAIS, theMode, Standard_False);
520     else 
521       myAIS->SetDisplayMode(theMode);
522   }
523 }
524
525 //=======================================================================
526 //function :UnsetMode
527 //purpose  : 
528 //=======================================================================
529 void TPrsStd_AISPresentation::UnsetMode()
530 {
531   // OCC2932 correction
532   if(HasOwnMode() == Standard_False && myAIS.IsNull() == Standard_False)
533     if(!myAIS->HasDisplayMode())
534       return;
535
536   Backup();
537   hasOwnMode = Standard_False;
538   if( myAIS.IsNull() ) AISUpdate();
539   if( !myAIS.IsNull() &&  myAIS->HasDisplayMode() ) {
540         Handle(AIS_InteractiveContext) ctx;
541         Handle(TPrsStd_AISViewer) viewer;
542         if( TPrsStd_AISViewer::Find(Label(), viewer) )
543         ctx = viewer->GetInteractiveContext(); 
544         if( !ctx.IsNull() )
545         ctx->UnsetDisplayMode(myAIS, Standard_False);
546     else  
547         myAIS->UnsetDisplayMode();
548   }
549 }
550
551 #ifdef BUC61050
552 //=======================================================================
553 //function : SelectionMode
554 //purpose  : 
555 //=======================================================================
556
557 Standard_Integer TPrsStd_AISPresentation::SelectionMode() const
558 {
559    return mySelectionMode;
560 }
561
562 //=======================================================================
563 //function :HasOwnSelectionMode
564 //purpose  : 
565 //=======================================================================
566 Standard_Boolean TPrsStd_AISPresentation::HasOwnSelectionMode() const
567 {
568   return hasOwnSelectionMode;
569 }
570
571 //=======================================================================
572 //function :SetSelectionMode
573 //purpose  : 
574 //=======================================================================
575 void TPrsStd_AISPresentation::SetSelectionMode(const Standard_Integer theSelectionMode) 
576 {
577   // OCC2932 correction
578   if(hasOwnSelectionMode && mySelectionMode == theSelectionMode && !myAIS.IsNull())
579     if(myAIS->SelectionMode() == theSelectionMode )
580       return;
581
582   Backup();
583   mySelectionMode = theSelectionMode;
584   hasOwnSelectionMode = Standard_True;
585   if( myAIS.IsNull() ) AISUpdate();
586   if( !myAIS.IsNull() ) {
587     if(  myAIS->SelectionMode() == theSelectionMode ) return;
588     myAIS->SetSelectionMode(theSelectionMode);
589   }
590 }
591
592 //=======================================================================
593 //function :UnsetSelectionMode
594 //purpose  : 
595 //=======================================================================
596 void TPrsStd_AISPresentation::UnsetSelectionMode()
597 {
598   if(!hasOwnSelectionMode && !myAIS.IsNull())
599     if(!myAIS->HasSelectionMode())
600       return;
601
602   Backup();
603   hasOwnSelectionMode = Standard_False;
604   if( myAIS.IsNull() ) AISUpdate();
605   if( !myAIS.IsNull() &&  myAIS->HasSelectionMode() ) {
606     myAIS->UnsetSelectionMode();
607   }
608 }
609 #endif
610
611
612 //=======================================================================
613 //function : ID
614 //purpose  : 
615 //=======================================================================
616 const Standard_GUID& TPrsStd_AISPresentation::ID() const { return GetID(); }
617
618
619 //=======================================================================
620 //function : BackupCopy
621 //purpose  : 
622 //=======================================================================
623 Handle(TDF_Attribute) TPrsStd_AISPresentation::BackupCopy() const 
624 {
625   Handle(TPrsStd_AISPresentation) copy = new TPrsStd_AISPresentation;
626   copy->myTransparency = myTransparency;
627   copy->myColor = myColor;
628   copy->myMode= myMode;
629 #ifdef BUC60917
630   copy->myWidth= myWidth;
631 #endif
632   copy->myMaterial = myMaterial;
633   copy->hasOwnColor = hasOwnColor;
634   copy->hasOwnMaterial = hasOwnMaterial;
635   copy->hasOwnWidth = hasOwnWidth;
636   copy->hasOwnMode=hasOwnMode;
637   copy->hasOwnTransparency = hasOwnTransparency;
638   copy->myAIS.Nullify();
639   copy->isDisplayed = isDisplayed;
640   copy->myDriverGUID = myDriverGUID;
641 #ifdef BUC61050
642   copy->mySelectionMode= mySelectionMode;
643   copy->hasOwnSelectionMode = hasOwnSelectionMode;
644 #endif
645   return copy; 
646 }
647
648
649 //=======================================================================
650 //function : NewEmpty
651 //purpose  : 
652 //=======================================================================
653 Handle(TDF_Attribute) TPrsStd_AISPresentation::NewEmpty() const
654 {   
655   return new TPrsStd_AISPresentation ();
656 }
657
658 //=======================================================================
659 //function : Restore
660 //purpose  : 
661 //=======================================================================
662 void TPrsStd_AISPresentation::Restore (const Handle(TDF_Attribute)& With) 
663
664   Handle(TPrsStd_AISPresentation) with = Handle(TPrsStd_AISPresentation)::DownCast(With);
665
666   myAIS.Nullify();
667
668   if(!with->HasOwnMaterial()) hasOwnMaterial = Standard_False;
669   else { 
670 #ifndef OCC1031
671     myMaterial = with->Material();
672 #endif
673     hasOwnMaterial = Standard_True;
674   }
675 #ifdef OCC1031
676   myMaterial = with->Material();
677 #endif
678
679   if(!with->HasOwnColor()) hasOwnColor = Standard_False;
680   else { 
681 #ifndef OCC1030
682     myColor = with->Color(); 
683 #endif
684     hasOwnColor = Standard_True;
685   }
686 #ifdef OCC1030
687   myColor = with->Color(); 
688 #endif
689
690   if(!with->HasOwnWidth()) hasOwnWidth = Standard_False;
691   else { 
692 #ifndef OCC1032
693     myWidth = with->Width();
694 #endif
695     hasOwnWidth = Standard_True;
696   }
697 #ifdef OCC1032
698   myWidth = with->Width();
699 #endif
700
701  if(!with->HasOwnMode()) hasOwnMode = Standard_False;
702   else { 
703 #ifndef OCC1033
704     myMode = with->Mode();
705 #endif
706     hasOwnMode = Standard_True;
707   }
708 #ifdef OCC1033
709   myMode = with->Mode();
710 #endif
711   
712 #ifdef BUC61050
713   if(!with->HasOwnSelectionMode()) hasOwnSelectionMode = Standard_False;
714   else { 
715 #ifndef OCC1034
716     mySelectionMode = with->SelectionMode();
717 #endif
718     hasOwnSelectionMode = Standard_True;
719   }
720 #ifdef OCC1034
721   mySelectionMode = with->SelectionMode();
722 #endif
723 #endif
724
725   if(!with->HasOwnTransparency()) hasOwnTransparency = Standard_False;
726   else { 
727 #ifndef OCC1029
728     myTransparency = with->Transparency();
729 #endif
730     hasOwnTransparency = Standard_True;
731   }
732 #ifdef OCC1029
733   myTransparency = with->Transparency();
734 #endif
735
736   isDisplayed = with->IsDisplayed();
737   myDriverGUID  = with->GetDriverGUID();
738 }
739
740 //=======================================================================
741 //function : Paste
742 //purpose  : 
743 //=======================================================================
744 void TPrsStd_AISPresentation::Paste (const Handle(TDF_Attribute)& Into,
745                                      const Handle(TDF_RelocationTable)& ) const
746 {  
747   Handle(TPrsStd_AISPresentation) into = Handle(TPrsStd_AISPresentation)::DownCast(Into);
748   
749   into->Backup();
750
751   if(!hasOwnMaterial) into->hasOwnMaterial = Standard_False;
752   else {
753     into->myMaterial = myMaterial;
754     into->hasOwnMaterial = Standard_True;
755   }
756
757   if(!hasOwnColor) into->hasOwnColor = Standard_False;
758   else {
759     into->myColor = myColor; 
760     into->hasOwnColor = Standard_True;
761   }
762
763   if(!hasOwnWidth) into->hasOwnWidth = Standard_False;
764   else {
765     into->myWidth = myWidth;
766     into->hasOwnWidth = Standard_True;
767   }
768  if(!hasOwnMode) into->hasOwnMode = Standard_False;
769   else {
770     into->myMode = myMode;
771     into->hasOwnMode = Standard_True;
772   }
773
774 #ifdef BUC61050
775  if(!hasOwnSelectionMode) into->hasOwnSelectionMode = Standard_False;
776   else {
777     into->mySelectionMode = mySelectionMode;
778     into->hasOwnSelectionMode = Standard_True;
779   }
780 #endif
781
782   if(!hasOwnTransparency) into->hasOwnTransparency = Standard_False;
783   else {
784     into->myTransparency = myTransparency;
785     into->hasOwnTransparency = Standard_True;
786   }
787
788   if (into->isDisplayed)
789     into->AISErase(Standard_True);
790
791   into->isDisplayed = isDisplayed;   
792   into->myDriverGUID = myDriverGUID;
793
794   into->myAIS.Nullify();
795 }
796
797 //=======================================================================
798 //function : AfterAddition
799 //purpose  : erase if displayed
800 //=======================================================================
801 void TPrsStd_AISPresentation::AfterAddition() 
802
803   AfterResume();
804 }
805
806 //=======================================================================
807 //function : BeforeRemoval
808 //purpose  : erase if displayed
809 //=======================================================================
810 void TPrsStd_AISPresentation::BeforeRemoval() 
811
812    BeforeForget();
813 }
814
815 //=======================================================================
816 //function : BeforeForget
817 //purpose  : erase if displayed
818 //=======================================================================
819 void TPrsStd_AISPresentation::BeforeForget() 
820
821   if( !myAIS.IsNull() ) {
822     AISErase(Standard_True);   //Remove AISObject from context
823     myAIS.Nullify();
824   }
825 }
826
827
828 //=======================================================================
829 //function : AfterResume
830 //purpose  : display if displayed
831 //=======================================================================
832 void TPrsStd_AISPresentation::AfterResume() 
833 {
834   AISUpdate();
835   if( IsDisplayed() ) AISDisplay();
836   else AISErase();
837 }
838
839 //=======================================================================
840 //function : BeforeUndo
841 //purpose  : le NamedShape associe doit etre present
842 //=======================================================================
843
844 Standard_Boolean TPrsStd_AISPresentation::BeforeUndo (const Handle(TDF_AttributeDelta)& AD,
845                                                       const Standard_Boolean ) 
846 {
847   Handle(TPrsStd_AISPresentation) P;
848   AD->Label().FindAttribute(TPrsStd_AISPresentation::GetID(), P); 
849
850   if (AD->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) {    
851     if( !P.IsNull() ) P->BeforeForget();
852   }
853   else if (AD->IsKind(STANDARD_TYPE(TDF_DefaultDeltaOnRemoval))) {
854   }  
855   else if (AD->IsKind(STANDARD_TYPE(TDF_DefaultDeltaOnModification))) {
856     if( !P.IsNull() ) P->BeforeForget();
857   } 
858
859   return Standard_True;
860 }
861
862
863 //=======================================================================
864 //function : AfterUndo
865 //purpose  : le NamedShape associe doit etre present
866 //=======================================================================
867
868 Standard_Boolean TPrsStd_AISPresentation::AfterUndo (const Handle(TDF_AttributeDelta)& AD,
869                                                      const Standard_Boolean ) 
870
871   Handle(TPrsStd_AISPresentation) P;
872   AD->Label().FindAttribute(TPrsStd_AISPresentation::GetID(), P);
873
874   if (AD->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) {
875   }
876   else if (AD->IsKind(STANDARD_TYPE(TDF_DefaultDeltaOnRemoval))) {  
877     if( !P.IsNull() ) P->AfterAddition();
878   }  
879   else if (AD->IsKind(STANDARD_TYPE(TDF_DefaultDeltaOnModification))) {
880     if( !P.IsNull() ) P->AfterResume();
881   }
882
883   return Standard_True;
884 }
885
886
887
888 //=======================================================================
889 //function : AISUpdate
890 //purpose  : 
891 //=======================================================================
892
893 void TPrsStd_AISPresentation::AISUpdate ()
894
895   Backup();
896
897   Handle(AIS_InteractiveContext) ctx;
898   if(!Label().IsNull()) {  
899     Handle(TPrsStd_AISViewer) viewer;
900     if( TPrsStd_AISViewer::Find(Label(), viewer) ) ctx = viewer->GetInteractiveContext();
901
902     Handle(TPrsStd_Driver) driver;
903     if (TPrsStd_DriverTable::Get()->FindDriver(GetDriverGUID(), driver)) {
904       if (myAIS.IsNull()) {              // build a new  AIS
905         Handle(AIS_InteractiveObject) newais;
906         if (driver->Update (Label(), newais))  {
907           myAIS = newais;
908           newais->SetOwner(this);
909         }
910       }
911       else {
912         Handle(AIS_InteractiveObject) theais = myAIS;
913         if (driver->Update (Label(), theais)) {
914           if (! (theais ==  myAIS)) {    
915             if(!ctx.IsNull()) ctx->Remove(myAIS);
916             myAIS = theais;               //Driver has built new AIS
917             theais->SetOwner(this);
918           }
919         }
920       }
921     }
922   }
923   else return;
924
925 //Apply the visualization settings
926   if( !myAIS.IsNull() ) {
927
928     if( hasOwnColor ) { 
929       if( !(myAIS->HasColor()) || (myAIS->HasColor() && myAIS->Color() != myColor) ) {
930         if(!ctx.IsNull()) ctx->SetColor(myAIS, myColor, Standard_False);
931         else myAIS->SetColor(myColor);  
932       }
933     } 
934
935     if( hasOwnMaterial ) { 
936       if( !(myAIS->HasMaterial()) || (myAIS->HasMaterial() && myAIS->Material() != myMaterial) ) {
937         if(!ctx.IsNull()) ctx->SetMaterial(myAIS, myMaterial, Standard_False );
938         else myAIS->SetMaterial(myMaterial);  
939       }
940     } 
941     
942     if( hasOwnTransparency ) {
943       if(  myAIS->Transparency() != myTransparency )  {
944         if(!ctx.IsNull()) ctx->SetTransparency(myAIS, myTransparency, Standard_False);
945         else myAIS->SetTransparency(myTransparency);  
946       }
947     }
948
949     if( hasOwnWidth ) { 
950       if( !(myAIS->HasWidth()) || (myAIS->HasWidth() && myAIS->Width() != myWidth) ) {
951         if(!ctx.IsNull()) ctx->SetWidth(myAIS, myWidth, Standard_False);
952         else myAIS->SetWidth(myWidth); 
953       }
954     }
955
956     if( hasOwnMode) { 
957       if(  myAIS->DisplayMode() != myMode ) {
958           myAIS->SetDisplayMode(myMode); 
959       } 
960      
961            
962     }
963
964 #ifdef BUC61050
965     if (hasOwnSelectionMode) { 
966       if (myAIS->SelectionMode() != mySelectionMode ) {
967         myAIS->SetSelectionMode(mySelectionMode); 
968       } 
969     }
970 #endif
971
972   }
973   
974   if( isDisplayed && !ctx.IsNull() ) ctx->Redisplay(myAIS, Standard_False);
975  
976   return;
977 }
978
979 //=======================================================================
980 //function : AISDisplay
981 //purpose  : 
982 //=======================================================================
983
984 void TPrsStd_AISPresentation::AISDisplay ()
985 {   
986   
987   if (!Label().IsNull()) {  
988     Handle(TPrsStd_AISViewer) viewer;
989     if( !TPrsStd_AISViewer::Find(Label(), viewer) ) return;   
990     Handle(AIS_InteractiveContext) ctx = viewer->GetInteractiveContext();
991     if( ctx.IsNull() ) return;
992
993     if (!myAIS.IsNull()) { 
994
995       if( !(myAIS->GetContext()).IsNull() && (myAIS->GetContext()) != ctx ) myAIS->GetContext()->Remove(myAIS);
996       
997       if( isDisplayed && ctx->IsDisplayed(myAIS) ) return;
998
999       ctx->Display(myAIS, Standard_False);
1000       
1001       if( ctx->IsDisplayed(myAIS) ) SetDisplayed(Standard_True); 
1002     }
1003   }
1004 }
1005
1006
1007 //=======================================================================
1008 //function : AISErase
1009 //purpose  : 
1010 //=======================================================================
1011
1012 void TPrsStd_AISPresentation::AISErase (const Standard_Boolean remove)
1013 {   
1014   SetDisplayed(Standard_False);  
1015   Handle(AIS_InteractiveContext) ctx, ownctx;
1016
1017   if ( !myAIS.IsNull() ) {   
1018     ownctx = myAIS->GetContext();
1019     if ( !Label().IsNull()) {  
1020       Handle(TPrsStd_AISViewer) viewer;
1021       if( !TPrsStd_AISViewer::Find(Label(), viewer) ) return;   
1022       ctx = viewer->GetInteractiveContext();
1023       if( remove ) {
1024         if( !ctx.IsNull() ) ctx->Remove (myAIS,Standard_False); 
1025         if( !ownctx.IsNull() && ownctx != ctx ) ownctx->Remove (myAIS,Standard_False);
1026         myAIS->SetToUpdate();
1027       }
1028       else {
1029         if( !ctx.IsNull() ) ctx->Erase (myAIS,Standard_False); 
1030         if( !ownctx.IsNull() && ownctx != ctx ) ownctx->Erase (myAIS,Standard_False);
1031       }
1032     }
1033     else {
1034      if( remove ) {
1035       if( !ownctx.IsNull() ) {
1036         ownctx->Remove (myAIS,Standard_False);
1037         myAIS->SetToUpdate();
1038       }
1039      } else
1040       if( !ownctx.IsNull() ) ownctx->Erase (myAIS,Standard_False); 
1041     }
1042   }
1043 }
1044
1045
1046 //=======================================================================
1047 //function :GetAIS
1048 //purpose  : 
1049 //=======================================================================
1050 Handle(AIS_InteractiveObject) TPrsStd_AISPresentation::GetAIS() const
1051 {
1052   return myAIS;
1053 }
1054
1055
1056 //=======================================================================
1057 //function :SetDisplayed
1058 //purpose  : 
1059 //=======================================================================
1060 void TPrsStd_AISPresentation::SetDisplayed(const Standard_Boolean B) 
1061 {
1062   Backup();
1063   isDisplayed = B;
1064 }
1065