0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / AIS / AIS_InteractiveContext_2.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 0823bc0..9ce6fa8
-// File:        AIS_InteractiveContext_2.cxx
-// Created:     Wed Jan 29 10:55:05 1997
-// Author:      Robert COUBLANC
-//              <rob@robox.paris1.matra-dtv.fr>
+// Created on: 1997-01-29
+// Created by: Robert COUBLANC
+// Copyright (c) 1997-1999 Matra Datavision
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
-#define IMP051001       //GG Adds SetZDetected() and ZDetected() methods
-
-#include <AIS_InteractiveContext.jxx>
-
-#include <AIS_LocalContext.hxx>
-
-#include <AIS_GlobalStatus.hxx>
-#include <TColStd_ListIteratorOfListOfInteger.hxx>
 
 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
-#include <AIS_DataMapIteratorOfDataMapOfILC.hxx>
-#include <Graphic3d_StructureManager.hxx>
-#include <Graphic3d_Structure.hxx>
-#include <Graphic3d_MapOfStructure.hxx>
-#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
+#include <AIS_GlobalStatus.hxx>
+#include <AIS_InteractiveContext.hxx>
+#include <AIS_InteractiveObject.hxx>
 #include <AIS_Selection.hxx>
+#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
+#include <Graphic3d_MapOfStructure.hxx>
+#include <Graphic3d_Structure.hxx>
+#include <Graphic3d_StructureManager.hxx>
+#include <Prs3d_BasicAspect.hxx>
+#include <Prs3d_LineAspect.hxx>
+#include <Quantity_Color.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+#include <SelectMgr_Filter.hxx>
+#include <SelectMgr_OrFilter.hxx>
+#include <SelectMgr_SelectionManager.hxx>
+#include <Standard_Transient.hxx>
+#include <StdSelect_ViewerSelector3d.hxx>
+#include <TCollection_AsciiString.hxx>
+#include <TCollection_ExtendedString.hxx>
+#include <TColStd_ListIteratorOfListOfInteger.hxx>
+#include <TopLoc_Location.hxx>
+#include <TopoDS_Shape.hxx>
+#include <V3d_View.hxx>
+#include <V3d_Viewer.hxx>
 
-
-static TColStd_ListIteratorOfListOfInteger ItL;
 //=======================================================================
-//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(!IsCurrent(myLastPicked)){
-    if(!myLastPicked.IsNull()){
-      Standard_Integer HiMod = myLastPicked->HasHilightMode()?myLastPicked->HilightMode():0;
-      myMainPM->Unhighlight(myLastPicked,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();
-  myLastinColl.Nullify();
-  myLastPicked.Nullify();
-  myWasLastMain = Standard_True;
-
-
-
-  Standard_Integer untilnow = myCurLocalIndex;
-  
-  myCurLocalIndex = HighestIndex() + 1;
-  
-  Handle(AIS_LocalContext) NewLocal= new AIS_LocalContext(this,myCurLocalIndex,
-                                                          UseDisplayedObjects,
-                                                          AllowShapeDecomposition,
-                                                          AcceptEraseOfTemporary);
-  
-  // rob 16/04/97 Problems of asynchronous orders
-  if(myLocalContexts.Extent()>0){
-    const Select3D_Projector& Prj = myLocalContexts(untilnow)->MainSelector()->Projector();
-    NewLocal->MainSelector()->Set(Prj);
-  }
-  else{
-    const Select3D_Projector& Prj = myMainSel->Projector();
-    NewLocal->MainSelector()->Set(Prj);
-  }
-  
-  NewLocal->MainSelector()->UpdateConversion();
-  
-  myLocalContexts.Bind(myCurLocalIndex,NewLocal);
-
-
-#ifdef DEB
-  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 DEB 
- 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){
-   
-   Standard_Boolean updateproj = !(myLocalContexts(myCurLocalIndex)->HasSameProjector(myMainSel->Projector()));
-   myLocalContexts(myCurLocalIndex)->Terminate( updateviewer );
-   myLocalContexts.UnBind(myCurLocalIndex);
-   myCurLocalIndex = 0;
-
-   ResetOriginalState(Standard_False);
-   if(updateproj)
-     myMainSel->UpdateConversion();
-   else{
-     myMainSel->ReactivateProjector();
-     myMainSel->UpdateSort();
-   }
-   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();
-     const Handle(AIS_LocalContext)& LocCtx = myLocalContexts(myCurLocalIndex);
-     if(LocCtx->HasSameProjector(VS->Projector())){
-       LocCtx->MainSelector()->ReactivateProjector();
-     }
-     else
-       LocCtx->MainSelector()->UpdateConversion();
-   }
-   else if(debugmode)
-     cout<<"a No Current Local Context WasClosed"<<endl;
-   
-   if(debugmode) cout<<"Index Of CurrentLocalContext:"<<myCurLocalIndex<<endl;
-   
- }
-   
- if(updateviewer) myMainVwr->Update();
-}
+  const Handle(AIS_GlobalStatus)* aStat = myObjects.Seek (theObj);
+  if (aStat == NULL)
+  {
+    return;
+  }
 
