0031221: Visualization - selection filter in context
[occt.git] / src / AIS / AIS_InteractiveContext.cxx
index 5c8aa13..67fece1 100644 (file)
@@ -37,7 +37,6 @@
 #include <Prs3d_PlaneAspect.hxx>
 #include <Prs3d_PointAspect.hxx>
 #include <Prs3d_ShadingAspect.hxx>
-#include <PrsMgr_ModedPresentation.hxx>
 #include <PrsMgr_PresentableObject.hxx>
 #include <Quantity_Color.hxx>
 #include <SelectMgr_EntityOwner.hxx>
@@ -66,13 +65,15 @@ namespace
   typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)>::Iterator AIS_MapIteratorOfMapOfObjectOwners;
 
   //! Initialize default highlighting attributes.
-  static void initDefaultHilightAttributes (const Handle(Prs3d_Drawer)& theDrawer)
+  static void initDefaultHilightAttributes (const Handle(Prs3d_Drawer)& theDrawer,
+                                            const Quantity_Color& theColor)
   {
     theDrawer->SetMethod (Aspect_TOHM_COLOR);
     theDrawer->SetDisplayMode (0);
+    theDrawer->SetColor (theColor);
 
-    theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_BLACK, 1.0));
-    *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
+    theDrawer->SetupOwnShadingAspect();
+    theDrawer->SetupOwnPointAspect();
     theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
     *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
     theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
@@ -83,6 +84,24 @@ namespace
     *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
     theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
     *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
+    theDrawer->SetDatumAspect (new Prs3d_DatumAspect());
+
+    theDrawer->ShadingAspect()->SetColor (theColor);
+    theDrawer->WireAspect()->SetColor (theColor);
+    theDrawer->LineAspect()->SetColor (theColor);
+    theDrawer->PlaneAspect()->ArrowAspect()->SetColor (theColor);
+    theDrawer->PlaneAspect()->IsoAspect()->SetColor (theColor);
+    theDrawer->PlaneAspect()->EdgesAspect()->SetColor (theColor);
+    theDrawer->FreeBoundaryAspect()->SetColor (theColor);
+    theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
+    theDrawer->PointAspect()->SetColor (theColor);
+    for (Standard_Integer aPartIter = 0; aPartIter < Prs3d_DP_None; ++aPartIter)
+    {
+      if (Handle(Prs3d_LineAspect) aLineAsp = theDrawer->DatumAspect()->LineAspect ((Prs3d_DatumParts )aPartIter))
+      {
+        aLineAsp->SetColor (theColor);
+      }
+    }
 
     theDrawer->WireAspect()->SetWidth (2.0);
     theDrawer->LineAspect()->SetWidth (2.0);
@@ -107,10 +126,9 @@ AIS_InteractiveContext::AIS_InteractiveContext(const Handle(V3d_Viewer)& MainVie
 myMainPM(new PrsMgr_PresentationManager3d(MainViewer->StructureManager())),
 myMainVwr(MainViewer),
 myMainSel(new StdSelect_ViewerSelector3d()),
-myWasLastMain(Standard_False),
 myToHilightSelected(Standard_True),
 mySelection(new AIS_Selection()),
-myFilters(new SelectMgr_OrFilter()),
+myFilters (new SelectMgr_AndOrFilter(SelectMgr_FilterType_OR)),
 myDefaultDrawer(new Prs3d_Drawer()),
 myCurDetected(0),
 myCurHighlighted(0),
@@ -132,30 +150,26 @@ myIsAutoActivateSelMode(Standard_True)
   {
     const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Dynamic];
     aStyle->Link (myDefaultDrawer);
-    initDefaultHilightAttributes (aStyle);
+    initDefaultHilightAttributes (aStyle, Quantity_NOC_CYAN1);
     aStyle->SetZLayer(Graphic3d_ZLayerId_Top);
-    aStyle->SetColor (Quantity_NOC_CYAN1);
   }
   {
     const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalDynamic];
     aStyle->Link (myDefaultDrawer);
