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