0027285: Visualization - selection of AIS_MultipleConnectedInteractive is broken
[occt.git] / src / SelectMgr / SelectMgr_SelectableObject.cxx
index 7a64cbb..6a96a33 100644 (file)
@@ -39,6 +39,8 @@
 #include <Standard_Type.hxx>
 #include <TopLoc_Location.hxx>
 
+IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_SelectableObject,PrsMgr_PresentableObject)
+
 static Standard_Integer Search (const SelectMgr_SequenceOfSelection& seq,
                                 const Handle (SelectMgr_Selection)& theSel)
 {
@@ -55,12 +57,13 @@ static Standard_Integer Search (const SelectMgr_SequenceOfSelection& seq,
 // Purpose :
 //==================================================
 
-SelectMgr_SelectableObject::SelectMgr_SelectableObject( const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d):
-  PrsMgr_PresentableObject (aTypeOfPresentation3d),
+SelectMgr_SelectableObject::SelectMgr_SelectableObject (const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d)
+: PrsMgr_PresentableObject (aTypeOfPresentation3d),
   myDrawer                 (new Prs3d_Drawer()),
   myHilightDrawer          (new Prs3d_Drawer()),
   myAssemblyOwner          (NULL),
-  myAutoHilight            (Standard_True)
+  myAutoHilight            (Standard_True),
+  myGlobalSelMode          (0)
 {
   InitDefaultHilightAttributes (myHilightDrawer);
   myHilightDrawer->Link (myDrawer);
@@ -68,18 +71,16 @@ SelectMgr_SelectableObject::SelectMgr_SelectableObject( const PrsMgr_TypeOfPrese
 
 
 //==================================================
-// Function: 
+// Function: HasSelection
 // Purpose :
 //==================================================
-
-Standard_Boolean SelectMgr_SelectableObject
-::HasSelection(const Standard_Integer aMode) const
+Standard_Boolean SelectMgr_SelectableObject::HasSelection (const Standard_Integer theMode) const
 {
-  Standard_Boolean Found=Standard_False;
-  for (Standard_Integer I=1;I<= myselections.Length() && !Found;I++)
-    { if(((myselections.Value(I))->Mode())==aMode) 
-        return Standard_True;
-    }
+  for (Standard_Integer aSelIdx = 1; aSelIdx <= myselections.Length(); ++aSelIdx)
+  {
+    if (((myselections.Value (aSelIdx))->Mode()) == theMode)
+      return Standard_True;
+  }
   return Standard_False;
 }
 
@@ -634,3 +635,25 @@ Bnd_Box SelectMgr_SelectableObject::BndBoxOfSelected (Handle(SelectMgr_IndexedMa
 
   return aBnd;
 }
+
+//=======================================================================
+//function : GlobalSelOwner
+//purpose  : Returns entity owner corresponding to selection of the object as a whole
+//=======================================================================
+Handle(SelectMgr_EntityOwner) SelectMgr_SelectableObject::GlobalSelOwner() const
+{
+   Handle(SelectMgr_EntityOwner) anOwner;
+
+  if (!HasSelection (myGlobalSelMode))
+    return anOwner;
+
+  const Handle(SelectMgr_Selection)& aGlobalSel = Selection (myGlobalSelMode);
+  if (aGlobalSel->IsEmpty())
+    return anOwner;
+
+  aGlobalSel->Init();
+  anOwner =
+    Handle(SelectMgr_EntityOwner)::DownCast (aGlobalSel->Sensitive()->BaseSensitive()->OwnerId());
+
+  return anOwner;
+}