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