0028888: Visualization - AIS_InteractiveContext should not hold V3d_View handle which...
[occt.git] / src / AIS / AIS_LocalContext_1.cxx
index 921d245..7b83743 100644 (file)
 
 namespace
 {
-  TopoDS_Shape AIS_myDummyShape;
-}
-
-static Standard_Integer GetHiMod(const Handle(AIS_InteractiveObject)& IO)
-{
-  return IO->HasHilightMode() ? IO->HilightMode():0;
-}
-
-//=======================================================================
-//function : getHiStyle
-//purpose  :
-//=======================================================================
-const Handle(Graphic3d_HighlightStyle)& AIS_LocalContext::getHiStyle (const Handle(SelectMgr_SelectableObject)& theObj) const
-{
-  const Handle(Prs3d_Drawer)& aHiDrawer = theObj->HilightAttributes();
-  return !aHiDrawer.IsNull() && aHiDrawer->HasOwnHighlightStyle()
-    ? aHiDrawer->HighlightStyle() : myCTX->HighlightStyle();
-}
-
-//=======================================================================
-//function : getSelStyle
-//purpose  :
-//=======================================================================
-const Handle(Graphic3d_HighlightStyle)& AIS_LocalContext::getSelStyle (const Handle(AIS_InteractiveObject)& theObj) const
-{
-  const Handle(Prs3d_Drawer)& aHiDrawer = theObj->HilightAttributes();
-  return !aHiDrawer.IsNull() && aHiDrawer->HasOwnSelectionStyle()
-    ? aHiDrawer->SelectionStyle() : myCTX->SelectionStyle();
+  TopoDS_Shape AIS_LocalContext_myDummyShape;
 }
 
 //==================================================
@@ -502,9 +475,11 @@ void AIS_LocalContext::Hilight (const Handle(SelectMgr_EntityOwner)& theOwner,
     return;
   }
 
-  const Standard_Integer aHilightMode = GetHiMod (Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()));
+  const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
+  const Handle(Prs3d_Drawer)& aHiStyle = myCTX->getHiStyle (anObj, theOwner);
+  const Standard_Integer aHiMode = myCTX->getHilightMode (anObj, aHiStyle, -1);
   myMainPM->BeginImmediateDraw();
-  theOwner->HilightWithColor (myMainPM, getHiStyle (theOwner->Selectable()), aHilightMode);
+  theOwner->HilightWithColor (myMainPM, aHiStyle, aHiMode);
   myMainPM->EndImmediateDraw (theView->Viewer());
 }
 
@@ -520,18 +495,19 @@ void AIS_LocalContext::Unhilight (const Handle(SelectMgr_EntityOwner)& theOwner,
     return;
   }
 
-  const Handle(AIS_InteractiveObject)& anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
-  const Standard_Integer aHilightMode = GetHiMod (anObj);
+  const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
   if (IsSelected (theOwner))
   {
     if (theOwner->IsAutoHilight())
     {
-      theOwner->HilightWithColor (myMainPM, getSelStyle (anObj), aHilightMode);
+      const Handle(Prs3d_Drawer)& aSelStyle = myCTX->getSelStyle (anObj, theOwner);
+      const Standard_Integer aHiMode = myCTX->getHilightMode (anObj, aSelStyle, -1);
+      theOwner->HilightWithColor (myMainPM, aSelStyle, aHiMode);
     }
   }
   else
   {
-    theOwner->Unhilight (myMainPM, aHilightMode);
+    theOwner->Unhilight (myMainPM);
   }
 }
 
@@ -558,8 +534,9 @@ void AIS_LocalContext::HilightPicked (const Standard_Boolean theToUpdateviewer)
     if (anOwner->IsAutoHilight())
     {
       Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(aSelObj);
-      const Standard_Integer aHighMode = GetHiMod (anIO);
-      anOwner->HilightWithColor (myMainPM, getSelStyle (anIO), aHighMode);
+      const Handle(Prs3d_Drawer)& aSelStyle = myCTX->getSelStyle (anIO, anOwner);
+      const Standard_Integer aHiMode = myCTX->getHilightMode (anIO, aSelStyle, -1);
+      anOwner->HilightWithColor (myMainPM, aSelStyle, aHiMode);
       continue;
     }
 