-//=======================================================================
-//function : CloseAllContexts
-//purpose  : 
-//=======================================================================
+  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);
+      }
+    }
 
-void AIS_InteractiveContext::CloseAllContexts(const Standard_Boolean updateviewer)
-{
-  
-  while(!myLocalContexts.IsEmpty()){
-    CloseLocalContext(myCurLocalIndex,Standard_False);
+    if (theMode == -1)
+    {
+      (*aStat)->ClearSelectionModes();
+    }
+    else
+    {
+      (*aStat)->RemoveSelectionMode (theMode);
+    }
+    return;
+  }
+  else if (theMode == -1)
+  {
+    return;
   }
-  
-  ResetOriginalState(Standard_False);
-
-  myMainSel->UpdateSort();
-  if(!myIsCollClosed && !myCollectorSel.IsNull())
-    myCollectorSel->UpdateSort();
-  if(updateviewer) myMainVwr->Update();
-}
 
-//=======================================================================
-//function : IndexOfCurrentLocal
-//purpose  : 
-//=======================================================================
+  if ((*aStat)->SelectionModes().Size() == 1
+   && (*aStat)->SelectionModes().First() == theMode)
+  {
+    return;
+  }
 
-Standard_Integer AIS_InteractiveContext::IndexOfCurrentLocal() const
-{
-  return myCurLocalIndex;
+  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 : ClearLocalContext
-//purpose  : 
-//=======================================================================
-
-void AIS_InteractiveContext::ClearLocalContext(const AIS_ClearMode aMode)
+// ============================================================================
+// function : Activate
+// purpose  :
+// ============================================================================
+void AIS_InteractiveContext::Activate (const Standard_Integer theMode,
+                                       const Standard_Boolean theIsForce)
 {
-  if (!HasOpenedContext()) return;
-  myLocalContexts(myCurLocalIndex)->Clear(aMode);
-
-}
-
-//=======================================================================
-//function : HighestIndex
-//purpose  : 
-//=======================================================================
+  AIS_ListOfInteractive aDisplayedObjects;
+  DisplayedObjects (aDisplayedObjects);
 
-Standard_Integer AIS_InteractiveContext::HighestIndex() const
-{
-  AIS_DataMapIteratorOfDataMapOfILC It(myLocalContexts);
-  Standard_Integer HiInd = 0;
-  for(;It.More();It.Next())
-    HiInd = (It.Key()>HiInd) ? It.Key() : HiInd;
-  return HiInd;
-
-}
-
-
-//=======================================================================
-//function : Activate
-//purpose  : 
-//=======================================================================
-
-void AIS_InteractiveContext::
-Activate(const Handle(AIS_InteractiveObject)& anIObj, 
-         const Standard_Integer aMode)
-{
-  if(!HasOpenedContext()){
-    if(!myObjects.IsBound(anIObj)) return;
-    const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
-    if(STAT->GraphicStatus()==AIS_DS_Displayed)
-      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;
-    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
 {
-  if(!HasOpenedContext()){
-    if(myObjects.IsBound(anIObj)){
-      //ItL is a static variable... 
-      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  : 
@@ -363,145 +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),UpdColl(Standard_False);
-    
-    for(TColStd_ListIteratorOfListOfInteger It(GB->DisplayedModes());It.More();It.Next()){
-      if(GB->GraphicStatus()==AIS_DS_Displayed){
-        myMainPM->Color(anIObj,mySubIntensity,It.Value());
-        UpdMain = Standard_True;}
-      else if(GB->GraphicStatus()==AIS_DS_Erased){
-        myCollectorPM->Color(anIObj,mySubIntensity,It.Value());
-        UpdColl=Standard_True;
-      }
-    }
-    if(updateviewer){
-      if(UpdMain)
-        myMainVwr->Update();
-      if(UpdColl)
-        myCollectorVwr->Update();
-    }
-  }
-  else {
-    if(myObjects.IsBound(anIObj)){
-      const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
-      STAT->SubIntensityOn();
-      for (ItL.Initialize(STAT->DisplayedModes());ItL.More();ItL.Next())
-        myMainPM->Color(anIObj,mySubIntensity,ItL.Value());
-    }
-    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),UpdColl(Standard_False);
-    
-    for(TColStd_ListIteratorOfListOfInteger It(GB->DisplayedModes());It.More();It.Next()){
-      if(GB->GraphicStatus()!=AIS_DS_Erased){
-        myMainPM->Unhighlight(anIObj,It.Value());
-        UpdMain = Standard_True;}
-      else {
-        myCollectorPM->Unhighlight(anIObj,It.Value());
-        UpdColl=Standard_True;
-      }
-    }
-    
-    Standard_Integer DM,HM,SM;
-    GetDefModes(anIObj,DM,HM,SM);
-    if(AIS_Selection::IsSelected(anIObj))
-      myMainPM->Highlight(anIObj,HM);
-    
-    if(updateviewer){
-      if(UpdMain)
-        myMainVwr->Update();
-      if(UpdColl)
-        myCollectorVwr->Update();
-    }
-  }
-  else {
-    if(myObjects.IsBound(anIObj)){
-      const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
-      STAT->SubIntensityOff();
-      for (ItL.Initialize(STAT->DisplayedModes());ItL.More();ItL.Next())
-        myMainPM->Unhighlight(anIObj,ItL.Value());
-      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);
-  TColStd_ListIteratorOfListOfInteger ItM;
-  for(;It.More();It.Next()){
-    const Handle(AIS_GlobalStatus)& STAT = It.Value();
-    if(STAT->GraphicStatus()==AIS_DS_Displayed)
-      {
-        STAT->SubIntensityOn();
-        for(ItM.Initialize(STAT->DisplayedModes());ItM.More();ItM.Next())
-          {myMainPM->Color(It.Key(),mySubIntensity,ItM.Value());}
-      }
+  (*aStatus)->SubIntensityOff();
+  Standard_Boolean toUpdateMain = Standard_False;
+  if ((*aStatus)->GraphicStatus() == AIS_DS_Displayed)
+  {
+    myMainPM->Unhighlight (theObj);
+    toUpdateMain = Standard_True;
+  }
+    
+  if (IsSelected (theObj))
+  {
+    highlightSelected (theObj->GlobalSelOwner());
   }
-  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();
-    for(ItL.Initialize(STAT->DisplayedModes());ItL.More();ItL.Next())
-      myMainPM->Unhighlight(It.Key());
+  if (theToUpdateViewer && toUpdateMain)
+  {
+    myMainVwr->Update();
   }
-  
-  if(updateviewer) myMainVwr->Update();
 }
 
 //=======================================================================
@@ -510,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);
 }
 
 //=======================================================================
@@ -542,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);
 }
 
 //=======================================================================
