]> OCCT Git - occt-copy.git/commitdiff
0030737: Visualization - implementing new selection schemes in context CR0_DMUReviewer_IR-2019-08-30_CR30737
authorage <age@opencascade.com>
Wed, 25 Nov 2020 11:53:20 +0000 (14:53 +0300)
committerage <age@opencascade.com>
Wed, 25 Nov 2020 13:05:50 +0000 (16:05 +0300)
Improved AIS_SelectionScheme_ReplaceExtra scheme (now is a part of AIS_SelectionScheme_Replace)
Replaced AIS_NListOfEntityOwner with AIS_NArray1OfEntityOwner
Fixed bug with incorrect highlighting in xor mode (select several times the same objects)

src/AIS/AIS_InteractiveContext.hxx
src/AIS/AIS_InteractiveContext_1.cxx
src/AIS/AIS_NArray1OfEntityOwner.hxx [new file with mode: 0644]
src/AIS/AIS_Selection.cxx
src/AIS/AIS_Selection.hxx
src/AIS/AIS_ViewController.cxx
src/AIS/FILES

index da3a5b59d1ffb456fc1b372233e918c2b301fe53..2927d7076f4f3a3eb4259eb4fefcccede799efd3 100644 (file)
@@ -568,7 +568,7 @@ public: //! @name Selection management
   //! @param theOwners owners to change selection state
   //! @param theSelScheme selection scheme
   //! @return picking status
-  Standard_EXPORT AIS_StatusOfPick Select (const AIS_NListOfEntityOwner& theOwners,
+  Standard_EXPORT AIS_StatusOfPick Select (const AIS_NArray1OfEntityOwner& theOwners,
                                            const AIS_SelectionScheme theSelScheme);
 
   //! Fits the view correspondingly to the bounds of selected objects.
index 4c535c3cfc04177b489bba763729af173b891dff..48eb874e0ee37a20cdca25c14b13a738b7292487 100644 (file)
@@ -507,13 +507,18 @@ AIS_StatusOfPick AIS_InteractiveContext::SelectRectangle (const Graphic3d_Vec2i&
   }
   myMainSel->Pick (thePntMin.x(), thePntMin.y(), thePntMax.x(), thePntMax.y(), theView);
 
-  AIS_NListOfEntityOwner aPickedOwners;
-  for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
+  if (myMainSel->NbPicked() > 0)
   {
-    aPickedOwners.Append (myMainSel->Picked (aPickIter));
+    AIS_NArray1OfEntityOwner aPickedOwners (1, myMainSel->NbPicked());
+    for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
+    {
+      aPickedOwners.ChangeValue (aPickIter) = myMainSel->Picked (aPickIter);
+    }
+
+    return Select (aPickedOwners, theSelScheme);
   }
 
-  return Select (aPickedOwners, theSelScheme);
+  return Select (AIS_NArray1OfEntityOwner(), theSelScheme);
 }
 
 //=======================================================================
@@ -536,13 +541,18 @@ AIS_StatusOfPick AIS_InteractiveContext::SelectPolygon (const TColgp_Array1OfPnt
   }
   myMainSel->Pick (thePolyline, theView);
 
-  AIS_NListOfEntityOwner aPickedOwners;
-  for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
+  if (myMainSel->NbPicked() > 0)
   {
-    aPickedOwners.Append (myMainSel->Picked (aPickIter));
+    AIS_NArray1OfEntityOwner aPickedOwners (1, myMainSel->NbPicked());
+    for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
+    {
+      aPickedOwners.ChangeValue (aPickIter) = myMainSel->Picked (aPickIter);
+    }
+
+    return Select (aPickedOwners, theSelScheme);
   }
 
-  return Select (aPickedOwners, theSelScheme);
+  return Select (AIS_NArray1OfEntityOwner(), theSelScheme);
 }
 
 //=======================================================================
