0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / AIS / AIS_InteractiveContext_2.cxx
index a993c16..9ce6fa8 100644 (file)
 // commercial license or contractual agreement.
 
 
-#include <AIS_DataMapIteratorOfDataMapOfILC.hxx>
 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
 #include <AIS_GlobalStatus.hxx>
 #include <AIS_InteractiveContext.hxx>
 #include <AIS_InteractiveObject.hxx>
-#include <AIS_LocalContext.hxx>
 #include <AIS_Selection.hxx>
 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
 #include <Graphic3d_MapOfStructure.hxx>
 #include <V3d_Viewer.hxx>
 
 //=======================================================================
-//function : OpenLocalContext
-//purpose  : 
+//function : SetSelectionModeActive
+//purpose  :
 //=======================================================================
-Standard_Integer AIS_InteractiveContext::
-OpenLocalContext(const Standard_Boolean UseDisplayedObjects, 
-                 const Standard_Boolean AllowShapeDecomposition, 
-                 const Standard_Boolean AcceptEraseOfTemporary,
-                 const Standard_Boolean /*BothViewers*/)
+void AIS_InteractiveContext::SetSelectionModeActive (const Handle(AIS_InteractiveObject)& theObj,
+                                                     const Standard_Integer theMode,
+                                                     const Standard_Boolean theIsActive,
+                                                     const AIS_SelectionModesConcurrency theActiveFilter,
+                                                     const Standard_Boolean theIsForce)
 {
-
-  // the entities eventually detected just before the context was opened are unhighlighted...
-  if(!IsSelected(myLastPicked)){
-    if(!myLastPicked.IsNull()){
-      const Handle(AIS_InteractiveObject) aLastPickedAIS =
-        Handle(AIS_InteractiveObject)::DownCast (myLastPicked->Selectable());
-      Standard_Integer HiMod = aLastPickedAIS->HasHilightMode()?aLastPickedAIS->HilightMode():0;
-      myMainPM->Unhighlight (aLastPickedAIS, HiMod);
-    }}
-  
-  if(!mylastmoveview.IsNull()){
-    if(myCurLocalIndex>0)
-      myLocalContexts(myCurLocalIndex)->UnhilightLastDetected(mylastmoveview);
-  }
-  
-  // entities connected to dynamic selection at neutral point are set to 0.
-  
-  myLastinMain.Nullify();
-  myLastPicked.Nullify();
-  myWasLastMain = Standard_True;
-
-  myCurLocalIndex = HighestIndex() + 1;
-  
-  Handle(AIS_LocalContext) NewLocal= new AIS_LocalContext(this,myCurLocalIndex,
-                                                          UseDisplayedObjects,
-                                                          AllowShapeDecomposition,
-                                                          AcceptEraseOfTemporary);
-  // the AIS_LocalContext bind itself to myLocalContexts
-  // because procedures performed in AIS_LocalContext constructor
-  // already may access myLocalContexts(myCurLocalIndex) (like methods AIS_LocalContext::IsSelected()).
-
-#ifdef OCCT_DEBUG
-  cout<<"\tOpen Local Context No "<<myCurLocalIndex<<endl;
-  if(UseDisplayedObjects){
-    cout<<"\t\tObjects from Neutral Point loaded"<<endl;
-    if(AllowShapeDecomposition)
-      cout<<"\t\tDecomposition Authorized for Loaded Shapes"<<endl;
-    else
-      cout<<"\t\tNo Decomposition Authorized for Loaded Shapes"<<endl;
+  if (theObj.IsNull())
+  {
+    return;
   }
-  else
-    cout<<"\t\tNo Objects Were Loaded "<<endl;
-#endif
-  return myCurLocalIndex;
-}
 
-//=======================================================================
-//function : CloseLocalContext
-//purpose  : 
-//=======================================================================
-
-void AIS_InteractiveContext::CloseLocalContext(const Standard_Integer Index,
-                                               const Standard_Boolean updateviewer)
-{
-
- Standard_Boolean debugmode(Standard_False);
-#ifdef OCCT_DEBUG
- debugmode = Standard_True;
-#endif
- Standard_Integer GoodIndex = (Index ==-1) ? myCurLocalIndex : Index;
-
- if(debugmode) cout<<"Call to CloseLocalContext - Index  "<<GoodIndex<<endl;
- if(!HasOpenedContext()){
-   if(debugmode) cout<<"\t But No Local Context is opened"<<endl;
-   return;
- }
- if(!myLocalContexts.IsBound(GoodIndex)) {
-   if(debugmode) cout<<" Attempt to Close a non-existent Local Context"<<endl;
-   return;
- }
- // the only open local context is closed...
- if(myLocalContexts.Extent()==1 && GoodIndex == myCurLocalIndex){
-   
-   myLocalContexts(myCurLocalIndex)->Terminate( updateviewer );
-   myLocalContexts.UnBind(myCurLocalIndex);
-   myCurLocalIndex = 0;
-
-   ResetOriginalState(Standard_False);
-   if(debugmode)
-     cout<<"No More Opened Local Context "<<endl;
- }
- // Otherwise the local context will be still open after the current is closed
- else{
-   Handle(StdSelect_ViewerSelector3d) VS = myLocalContexts(GoodIndex)->MainSelector();
-   myLocalContexts(GoodIndex)->Terminate();
-   myLocalContexts.UnBind(GoodIndex);
-   // the current is closed...
-   if(GoodIndex==myCurLocalIndex){
-     myCurLocalIndex = HighestIndex();
-   }
-   else if(debugmode)
-     cout<<"a No Current Local Context WasClosed"<<endl;
-
-   // restore activated selections of current local context
-   myLocalContexts (myCurLocalIndex)->RestoreActivatedModes();
-
-   if(debugmode) cout<<"Index Of CurrentLocalContext:"<<myCurLocalIndex<<endl;
-   
- }
-   
- if(updateviewer) myMainVwr->Update();
-}
-
-//=======================================================================
-//function : CloseAllContexts
-//purpose  : 
-//=======================================================================
-
-void AIS_InteractiveContext::CloseAllContexts(const Standard_Boolean updateviewer)
-{
-  
-  while(!myLocalContexts.IsEmpty()){
-    CloseLocalContext(myCurLocalIndex,Standard_False);
+  const Handle(AIS_GlobalStatus)* aStat = myObjects.Seek (theObj);
+  if (aStat == NULL)
+  {
+    return;
   }
-  
-  ResetOriginalState(Standard_False);
-
-  if(updateviewer) myMainVwr->Update();
-}
-
-//=======================================================================
-//function : IndexOfCurrentLocal
-//purpose  : 
-//=======================================================================
 
-Standard_Integer AIS_InteractiveContext::IndexOfCurrentLocal() const
-{
-  return myCurLocalIndex;
-}
+  if (!theIsActive
+   || (theMode == -1
+    && theActiveFilter == AIS_SelectionModesConcurrency_Single))
+  {
+    if ((*aStat)->GraphicStatus() == AIS_DS_Displayed
+     || theIsForce)
+    {
+      if (theMode == -1)
+      {
+        for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next())
+        {
+          mgrSelector->Deactivate (theObj, aModeIter.Value());
+        }
+      }
+      else
+      {
+        mgrSelector->Deactivate (theObj, theMode);
+      }
+    }
 
-//=======================================================================
-//function : ClearLocalContext
-//purpose  : 
-//=======================================================================
+    if (theMode == -1)
+    {
+      (*aStat)->ClearSelectionModes();
+    }
+    else
+    {
+      (*aStat)->RemoveSelectionMode (theMode);
+    }
+    return;
+  }
+  else if (theMode == -1)
+  {
+    return;
+  }
 
-void AIS_InteractiveContext::ClearLocalContext(const AIS_ClearMode aMode)
-{
-  if (!HasOpenedContext()) return;
-  myLocalContexts(myCurLocalIndex)->Clear(aMode);
+  if ((*aStat)->SelectionModes().Size() == 1
+   && (*aStat)->SelectionModes().First() == theMode)
+  {
+    return;
+  }
 
+  if ((*aStat)->GraphicStatus() == AIS_DS_Displayed
+    || theIsForce)
+  {
+    switch (theActiveFilter)
+    {
+      case AIS_SelectionModesConcurrency_Single:
+      {
+        for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next())
+        {
+          mgrSelector->Deactivate (theObj, aModeIter.Value());
+        }
+        (*aStat)->ClearSelectionModes();
+        break;
+      }
+      case AIS_SelectionModesConcurrency_GlobalOrLocal:
+      {
+        const Standard_Integer aGlobSelMode = theObj->GlobalSelectionMode();
+        TColStd_ListOfInteger aRemovedModes;
+        for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next())
+        {
+          if ((theMode == aGlobSelMode && aModeIter.Value() != aGlobSelMode)
+           || (theMode != aGlobSelMode && aModeIter.Value() == aGlobSelMode))
+          {
+            mgrSelector->Deactivate (theObj, aModeIter.Value());
+            aRemovedModes.Append (aModeIter.Value());
+          }
+        }
+        if (aRemovedModes.Size() == (*aStat)->SelectionModes().Size())
+        {
+          (*aStat)->ClearSelectionModes();
+        }
+        else
+        {
+          for (TColStd_ListIteratorOfListOfInteger aModeIter (aRemovedModes); aModeIter.More(); aModeIter.Next())
+          {
+            (*aStat)->RemoveSelectionMode (aModeIter.Value());
+          }
+        }
+        break;
+      }
+      case AIS_SelectionModesConcurrency_Multiple:
+      {
+        break;
+      }
+    }
+    mgrSelector->Activate (theObj, theMode);
+  }
+  (*aStat)->AddSelectionMode (theMode);
 }
 