-    initDefaultHilightAttributes (aStyle);
+    initDefaultHilightAttributes (aStyle, Quantity_NOC_CYAN1);
     aStyle->SetZLayer(Graphic3d_ZLayerId_Topmost);
-    aStyle->SetColor (Quantity_NOC_CYAN1);
   }
   {
     const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Selected];
     aStyle->Link (myDefaultDrawer);
-    initDefaultHilightAttributes (aStyle);
+    initDefaultHilightAttributes (aStyle, Quantity_NOC_GRAY80);
     aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
-    aStyle->SetColor (Quantity_NOC_GRAY80);
   }
   {
     const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalSelected];
     aStyle->Link (myDefaultDrawer);
-    initDefaultHilightAttributes (aStyle);
+    initDefaultHilightAttributes (aStyle, Quantity_NOC_GRAY80);
     aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
-    aStyle->SetColor (Quantity_NOC_GRAY80);
   }
   {
     const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity];
@@ -189,6 +203,29 @@ AIS_InteractiveContext::~AIS_InteractiveContext()
   }
 }
 
+//=======================================================================
+//function : LastActiveView
+//purpose  :
+//=======================================================================
+Handle(V3d_View) AIS_InteractiveContext::LastActiveView() const
+{
+  if (myLastActiveView == NULL
+   || myMainVwr.IsNull())
+  {
+    return Handle(V3d_View)();
+  }
+
+  // as a precaution - check that myLastActiveView pointer is a valid active View
+  for (V3d_ListOfViewIterator aViewIter = myMainVwr->ActiveViewIterator(); aViewIter.More(); aViewIter.Next())
+  {
+    if (aViewIter.Value() == myLastActiveView)
+    {
+      return aViewIter.Value();
+    }
+  }
+  return Handle(V3d_View)();
+}
+
 //=======================================================================
 //function : UpdateCurrentViewer
 //purpose  : 
@@ -426,8 +463,7 @@ void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIO
   setContextToObject (theIObj);
   if (!myObjects.IsBound (theIObj))
   {
-    Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
-    myObjects.Bind   (theIObj, aStatus);
+    setObjectStatus (theIObj, AIS_DS_Displayed, theDispMode, theSelectionMode);
     myMainVwr->StructureManager()->RegisterObject (theIObj);
     myMainPM->Display(theIObj, theDispMode);
     if (theSelectionMode != -1)
@@ -504,8 +540,7 @@ void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
   {
     Standard_Integer aDispMode, aHiMod, aSelModeDef;
     GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
-    Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Erased, aDispMode, theSelMode != -1 ? theSelMode : aSelModeDef);
-    myObjects.Bind (theIObj, aStatus);
+    setObjectStatus (theIObj, AIS_DS_Erased, aDispMode, theSelMode != -1 ? theSelMode : aSelModeDef);
     myMainVwr->StructureManager()->RegisterObject (theIObj);
   }
 
@@ -756,7 +791,9 @@ Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_Ent
     return myObjects (anObj)->IsHilighted();
   }
 
-  return theOwner->IsSelected();
+  const Handle(Prs3d_Drawer)& aStyle = getSelStyle (anObj, theOwner);
+  const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1);
+  return theOwner->IsHilighted (myMainPM, aHiMode);
 }
 
 //=======================================================================
@@ -952,7 +989,8 @@ void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObjec
     return;
   }
 
-  theIObj->Update (theAllModes);
+  theIObj->SetToUpdate();
+  theIObj->UpdatePresentations (theAllModes);
   if (!theToUpdateViewer)
   {
     return;
@@ -1006,13 +1044,7 @@ void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIOb
     return;
   }
 
-  TColStd_ListOfInteger aPrsModes;
-  theIObj->ToBeUpdated (aPrsModes);
-  for (TColStd_ListIteratorOfListOfInteger aPrsModesIt (aPrsModes); aPrsModesIt.More(); aPrsModesIt.Next())
-  {
-    theIObj->Update (aPrsModesIt.Value(), Standard_False);
-  }
-
+  theIObj->UpdatePresentations();
   mgrSelector->Update(theIObj);
 
   if (theUpdateViewer)
