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