@@ -555,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();
 }
 
 //=======================================================================
@@ -576,186 +298,57 @@ const TColStd_ListOfInteger& AIS_InteractiveContext::ActivatedStandardModes() co
 //=======================================================================
 const SelectMgr_ListOfFilter& AIS_InteractiveContext::Filters() const 
 {
-  if(HasOpenedContext())
-    return myLocalContexts(myCurLocalIndex)->ListOfFilter();
   return myFilters->StoredFilters();
 }
 
-//=======================================================================
-//function : DisplayActiveAreas
-//purpose  : 
-//=======================================================================
-void AIS_InteractiveContext::DisplayActiveAreas(const Handle(V3d_View)& aviou)
-{
-  if(HasOpenedContext())
-    myLocalContexts(myCurLocalIndex)->DisplayAreas(aviou);
-  else
-    myMainSel->DisplayAreas(aviou);
-  
-}
-
-//=======================================================================
-//function : ClearActiveAreas
-//purpose  : 
-//=======================================================================
-void AIS_InteractiveContext::ClearActiveAreas(const Handle(V3d_View)& aviou)
-{
-  if(HasOpenedContext())
-    myLocalContexts(myCurLocalIndex)->ClearAreas(aviou);
-  else
-    myMainSel->ClearAreas(aviou);
-}
-
 //=======================================================================
 //function : DisplayActiveSensitive
 //purpose  : 
 //=======================================================================
 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();