@@ -1141,57 +1173,6 @@ Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
   return myDefaultDrawer->DeviationCoefficient();
 }
 
-//=======================================================================
-//function : SetHLRDeviationCoefficient
-//purpose  :
-//=======================================================================
-void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
-{
-  myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
-}
-
-//=======================================================================
-//function : HLRDeviationCoefficient
-//purpose  :
-//=======================================================================
-Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
-{
-  return myDefaultDrawer->HLRDeviationCoefficient();
-}
-
-//=======================================================================
-//function : SetHLRAngle
-//purpose  :
-//=======================================================================
-void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
-{
-  myDefaultDrawer->SetHLRAngle (theAngle);
-}
-
-//=======================================================================
-//function : SetHLRAngleAndDeviation
-//purpose  : compute with anangle a HLRAngle and a HLRDeviationCoefficient 
-//           and set them in myHLRAngle and in myHLRDeviationCoefficient
-//           of myDefaultDrawer 
-//=======================================================================
-void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
-{
-  Standard_Real anOutAngl, anOutDefl;
-  HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
-
-  myDefaultDrawer->SetHLRAngle                (anOutAngl);
-  myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
-}
-
-//=======================================================================
-//function : HLRAngle
-//purpose  :
-//=======================================================================
-Standard_Real AIS_InteractiveContext::HLRAngle() const 
-{
-  return myDefaultDrawer->HLRAngle();
-}
-
 //=======================================================================
 //function : SetDisplayMode
 //purpose  :
@@ -1369,63 +1350,6 @@ void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_Interactive
   }
 }
 
-//=======================================================================
-//function : redisplayPrsRecModes
-//purpose  :
-//=======================================================================
-void AIS_InteractiveContext::redisplayPrsRecModes (const Handle(AIS_InteractiveObject)& theIObj,
-                                                   const Standard_Boolean               theToUpdateViewer)
-{
-  if (theIObj->RecomputeEveryPrs())
-  {
-    theIObj->Update (Standard_True);
-    theIObj->UpdateSelection();
-  }
-  else
-  {
-    for (TColStd_ListIteratorOfListOfInteger aModes (theIObj->ListOfRecomputeModes()); aModes.More(); aModes.Next())
-    {
-      theIObj->Update (aModes.Value(), Standard_False);
-    }
-    theIObj->UpdateSelection();
-    theIObj->SetRecomputeOk();
-  }
-
-  if (theToUpdateViewer)
-  {
-    UpdateCurrentViewer();
-  }
-}
-
-//=======================================================================
-//function : redisplayPrsModes
-//purpose  :
-//=======================================================================
-void AIS_InteractiveContext::redisplayPrsModes (const Handle(AIS_InteractiveObject)& theIObj,
-                                                const Standard_Boolean               theToUpdateViewer)
-{
-  if (theIObj->RecomputeEveryPrs())
-  {
-    theIObj->Update (Standard_True);
-    theIObj->UpdateSelection();
-  }
-  else
-  {
-    TColStd_ListOfInteger aModes;
-    theIObj->ToBeUpdated (aModes);
-    for (TColStd_ListIteratorOfListOfInteger aModeIter (aModes); aModeIter.More(); aModeIter.Next())
-    {
-      theIObj->Update (aModeIter.Value(), Standard_False);
-    }
-    theIObj->SetRecomputeOk();
-  }
-
-  if (theToUpdateViewer)
-  {
-    UpdateCurrentViewer();
-  }
-}
-
 //=======================================================================
 //function : SetColor
 //purpose  :
@@ -1441,7 +1365,11 @@ void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theI
 
   setContextToObject (theIObj);
   theIObj->SetColor (theColor);