@@ -606,8 +583,7 @@ void AIS_LocalContext::UnhilightPicked (const Standard_Boolean theToUpdateViewer
     Handle(SelectMgr_SelectableObject) aSelObj = anOwner->Selectable();
     Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aSelObj);
     anObjMap.Add (aSelObj);
-    Standard_Integer aHighMode = GetHiMod (anIO);
-    anOwner->Unhilight (myMainPM, aHighMode);
+    anOwner->Unhilight (myMainPM);
   }
 
   for (NCollection_Map<Handle(SelectMgr_SelectableObject)>::Iterator aMapIter (anObjMap);
@@ -1031,14 +1007,10 @@ void AIS_LocalContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,
 
   Handle(SelectMgr_EntityOwner) EO = FindSelectedOwnerFromIO(anIObj);
   if(EO.IsNull()){
-    //check if in selection number 0 there is an owner that can be triturated...
-    if(anIObj->HasSelection(0)){
-      const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0);
-      SIOBJ->Init();
-      if(SIOBJ->More()){
-        Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->BaseSensitive()->OwnerId();
-       EO = Handle(SelectMgr_EntityOwner)::DownCast (BO);
-      }
+    //check if global selection there is an owner that can be triturated...
+    if (anIObj->HasSelection (anIObj->GlobalSelectionMode()))
+    {
+      EO = anIObj->GlobalSelOwner();
     }
     if(EO.IsNull()) 
       EO = new SelectMgr_EntityOwner((const Handle(SelectMgr_SelectableObject)&)anIObj);
@@ -1069,14 +1041,9 @@ void AIS_LocalContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)&
 
   if (EO.IsNull())
   {
-    if(anIObj->HasSelection(0))
+    if(anIObj->HasSelection (anIObj->GlobalSelectionMode()))
     {
-      const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0);
-      SIOBJ->Init();
-      if(SIOBJ->More()){
-        Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->BaseSensitive()->OwnerId();
-       EO = Handle(SelectMgr_EntityOwner)::DownCast (BO);
-      }
+      EO = anIObj->GlobalSelOwner();
     }
     if(EO.IsNull())
     {
@@ -1242,10 +1209,10 @@ AIS_LocalContext::DetectedShape() const
   if(mylastindex != 0)
   {
     Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner->FindKey (mylastindex));
-    if(BROwnr.IsNull()) return AIS_myDummyShape;
+    if(BROwnr.IsNull()) return AIS_LocalContext_myDummyShape;
     return BROwnr->Shape();
   }
-  return AIS_myDummyShape;
+  return AIS_LocalContext_myDummyShape;
 }                                          
 
 //=======================================================================
@@ -1395,6 +1362,15 @@ Standard_Integer AIS_LocalContext::HilightPreviousDetected (const Handle(V3d_Vie
 //purpose  :
 //=======================================================================
 Standard_Boolean AIS_LocalContext::UnhilightLastDetected (const Handle(V3d_View)& theView)
+{
+  return UnhilightLastDetected (theView->Viewer());
+}
+
+//=======================================================================
+//function : UnhilightLastDetected
+//purpose  :
+//=======================================================================
+Standard_Boolean AIS_LocalContext::UnhilightLastDetected (const Handle(V3d_Viewer)& theViewer)
 {
   if (!IsValidIndex (mylastindex))
   {
@@ -1403,12 +1379,8 @@ Standard_Boolean AIS_LocalContext::UnhilightLastDetected (const Handle(V3d_View)
 
   myMainPM->BeginImmediateDraw();
   const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner->FindKey (mylastindex);
-  const Standard_Integer aHilightMode = anOwner->HasSelectable()
-                                      ? GetHiMod (Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()))
-                                      : 0;
-
-  myMapOfOwner->FindKey (mylastindex)->Unhilight (myMainPM, aHilightMode);
-  myMainPM->EndImmediateDraw (theView->Viewer());
+  anOwner->Unhilight (myMainPM);
+  myMainPM->EndImmediateDraw (theViewer);
   mylastindex = 0;
   return Standard_True;
 }
@@ -1513,7 +1485,7 @@ const TopoDS_Shape& AIS_LocalContext::DetectedCurrentShape() const
 
   if (aCurrentShape.IsNull())
   {
-    return AIS_myDummyShape;
+    return AIS_LocalContext_myDummyShape;
   }
 
   return aCurrentShape->Shape();