-//=======================================================================
-//function : HighestIndex
-//purpose  : 
-//=======================================================================
-
-Standard_Integer AIS_InteractiveContext::HighestIndex() const
+// ============================================================================
+// function : Activate
+// purpose  :
+// ============================================================================
+void AIS_InteractiveContext::Activate (const Standard_Integer theMode,
+                                       const Standard_Boolean theIsForce)
 {
-  AIS_DataMapIteratorOfDataMapOfILC It(myLocalContexts);
-  Standard_Integer HiInd = 0;
-  for(;It.More();It.Next())
-    HiInd = (It.Key()>HiInd) ? It.Key() : HiInd;
-  return HiInd;
+  AIS_ListOfInteractive aDisplayedObjects;
+  DisplayedObjects (aDisplayedObjects);
 
-}
-
-
-//=======================================================================
-//function : Activate
-//purpose  : 
-//=======================================================================
-
-void AIS_InteractiveContext::
-Activate(const Handle(AIS_InteractiveObject)& anIObj, 
-         const Standard_Integer aMode,
-         const Standard_Boolean theIsForce)
-{
-  if(!HasOpenedContext()){
-    if(!myObjects.IsBound(anIObj)) return;
-    const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
-    if(STAT->GraphicStatus()==AIS_DS_Displayed || theIsForce)
-      mgrSelector->Activate(anIObj,aMode,myMainSel);
-    STAT ->AddSelectionMode(aMode);
-  }
-  else{
-   myLocalContexts(myCurLocalIndex)->ActivateMode(anIObj,aMode);
+  for (AIS_ListIteratorOfListOfInteractive anIter (aDisplayedObjects); anIter.More(); anIter.Next())
+  {
+    Load (anIter.Value(), -1);
+    Activate (anIter.Value(), theMode, theIsForce);
   }
-}
 
-//=======================================================================
-//function : LocalSelector
-//purpose  : 
-//=======================================================================
-Handle( StdSelect_ViewerSelector3d ) AIS_InteractiveContext::LocalSelector() const
-{
-  if( !HasOpenedContext() )
-      return Handle( StdSelect_ViewerSelector3d )();
-  else
-      return myLocalContexts( myCurLocalIndex )->MainSelector();
 }
 
-
-//=======================================================================
-//function : DeActivate
-//purpose  : 
-//=======================================================================
-void AIS_InteractiveContext::
-Deactivate(const Handle(AIS_InteractiveObject)& anIObj)
+// ============================================================================
+// function : Deactivate
+// purpose  :
+// ============================================================================
+void AIS_InteractiveContext::Deactivate (const Standard_Integer theMode)
 {
-  if(!HasOpenedContext()){
-    if(!myObjects.IsBound(anIObj)) return;
-    TColStd_ListIteratorOfListOfInteger ItL;
-    for(ItL.Initialize(myObjects(anIObj)->SelectionModes());
-        ItL.More();
-        ItL.Next()){
-      if(myObjects(anIObj)->GraphicStatus() == AIS_DS_Displayed)
-        mgrSelector->Deactivate(anIObj,ItL.Value(),myMainSel);
-    }
-    myObjects(anIObj)->ClearSelectionModes();
-  }
-  else{
-    const Handle(AIS_LocalContext)& LC = myLocalContexts(myCurLocalIndex);
-    LC->Deactivate(anIObj);
+  AIS_ListOfInteractive aDisplayedObjects;
+  DisplayedObjects (aDisplayedObjects);
+
+  for (AIS_ListIteratorOfListOfInteractive anIter (aDisplayedObjects); anIter.More(); anIter.Next())
+  {
+    Deactivate (anIter.Value(), theMode);
   }
 }
 
-//=======================================================================
-//function : Deactivate
-//purpose  : 
-//=======================================================================
-
-void AIS_InteractiveContext::Deactivate(const Handle(AIS_InteractiveObject)& anIObj, 
-           const Standard_Integer aMode)
+// ============================================================================
+// function : Deactivate
+// purpose  :
+// ============================================================================
+void AIS_InteractiveContext::Deactivate()
 {
-  if(!HasOpenedContext()){
-    if(!myObjects.IsBound(anIObj)) return;
-    const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
+  AIS_ListOfInteractive aDisplayedObjects;
+  DisplayedObjects (aDisplayedObjects);
 
-    if(STAT->GraphicStatus() == AIS_DS_Displayed)
-      mgrSelector->Deactivate(anIObj,aMode,myMainSel);
-    STAT->RemoveSelectionMode(aMode);
-  }
-  else{
-   myLocalContexts(myCurLocalIndex)->DeactivateMode(anIObj,aMode);
+  for (AIS_ListIteratorOfListOfInteractive anIter (aDisplayedObjects); anIter.More(); anIter.Next())
+  {
+    Deactivate (anIter.Value());
   }
 }
 
 //=======================================================================
 //function : ActivatedModes
-//purpose  : 
+//purpose  :
 //=======================================================================
-
-void AIS_InteractiveContext::
-ActivatedModes(const Handle(AIS_InteractiveObject)& anIObj, 
-               TColStd_ListOfInteger& theList) const 
+void AIS_InteractiveContext::ActivatedModes (const Handle(AIS_InteractiveObject)& theObj,
+                                             TColStd_ListOfInteger& theList) const
 {
-  TColStd_ListIteratorOfListOfInteger ItL;
-  if(!HasOpenedContext()){
-    if(myObjects.IsBound(anIObj)){
-      for(ItL.Initialize(myObjects(anIObj)->SelectionModes());
-          ItL.More();
-          ItL.Next())
-        theList.Append(ItL.Value());
-      
-    }
-  }
-  else{
-    if(myLocalContexts(myCurLocalIndex)->IsIn(anIObj)){
-      for(ItL.Initialize(myLocalContexts(myCurLocalIndex)->SelectionModes(anIObj));
-          ItL.More();
-          ItL.Next())
-        theList.Append(ItL.Value());
+  const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
+  if (aStatus != NULL)
+  {
+    for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStatus)->SelectionModes()); aModeIter.More(); aModeIter.Next())
+    {
+      theList.Append (aModeIter.Value());
     }
   }
 }
 
-//=======================================================================
-//function : SetShapeDecomposition
-//purpose  : 
-//=======================================================================
-
-void AIS_InteractiveContext::SetShapeDecomposition(const Handle(AIS_InteractiveObject)& anIObj,
-                                                   const Standard_Boolean StdModeSensitive)
-{
-  if(!HasOpenedContext()) return;
-  myLocalContexts(myCurLocalIndex)->SetShapeDecomposition(anIObj,StdModeSensitive);
-}
-
-//=======================================================================
-//function : SetTemporaryAttributes
-//purpose  : 
-//=======================================================================
-
-void AIS_InteractiveContext::
-SetTemporaryAttributes(const Handle(AIS_InteractiveObject)& /*anObj*/,
-                       const Handle(Prs3d_Drawer)& /*aDrawer*/,
-                       const Standard_Boolean /*updateviewer*/)
-{
-}
-
 //=======================================================================
 //function : SubIntensityOn
 //purpose  : 
@@ -356,126 +226,42 @@ void AIS_InteractiveContext::
 SubIntensityOn(const Handle(AIS_InteractiveObject)& anIObj,
                const Standard_Boolean updateviewer)
 {
-  if(!HasOpenedContext()){
-    if(!myObjects.IsBound(anIObj))
-      return;
-    const Handle(AIS_GlobalStatus)& GB=myObjects(anIObj);
-    if(GB->IsSubIntensityOn())
-      return;
-    GB->SubIntensityOn();
-    Standard_Boolean UpdMain(Standard_False);
-    
-    if (GB->GraphicStatus() == AIS_DS_Displayed)
-    {
-      myMainPM->Color (anIObj, mySubIntensity, GB->DisplayMode());
-      UpdMain = Standard_True;
-    }
-    if(updateviewer){
-      if(UpdMain)
-        myMainVwr->Update();
-    }
-  }
-  else {
-    if(myObjects.IsBound(anIObj)){
-      const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
-      STAT->SubIntensityOn();
-      myMainPM->Color (anIObj, mySubIntensity, STAT->DisplayMode());
-    }
-    else
-      myLocalContexts(myCurLocalIndex)->SubIntensityOn(anIObj);
-    
-    if(updateviewer) myMainVwr->Update();
-  }
+  turnOnSubintensity (anIObj);
+  if (updateviewer)
+    myMainVwr->Update();
 }
 //=======================================================================
 //function : SubIntensityOff
 //purpose  : 
 //=======================================================================
 
-void AIS_InteractiveContext::
-SubIntensityOff(const Handle(AIS_InteractiveObject)& anIObj,
-                const Standard_Boolean updateviewer)
+void AIS_InteractiveContext::SubIntensityOff (const Handle(AIS_InteractiveObject)& theObj,
+                                              const Standard_Boolean theToUpdateViewer)
 {
-  if(!HasOpenedContext()){
-    if(!myObjects.IsBound(anIObj))
-      return;
-    const Handle(AIS_GlobalStatus)& GB=myObjects(anIObj);
-    if(!GB->IsSubIntensityOn())
-      return;
-    GB->SubIntensityOff();
-    Standard_Boolean UpdMain(Standard_False);
-    
-    if(GB->GraphicStatus() == AIS_DS_Displayed)
-    {
-      myMainPM->Unhighlight (anIObj, GB->DisplayMode());
-      UpdMain = Standard_True;
-    }
-    
-    Standard_Integer DM,HM,SM;
-    GetDefModes(anIObj,DM,HM,SM);
-    if(mySelection->IsSelected(anIObj))
-      myMainPM->Highlight(anIObj,HM);
-    
-    if(updateviewer){
-      if(UpdMain)
-        myMainVwr->Update();
-    }
-  }
-  else {
-    if(myObjects.IsBound(anIObj)){
-      const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
-      STAT->SubIntensityOff();
-      myMainPM->Unhighlight (anIObj, STAT->DisplayMode());
-      if(STAT->IsHilighted())
-        Hilight(anIObj);
-    }
-    else
-      myLocalContexts(myCurLocalIndex)->SubIntensityOff(anIObj);
-    if(IsSelected(anIObj))
-      Hilight(anIObj);
-    
-    if(updateviewer) myMainVwr->Update();
+  const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
+  if (aStatus == NULL
+   || !(*aStatus)->IsSubIntensityOn())
+  {
+    return;
   }
-}
-
-//=======================================================================
-//function : SubIntensityOn
-//purpose  : ALL THE DISPLAYED OBJECTS HAVE SUBINTENSITY...
-//=======================================================================
 
-void AIS_InteractiveContext::SubIntensityOn(const Standard_Boolean updateviewer)
-{
-  if(!HasOpenedContext()) return;
-  
-  AIS_DataMapIteratorOfDataMapOfIOStatus It (myObjects);
-  for(;It.More();It.Next()){
-    const Handle(AIS_GlobalStatus)& STAT = It.Value();
-    if(STAT->GraphicStatus()==AIS_DS_Displayed)
-      {
-        STAT->SubIntensityOn();
-        myMainPM->Color (It.Key(), mySubIntensity, STAT->DisplayMode());
-      }
+  (*aStatus)->SubIntensityOff();
+  Standard_Boolean toUpdateMain = Standard_False;
+  if ((*aStatus)->GraphicStatus() == AIS_DS_Displayed)
+  {
+    myMainPM->Unhighlight (theObj);
+    toUpdateMain = Standard_True;
   }
-  if(updateviewer) myMainVwr->Update();
-}
-
-//=======================================================================
-//function : SubIntensityOff
-//purpose  : 
-//=======================================================================
-void AIS_InteractiveContext::SubIntensityOff(const Standard_Boolean updateviewer)
-{
-  if(!HasOpenedContext()) return;
-
-  AIS_DataMapIteratorOfDataMapOfIOStatus It (myObjects);
-  for(;It.More();It.Next()){
-    const Handle(AIS_GlobalStatus)& STAT = It.Value();
-    if(STAT->IsSubIntensityOn())
-      STAT->SubIntensityOff();
-    myMainPM->Unhighlight (It.Key());
+    
+  if (IsSelected (theObj))
+  {
+    highlightSelected (theObj->GlobalSelOwner());
   }
 
-  if(updateviewer) myMainVwr->Update();
+  if (theToUpdateViewer && toUpdateMain)
+  {
+    myMainVwr->Update();
+  }
 }
 
 //=======================================================================
@@ -484,30 +270,7 @@ void AIS_InteractiveContext::SubIntensityOff(const Standard_Boolean updateviewer
 //=======================================================================
 void AIS_InteractiveContext::AddFilter(const Handle(SelectMgr_Filter)& aFilter)
 {
-  if(HasOpenedContext())
-    myLocalContexts(myCurLocalIndex)->AddFilter(aFilter);
-  else
-    myFilters->Add(aFilter);
-}
-
-//=======================================================================
-//function : ActivateStandardMode
-//purpose  : 
-//=======================================================================
-void AIS_InteractiveContext::ActivateStandardMode(const TopAbs_ShapeEnum aStandardActivation)
-{
-  if(!HasOpenedContext()) return;
-  myLocalContexts(myCurLocalIndex)->ActivateStandardMode (aStandardActivation);
-}
-
-//=======================================================================
-//function : DeActivateStandardMode
-//purpose  : 
-//=======================================================================
-void AIS_InteractiveContext::DeactivateStandardMode(const TopAbs_ShapeEnum aStandardActivation)
-{
-  if(!HasOpenedContext()) return;
-  myLocalContexts(myCurLocalIndex)->DeactivateStandardMode (aStandardActivation);
+  myFilters->Add(aFilter);
 }
 
 //=======================================================================
@@ -516,10 +279,7 @@ void AIS_InteractiveContext::DeactivateStandardMode(const TopAbs_ShapeEnum aStan
 //=======================================================================
 void AIS_InteractiveContext::RemoveFilter(const Handle(SelectMgr_Filter)& aFilter)
 {
-  if(HasOpenedContext())
-    myLocalContexts(myCurLocalIndex)->RemoveFilter (aFilter);
-  else
-    myFilters->Remove(aFilter);
+  myFilters->Remove(aFilter);
 }
 
 //=======================================================================
@@ -529,19 +289,7 @@ void AIS_InteractiveContext::RemoveFilter(const Handle(SelectMgr_Filter)& aFilte
 
 void AIS_InteractiveContext::RemoveFilters()
 {
-  if(!HasOpenedContext())
-    myFilters->Clear();
-  else
-    myLocalContexts(myCurLocalIndex)->Clear(AIS_CM_Filters);
-}
-
-//=======================================================================
-//function : ActivatedStandardModes
-//purpose  : 
-//=======================================================================
-const TColStd_ListOfInteger& AIS_InteractiveContext::ActivatedStandardModes() const 
-{
-  return myLocalContexts(myCurLocalIndex)->StandardModes();
+  myFilters->Clear();
 }
 
 //=======================================================================
@@ -550,8 +298,6 @@ const TColStd_ListOfInteger& AIS_InteractiveContext::ActivatedStandardModes() co
 //=======================================================================
 const SelectMgr_ListOfFilter& AIS_InteractiveContext::Filters() const 
 {
-  if(HasOpenedContext())
-    return myLocalContexts(myCurLocalIndex)->ListOfFilter();
   return myFilters->StoredFilters();
 }
 
@@ -561,101 +307,38 @@ const SelectMgr_ListOfFilter& AIS_InteractiveContext::Filters() const
 //=======================================================================
 void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(V3d_View)& aviou)
 {
-  if(HasOpenedContext())
-    myLocalContexts(myCurLocalIndex)->DisplaySensitive(aviou);
-  else
-    myMainSel->DisplaySensitive(aviou);
+  myMainSel->DisplaySensitive(aviou);
 }
 //=======================================================================
 //function : DisplayActiveSensitive
 //purpose  : 
 //=======================================================================
 
-void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(AIS_InteractiveObject)& anIObj,
-                                                    const Handle(V3d_View)& aviou)
+void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(AIS_InteractiveObject)& theObj,
+                                                    const Handle(V3d_View)& theView)
 {
-  TColStd_ListIteratorOfListOfInteger It;
-  Handle(StdSelect_ViewerSelector3d) VS;
-  if(HasOpenedContext()){
-    const Handle(AIS_LocalContext)& LC = myLocalContexts(myCurLocalIndex);
-    if(!LC->IsIn(anIObj)) return;
-    It.Initialize(LC->SelectionModes(anIObj));
-    VS = LC->MainSelector();
+  const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
+  if (aStatus == NULL)
+  {
+    return;
   }
-  else{
-    if(!myObjects.IsBound(anIObj)) return;
-    It.Initialize(myObjects(anIObj)->SelectionModes());
-    VS = myMainSel;
+
+  for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStatus)->SelectionModes()); aModeIter.More(); aModeIter.Next())
+  {
+    const Handle(SelectMgr_Selection)& aSel = theObj->Selection (aModeIter.Value());
+    myMainSel->DisplaySensitive (aSel, theObj->Transformation(), theView, Standard_False);
   }
-  
-  
-  for(;It.More();It.Next()){
-    const Handle(SelectMgr_Selection)& Sel = anIObj->Selection(It.Value());
-    VS->DisplaySensitive(Sel,anIObj->Transformation(), aviou,Standard_False);
-  }  
-  
 }
 
 //=======================================================================
 //function : ClearActiveSensitive
 //purpose  : 
 //=======================================================================
-void AIS_InteractiveContext::ClearActiveSensitive(const Handle(V3d_View)& aviou)
-{
-  
-  if(HasOpenedContext())
-    myLocalContexts(myCurLocalIndex)->ClearSensitive(aviou);
-  else
-    myMainSel->ClearSensitive(aviou);
-}
-
-//=======================================================================
-//function : SetAutomaticHilight
-//purpose  : 
-//=======================================================================
-void  AIS_InteractiveContext::SetAutomaticHilight(const Standard_Boolean aStatus)
+void AIS_InteractiveContext::ClearActiveSensitive (const Handle(V3d_View)& theView)
 {
-
-  if(HasOpenedContext())
-    myLocalContexts(myCurLocalIndex)->SetAutomaticHilight(aStatus);
+  myMainSel->ClearSensitive (theView);
 }
 
-//=======================================================================
-//function : AutomaticHilight
-//purpose  : 
-//=======================================================================
-Standard_Boolean AIS_InteractiveContext::AutomaticHilight() const 
-{
-  if(HasOpenedContext())
-    return myLocalContexts(myCurLocalIndex)->AutomaticHilight();
-  return Standard_True;
-}
-
-//=======================================================================
-//function : UseDisplayedObjects
-//purpose  : 
-//=======================================================================
-
-void AIS_InteractiveContext::UseDisplayedObjects()
-{
-  if(HasOpenedContext())
-    myLocalContexts(myCurLocalIndex)->LoadContextObjects();
-}
-
-//=======================================================================
-//function : NotUseDisplayedObjects
-//purpose  : 
-//=======================================================================
-
-void AIS_InteractiveContext::NotUseDisplayedObjects()
-{
-  if(HasOpenedContext())
-    myLocalContexts(myCurLocalIndex)->UnloadContextObjects();
-}
-
-
-
-
 //=======================================================================
 //function : PurgeDisplay
 //purpose  : 
@@ -663,12 +346,9 @@ void AIS_InteractiveContext::NotUseDisplayedObjects()
 
 Standard_Integer AIS_InteractiveContext::PurgeDisplay()
 {
-  if(HasOpenedContext()) return 0;
-  
   Standard_Integer NbStr = PurgeViewer(myMainVwr);
   myMainVwr->Update();
   return NbStr;
-
 }
 
 
@@ -708,8 +388,7 @@ Standard_Integer AIS_InteractiveContext::PurgeViewer(const Handle(V3d_Viewer)& V
 
 Standard_Boolean AIS_InteractiveContext::IsImmediateModeOn()  const 
 {
-  if(!HasOpenedContext()) return Standard_False;
-  return myLocalContexts(myCurLocalIndex)->IsImmediateModeOn();
+  return myMainPM->IsImmediateModeOn();
 }
 
 //=======================================================================
@@ -719,8 +398,12 @@ Standard_Boolean AIS_InteractiveContext::IsImmediateModeOn()  const
 
 Standard_Boolean AIS_InteractiveContext::BeginImmediateDraw()
 {
-  return HasOpenedContext()
-      && myLocalContexts (myCurLocalIndex)->BeginImmediateDraw();
+  if (myMainPM->IsImmediateModeOn())
+  {
+    myMainPM->BeginImmediateDraw();
+    return Standard_True;
+  }
+  return Standard_False;
 }
 
 //=======================================================================
@@ -731,8 +414,13 @@ Standard_Boolean AIS_InteractiveContext::BeginImmediateDraw()
 Standard_Boolean AIS_InteractiveContext::ImmediateAdd (const Handle(AIS_InteractiveObject)& theObj,
                                                        const Standard_Integer               theMode)
 {
-  return HasOpenedContext()
-      && myLocalContexts (myCurLocalIndex)->ImmediateAdd (theObj, theMode);
+  if (!myMainPM->IsImmediateModeOn())
+  {
+    return Standard_False;
+  }
+
+  myMainPM->AddToImmediateList (myMainPM->Presentation (theObj, theMode));
+  return Standard_True;
 }
 
 //=======================================================================
@@ -742,8 +430,13 @@ Standard_Boolean AIS_InteractiveContext::ImmediateAdd (const Handle(AIS_Interact
 
 Standard_Boolean AIS_InteractiveContext::EndImmediateDraw (const Handle(V3d_View)& theView)
 {
-  return HasOpenedContext()
-      && myLocalContexts (myCurLocalIndex)->EndImmediateDraw (theView->Viewer());
+  if (!myMainPM->IsImmediateModeOn())
+  {
+    return Standard_False;
+  }
+
+  myMainPM->EndImmediateDraw (theView->Viewer());
+  return Standard_True;
 }
 
 //=======================================================================
@@ -753,83 +446,11 @@ Standard_Boolean AIS_InteractiveContext::EndImmediateDraw (const Handle(V3d_View
 
 Standard_Boolean AIS_InteractiveContext::EndImmediateDraw()
 {
-  if (!HasOpenedContext())
-  {
-    return Standard_False;
-  }
-
-  myMainVwr->InitActiveViews();
-  if (!myMainVwr->MoreActiveViews())
+  if (!myMainPM->IsImmediateModeOn())
   {
     return Standard_False;
   }
 
-  Handle(V3d_View) aView = myMainVwr->ActiveView();
-  return myLocalContexts (myCurLocalIndex)->EndImmediateDraw (aView->Viewer());
-}
-
-
-//=======================================================================
-//function : ResetOriginalState
-//purpose  : 
-//=======================================================================
-
-void AIS_InteractiveContext::ResetOriginalState(const Standard_Boolean updateviewer)
-{
-  Standard_Boolean upd_main(Standard_False);
-  TColStd_ListIteratorOfListOfInteger itl;
-  myMainSel->ResetSelectionActivationStatus();
-
-  for (AIS_DataMapIteratorOfDataMapOfIOStatus it(myObjects);it.More();it.Next()){
-    const Handle(AIS_InteractiveObject)& iobj = it.Key();
-    const Handle(AIS_GlobalStatus)& STAT = it.Value();
-    switch(STAT->GraphicStatus()){
-    case AIS_DS_Displayed:{
-      upd_main = Standard_True;
-      
-      // part display...
-      myMainPM->Display (iobj, STAT->DisplayMode());
-      if(STAT->IsHilighted()){
-        if(STAT->HilightColor()!=Quantity_NOC_WHITE)
-          HilightWithColor(iobj,STAT->HilightColor(),Standard_False);
-        else
-          Hilight(iobj,Standard_False);
-      }
-      //part selection
-      for(itl.Initialize(STAT->SelectionModes());itl.More();itl.Next()){
-        if(itl.Value()!=-1)
-          mgrSelector->Activate(iobj,itl.Value(),myMainSel);
-      }
-      break; 
-    }
-    case AIS_DS_Erased:{
-      EraseGlobal(iobj,Standard_False);
-      break;
-    }
-    default:
-      break;
-    }
-  }
-  if(updateviewer){
-    if(upd_main) 
-      myMainVwr->Update();
-  }
-}
-
-//=======================================================================
-//function : SetZDetection
-//purpose  : 
-//=======================================================================
-void  AIS_InteractiveContext::SetZDetection(const Standard_Boolean aStatus)
-{
-  myZDetectionFlag = aStatus;
-}
-
-//=======================================================================
-//function : ZDetection 
-//purpose  : 
-//=======================================================================
-Standard_Boolean AIS_InteractiveContext::ZDetection() const 
-{
-  return myZDetectionFlag;
+  myMainPM->EndImmediateDraw (myMainVwr);
+  return Standard_True;
 }