-  redisplayPrsRecModes (theIObj, theToUpdateViewer);
+  theIObj->UpdatePresentations();
+  if (theToUpdateViewer)
+  {
+    UpdateCurrentViewer();
+  }
 }
 
 //=======================================================================
@@ -1486,37 +1414,11 @@ void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_Interacti
 
   Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
   aShape->SetOwnDeviationCoefficient (theCoefficient);
-  redisplayPrsModes (theIObj, theToUpdateViewer);
-}
-
-//=======================================================================
-//function : SetHLRDeviationCoefficient
-//purpose  :
-//=======================================================================
-void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
-                                                         const Standard_Real                  theCoefficient,
-                                                         const Standard_Boolean               theToUpdateViewer)
-{
-  if (theIObj.IsNull())
-  {
-    return;
-  }
-
-  // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
-  setContextToObject (theIObj);
-  if (theIObj->Type() != AIS_KOI_Object
-   && theIObj->Type() != AIS_KOI_Shape)
-  {
-    return;
-  }
-  else if (theIObj->Signature() != 0)
+  aShape->UpdatePresentations();
+  if (theToUpdateViewer)
   {
-    return;
+    UpdateCurrentViewer();
   }
-
-  Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
-  aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
-  redisplayPrsModes (theIObj, theToUpdateViewer);
 }
 
 //=======================================================================
@@ -1545,7 +1447,11 @@ void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObje
 
   Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
   aShape->SetOwnDeviationAngle (theAngle);
-  redisplayPrsModes (theIObj, theToUpdateViewer);
+  aShape->UpdatePresentations();
+  if (theToUpdateViewer)
+  {
+    UpdateCurrentViewer();
+  }
 }
 
 //=======================================================================
@@ -1574,72 +1480,11 @@ void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveO
 
   Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
   aShape->SetAngleAndDeviation (theAngle);
-
-  if (theIObj->RecomputeEveryPrs())
-  {
-    theIObj->Update (Standard_True);
-    theIObj->UpdateSelection();
-  }
-  else
-  {
-    Update (theIObj, theToUpdateViewer);
-  }
-}
-
-//=======================================================================
-//function : SetHLRAngleAndDeviation
-//purpose  :
-//=======================================================================
-void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
-                                                      const Standard_Real                  theAngle,
-                                                      const Standard_Boolean               theToUpdateViewer)
-{
-  if (theIObj.IsNull())
-  {
-    return;
-  }
-
-  // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
-  setContextToObject (theIObj);
-  if (theIObj->Type() != AIS_KOI_Shape)
-  {
-    return;
-  }
-  if (theIObj->Signature() != 0)
-  {
-    return;
-  }
-  Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
-  aShape->SetHLRAngleAndDeviation (theAngle);
-  redisplayPrsModes (theIObj, theToUpdateViewer);
-}
-
-//=======================================================================
-//function : SetHLRDeviationAngle
-//purpose  :
-//=======================================================================
-void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
-                                                   const Standard_Real                  theAngle,
-                                                   const Standard_Boolean               theToUpdateViewer)
-{
-  if (theIObj.IsNull())
-  {
-    return;
-  }
-
-  // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
-  setContextToObject (theIObj);
-  if (theIObj->Type() != AIS_KOI_Shape)
-  {
-    return;
-  }
-  if (theIObj->Signature() != 0)
+  aShape->UpdatePresentations();
+  if (theToUpdateViewer)
   {
-    return;
+    UpdateCurrentViewer();
   }
-  Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
-  aShape->SetOwnHLRDeviationAngle (theAngle);
-  redisplayPrsModes (theIObj, theToUpdateViewer);
 }
 
 //=======================================================================
@@ -1655,7 +1500,11 @@ void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& th
   }
 
   theIObj->UnsetColor();
-  redisplayPrsRecModes (theIObj, theToUpdateViewer);
+  theIObj->UpdatePresentations();
+  if (theToUpdateViewer)
+  {
+    UpdateCurrentViewer();
+  }
 }
 
 //=======================================================================