@@ -566,13 +576,18 @@ AIS_StatusOfPick AIS_InteractiveContext::SelectPoint (const Graphic3d_Vec2i&
   myLastActiveView = theView.get();
   myMainSel->Pick (thePnt.x(), thePnt.y(), theView);
 
-  AIS_NListOfEntityOwner aPickedOwners;
-  for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
+  if (myMainSel->NbPicked() > 0)
   {
-    aPickedOwners.Append (myMainSel->Picked (aPickIter));
+    AIS_NArray1OfEntityOwner aPickedOwners (1, myMainSel->NbPicked());
+    for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
+    {
+      aPickedOwners.ChangeValue (aPickIter) = myMainSel->Picked (aPickIter);
+    }
+
+    return Select (aPickedOwners, theSelScheme);
   }
 
-  return Select (aPickedOwners, theSelScheme);
+  return Select (AIS_NArray1OfEntityOwner(), theSelScheme);
 }
 
 //=======================================================================
@@ -595,13 +610,13 @@ AIS_StatusOfPick AIS_InteractiveContext::SelectDetected (const AIS_SelectionSche
     }
   }
 
-  if (myAutoHilight && theSelScheme != AIS_SelectionScheme_XOR)
+  if (myAutoHilight/* && theSelScheme != AIS_SelectionScheme_XOR*/)
   {
     UnhilightSelected (Standard_False);
   }
 
-  AIS_NListOfEntityOwner aPickedOwners;
-  aPickedOwners.Append (myLastPicked);
+  AIS_NArray1OfEntityOwner aPickedOwners(1, 1);
+  aPickedOwners.ChangeValue (1) = myLastPicked;
   return Select (aPickedOwners, theSelScheme);
 }
 
@@ -712,7 +727,7 @@ AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d
 //function : Select
 //purpose  :
 //=======================================================================
