0026172: Visualization, AIS_LocalContext - locally selected object should not stay...
authorapl <apl@opencascade.com>
Wed, 6 May 2015 09:06:54 +0000 (12:06 +0300)
committerabv <abv@opencascade.com>
Fri, 8 May 2015 05:51:44 +0000 (08:51 +0300)
Fix for AIS_LocalContext::ClearOutdatedSelection()
Added test case bugs/vis/bug26172

src/AIS/AIS_LocalContext_1.cxx
src/QABugs/QABugs_19.cxx
tests/bugs/vis/bug26172 [new file with mode: 0644]

index c5a9217..04c094d 100644 (file)
@@ -905,7 +905,7 @@ void AIS_LocalContext::ClearOutdatedSelection (const Handle(AIS_InteractiveObjec
 
   Standard_Boolean isAISRemainsDetected = Standard_False;
 
-  // 3. Remove entity owners from AIS_Selection
+  // 3. AIS_Selection : remove entity owners from AIS_Selection
   const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer();
   Handle(AIS_Selection) aSelection = AIS_Selection::Selection (mySelName.ToCString());
   AIS_NListTransient::Iterator anIter (aSelection->Objects());
@@ -922,22 +922,23 @@ void AIS_LocalContext::ClearOutdatedSelection (const Handle(AIS_InteractiveObjec
     {
       isAISRemainsDetected = Standard_True;
     }
-
-    aRemoveEntites.Append (anOwner);
-    anOwner->SetSelected (Standard_False);
-    for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
+    else
     {
-      Unhilight (anOwner, aViewer->ActiveView());
+      aRemoveEntites.Append (anOwner);
+      anOwner->SetSelected (Standard_False);
+      for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews())
+      {
+        Unhilight (anOwner, aViewer->ActiveView());
+      }
     }
   }
-
   AIS_NListTransient::Iterator anIterRemove (aRemoveEntites);
   for (; anIterRemove.More(); anIterRemove.Next())
   {
     aSelection->Select (anIterRemove.Value());
   }
 
-  // 4. Remove entity owners from myMapOfOwner
+  // 4. AIS_LocalContext - myMapOfOwner : remove entity owners from myMapOfOwner
   SelectMgr_IndexedMapOfOwner anOwnersToKeep;
   for (Standard_Integer anIdx = 1; anIdx <= myMapOfOwner.Extent(); anIdx++)
   {
index acff2f1..f131aab 100755 (executable)
@@ -22,6 +22,7 @@
 #include <V3d_View.hxx>
 #include <TopoDS_Shape.hxx>
 #include <AIS_InteractiveContext.hxx>
+#include <AIS_LocalContext.hxx>
 #include <AIS_TexturedShape.hxx>
 #include <Image_PixMap.hxx>
 #include <Image_Color.hxx>
@@ -3551,6 +3552,95 @@ static Standard_Integer OCC24881 (Draw_Interpretor& di, Standard_Integer narg ,
   return 0;
 }
 
+//=======================================================================
+//function : OCC26172
+//purpose  :
+//=======================================================================
+static Standard_Integer OCC26172 (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec)
+{
+  if (theArgNb != 1)
+  {
+    std::cerr << "Error: wrong number of arguments! See usage:\n";
+    theDI.PrintHelp (theArgVec[0]);
+    return 1;
+  }
+
+  Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
+  if(anAISContext.IsNull())
+  {
+    std::cerr << "Error: no active view. Please call vinit.\n";
+    return 1;
+  }
+
+  gp_Pnt aStart (100, 100, 100);
+  gp_Pnt anEnd (300, 400, 600);
+  BRepBuilderAPI_MakeEdge anEdgeBuilder (aStart, anEnd);
+  TopoDS_Edge anEdge = anEdgeBuilder.Edge();
+  Handle(AIS_Shape) aTestAISShape = new AIS_Shape (anEdge);
+  anAISContext->Display (aTestAISShape);
+
+  // 2. activate it in selection modes
+  TColStd_SequenceOfInteger aModes;
+  aModes.Append (AIS_Shape::SelectionMode ((TopAbs_ShapeEnum) TopAbs_VERTEX));
+  aModes.Append (AIS_Shape::SelectionMode ((TopAbs_ShapeEnum) TopAbs_EDGE));
+
+  anAISContext->OpenLocalContext();
+  anAISContext->Deactivate (aTestAISShape);
+  anAISContext->Load (aTestAISShape, -1, true);
+  for (Standard_Integer anIt = 1; anIt <= aModes.Length(); ++anIt)
+  {
+    anAISContext->Activate (aTestAISShape, aModes (anIt));
+  }
+
+  // select entities in vertex selection mode
+  Handle(SelectMgr_Selection) aSelection = aTestAISShape->Selection (aModes (1));
+  for (aSelection->Init(); aSelection->More(); aSelection->Next())
+  {
+    Handle(SelectBasics_SensitiveEntity) anEntity = aSelection->Sensitive()->BaseSensitive();
+    if (anEntity.IsNull())
+    {
+      continue;
+    }
+
+    Handle(SelectMgr_EntityOwner) anOwner =
+      Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
+
+    if (anOwner.IsNull())
+    {
+      continue;
+    }
+
+    anAISContext->LocalContext()->AddOrRemoveSelected (anOwner);
+  }
+
+  // select entities in edge selection mode
+  aSelection = aTestAISShape->Selection (aModes (2));
+  for (aSelection->Init(); aSelection->More(); aSelection->Next())
+  {
+    Handle(SelectBasics_SensitiveEntity) anEntity = aSelection->Sensitive()->BaseSensitive();
+    if (anEntity.IsNull())
+    {
+      continue;
+    }
+
+    Handle(SelectMgr_EntityOwner) anOwner =
+      Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
+
+    if (anOwner.IsNull())
+    {
+      continue;
+    }
+
+    anAISContext->LocalContext()->AddOrRemoveSelected (anOwner);
+  }
+
+  // deactivate vertex mode and check clearing of outdated selection
+  anAISContext->Deactivate (aTestAISShape, aModes (1));
+  anAISContext->LocalContext()->ClearOutdatedSelection (aTestAISShape, true);
+
+  return 0;
+}
+
 #include <IntTools_Context.hxx>
 #include <GeomAPI_ProjectPointOnSurf.hxx>
 
@@ -3758,6 +3848,7 @@ void QABugs::Commands_19(Draw_Interpretor& theCommands) {
                    __FILE__, OCC25545, group);
   theCommands.Add ("OCC25547", "OCC25547", __FILE__, OCC25547, group);
   theCommands.Add ("OCC24881", "OCC24881 shape", __FILE__, OCC24881, group);
+  theCommands.Add ("OCC26172", "OCC26172", __FILE__, OCC26172, group);
   theCommands.Add ("xprojponf", "xprojponf p f", __FILE__, xprojponf, group);
   theCommands.Add ("OCC24923", "OCC24923", __FILE__, OCC24923, group);
   return;
diff --git a/tests/bugs/vis/bug26172 b/tests/bugs/vis/bug26172
new file mode 100644 (file)
index 0000000..5c335ee
--- /dev/null
@@ -0,0 +1,29 @@
+puts "============"
+puts "CR26172"
+puts "============"
+puts ""
+
+##########################################################################################
+puts "Locally selected object stays in the viewer after object deactivation in the local context"
+##########################################################################################
+
+set check_x 102
+set check_y 333
+
+pload VISUALIZATION MODELING
+
+vinit View1
+vclear
+vaxo
+
+OCC26172
+
+vfit
+
+# check that the selection is cleared properly
+checkcolor $check_x $check_y 0.8 0.8 0.8
+if { [checkcolor $check_x $check_y 0.8 0.8 0.8] != 1 } {
+  puts "Error: selection is cleared incorrectly by AIS_LocalContext::ClearOutdatedSelection()"
+}
+
+vdump ${imagedir}/${casename}.png