@@ -1701,23 +1550,27 @@ void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theI
 
   setContextToObject (theIObj);
   theIObj->SetWidth (theWidth);
-  redisplayPrsRecModes (theIObj, theToUpdateViewer);
-  if (!myLastinMain.IsNull() && myLastinMain->IsSameSelectable (theIObj))
+  theIObj->UpdatePresentations();
+  if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
   {
-    if (myLastinMain->IsAutoHilight())
+    if (myLastPicked->IsAutoHilight())
     {
       const Standard_Integer aHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
-      myLastinMain->HilightWithColor (myMainPM,
-                                      myLastinMain->IsSelected() ? getSelStyle (theIObj, myLastinMain) : getHiStyle (theIObj, myLastinMain),
+      myLastPicked->HilightWithColor (myMainPM,
+                                      myLastPicked->IsSelected() ? getSelStyle (theIObj, myLastPicked) : getHiStyle (theIObj, myLastPicked),
                                       aHiMode);
     }
     else
     {
       theIObj->HilightOwnerWithColor (myMainPM,
-                                      myLastinMain->IsSelected() ? getSelStyle (theIObj, myLastinMain) : getHiStyle (theIObj, myLastinMain),
-                                      myLastinMain);
+                                      myLastPicked->IsSelected() ? getSelStyle (theIObj, myLastPicked) : getHiStyle (theIObj, myLastPicked),
+                                      myLastPicked);
     }
   }
+  if (theToUpdateViewer)
+  {
+    UpdateCurrentViewer();
+  }
 }
 
 //=======================================================================
@@ -1733,7 +1586,11 @@ void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& th
   }
 
   theIObj->UnsetWidth();
-  redisplayPrsRecModes (theIObj, theToUpdateViewer);
+  theIObj->UpdatePresentations();
+  if (theToUpdateViewer)
+  {
+    UpdateCurrentViewer();
+  }
 }
 
 //=======================================================================
@@ -1751,7 +1608,11 @@ void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& t
 
   setContextToObject (theIObj);
   theIObj->SetMaterial (theMaterial);
-  redisplayPrsRecModes (theIObj, theToUpdateViewer);
+  theIObj->UpdatePresentations();
+  if (theToUpdateViewer)
+  {
+    UpdateCurrentViewer();
+  }
 }
 
 //=======================================================================
@@ -1766,7 +1627,11 @@ void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)&
     return;
   }
   theIObj->UnsetMaterial();
-  redisplayPrsRecModes (theIObj, theToUpdateViewer);
+  theIObj->UpdatePresentations();
+  if (theToUpdateViewer)
+  {
+    UpdateCurrentViewer();
+  }
 }
 
 //=======================================================================
@@ -1796,7 +1661,11 @@ void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject
   }
 
   theIObj->SetTransparency (theValue);
-  redisplayPrsRecModes (theIObj, theToUpdateViewer);
+  theIObj->UpdatePresentations();
+  if (theToUpdateViewer)
+  {
+    UpdateCurrentViewer();
+  }
 }
 
 //=======================================================================
@@ -1812,7 +1681,11 @@ void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObje
   }
 
   theIObj->UnsetTransparency();
-  redisplayPrsRecModes (theIObj, theToUpdateViewer);
+  theIObj->UpdatePresentations();
+  if (theToUpdateViewer)
+  {
+    UpdateCurrentViewer();
+  }
 }
 
 //=======================================================================
@@ -1822,6 +1695,7 @@ void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObje
 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
                                                 const Standard_Boolean           theToUpdateViewer)
 {
+  Standard_DISABLE_DEPRECATION_WARNINGS
   Standard_Boolean isFound = Standard_False;
   for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
   {
@@ -1829,6 +1703,7 @@ void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)&
     Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
     anObj->SetAspect (theAspect);
   }