-  }
-  else{
-    if(!myObjects.IsBound(anIObj)) return;
-    It.Initialize(myObjects(anIObj)->SelectionModes());
-    VS = myMainSel;
+  const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
+  if (aStatus == NULL)
+  {
+    return;
   }
-  
-  
-  for(;It.More();It.Next()){
-    const Handle(SelectMgr_Selection)& Sel = anIObj->Selection(It.Value());
-    VS->DisplaySensitive(Sel,aviou,Standard_False);
-  }  
-  
-}
 
-//=======================================================================
-//function : DisplayActiveAreas
-//purpose  : 
-//=======================================================================
-
-void AIS_InteractiveContext::DisplayActiveAreas(const Handle(AIS_InteractiveObject)& anIObj,
-                                                const Handle(V3d_View)& aviou)
-{
-  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();
+  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);
   }
-  else{
-    if(!myObjects.IsBound(anIObj)) return;
-    It.Initialize(myObjects(anIObj)->SelectionModes());
-    VS = myMainSel;
-  }
-  
-  
-  for(;It.More();It.Next()){
-    const Handle(SelectMgr_Selection)& Sel = anIObj->Selection(It.Value());
-    VS->DisplayAreas(Sel,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)
-{
-
-  if(HasOpenedContext())
-    myLocalContexts(myCurLocalIndex)->SetAutomaticHilight(aStatus);
-}
-
-//=======================================================================
-//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
+//function : ClearActiveSensitive
 //purpose  : 
 //=======================================================================
-
-void AIS_InteractiveContext::NotUseDisplayedObjects()
+void AIS_InteractiveContext::ClearActiveSensitive (const Handle(V3d_View)& theView)
 {
-  if(HasOpenedContext())
-    myLocalContexts(myCurLocalIndex)->UnloadContextObjects();
+  myMainSel->ClearSensitive (theView);
 }
 
-
-
-
 //=======================================================================
 //function : PurgeDisplay
 //purpose  : 
 //=======================================================================
 
-Standard_Integer AIS_InteractiveContext::PurgeDisplay(const Standard_Boolean CollectorToo)
+Standard_Integer AIS_InteractiveContext::PurgeDisplay()
 {
-  if(HasOpenedContext()) return 0;
-  
   Standard_Integer NbStr = PurgeViewer(myMainVwr);
-  if(!myCollectorVwr.IsNull())
-    if(CollectorToo){
-      NbStr+=PurgeViewer(myCollectorVwr);
-      if(!IsCollectorClosed())
-        myCollectorVwr->Update();
-    }
   myMainVwr->Update();
   return NbStr;
-
 }
 
 
@@ -765,7 +358,7 @@ Standard_Integer AIS_InteractiveContext::PurgeDisplay(const Standard_Boolean Col
 //=======================================================================
 Standard_Integer AIS_InteractiveContext::PurgeViewer(const Handle(V3d_Viewer)& Vwr)
 {
-  const Handle(Graphic3d_StructureManager)& GSM = Vwr->Viewer();
+  Handle(Graphic3d_StructureManager) GSM = Vwr->StructureManager();
   Standard_Integer NbCleared(0);
   Graphic3d_MapOfStructure SOS;
   GSM->DisplayedStructures(SOS);
@@ -788,155 +381,76 @@ Standard_Integer AIS_InteractiveContext::PurgeViewer(const Handle(V3d_Viewer)& V
   return NbCleared;
 }
 
-
 //=======================================================================
 //function : IsImmediateModeOn
-//purpose  : 
+//purpose  :
 //=======================================================================
-Standard_Boolean AIS_InteractiveContext::IsImmediateModeOn()  const 
-{
-  if(!HasOpenedContext()) return Standard_False;
-  return myLocalContexts(myCurLocalIndex)->IsImmediateModeOn();
-}
 
-Standard_Boolean  AIS_InteractiveContext::BeginImmediateDraw()
+Standard_Boolean AIS_InteractiveContext::IsImmediateModeOn()  const 
 {
-  if(HasOpenedContext())
-    return myLocalContexts(myCurLocalIndex)->BeginImmediateDraw();
-  return Standard_False;
+  return myMainPM->IsImmediateModeOn();
 }
 
 //=======================================================================
-//function : ImmediateAdd
-//purpose  : 
+//function : BeginImmediateDraw
+//purpose  :
 //=======================================================================
 
-Standard_Boolean AIS_InteractiveContext::ImmediateAdd(const Handle(AIS_InteractiveObject)& anIObj,
-                                                      const Standard_Integer AMode)
-{ 
-  if(HasOpenedContext()){
-    return myLocalContexts(myCurLocalIndex)->ImmediateAdd(anIObj,AMode);}
-  return Standard_False;
-}
-
-//=======================================================================
-//function : ImmediateRemove
-//purpose  : 
-//=======================================================================
-
-Standard_Boolean AIS_InteractiveContext::ImmediateRemove(const Handle(AIS_InteractiveObject)& anIObj,
-                                                         const Standard_Integer aMode)
+Standard_Boolean AIS_InteractiveContext::BeginImmediateDraw()
 {
-  if(HasOpenedContext())
-    return myLocalContexts(myCurLocalIndex)->ImmediateRemove(anIObj,aMode);
+  if (myMainPM->IsImmediateModeOn())
+  {
+    myMainPM->BeginImmediateDraw();
+    return Standard_True;
+  }
   return Standard_False;
 }
 
 //=======================================================================
-//function : EndImmediateDraw
-//purpose  : 
+//function : ImmediateAdd
+//purpose  :
 //=======================================================================
 
-Standard_Boolean AIS_InteractiveContext::EndImmediateDraw(const Handle(V3d_View)& aView,
-                                                          const Standard_Boolean DoubleBuf)
+Standard_Boolean AIS_InteractiveContext::ImmediateAdd (const Handle(AIS_InteractiveObject)& theObj,
+                                                       const Standard_Integer               theMode)
 {
-  if(HasOpenedContext())
-    return myLocalContexts(myCurLocalIndex)->EndImmediateDraw(aView,DoubleBuf);
-  return Standard_False;
-  
+  if (!myMainPM->IsImmediateModeOn())
+  {
+    return Standard_False;
+  }
+
+  myMainPM->AddToImmediateList (myMainPM->Presentation (theObj, theMode));
+  return Standard_True;
 }
 
 //=======================================================================
 //function : EndImmediateDraw
-//purpose  : 
+//purpose  :
 //=======================================================================
 
-Standard_Boolean AIS_InteractiveContext::EndImmediateDraw(const Standard_Boolean DoubleBuf)
+Standard_Boolean AIS_InteractiveContext::EndImmediateDraw (const Handle(V3d_View)& theView)
 {
-  if(HasOpenedContext()){
-    Handle(V3d_View) V ;
-    myMainVwr->InitActiveViews();
-    if(myMainVwr->MoreActiveViews()){
-      V = myMainVwr->ActiveView();
-      
-      return myLocalContexts(myCurLocalIndex)->EndImmediateDraw(V,DoubleBuf);
-    }
+  if (!myMainPM->IsImmediateModeOn())
+  {
+    return Standard_False;
   }
-  return Standard_False;
-  
-}
 
+  myMainPM->EndImmediateDraw (theView->Viewer());
+  return Standard_True;
+}
 
 //=======================================================================
-//function : ResetOriginalState
-//purpose  : 
+//function : EndImmediateDraw
+//purpose  :
 //=======================================================================
 
-void AIS_InteractiveContext::ResetOriginalState(const Standard_Boolean updateviewer)
+Standard_Boolean AIS_InteractiveContext::EndImmediateDraw()
 {
-  Standard_Boolean upd_main(Standard_False),upd_col(Standard_False);
-  TColStd_ListIteratorOfListOfInteger itl;
-  
-  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...
-      for(itl.Initialize(STAT->DisplayedModes());itl.More();itl.Next())
-        myMainPM->Display(iobj,itl.Value());
-      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:{
-      upd_col = Standard_True;
-      EraseGlobal(iobj,Standard_False,Standard_True);
-      break;
-    }
-    case AIS_DS_FullErased:{
-      EraseGlobal(iobj,Standard_False,Standard_False);
-      break;
-    }
-    default:
-      break;
-    }
-  }
-  if(updateviewer){
-    if(upd_main) 
-      myMainVwr->Update();
-    if(upd_col)
-      myCollectorVwr->Update();
+  if (!myMainPM->IsImmediateModeOn())
+  {
+    return Standard_False;
   }
-}
 
-#ifdef IMP051001
-//=======================================================================
-//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;
 }
-#endif