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