+  Standard_ENABLE_DEPRECATION_WARNINGS
 
   if (isFound && theToUpdateViewer)
   {
@@ -1951,42 +1826,18 @@ void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& t
 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
                                           const Standard_Boolean               theToUpdateviewer)
 {
+  Handle(AIS_GlobalStatus) aStatus;
   if (theIObj.IsNull()
-  || !myObjects.IsBound (theIObj))
+  || !myObjects.Find (theIObj, aStatus)
+  ||  aStatus->GraphicStatus() == AIS_DS_Erased)
   {
     return;
   }
 
-  Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
-
   const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
-  if (aStatus->GraphicStatus() == AIS_DS_Erased)
-  {
-    return;
-  }
-
-  if (aStatus->IsHilighted())
-  {
-    Standard_DISABLE_DEPRECATION_WARNINGS
-    if (IsCurrent (theIObj))
-    {
-      AddOrRemoveCurrentObject (theIObj, Standard_False);
-    }
-    else if (myMainPM->IsHighlighted (theIObj, aStatus->DisplayMode()))
-    {
-      unhighlightGlobal (theIObj);
-    }
-    Standard_ENABLE_DEPRECATION_WARNINGS
-  }
-
+  unselectOwners (theIObj);
   myMainPM->SetVisibility (theIObj, aStatus->DisplayMode(), Standard_False);
 
-  if (aStatus->IsHilighted()
-   && theIObj->HasHilightMode())
-  {
-    unhighlightGlobal (theIObj);
-  }
-
   if (!myLastPicked.IsNull()
     && myLastPicked->IsSameSelectable (theIObj))
   {
@@ -2016,10 +1867,10 @@ void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& t
 }
 
 //=======================================================================
-//function : unhighlightOwners
+//function : unselectOwners
 //purpose  :
 //=======================================================================
-void AIS_InteractiveContext::unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject)
+void AIS_InteractiveContext::unselectOwners (const Handle(AIS_InteractiveObject)& theObject)
 {
   SelectMgr_SequenceOfOwner aSeq;
   for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
@@ -2042,8 +1893,9 @@ void AIS_InteractiveContext::unhighlightOwners (const Handle(AIS_InteractiveObje
 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
                                           const Standard_Boolean               theToUpdateviewer)
 {
+  Handle(AIS_GlobalStatus) aStatus;
   if (theIObj.IsNull()
-  || !myObjects.IsBound (theIObj))
+  || !myObjects.Find (theIObj, aStatus))
   {
     // for cases when reference shape of connected interactives was not displayed
     // but its selection primitives were calculated
@@ -2052,8 +1904,7 @@ void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& t
     return;
   }
 
-  Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
-  unhighlightOwners (theIObj);
+  unselectOwners (theIObj);
 
   myMainPM->Erase (theIObj, -1);
   theIObj->ErasePresentations (true); // make sure highlighting presentations are properly erased
@@ -2093,7 +1944,7 @@ void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& t
   const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
   mgrSelector->Remove (anObj);
 
-  myObjects.UnBind (theIObj);
+  setObjectStatus (theIObj, AIS_DS_None, -1, -1);
   myMainVwr->StructureManager()->UnregisterObject (theIObj);
 
   for (V3d_ListOfViewIterator aDefViewIter (myMainVwr->DefinedViewIterator()); aDefViewIter.More(); aDefViewIter.Next())
@@ -2101,13 +1952,11 @@ void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& t
     aDefViewIter.Value()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
   }
 
-  if (!myLastinMain.IsNull())
+  if (!myLastPicked.IsNull())
   {
-    if (myLastinMain->IsSameSelectable (theIObj)
-     || myLastPicked->IsSameSelectable(theIObj))
+    if (myLastPicked->IsSameSelectable (theIObj))
     {
       clearDynamicHighlight();
-      myLastinMain.Nullify();
       myLastPicked.Nullify();
     }
   }
@@ -2161,15 +2010,12 @@ Standard_Boolean AIS_InteractiveContext::ClearDetected (Standard_Boolean theToRe
   myCurDetected = 0;
   myCurHighlighted = 0;
   myDetectedSeq.Clear();
-  myLastPicked  = myLastinMain;
-  myWasLastMain = Standard_True;
   Standard_Boolean toUpdate = Standard_False;
   if (!myLastPicked.IsNull() && myLastPicked->HasSelectable())
   {
     toUpdate = Standard_True;
     clearDynamicHighlight();
   }
-  myLastinMain.Nullify();
   myLastPicked.Nullify();
   myMainSel->ClearPicked();
   if (toUpdate && theToRedrawImmediate)
@@ -2460,6 +2306,13 @@ void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& th
   {
     Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
     theObj->Disconnect (theObjToDisconnect);
+    if (!myObjects.IsBound (theObjToDisconnect))
+    {
+      // connected presentation might contain displayed presentations
+      myMainPM->Erase (theObjToDisconnect, -1);
+      theObjToDisconnect->ErasePresentations (true);
+    }
+
     const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
     mgrSelector->Remove (anObj);
   }
@@ -2484,12 +2337,10 @@ void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView)
 }
 
 //=======================================================================