-AIS_StatusOfPick AIS_InteractiveContext::Select (const AIS_NListOfEntityOwner& theOwners,
+AIS_StatusOfPick AIS_InteractiveContext::Select (const AIS_NArray1OfEntityOwner& theOwners,
                                                  const AIS_SelectionScheme theSelScheme)
 {
   // all objects detected by the selector are taken, previous current objects are emptied,
diff --git a/src/AIS/AIS_NArray1OfEntityOwner.hxx b/src/AIS/AIS_NArray1OfEntityOwner.hxx
new file mode 100644 (file)
index 0000000..87bd4bf
--- /dev/null
@@ -0,0 +1,24 @@
+// Created on: 2003-05-04
+// Created by: Alexander Grigoriev (a-grigoriev@opencascade.com)
+// Copyright (c) 2003-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef _AIS_NArray1Transient_HeaderFile
+#define _AIS_NArray1Transient_HeaderFile
+
+#include <SelectMgr_EntityOwner.hxx>
+#include <NCollection_Array1.hxx>
+
+typedef NCollection_Array1<Handle(SelectMgr_EntityOwner)> AIS_NArray1OfEntityOwner;
+
+#endif
index e310e8df96f7c4a80bd99053b5643281f6ef51a2..659b67d0d935038469450533b1ba8f23464b9f2a 100644 (file)
@@ -137,7 +137,7 @@ AIS_SelectStatus AIS_Selection::AddSelect (const Handle(SelectMgr_EntityOwner)&
 //function : SelectOwners
 //purpose  :
 //=======================================================================
-void AIS_Selection::SelectOwners (const AIS_NListOfEntityOwner& thePickedOwners,
+void AIS_Selection::SelectOwners (const AIS_NArray1OfEntityOwner& thePickedOwners,
                                   const AIS_SelectionScheme theSelScheme,
                                   const Handle(SelectMgr_Filter)& theFilter)
 {
@@ -147,10 +147,32 @@ void AIS_Selection::SelectOwners (const AIS_NListOfEntityOwner& thePickedOwners,
     {
       return;
     }
+    case AIS_SelectionScheme_ReplaceExtra:
+    {
+      // If picked owners is equivalent to the selected then just clear selected
+      // Else go to AIS_SelectionScheme_Replace
+      if (thePickedOwners.Size() == myresult.Size())
+      {
+        Standard_Boolean isTheSame = Standard_True;
+        for (AIS_NArray1OfEntityOwner::Iterator aSelIter (thePickedOwners); aSelIter.More(); aSelIter.Next())
+        {
+          if (!myResultMap.IsBound (aSelIter.Value()))
+          {
+            isTheSame = Standard_False;
+            break;
+          }
+        }
+        if (isTheSame)
+        {
+          Clear();
+          return;
+        }
+      }
+    }
     case AIS_SelectionScheme_Replace:
     {
       Clear();
-      for (AIS_NListOfEntityOwner::Iterator aSelIter (thePickedOwners); aSelIter.More(); aSelIter.Next())
+      for (AIS_NArray1OfEntityOwner::Iterator aSelIter (thePickedOwners); aSelIter.More(); aSelIter.Next())
       {
         appendOwner (aSelIter.Value(), theFilter);
       }
@@ -159,7 +181,7 @@ void AIS_Selection::SelectOwners (const AIS_NListOfEntityOwner& thePickedOwners,
     }
     case AIS_SelectionScheme_Add:
     {
-      for (AIS_NListOfEntityOwner::Iterator aSelIter (thePickedOwners); aSelIter.More(); aSelIter.Next())
+      for (AIS_NArray1OfEntityOwner::Iterator aSelIter (thePickedOwners); aSelIter.More(); aSelIter.Next())
       {
         appendOwner (aSelIter.Value(), theFilter);
       }
@@ -167,7 +189,7 @@ void AIS_Selection::SelectOwners (const AIS_NListOfEntityOwner& thePickedOwners,
     }
     case AIS_SelectionScheme_Remove:
     {
-      for (AIS_NListOfEntityOwner::Iterator aSelIter (thePickedOwners); aSelIter.More(); aSelIter.Next())
+      for (AIS_NArray1OfEntityOwner::Iterator aSelIter (thePickedOwners); aSelIter.More(); aSelIter.Next())
       {
         if (myResultMap.IsBound (aSelIter.Value()))
         {
@@ -178,7 +200,7 @@ void AIS_Selection::SelectOwners (const AIS_NListOfEntityOwner& thePickedOwners,
     }
     case AIS_SelectionScheme_XOR:
     {
-      for (AIS_NListOfEntityOwner::Iterator aSelIter (thePickedOwners); aSelIter.More(); aSelIter.Next())
+      for (AIS_NArray1OfEntityOwner::Iterator aSelIter (thePickedOwners); aSelIter.More(); aSelIter.Next())
       {
         const Handle(SelectMgr_EntityOwner)& anOwner = aSelIter.Value();
         if (anOwner.IsNull()
@@ -197,35 +219,6 @@ void AIS_Selection::SelectOwners (const AIS_NListOfEntityOwner& thePickedOwners,
       Clear();
       return;
     }
-    case AIS_SelectionScheme_ReplaceExtra:
-    {
-      AIS_NListOfEntityOwner aPrevSelected = Objects();
-      Clear();
-
-      Standard_Boolean toAppend = false;
-      if (thePickedOwners.Size() < aPrevSelected.Size())
-      {
-        // check if all picked objects are in previous selected list, if so, all objects will be deselected,
-        // but in mode AIS_SelectionScheme_PickedIfEmpty new picked objects should be selected, here, after Clear, Add
-        Standard_Boolean anOtherFound = Standard_False;
-        for (AIS_NListOfEntityOwner::Iterator aSelIter (thePickedOwners); aSelIter.More(); aSelIter.Next())
-        {
-          anOtherFound = !aPrevSelected.Contains (aSelIter.Value());
-          if (anOtherFound)
-            break;
-        }
-        if (!anOtherFound)
-          toAppend = Standard_True;
-      }
-      for (AIS_NListOfEntityOwner::Iterator aSelIter (thePickedOwners); aSelIter.More(); aSelIter.Next())
-      {
-        if (toAppend)
-          appendOwner (aSelIter.Value(), theFilter);
-        else
-          XOROwner(aSelIter.Value(), aPrevSelected, theFilter);
-      }
-      return;
-    }
   }
 }
 
index 2e0bca838090a2dded2c180fa8d7826657324fb6..d6b481f5879d0cbdb33396605fce760729780fe9 100644 (file)
@@ -18,6 +18,7 @@
 #define _AIS_Selection_HeaderFile
 
 #include <AIS_NListOfEntityOwner.hxx>
+#include <AIS_NArray1OfEntityOwner.hxx>
 #include <AIS_SelectionScheme.hxx>
 #include <AIS_SelectStatus.hxx>
 #include <Standard.hxx>
@@ -82,7 +83,7 @@ public:
   //! @param theOwners [in] elements to change selection state
   //! @param theSelScheme [in] selection scheme, defines how owner is selected
   //! @param theFilter [in] context filter to skip not acceptable owners
-  Standard_EXPORT virtual void SelectOwners (const AIS_NListOfEntityOwner& thePickedOwners,
+  Standard_EXPORT virtual void SelectOwners (const AIS_NArray1OfEntityOwner& thePickedOwners,
                                              const AIS_SelectionScheme theSelScheme,
                                              const Handle(SelectMgr_Filter)& theFilter);
 
index 4f3d19e0b2c960209a10285fadc1446ed6e6020b..71f543a0157e1f2d5ba10ec55f643be8ab5df776 100644 (file)
@@ -2160,21 +2160,10 @@ void AIS_ViewController::handleSelectionPoly (const Handle(AIS_InteractiveContex
           const Graphic3d_Vec2i aPnt1 (aPoints.Value (1).x(), -aPoints.Value (1).y());
           const Graphic3d_Vec2i aPnt2 (aPoints.Value (3).x(), -aPoints.Value (3).y());
           theCtx->MainSelector()->AllowOverlapDetection (aPnt1.y() != Min (aPnt1.y(), aPnt2.y()));
-          if (myGL.Selection.IsXOR)
-          {
-            theCtx->ShiftSelect (Min (aPnt1.x(), aPnt2.x()), Min (aPnt1.y(), aPnt2.y()),
-                                 Max (aPnt1.x(), aPnt2.x()), Max (aPnt1.y(), aPnt2.y()),
-                                 theView, false);
-          }
-          else
-          {
-            theCtx->MainSelector()->AllowOverlapDetection (aPnt1.y() != Min (aPnt1.y(), aPnt2.y()));
-            theCtx->SelectRectangle (Graphic3d_Vec2i (Min (aPnt1.x(), aPnt2.x()), Min (aPnt1.y(), aPnt2.y())),
-                                     Graphic3d_Vec2i (Max (aPnt1.x(), aPnt2.x()), Max (aPnt1.y(), aPnt2.y())),
-                                      theView,
-                                      myGL.Selection.IsXOR ? AIS_SelectionScheme_XOR : AIS_SelectionScheme_Replace);
-            theCtx->MainSelector()->AllowOverlapDetection (false);
-          }
+          theCtx->SelectRectangle (Graphic3d_Vec2i (Min (aPnt1.x(), aPnt2.x()), Min (aPnt1.y(), aPnt2.y())),
+                                   Graphic3d_Vec2i (Max (aPnt1.x(), aPnt2.x()), Max (aPnt1.y(), aPnt2.y())),
+                                   theView,
+                                   myGL.Selection.IsXOR ? AIS_SelectionScheme_XOR : AIS_SelectionScheme_Replace);
           theCtx->MainSelector()->AllowOverlapDetection (false);
         }
         else if (aPoints.Length() >= 3)
index e26ea6ae8b29766afe12a5270efc6d066901866d..c863075e7bf810eb70a949052571408201e05be6 100644 (file)
@@ -118,6 +118,7 @@ AIS_MultipleConnectedInteractive.hxx
 AIS_MultipleConnectedInteractive.lxx
 AIS_NavigationMode.hxx
 AIS_NListOfEntityOwner.hxx
+AIS_NArray1OfEntityOwner.hxx
 AIS_OffsetDimension.cxx
 AIS_OffsetDimension.hxx
 AIS_OffsetDimension.lxx