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