-//function : FitSelected
-//purpose  : Fits the view corresponding to the bounds of selected objects
+//function : BoundingBoxOfSelection
+//purpose  :
 //=======================================================================
-void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
-                                          const Standard_Real theMargin,
-                                          const Standard_Boolean theToUpdate)
+Bnd_Box AIS_InteractiveContext::BoundingBoxOfSelection() const
 {
   Bnd_Box aBndSelected;
   AIS_MapOfObjectOwners anObjectOwnerMap;
@@ -2528,12 +2379,22 @@ void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
     aBndSelected.Add (aTmpBox);
   }
 
-  anObjectOwnerMap.Clear();
-
-  if (aBndSelected.IsVoid())
-    return;
+  return aBndSelected;
+}
 
-  theView->FitAll (aBndSelected, theMargin, theToUpdate);
+//=======================================================================
+//function : FitSelected
+//purpose  : Fits the view corresponding to the bounds of selected objects
+//=======================================================================
+void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
+                                          const Standard_Real theMargin,
+                                          const Standard_Boolean theToUpdate)
+{
+  Bnd_Box aBndSelected = BoundingBoxOfSelection();
+  if (!aBndSelected.IsVoid())
+  {
+    theView->FitAll (aBndSelected, theMargin, theToUpdate);
+  }
 }
 
 //=======================================================================
@@ -2559,3 +2420,38 @@ void AIS_InteractiveContext::SetTransformPersistence (const Handle(AIS_Interacti
     anActiveViewIter.Value()->View()->InvalidateZLayerBoundingBox (aLayerId);
   }
 }
+
+//=======================================================================
+//function : GravityPoint
+//purpose  :
+//=======================================================================
+gp_Pnt AIS_InteractiveContext::GravityPoint (const Handle(V3d_View)& theView) const
+{
+  return theView->GravityPoint();
+}
+//=======================================================================
+//function : setObjectStatus
+//purpose  :
+//=======================================================================
+void AIS_InteractiveContext::setObjectStatus (const Handle(AIS_InteractiveObject)& theIObj,
+                                              const AIS_DisplayStatus theStatus,
+                                              const Standard_Integer theDispMode,
+                                              const Standard_Integer theSelectionMode)
+{
+  if (theStatus != AIS_DS_None)
+  {
+    Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
+    myObjects.Bind (theIObj, aStatus);
+  }
+  else
+    myObjects.UnBind (theIObj);
+
+  for (PrsMgr_ListOfPresentableObjectsIter aPrsIter (theIObj->Children()); aPrsIter.More(); aPrsIter.Next())
+  {
+    Handle(AIS_InteractiveObject) aChild (Handle(AIS_InteractiveObject)::DownCast (aPrsIter.Value()));
+    if (aChild.IsNull())
+      continue;
+
+    setObjectStatus (aChild, theStatus, theDispMode, theSelectionMode);
+  }
+}