0026172: Visualization, AIS_LocalContext - locally selected object should not stay...
[occt.git] / src / AIS / AIS_InteractiveContext_2.cxx
CommitLineData
b311480e 1// Created on: 1997-01-29
2// Created by: Robert COUBLANC
3// Copyright (c) 1997-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
7fd59977 17#include <AIS_InteractiveContext.jxx>
18
19#include <AIS_LocalContext.hxx>
20
21#include <AIS_GlobalStatus.hxx>
22#include <TColStd_ListIteratorOfListOfInteger.hxx>
23
24#include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
25#include <AIS_DataMapIteratorOfDataMapOfILC.hxx>
26#include <Graphic3d_StructureManager.hxx>
27#include <Graphic3d_Structure.hxx>
28#include <Graphic3d_MapOfStructure.hxx>
29#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
30#include <AIS_Selection.hxx>
31
f751596e 32#include <StdSelect_ViewerSelector3d.hxx>
33
7fd59977 34//=======================================================================
35//function : OpenLocalContext
36//purpose :
37//=======================================================================
38
39Standard_Integer AIS_InteractiveContext::
40OpenLocalContext(const Standard_Boolean UseDisplayedObjects,
41 const Standard_Boolean AllowShapeDecomposition,
42 const Standard_Boolean AcceptEraseOfTemporary,
43 const Standard_Boolean /*BothViewers*/)
44{
45
81bba717 46 // the entities eventually detected just before the context was opened are unhighlighted...
7fd59977 47 if(!IsCurrent(myLastPicked)){
48 if(!myLastPicked.IsNull()){
49 Standard_Integer HiMod = myLastPicked->HasHilightMode()?myLastPicked->HilightMode():0;
50 myMainPM->Unhighlight(myLastPicked,HiMod);
51 }}
52
53 if(!mylastmoveview.IsNull()){
54 if(myCurLocalIndex>0)
55 myLocalContexts(myCurLocalIndex)->UnhilightLastDetected(mylastmoveview);
56 }
57
81bba717 58 // entities connected to dynamic selection at neutral point are set to 0.
7fd59977 59
60 myLastinMain.Nullify();
7fd59977 61 myLastPicked.Nullify();
62 myWasLastMain = Standard_True;
63
7fd59977 64 myCurLocalIndex = HighestIndex() + 1;
65
66 Handle(AIS_LocalContext) NewLocal= new AIS_LocalContext(this,myCurLocalIndex,
67 UseDisplayedObjects,
68 AllowShapeDecomposition,
69 AcceptEraseOfTemporary);
64e2d3bd 70 // the AIS_LocalContext bind itself to myLocalContexts
71 // because procedures performed in AIS_LocalContext constructor
72 // already may access myLocalContexts(myCurLocalIndex) (like methods AIS_LocalContext::IsSelected()).
7fd59977 73
0797d9d3 74#ifdef OCCT_DEBUG
7fd59977 75 cout<<"\tOpen Local Context No "<<myCurLocalIndex<<endl;
76 if(UseDisplayedObjects){
77 cout<<"\t\tObjects from Neutral Point loaded"<<endl;
78 if(AllowShapeDecomposition)
79 cout<<"\t\tDecomposition Authorized for Loaded Shapes"<<endl;
80 else
81 cout<<"\t\tNo Decomposition Authorized for Loaded Shapes"<<endl;
82 }
83 else
84 cout<<"\t\tNo Objects Were Loaded "<<endl;
85#endif
86 return myCurLocalIndex;
7fd59977 87}
88
89//=======================================================================
90//function : CloseLocalContext
91//purpose :
92//=======================================================================
93
94void AIS_InteractiveContext::CloseLocalContext(const Standard_Integer Index,
95 const Standard_Boolean updateviewer)
96{
97
98 Standard_Boolean debugmode(Standard_False);
0797d9d3 99#ifdef OCCT_DEBUG
7fd59977 100 debugmode = Standard_True;
101#endif
102
103 Standard_Integer GoodIndex = (Index ==-1) ? myCurLocalIndex : Index;
104
105 if(debugmode) cout<<"Call to CloseLocalContext - Index "<<GoodIndex<<endl;
106 if(!HasOpenedContext()){
107 if(debugmode) cout<<"\t But No Local Context is opened"<<endl;
108 return;
109 }
110 if(!myLocalContexts.IsBound(GoodIndex)) {
111 if(debugmode) cout<<" Attempt to Close a non-existent Local Context"<<endl;
112 return;
113 }
114
81bba717 115 // the only open local context is closed...
7fd59977 116 if(myLocalContexts.Extent()==1 && GoodIndex == myCurLocalIndex){
117
7fd59977 118 myLocalContexts(myCurLocalIndex)->Terminate( updateviewer );
119 myLocalContexts.UnBind(myCurLocalIndex);
120 myCurLocalIndex = 0;
121
122 ResetOriginalState(Standard_False);
7fd59977 123 if(debugmode)
124 cout<<"No More Opened Local Context "<<endl;
125 }
126
81bba717 127 // Otherwise the local context will be still open after the current is closed
7fd59977 128 else{
129 Handle(StdSelect_ViewerSelector3d) VS = myLocalContexts(GoodIndex)->MainSelector();
130 myLocalContexts(GoodIndex)->Terminate();
131 myLocalContexts.UnBind(GoodIndex);
81bba717 132 // the current is closed...
7fd59977 133 if(GoodIndex==myCurLocalIndex){
134 myCurLocalIndex = HighestIndex();
7fd59977 135 }
136 else if(debugmode)
137 cout<<"a No Current Local Context WasClosed"<<endl;
138
139 if(debugmode) cout<<"Index Of CurrentLocalContext:"<<myCurLocalIndex<<endl;
140
141 }
142
143
144 if(updateviewer) myMainVwr->Update();
145}
146
147//=======================================================================
148//function : CloseAllContexts
149//purpose :
150//=======================================================================
151
152void AIS_InteractiveContext::CloseAllContexts(const Standard_Boolean updateviewer)
153{
154
155 while(!myLocalContexts.IsEmpty()){
156 CloseLocalContext(myCurLocalIndex,Standard_False);
157 }
158
159 ResetOriginalState(Standard_False);
160
7fd59977 161 if(updateviewer) myMainVwr->Update();
162}
163
164//=======================================================================
165//function : IndexOfCurrentLocal
166//purpose :
167//=======================================================================
168
169Standard_Integer AIS_InteractiveContext::IndexOfCurrentLocal() const
170{
171 return myCurLocalIndex;
172}
173
174//=======================================================================
175//function : ClearLocalContext
176//purpose :
177//=======================================================================
178
179void AIS_InteractiveContext::ClearLocalContext(const AIS_ClearMode aMode)
180{
181 if (!HasOpenedContext()) return;
182 myLocalContexts(myCurLocalIndex)->Clear(aMode);
183
184}
185
186//=======================================================================
187//function : HighestIndex
188//purpose :
189//=======================================================================
190
191Standard_Integer AIS_InteractiveContext::HighestIndex() const
192{
193 AIS_DataMapIteratorOfDataMapOfILC It(myLocalContexts);
194 Standard_Integer HiInd = 0;
195 for(;It.More();It.Next())
196 HiInd = (It.Key()>HiInd) ? It.Key() : HiInd;
197 return HiInd;
198
199}
200
201
202//=======================================================================
203//function : Activate
204//purpose :
205//=======================================================================
206
207void AIS_InteractiveContext::
208Activate(const Handle(AIS_InteractiveObject)& anIObj,
f751596e 209 const Standard_Integer aMode,
210 const Standard_Boolean theIsForce)
7fd59977 211{
212 if(!HasOpenedContext()){
213 if(!myObjects.IsBound(anIObj)) return;
214 const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
f751596e 215 if(STAT->GraphicStatus()==AIS_DS_Displayed || theIsForce)
7fd59977 216 mgrSelector->Activate(anIObj,aMode,myMainSel);
217 STAT ->AddSelectionMode(aMode);
218 }
219 else{
220 myLocalContexts(myCurLocalIndex)->ActivateMode(anIObj,aMode);
221 }
222}
223
224//=======================================================================
225//function : LocalSelector
226//purpose :
227//=======================================================================
228Handle( StdSelect_ViewerSelector3d ) AIS_InteractiveContext::LocalSelector() const
229{
230 if( !HasOpenedContext() )
231 return Handle( StdSelect_ViewerSelector3d )();
232 else
233 return myLocalContexts( myCurLocalIndex )->MainSelector();
234}
235
236
237//=======================================================================
238//function : DeActivate
239//purpose :
240//=======================================================================
241void AIS_InteractiveContext::
242Deactivate(const Handle(AIS_InteractiveObject)& anIObj)
243{
244 if(!HasOpenedContext()){
245 if(!myObjects.IsBound(anIObj)) return;
ab943560 246 TColStd_ListIteratorOfListOfInteger ItL;
7fd59977 247 for(ItL.Initialize(myObjects(anIObj)->SelectionModes());
248 ItL.More();
249 ItL.Next()){
250 if(myObjects(anIObj)->GraphicStatus() == AIS_DS_Displayed)
251 mgrSelector->Deactivate(anIObj,ItL.Value(),myMainSel);
252 }
253 myObjects(anIObj)->ClearSelectionModes();
254 }
255 else{
256 const Handle(AIS_LocalContext)& LC = myLocalContexts(myCurLocalIndex);
257 LC->Deactivate(anIObj);
258 }
259}
260
261//=======================================================================
262//function : Deactivate
263//purpose :
264//=======================================================================
265
266void AIS_InteractiveContext::Deactivate(const Handle(AIS_InteractiveObject)& anIObj,
267 const Standard_Integer aMode)
268{
269 if(!HasOpenedContext()){
270 if(!myObjects.IsBound(anIObj)) return;
271 const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
272
273 if(STAT->GraphicStatus() == AIS_DS_Displayed)
274 mgrSelector->Deactivate(anIObj,aMode,myMainSel);
275 STAT->RemoveSelectionMode(aMode);
276 }
277 else{
278 myLocalContexts(myCurLocalIndex)->DeactivateMode(anIObj,aMode);
279 }
280}
281
282//=======================================================================
283//function : ActivatedModes
284//purpose :
285//=======================================================================
286
287void AIS_InteractiveContext::
288ActivatedModes(const Handle(AIS_InteractiveObject)& anIObj,
289 TColStd_ListOfInteger& theList) const
290{
ab943560 291 TColStd_ListIteratorOfListOfInteger ItL;
7fd59977 292 if(!HasOpenedContext()){
293 if(myObjects.IsBound(anIObj)){
7fd59977 294 for(ItL.Initialize(myObjects(anIObj)->SelectionModes());
295 ItL.More();
296 ItL.Next())
297 theList.Append(ItL.Value());
298
299 }
300 }
301 else{
302 if(myLocalContexts(myCurLocalIndex)->IsIn(anIObj)){
303 for(ItL.Initialize(myLocalContexts(myCurLocalIndex)->SelectionModes(anIObj));
304 ItL.More();
305 ItL.Next())
306 theList.Append(ItL.Value());
307 }
308 }
309}
310
311//=======================================================================
312//function : SetShapeDecomposition
313//purpose :
314//=======================================================================
315
316void AIS_InteractiveContext::SetShapeDecomposition(const Handle(AIS_InteractiveObject)& anIObj,
317 const Standard_Boolean StdModeSensitive)
318{
319 if(!HasOpenedContext()) return;
320 myLocalContexts(myCurLocalIndex)->SetShapeDecomposition(anIObj,StdModeSensitive);
321}
322
323//=======================================================================
324//function : SetTemporaryAttributes
325//purpose :
326//=======================================================================
327
328void AIS_InteractiveContext::
329SetTemporaryAttributes(const Handle(AIS_InteractiveObject)& /*anObj*/,
330 const Handle(Prs3d_Drawer)& /*aDrawer*/,
331 const Standard_Boolean /*updateviewer*/)
332{
333}
334
335//=======================================================================
336//function : SubIntensityOn
337//purpose :
338//=======================================================================
339void AIS_InteractiveContext::
340SubIntensityOn(const Handle(AIS_InteractiveObject)& anIObj,
341 const Standard_Boolean updateviewer)
342{
343 if(!HasOpenedContext()){
344 if(!myObjects.IsBound(anIObj))
345 return;
346 const Handle(AIS_GlobalStatus)& GB=myObjects(anIObj);
347 if(GB->IsSubIntensityOn())
348 return;
349 GB->SubIntensityOn();
eb4320f2 350 Standard_Boolean UpdMain(Standard_False);
7fd59977 351
352 for(TColStd_ListIteratorOfListOfInteger It(GB->DisplayedModes());It.More();It.Next()){
eb4320f2 353 if (GB->GraphicStatus()==AIS_DS_Displayed)
354 {
7fd59977 355 myMainPM->Color(anIObj,mySubIntensity,It.Value());
eb4320f2 356 UpdMain = Standard_True;
7fd59977 357 }
358 }
359 if(updateviewer){
360 if(UpdMain)
361 myMainVwr->Update();
7fd59977 362 }
363 }
364 else {
365 if(myObjects.IsBound(anIObj)){
366 const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
367 STAT->SubIntensityOn();
ab943560 368 TColStd_ListIteratorOfListOfInteger ItL;
7fd59977 369 for (ItL.Initialize(STAT->DisplayedModes());ItL.More();ItL.Next())
370 myMainPM->Color(anIObj,mySubIntensity,ItL.Value());
371 }
372 else
373 myLocalContexts(myCurLocalIndex)->SubIntensityOn(anIObj);
374
375 if(updateviewer) myMainVwr->Update();
376 }
377}
378//=======================================================================
379//function : SubIntensityOff
380//purpose :
381//=======================================================================
382
383void AIS_InteractiveContext::
384SubIntensityOff(const Handle(AIS_InteractiveObject)& anIObj,
385 const Standard_Boolean updateviewer)
386{
387 if(!HasOpenedContext()){
388 if(!myObjects.IsBound(anIObj))
389 return;
390 const Handle(AIS_GlobalStatus)& GB=myObjects(anIObj);
391 if(!GB->IsSubIntensityOn())
392 return;
393 GB->SubIntensityOff();
eb4320f2 394 Standard_Boolean UpdMain(Standard_False);
7fd59977 395
396 for(TColStd_ListIteratorOfListOfInteger It(GB->DisplayedModes());It.More();It.Next()){
eb4320f2 397 if(GB->GraphicStatus()==AIS_DS_Displayed)
398 {
7fd59977 399 myMainPM->Unhighlight(anIObj,It.Value());
eb4320f2 400 UpdMain = Standard_True;
7fd59977 401 }
402 }
403
404 Standard_Integer DM,HM,SM;
405 GetDefModes(anIObj,DM,HM,SM);
406 if(AIS_Selection::IsSelected(anIObj))
407 myMainPM->Highlight(anIObj,HM);
408
409 if(updateviewer){
410 if(UpdMain)
411 myMainVwr->Update();
7fd59977 412 }
413 }
414 else {
415 if(myObjects.IsBound(anIObj)){
416 const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
417 STAT->SubIntensityOff();
ab943560 418 TColStd_ListIteratorOfListOfInteger ItL;
7fd59977 419 for (ItL.Initialize(STAT->DisplayedModes());ItL.More();ItL.Next())
420 myMainPM->Unhighlight(anIObj,ItL.Value());
421 if(STAT->IsHilighted())
422 Hilight(anIObj);
423 }
424 else
425 myLocalContexts(myCurLocalIndex)->SubIntensityOff(anIObj);
426 if(IsSelected(anIObj))
427 Hilight(anIObj);
428
429 if(updateviewer) myMainVwr->Update();
430 }
431}
432
433//=======================================================================
434//function : SubIntensityOn
435//purpose : ALL THE DISPLAYED OBJECTS HAVE SUBINTENSITY...
436//=======================================================================
437
438void AIS_InteractiveContext::SubIntensityOn(const Standard_Boolean updateviewer)
439{
440 if(!HasOpenedContext()) return;
441
442 AIS_DataMapIteratorOfDataMapOfIOStatus It (myObjects);
443 TColStd_ListIteratorOfListOfInteger ItM;
444 for(;It.More();It.Next()){
445 const Handle(AIS_GlobalStatus)& STAT = It.Value();
446 if(STAT->GraphicStatus()==AIS_DS_Displayed)
447 {
448 STAT->SubIntensityOn();
449 for(ItM.Initialize(STAT->DisplayedModes());ItM.More();ItM.Next())
450 {myMainPM->Color(It.Key(),mySubIntensity,ItM.Value());}
451 }
452 }
453 if(updateviewer) myMainVwr->Update();
454}
455
456//=======================================================================
457//function : SubIntensityOff
458//purpose :
459//=======================================================================
460void AIS_InteractiveContext::SubIntensityOff(const Standard_Boolean updateviewer)
461{
7fd59977 462 if(!HasOpenedContext()) return;
ab943560 463
7fd59977 464 AIS_DataMapIteratorOfDataMapOfIOStatus It (myObjects);
ab943560 465 TColStd_ListIteratorOfListOfInteger ItL;
7fd59977 466 for(;It.More();It.Next()){
467 const Handle(AIS_GlobalStatus)& STAT = It.Value();
468 if(STAT->IsSubIntensityOn())
469 STAT->SubIntensityOff();
470 for(ItL.Initialize(STAT->DisplayedModes());ItL.More();ItL.Next())
471 myMainPM->Unhighlight(It.Key());
472 }
ab943560 473
7fd59977 474 if(updateviewer) myMainVwr->Update();
475}
476
477//=======================================================================
478//function : AddFilter
479//purpose :
480//=======================================================================
481void AIS_InteractiveContext::AddFilter(const Handle(SelectMgr_Filter)& aFilter)
482{
483 if(HasOpenedContext())
484 myLocalContexts(myCurLocalIndex)->AddFilter(aFilter);
485 else
486 myFilters->Add(aFilter);
487}
488
489//=======================================================================
490//function : ActivateStandardMode
491//purpose :
492//=======================================================================
493void AIS_InteractiveContext::ActivateStandardMode(const TopAbs_ShapeEnum aStandardActivation)
494{
495 if(!HasOpenedContext()) return;
496 myLocalContexts(myCurLocalIndex)->ActivateStandardMode (aStandardActivation);
497}
498
499//=======================================================================
500//function : DeActivateStandardMode
501//purpose :
502//=======================================================================
503void AIS_InteractiveContext::DeactivateStandardMode(const TopAbs_ShapeEnum aStandardActivation)
504{
505 if(!HasOpenedContext()) return;
506 myLocalContexts(myCurLocalIndex)->DeactivateStandardMode (aStandardActivation);
507}
508
509//=======================================================================
510//function : RemoveFilter
511//purpose :
512//=======================================================================
513void AIS_InteractiveContext::RemoveFilter(const Handle(SelectMgr_Filter)& aFilter)
514{
515 if(HasOpenedContext())
516 myLocalContexts(myCurLocalIndex)->RemoveFilter (aFilter);
517 else
518 myFilters->Remove(aFilter);
519}
520
521//=======================================================================
522//function : RemoveFilters
523//purpose :
524//=======================================================================
525
526void AIS_InteractiveContext::RemoveFilters()
527{
528 if(!HasOpenedContext())
529 myFilters->Clear();
530 else
531 myLocalContexts(myCurLocalIndex)->Clear(AIS_CM_Filters);
532}
533
534//=======================================================================
535//function : ActivatedStandardModes
536//purpose :
537//=======================================================================
538const TColStd_ListOfInteger& AIS_InteractiveContext::ActivatedStandardModes() const
539{
540 return myLocalContexts(myCurLocalIndex)->StandardModes();
541}
542
543//=======================================================================
544//function : Filters
545//purpose :
546//=======================================================================
547const SelectMgr_ListOfFilter& AIS_InteractiveContext::Filters() const
548{
549 if(HasOpenedContext())
550 return myLocalContexts(myCurLocalIndex)->ListOfFilter();
551 return myFilters->StoredFilters();
552}
553
7fd59977 554//=======================================================================
555//function : DisplayActiveSensitive
556//purpose :
557//=======================================================================
558void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(V3d_View)& aviou)
559{
560 if(HasOpenedContext())
561 myLocalContexts(myCurLocalIndex)->DisplaySensitive(aviou);
562 else
563 myMainSel->DisplaySensitive(aviou);
564}
565//=======================================================================
566//function : DisplayActiveSensitive
567//purpose :
568//=======================================================================
569
570void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(AIS_InteractiveObject)& anIObj,
571 const Handle(V3d_View)& aviou)
572{
573 TColStd_ListIteratorOfListOfInteger It;
574 Handle(StdSelect_ViewerSelector3d) VS;
575 if(HasOpenedContext()){
576 const Handle(AIS_LocalContext)& LC = myLocalContexts(myCurLocalIndex);
577 if(!LC->IsIn(anIObj)) return;
578 It.Initialize(LC->SelectionModes(anIObj));
579 VS = LC->MainSelector();
580 }
581 else{
582 if(!myObjects.IsBound(anIObj)) return;
583 It.Initialize(myObjects(anIObj)->SelectionModes());
584 VS = myMainSel;
585 }
586
587
588 for(;It.More();It.Next()){
589 const Handle(SelectMgr_Selection)& Sel = anIObj->Selection(It.Value());
f751596e 590 VS->DisplaySensitive(Sel,anIObj->Transformation(), aviou,Standard_False);
7fd59977 591 }
592
593}
594
7fd59977 595//=======================================================================
596//function : ClearActiveSensitive
597//purpose :
598//=======================================================================
599void AIS_InteractiveContext::ClearActiveSensitive(const Handle(V3d_View)& aviou)
600{
601
602 if(HasOpenedContext())
603 myLocalContexts(myCurLocalIndex)->ClearSensitive(aviou);
604 else
605 myMainSel->ClearSensitive(aviou);
606}
607
608//=======================================================================
609//function : SetAutomaticHilight
610//purpose :
611//=======================================================================
612void AIS_InteractiveContext::SetAutomaticHilight(const Standard_Boolean aStatus)
613{
614
615 if(HasOpenedContext())
616 myLocalContexts(myCurLocalIndex)->SetAutomaticHilight(aStatus);
617}
618
619//=======================================================================
620//function : AutomaticHilight
621//purpose :
622//=======================================================================
623Standard_Boolean AIS_InteractiveContext::AutomaticHilight() const
624{
625 if(HasOpenedContext())
626 return myLocalContexts(myCurLocalIndex)->AutomaticHilight();
627 return Standard_True;
628}
629
630//=======================================================================
631//function : UseDisplayedObjects
632//purpose :
633//=======================================================================
634
635void AIS_InteractiveContext::UseDisplayedObjects()
636{
637 if(HasOpenedContext())
638 myLocalContexts(myCurLocalIndex)->LoadContextObjects();
639}
640
641//=======================================================================
642//function : NotUseDisplayedObjects
643//purpose :
644//=======================================================================
645
646void AIS_InteractiveContext::NotUseDisplayedObjects()
647{
648 if(HasOpenedContext())
649 myLocalContexts(myCurLocalIndex)->UnloadContextObjects();
650}
651
652
653
654
655//=======================================================================
656//function : PurgeDisplay
657//purpose :
658//=======================================================================
659
eb4320f2 660Standard_Integer AIS_InteractiveContext::PurgeDisplay()
7fd59977 661{
662 if(HasOpenedContext()) return 0;
663
664 Standard_Integer NbStr = PurgeViewer(myMainVwr);
7fd59977 665 myMainVwr->Update();
666 return NbStr;
667
668}
669
670
671//=======================================================================
672//function : PurgeViewer
673//purpose :
674//=======================================================================
675Standard_Integer AIS_InteractiveContext::PurgeViewer(const Handle(V3d_Viewer)& Vwr)
676{
677 const Handle(Graphic3d_StructureManager)& GSM = Vwr->Viewer();
678 Standard_Integer NbCleared(0);
679 Graphic3d_MapOfStructure SOS;
680 GSM->DisplayedStructures(SOS);
681
682 Handle(Graphic3d_Structure) G;
683 for(Graphic3d_MapIteratorOfMapOfStructure It(SOS); It.More();It.Next()){
684 G = It.Key();
685 Standard_Address Add = G->Owner();
686 if(Add==NULL){
687 G->Erase();
81bba717 688 G->Clear();// it means that it is not referenced as a presentation of InterfactiveObject...
7fd59977 689 NbCleared++;
690 }
691 Handle(AIS_InteractiveObject) IO = (AIS_InteractiveObject*)Add;
692 if(!myObjects.IsBound(IO)){
693 G->Erase();
694 NbCleared++;
695 }
696 }
697 return NbCleared;
698}
699
7fd59977 700//=======================================================================
701//function : IsImmediateModeOn
679ecdee 702//purpose :
7fd59977 703//=======================================================================
679ecdee 704
7fd59977 705Standard_Boolean AIS_InteractiveContext::IsImmediateModeOn() const
706{
707 if(!HasOpenedContext()) return Standard_False;
708 return myLocalContexts(myCurLocalIndex)->IsImmediateModeOn();
709}
710
7fd59977 711//=======================================================================
679ecdee 712//function : BeginImmediateDraw
713//purpose :
7fd59977 714//=======================================================================
715
679ecdee 716Standard_Boolean AIS_InteractiveContext::BeginImmediateDraw()
717{
718 return HasOpenedContext()
719 && myLocalContexts (myCurLocalIndex)->BeginImmediateDraw();
7fd59977 720}
721
722//=======================================================================
679ecdee 723//function : ImmediateAdd
724//purpose :
7fd59977 725//=======================================================================
726
679ecdee 727Standard_Boolean AIS_InteractiveContext::ImmediateAdd (const Handle(AIS_InteractiveObject)& theObj,
728 const Standard_Integer theMode)
7fd59977 729{
679ecdee 730 return HasOpenedContext()
731 && myLocalContexts (myCurLocalIndex)->ImmediateAdd (theObj, theMode);
7fd59977 732}
733
734//=======================================================================
735//function : EndImmediateDraw
679ecdee 736//purpose :
7fd59977 737//=======================================================================
738
679ecdee 739Standard_Boolean AIS_InteractiveContext::EndImmediateDraw (const Handle(V3d_View)& theView)
7fd59977 740{
679ecdee 741 return HasOpenedContext()
742 && myLocalContexts (myCurLocalIndex)->EndImmediateDraw (theView);
7fd59977 743}
744
745//=======================================================================
746//function : EndImmediateDraw
679ecdee 747//purpose :
7fd59977 748//=======================================================================
749
679ecdee 750Standard_Boolean AIS_InteractiveContext::EndImmediateDraw()
7fd59977 751{
679ecdee 752 if (!HasOpenedContext())
753 {
754 return Standard_False;
7fd59977 755 }
679ecdee 756
757 myMainVwr->InitActiveViews();
758 if (!myMainVwr->MoreActiveViews())
759 {
760 return Standard_False;
761 }
762
763 Handle(V3d_View) aView = myMainVwr->ActiveView();
764 return myLocalContexts (myCurLocalIndex)->EndImmediateDraw (aView);
7fd59977 765}
766
767
768//=======================================================================
769//function : ResetOriginalState
770//purpose :
771//=======================================================================
772
773void AIS_InteractiveContext::ResetOriginalState(const Standard_Boolean updateviewer)
774{
eb4320f2 775 Standard_Boolean upd_main(Standard_False);
7fd59977 776 TColStd_ListIteratorOfListOfInteger itl;
f751596e 777 myMainSel->ResetSelectionActivationStatus();
ab943560 778
7fd59977 779 for (AIS_DataMapIteratorOfDataMapOfIOStatus it(myObjects);it.More();it.Next()){
780 const Handle(AIS_InteractiveObject)& iobj = it.Key();
781 const Handle(AIS_GlobalStatus)& STAT = it.Value();
782 switch(STAT->GraphicStatus()){
783 case AIS_DS_Displayed:{
784 upd_main = Standard_True;
785
81bba717 786 // part display...
7fd59977 787 for(itl.Initialize(STAT->DisplayedModes());itl.More();itl.Next())
788 myMainPM->Display(iobj,itl.Value());
789 if(STAT->IsHilighted()){
790 if(STAT->HilightColor()!=Quantity_NOC_WHITE)
791 HilightWithColor(iobj,STAT->HilightColor(),Standard_False);
792 else
793 Hilight(iobj,Standard_False);
794 }
81bba717 795 //part selection
7fd59977 796 for(itl.Initialize(STAT->SelectionModes());itl.More();itl.Next()){
797 if(itl.Value()!=-1)
798 mgrSelector->Activate(iobj,itl.Value(),myMainSel);
799 }
800 break;
801 }
802 case AIS_DS_Erased:{
eb4320f2 803 EraseGlobal(iobj,Standard_False);
7fd59977 804 break;
805 }
806 default:
807 break;
808 }
809 }
810 if(updateviewer){
811 if(upd_main)
812 myMainVwr->Update();
7fd59977 813 }
814}
815
7fd59977 816//=======================================================================
817//function : SetZDetection
818//purpose :
819//=======================================================================
820void AIS_InteractiveContext::SetZDetection(const Standard_Boolean aStatus)
821{
822 myZDetectionFlag = aStatus;
823}
824
825//=======================================================================
826//function : ZDetection
827//purpose :
828//=======================================================================
829Standard_Boolean AIS_InteractiveContext::ZDetection() const
830{
831 return myZDetectionFlag;
832}