0027893: Visualization - AIS_InteractiveContext::SetSelected does not work
authorvpa <vpa@opencascade.com>
Mon, 26 Sep 2016 17:34:26 +0000 (20:34 +0300)
committerkgv <kgv@opencascade.com>
Fri, 30 Sep 2016 08:17:13 +0000 (11:17 +0300)
- misprint in check of global selection existence in AIS_InteractiveContext::SetSelected was corrected;
- remaining occurrencies of hard-coded 0 selection mode were corrected to use global selection mode;
- test case for issue #27983

src/AIS/AIS_InteractiveContext_1.cxx
src/AIS/AIS_LocalContext_1.cxx
src/QABugs/QABugs_19.cxx
src/SelectMgr/SelectMgr_SelectionManager.cxx
tests/bugs/vis/bug27893 [new file with mode: 0644]

index e526bcd..efbfd12 100644 (file)
@@ -1029,7 +1029,7 @@ void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& t
     return;
   if(!myObjects.IsBound (theObject))
     Display (theObject, Standard_False);
-  if (theObject->HasSelection (0))
+  if (!theObject->HasSelection (theObject->GlobalSelectionMode()))
     return;
 
   const Handle(Graphic3d_HighlightStyle)& anObjSelStyle =
@@ -1067,20 +1067,11 @@ void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& t
   }
 
   // added to avoid untimely viewer update...
-  const Handle(SelectMgr_Selection)& aSel = theObject->Selection (0);
-  if (aSel->IsEmpty())
+  Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
+  if (anOwner.IsNull())
     return;
-  aSel->Init();
-  Handle(SelectMgr_EntityOwner) anOwner =
-    Handle(SelectMgr_EntityOwner)::DownCast (aSel->Sensitive()->BaseSensitive()->OwnerId());
   mySelection->ClearAndSelect (anOwner);
-  anOwner->State (1);
-  if (anOwner == theObject->GlobalSelOwner())
-  {
-    Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind (theObject);
-    aState->SetHilightStatus (Standard_True);
-    aState->SetHilightStyle (anObjSelStyle);
-  }
+
   Handle(Graphic3d_HighlightStyle) aCustomStyle;
   if (HighlightStyle (theObject, aCustomStyle))
   {
@@ -1093,6 +1084,7 @@ void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& t
   {
     HilightWithColor (theObject, anObjSelStyle, Standard_False);
   }
+  anOwner->State (1);
 
   if (theToUpdateViewer)
     UpdateCurrentViewer();
index 921d245..6a2a088 100644 (file)
@@ -1031,14 +1031,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 +1065,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())
     {
index e2d3828..0acfbd0 100644 (file)
@@ -5310,6 +5310,27 @@ static Standard_Integer OCC27818 (Draw_Interpretor& /*theDI*/, Standard_Integer
   return 0;
 }
 
+//========================================================================
+//function : OCC27893
+//purpose  : Creates a box and selects it via AIS_InteractiveContext API
+//========================================================================
+static Standard_Integer OCC27893 (Draw_Interpretor& /*theDI*/, Standard_Integer /*theArgc*/, const char** theArgv)
+{
+  const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
+  if (aCtx.IsNull())
+  {
+    std::cout << "No interactive context. Use 'vinit' command before " << theArgv[0] << "\n";
+    return 1;
+  }
+
+  TopoDS_Shape aBox = BRepPrimAPI_MakeBox (10.0, 10.0, 10.0).Shape();
+  Handle(AIS_InteractiveObject) aBoxObj = new AIS_Shape (aBox);
+  aCtx->Display (aBoxObj, AIS_Shaded, 0, Standard_False);
+  aCtx->SetSelected (aBoxObj, Standard_True);
+
+  return 0;
+}
+
 //========================================================================
 //function : Commands_19
 //purpose  :
@@ -5443,5 +5464,8 @@ void QABugs::Commands_19(Draw_Interpretor& theCommands) {
   theCommands.Add ("OCC27818",
                    "OCC27818: Creates three boxes and highlights one of them with own style",
                    __FILE__, OCC27818, group);
+  theCommands.Add ("OCC27893",
+                   "OCC27893: Creates a box and selects it via AIS_InteractiveContext API",
+                   __FILE__, OCC27893, group);
   return;
 }
index 20a10f8..3e6de7b 100644 (file)
@@ -370,9 +370,10 @@ void SelectMgr_SelectionManager::Activate (const Handle(SelectMgr_SelectableObje
 
   if (myGlobal.Contains (theObject))
   {
-    if (theMode != 0 && theSelector->IsActive (theObject, 0))
+    const Standard_Integer aGlobalSelMode = theObject->GlobalSelectionMode();
+    if (theMode != aGlobalSelMode && theSelector->IsActive (theObject, aGlobalSelMode))
     {
-      theSelector->Deactivate (theObject->Selection (0));
+      theSelector->Deactivate (theObject->Selection (aGlobalSelMode));
     }
     theSelector->Activate (theObject->Selection (theMode));
   }
diff --git a/tests/bugs/vis/bug27893 b/tests/bugs/vis/bug27893
new file mode 100644 (file)
index 0000000..3a12988
--- /dev/null
@@ -0,0 +1,17 @@
+puts "==========="
+puts "OCC27893"
+puts "==========="
+puts ""
+##########################################################################
+# Visualization - AIS_InteractiveContext::SetSelected does not work
+##########################################################################
+
+pload VISUALIZATION QAcommands
+
+vinit
+OCC27893
+vfit
+
+if {[vnbselected] != "1" || [vreadpixel 204 254 name] != "GRAY80 1"} {
+  puts "ERROR: The box is not selected, AIS_InteractiveContext::SetSelected works incorrect"
+}