1a0c69a6f91ca96763739d2e3ba8ec5a54b1630f
[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 = Handle(AIS_InteractiveObject)::DownCast (myLastPicked->Selectable());
61       unhighlightGlobal (aLastPickedAIS);
62     }}
63
64   if (myCurLocalIndex > 0)
65   {
66     myLocalContexts (myCurLocalIndex)->UnhilightLastDetected (myMainVwr);
67   }
68
69   // entities connected to dynamic selection at neutral point are set to 0.
70   
71   myLastinMain.Nullify();
72   myLastPicked.Nullify();
73   myWasLastMain = Standard_True;
74
75   Standard_DISABLE_DEPRECATION_WARNINGS
76   myCurLocalIndex = HighestIndex() + 1;
77   Standard_ENABLE_DEPRECATION_WARNINGS
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      Standard_DISABLE_DEPRECATION_WARNINGS
148      myCurLocalIndex = HighestIndex();
149      Standard_ENABLE_DEPRECATION_WARNINGS
150    }
151    else if(debugmode)
152      cout<<"a No Current Local Context WasClosed"<<endl;
153
154    // restore activated selections of current local context
155    myLocalContexts (myCurLocalIndex)->RestoreActivatedModes();
156
157    if(debugmode) cout<<"Index Of CurrentLocalContext:"<<myCurLocalIndex<<endl;
158    
159  }
160    
161  
162  if(updateviewer) myMainVwr->Update();
163 }
164
165 //=======================================================================
166 //function : CloseAllContexts
167 //purpose  : 
168 //=======================================================================
169 Standard_DISABLE_DEPRECATION_WARNINGS
170 void AIS_InteractiveContext::CloseAllContexts(const Standard_Boolean updateviewer)
171 {
172   while(!myLocalContexts.IsEmpty()){
173     CloseLocalContext(myCurLocalIndex,Standard_False);
174   }
175
176   ResetOriginalState(Standard_False);
177
178   if(updateviewer) myMainVwr->Update();
179 }
180 Standard_ENABLE_DEPRECATION_WARNINGS
181
182 //=======================================================================
183 //function : IndexOfCurrentLocal
184 //purpose  : 
185 //=======================================================================
186
187 Standard_Integer AIS_InteractiveContext::IndexOfCurrentLocal() const
188 {
189   return myCurLocalIndex;
190 }
191
192 //=======================================================================
193 //function : ClearLocalContext
194 //purpose  : 
195 //=======================================================================
196
197 void AIS_InteractiveContext::ClearLocalContext(const AIS_ClearMode aMode)
198 {
199   if (!HasOpenedContext()) return;
200   myLocalContexts(myCurLocalIndex)->Clear(aMode);
201
202 }
203
204 //=======================================================================
205 //function : HighestIndex
206 //purpose  : 
207 //=======================================================================
208
209 Standard_Integer AIS_InteractiveContext::HighestIndex() const
210 {
211   AIS_DataMapIteratorOfDataMapOfILC It(myLocalContexts);
212   Standard_Integer HiInd = 0;
213   for(;It.More();It.Next())
214     HiInd = (It.Key()>HiInd) ? It.Key() : HiInd;
215   return HiInd;
216
217 }
218
219 //=======================================================================
220 //function : SetSelectionModeActive
221 //purpose  :
222 //=======================================================================
223 void AIS_InteractiveContext::SetSelectionModeActive (const Handle(AIS_InteractiveObject)& theObj,
224                                                      const Standard_Integer theMode,
225                                                      const Standard_Boolean theIsActive,
226                                                      const AIS_SelectionModesConcurrency theActiveFilter,
227                                                      const Standard_Boolean theIsForce)
228 {
229   if (theObj.IsNull())
230   {
231     return;
232   }
233   else if (HasOpenedContext())
234   {
235     myLocalContexts (myCurLocalIndex)->SetSelectionModeActive (theObj, theMode, theIsActive, theActiveFilter);
236     return;
237   }
238
239   const Handle(AIS_GlobalStatus)* aStat = myObjects.Seek (theObj);
240   if (aStat == NULL)
241   {
242     return;
243   }
244
245   if (!theIsActive
246    || (theMode == -1
247     && theActiveFilter == AIS_SelectionModesConcurrency_Single))
248   {
249     if ((*aStat)->GraphicStatus() == AIS_DS_Displayed
250      || theIsForce)
251     {
252       if (theMode == -1)
253       {
254         for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next())
255         {
256           mgrSelector->Deactivate (theObj, aModeIter.Value(), myMainSel);
257         }
258       }
259       else
260       {
261         mgrSelector->Deactivate (theObj, theMode, myMainSel);
262       }
263     }
264
265     if (theMode == -1)
266     {
267       (*aStat)->ClearSelectionModes();
268     }
269     else
270     {
271       (*aStat)->RemoveSelectionMode (theMode);
272     }
273     return;
274   }
275   else if (theMode == -1)
276   {
277     return;
278   }
279
280   if ((*aStat)->SelectionModes().Size() == 1
281    && (*aStat)->SelectionModes().First() == theMode)
282   {
283     return;
284   }
285
286   if ((*aStat)->GraphicStatus() == AIS_DS_Displayed
287     || theIsForce)
288   {
289     switch (theActiveFilter)
290     {
291       case AIS_SelectionModesConcurrency_Single:
292       {
293         for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next())
294         {
295           mgrSelector->Deactivate (theObj, aModeIter.Value(), myMainSel);
296         }
297         (*aStat)->ClearSelectionModes();
298         break;
299       }
300       case AIS_SelectionModesConcurrency_GlobalOrLocal:
301       {
302         const Standard_Integer aGlobSelMode = theObj->GlobalSelectionMode();
303         TColStd_ListOfInteger aRemovedModes;
304         for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next())
305         {
306           if ((theMode == aGlobSelMode && aModeIter.Value() != aGlobSelMode)
307            || (theMode != aGlobSelMode && aModeIter.Value() == aGlobSelMode))
308           {
309             mgrSelector->Deactivate (theObj, aModeIter.Value(), myMainSel);
310             aRemovedModes.Append (aModeIter.Value());
311           }
312         }
313         if (aRemovedModes.Size() == (*aStat)->SelectionModes().Size())
314         {
315           (*aStat)->ClearSelectionModes();
316         }
317         else
318         {
319           for (TColStd_ListIteratorOfListOfInteger aModeIter (aRemovedModes); aModeIter.More(); aModeIter.Next())
320           {
321             (*aStat)->RemoveSelectionMode (aModeIter.Value());
322           }
323         }
324         break;
325       }
326       case AIS_SelectionModesConcurrency_Multiple:
327       {
328         break;
329       }
330     }
331     mgrSelector->Activate (theObj, theMode, myMainSel);
332   }
333   (*aStat)->AddSelectionMode (theMode);
334 }
335
336 // ============================================================================
337 // function : Activate
338 // purpose  :
339 // ============================================================================
340 void AIS_InteractiveContext::Activate (const Standard_Integer theMode,
341                                        const Standard_Boolean theIsForce)
342 {
343   AIS_ListOfInteractive aDisplayedObjects;
344   DisplayedObjects (aDisplayedObjects);
345
346   for (AIS_ListIteratorOfListOfInteractive anIter (aDisplayedObjects); anIter.More(); anIter.Next())
347   {
348     Load (anIter.Value(), -1, Standard_True);
349     Activate (anIter.Value(), theMode, theIsForce);
350   }
351
352 }
353
354 //=======================================================================
355 //function : LocalSelector
356 //purpose  : 
357 //=======================================================================
358 Handle( StdSelect_ViewerSelector3d ) AIS_InteractiveContext::LocalSelector() const
359 {
360   if( !HasOpenedContext() )
361       return Handle( StdSelect_ViewerSelector3d )();
362   else
363       return myLocalContexts( myCurLocalIndex )->MainSelector();
364 }
365
366 // ============================================================================
367 // function : Deactivate
368 // purpose  :
369 // ============================================================================
370 void AIS_InteractiveContext::Deactivate (const Standard_Integer theMode)
371 {
372   AIS_ListOfInteractive aDisplayedObjects;
373   DisplayedObjects (aDisplayedObjects);
374
375   for (AIS_ListIteratorOfListOfInteractive anIter (aDisplayedObjects); anIter.More(); anIter.Next())
376   {
377     Deactivate (anIter.Value(), theMode);
378   }
379 }
380
381 // ============================================================================
382 // function : Deactivate
383 // purpose  :
384 // ============================================================================
385 void AIS_InteractiveContext::Deactivate()
386 {
387   AIS_ListOfInteractive aDisplayedObjects;
388   DisplayedObjects (aDisplayedObjects);
389
390   for (AIS_ListIteratorOfListOfInteractive anIter (aDisplayedObjects); anIter.More(); anIter.Next())
391   {
392     Deactivate (anIter.Value());
393   }
394 }
395
396 //=======================================================================
397 //function : ActivatedModes
398 //purpose  : 
399 //=======================================================================
400
401 void AIS_InteractiveContext::
402 ActivatedModes(const Handle(AIS_InteractiveObject)& anIObj, 
403                TColStd_ListOfInteger& theList) const 
404 {
405   TColStd_ListIteratorOfListOfInteger ItL;
406   if(!HasOpenedContext()){
407     if(myObjects.IsBound(anIObj)){
408       for(ItL.Initialize(myObjects(anIObj)->SelectionModes());
409           ItL.More();
410           ItL.Next())
411         theList.Append(ItL.Value());
412       
413     }
414   }
415   else{
416     if(myLocalContexts(myCurLocalIndex)->IsIn(anIObj)){
417       for(ItL.Initialize(myLocalContexts(myCurLocalIndex)->SelectionModes(anIObj));
418           ItL.More();
419           ItL.Next())
420         theList.Append(ItL.Value());
421     }
422   }
423 }
424
425 //=======================================================================
426 //function : SetShapeDecomposition
427 //purpose  : 
428 //=======================================================================
429
430 void AIS_InteractiveContext::SetShapeDecomposition(const Handle(AIS_InteractiveObject)& anIObj,
431                                                    const Standard_Boolean StdModeSensitive)
432 {
433   if(!HasOpenedContext()) return;
434   myLocalContexts(myCurLocalIndex)->SetShapeDecomposition(anIObj,StdModeSensitive);
435 }
436
437 //=======================================================================
438 //function : SetTemporaryAttributes
439 //purpose  : 
440 //=======================================================================
441
442 void AIS_InteractiveContext::
443 SetTemporaryAttributes(const Handle(AIS_InteractiveObject)& /*anObj*/,
444                        const Handle(Prs3d_Drawer)& /*aDrawer*/,
445                        const Standard_Boolean /*updateviewer*/)
446 {
447 }
448
449 //=======================================================================
450 //function : SubIntensityOn
451 //purpose  : 
452 //=======================================================================
453 void AIS_InteractiveContext::
454 SubIntensityOn(const Handle(AIS_InteractiveObject)& anIObj,
455                const Standard_Boolean updateviewer)
456 {
457   if(!HasOpenedContext())
458   {
459     turnOnSubintensity (anIObj);
460   }
461   else
462   {
463     turnOnSubintensity (anIObj, -1, Standard_False);
464     myLocalContexts(myCurLocalIndex)->SubIntensityOn (anIObj);
465   }
466
467   if (updateviewer)
468     myMainVwr->Update();
469 }
470 //=======================================================================
471 //function : SubIntensityOff
472 //purpose  : 
473 //=======================================================================
474
475 void AIS_InteractiveContext::
476 SubIntensityOff(const Handle(AIS_InteractiveObject)& anIObj,
477                 const Standard_Boolean updateviewer)
478 {
479   if(!HasOpenedContext()){
480     if(!myObjects.IsBound(anIObj))
481       return;
482     const Handle(AIS_GlobalStatus)& GB=myObjects(anIObj);
483     if(!GB->IsSubIntensityOn())
484       return;
485     GB->SubIntensityOff();
486     Standard_Boolean UpdMain(Standard_False);
487     
488     if(GB->GraphicStatus() == AIS_DS_Displayed)
489     {
490       myMainPM->Unhighlight (anIObj);
491       UpdMain = Standard_True;
492     }
493     
494     if(IsSelected(anIObj))
495       highlightSelected (anIObj->GlobalSelOwner());
496     
497     if(updateviewer){
498       if(UpdMain)
499         myMainVwr->Update();
500     }
501   }
502   else {
503     const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anIObj, anIObj->GlobalSelOwner());
504     if(myObjects.IsBound(anIObj)){
505       const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
506       STAT->SubIntensityOff();
507       myMainPM->Unhighlight (anIObj);
508       if (STAT->IsHilighted())
509         HilightWithColor (anIObj, anObjSelStyle, Standard_False);
510     }
511     else
512       myLocalContexts(myCurLocalIndex)->SubIntensityOff(anIObj);
513     if (IsSelected(anIObj))
514       HilightWithColor (anIObj, anObjSelStyle, Standard_False);
515     
516     if(updateviewer) myMainVwr->Update();
517   }
518 }
519
520 //=======================================================================
521 //function : SubIntensityOn
522 //purpose  : ALL THE DISPLAYED OBJECTS HAVE SUBINTENSITY...
523 //=======================================================================
524 void AIS_InteractiveContext::SubIntensityOn (const Standard_Boolean theIsToUpdateViewer)
525 {
526   if (!HasOpenedContext())
527     return;
528
529   turnOnSubintensity();
530
531   if (theIsToUpdateViewer)
532     myMainVwr->Update();
533 }
534
535 //=======================================================================
536 //function : SubIntensityOff
537 //purpose  : 
538 //=======================================================================
539 void AIS_InteractiveContext::SubIntensityOff(const Standard_Boolean updateviewer)
540 {
541   if(!HasOpenedContext()) return;
542
543   AIS_DataMapIteratorOfDataMapOfIOStatus It (myObjects);
544   for(;It.More();It.Next()){
545     const Handle(AIS_GlobalStatus)& STAT = It.Value();
546     if(STAT->IsSubIntensityOn())
547       STAT->SubIntensityOff();
548     myMainPM->Unhighlight (It.Key());
549   }
550
551   if(updateviewer) myMainVwr->Update();
552 }
553
554 //=======================================================================
555 //function : AddFilter
556 //purpose  : 
557 //=======================================================================
558 void AIS_InteractiveContext::AddFilter(const Handle(SelectMgr_Filter)& aFilter)
559 {
560   if(HasOpenedContext())
561     myLocalContexts(myCurLocalIndex)->AddFilter(aFilter);
562   else
563     myFilters->Add(aFilter);
564 }
565
566 //=======================================================================
567 //function : ActivateStandardMode
568 //purpose  : 
569 //=======================================================================
570 void AIS_InteractiveContext::ActivateStandardMode(const TopAbs_ShapeEnum aStandardActivation)
571 {
572   if(!HasOpenedContext()) return;
573   myLocalContexts(myCurLocalIndex)->ActivateStandardMode (aStandardActivation);
574 }
575
576 //=======================================================================
577 //function : DeActivateStandardMode
578 //purpose  : 
579 //=======================================================================
580 void AIS_InteractiveContext::DeactivateStandardMode(const TopAbs_ShapeEnum aStandardActivation)
581 {
582   if(!HasOpenedContext()) return;
583   myLocalContexts(myCurLocalIndex)->DeactivateStandardMode (aStandardActivation);
584 }
585
586 //=======================================================================
587 //function : RemoveFilter
588 //purpose  : 
589 //=======================================================================
590 void AIS_InteractiveContext::RemoveFilter(const Handle(SelectMgr_Filter)& aFilter)
591 {
592   if(HasOpenedContext())
593     myLocalContexts(myCurLocalIndex)->RemoveFilter (aFilter);
594   else
595     myFilters->Remove(aFilter);
596 }
597
598 //=======================================================================
599 //function : RemoveFilters
600 //purpose  : 
601 //=======================================================================
602
603 void AIS_InteractiveContext::RemoveFilters()
604 {
605   if(!HasOpenedContext())
606     myFilters->Clear();
607   else
608     myLocalContexts(myCurLocalIndex)->Clear(AIS_CM_Filters);
609 }
610
611 //=======================================================================
612 //function : ActivatedStandardModes
613 //purpose  : 
614 //=======================================================================
615 const TColStd_ListOfInteger& AIS_InteractiveContext::ActivatedStandardModes() const 
616 {
617   return myLocalContexts(myCurLocalIndex)->StandardModes();
618 }
619
620 //=======================================================================
621 //function : Filters
622 //purpose  : 
623 //=======================================================================
624 const SelectMgr_ListOfFilter& AIS_InteractiveContext::Filters() const 
625 {
626   if(HasOpenedContext())
627     return myLocalContexts(myCurLocalIndex)->ListOfFilter();
628   return myFilters->StoredFilters();
629 }
630
631 //=======================================================================
632 //function : DisplayActiveSensitive
633 //purpose  : 
634 //=======================================================================
635 void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(V3d_View)& aviou)
636 {
637   if(HasOpenedContext())
638     myLocalContexts(myCurLocalIndex)->DisplaySensitive(aviou);
639   else
640     myMainSel->DisplaySensitive(aviou);
641 }
642 //=======================================================================
643 //function : DisplayActiveSensitive
644 //purpose  : 
645 //=======================================================================
646
647 void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(AIS_InteractiveObject)& anIObj,
648                                                     const Handle(V3d_View)& aviou)
649 {
650   TColStd_ListIteratorOfListOfInteger It;
651   Handle(StdSelect_ViewerSelector3d) VS;
652   if(HasOpenedContext()){
653     const Handle(AIS_LocalContext)& LC = myLocalContexts(myCurLocalIndex);
654     if(!LC->IsIn(anIObj)) return;
655     It.Initialize(LC->SelectionModes(anIObj));
656     VS = LC->MainSelector();
657   }
658   else{
659     if(!myObjects.IsBound(anIObj)) return;
660     It.Initialize(myObjects(anIObj)->SelectionModes());
661     VS = myMainSel;
662   }
663   
664   
665   for(;It.More();It.Next()){
666     const Handle(SelectMgr_Selection)& Sel = anIObj->Selection(It.Value());
667     VS->DisplaySensitive(Sel,anIObj->Transformation(), aviou,Standard_False);
668   }  
669   
670 }
671
672 //=======================================================================
673 //function : ClearActiveSensitive
674 //purpose  : 
675 //=======================================================================
676 void AIS_InteractiveContext::ClearActiveSensitive(const Handle(V3d_View)& aviou)
677 {
678   
679   if(HasOpenedContext())
680     myLocalContexts(myCurLocalIndex)->ClearSensitive(aviou);
681   else
682     myMainSel->ClearSensitive(aviou);
683 }
684
685 //=======================================================================
686 //function : SetAutomaticHilight
687 //purpose  : 
688 //=======================================================================
689 void  AIS_InteractiveContext::SetAutomaticHilight(const Standard_Boolean aStatus)
690 {
691
692   if(HasOpenedContext())
693     myLocalContexts(myCurLocalIndex)->SetAutomaticHilight(aStatus);
694 }
695
696 //=======================================================================
697 //function : AutomaticHilight
698 //purpose  : 
699 //=======================================================================
700 Standard_Boolean AIS_InteractiveContext::AutomaticHilight() const 
701 {
702   if(HasOpenedContext())
703     return myLocalContexts(myCurLocalIndex)->AutomaticHilight();
704   return Standard_True;
705 }
706
707 //=======================================================================
708 //function : UseDisplayedObjects
709 //purpose  : 
710 //=======================================================================
711
712 void AIS_InteractiveContext::UseDisplayedObjects()
713 {
714   if(HasOpenedContext())
715     myLocalContexts(myCurLocalIndex)->LoadContextObjects();
716 }
717
718 //=======================================================================
719 //function : NotUseDisplayedObjects
720 //purpose  : 
721 //=======================================================================
722
723 void AIS_InteractiveContext::NotUseDisplayedObjects()
724 {
725   if(HasOpenedContext())
726     myLocalContexts(myCurLocalIndex)->UnloadContextObjects();
727 }
728
729
730
731
732 //=======================================================================
733 //function : PurgeDisplay
734 //purpose  : 
735 //=======================================================================
736
737 Standard_Integer AIS_InteractiveContext::PurgeDisplay()
738 {
739   if(HasOpenedContext()) return 0;
740   
741   Standard_Integer NbStr = PurgeViewer(myMainVwr);
742   myMainVwr->Update();
743   return NbStr;
744
745 }
746
747
748 //=======================================================================
749 //function : PurgeViewer
750 //purpose  : 
751 //=======================================================================
752 Standard_Integer AIS_InteractiveContext::PurgeViewer(const Handle(V3d_Viewer)& Vwr)
753 {
754   Handle(Graphic3d_StructureManager) GSM = Vwr->StructureManager();
755   Standard_Integer NbCleared(0);
756   Graphic3d_MapOfStructure SOS;
757   GSM->DisplayedStructures(SOS);
758
759   Handle(Graphic3d_Structure) G;
760   for(Graphic3d_MapIteratorOfMapOfStructure It(SOS); It.More();It.Next()){
761     G = It.Key();
762     Standard_Address Add = G->Owner();
763     if(Add==NULL){
764       G->Erase();
765       G->Clear();// it means that it is not referenced as a presentation of InterfactiveObject...
766       NbCleared++;
767     }
768     Handle(AIS_InteractiveObject) IO = (AIS_InteractiveObject*)Add;
769     if(!myObjects.IsBound(IO)){
770       G->Erase();
771       NbCleared++;
772     }
773   }
774   return NbCleared;
775 }
776
777 //=======================================================================
778 //function : IsImmediateModeOn
779 //purpose  :
780 //=======================================================================
781
782 Standard_Boolean AIS_InteractiveContext::IsImmediateModeOn()  const 
783 {
784   if(!HasOpenedContext()) return Standard_False;
785   return myLocalContexts(myCurLocalIndex)->IsImmediateModeOn();
786 }
787
788 //=======================================================================
789 //function : BeginImmediateDraw
790 //purpose  :
791 //=======================================================================
792
793 Standard_Boolean AIS_InteractiveContext::BeginImmediateDraw()
794 {
795   return HasOpenedContext()
796       && myLocalContexts (myCurLocalIndex)->BeginImmediateDraw();
797 }
798
799 //=======================================================================
800 //function : ImmediateAdd
801 //purpose  :
802 //=======================================================================
803
804 Standard_Boolean AIS_InteractiveContext::ImmediateAdd (const Handle(AIS_InteractiveObject)& theObj,
805                                                        const Standard_Integer               theMode)
806 {
807   return HasOpenedContext()
808       && myLocalContexts (myCurLocalIndex)->ImmediateAdd (theObj, theMode);
809 }
810
811 //=======================================================================
812 //function : EndImmediateDraw
813 //purpose  :
814 //=======================================================================
815
816 Standard_Boolean AIS_InteractiveContext::EndImmediateDraw (const Handle(V3d_View)& theView)
817 {
818   return HasOpenedContext()
819       && myLocalContexts (myCurLocalIndex)->EndImmediateDraw (theView->Viewer());
820 }
821
822 //=======================================================================
823 //function : EndImmediateDraw
824 //purpose  :
825 //=======================================================================
826
827 Standard_Boolean AIS_InteractiveContext::EndImmediateDraw()
828 {
829   if (!HasOpenedContext())
830   {
831     return Standard_False;
832   }
833
834   return myLocalContexts (myCurLocalIndex)->EndImmediateDraw (myMainVwr);
835 }
836
837
838 //=======================================================================
839 //function : ResetOriginalState
840 //purpose  : 
841 //=======================================================================
842
843 void AIS_InteractiveContext::ResetOriginalState(const Standard_Boolean updateviewer)
844 {
845   Standard_Boolean upd_main(Standard_False);
846   TColStd_ListIteratorOfListOfInteger itl;
847   myMainSel->ResetSelectionActivationStatus();
848
849   for (AIS_DataMapIteratorOfDataMapOfIOStatus it(myObjects);it.More();it.Next()){
850     const Handle(AIS_InteractiveObject)& iobj = it.Key();
851     const Handle(AIS_GlobalStatus)& STAT = it.Value();
852     switch(STAT->GraphicStatus()){
853     case AIS_DS_Displayed:{
854       upd_main = Standard_True;
855       
856       // part display...
857       myMainPM->Display (iobj, STAT->DisplayMode());
858       if(STAT->IsHilighted())
859       {
860         const Handle(Prs3d_Drawer)& aStyle = STAT->HilightStyle();
861         if (!aStyle.IsNull() && getSelStyle (iobj, iobj->GlobalSelOwner()) != aStyle)
862           HilightWithColor(iobj,aStyle,Standard_False);
863       }
864       //part selection
865       for(itl.Initialize(STAT->SelectionModes());itl.More();itl.Next()){
866         if(itl.Value()!=-1)
867           mgrSelector->Activate(iobj,itl.Value(),myMainSel);
868       }
869       break; 
870     }
871     case AIS_DS_Erased:{
872       EraseGlobal(iobj,Standard_False);
873       break;
874     }
875     default:
876       break;
877     }
878   }
879   if(updateviewer){
880     if(upd_main) 
881       myMainVwr->Update();
882   }
883 }