From 8c4b24bbd250672179f5967269e3e4f1972eca99 Mon Sep 17 00:00:00 2001 From: age Date: Wed, 25 Nov 2020 14:53:20 +0300 Subject: [PATCH] 0030737: Visualization - implementing new selection schemes in context 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 | 2 +- src/AIS/AIS_InteractiveContext_1.cxx | 47 +++++++++++++-------- src/AIS/AIS_NArray1OfEntityOwner.hxx | 24 +++++++++++ src/AIS/AIS_Selection.cxx | 61 ++++++++++++---------------- src/AIS/AIS_Selection.hxx | 3 +- src/AIS/AIS_ViewController.cxx | 19 ++------- src/AIS/FILES | 1 + 7 files changed, 90 insertions(+), 67 deletions(-) create mode 100644 src/AIS/AIS_NArray1OfEntityOwner.hxx diff --git a/src/AIS/AIS_InteractiveContext.hxx b/src/AIS/AIS_InteractiveContext.hxx index da3a5b59d1..2927d7076f 100644 --- a/src/AIS/AIS_InteractiveContext.hxx +++ b/src/AIS/AIS_InteractiveContext.hxx @@ -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. diff --git a/src/AIS/AIS_InteractiveContext_1.cxx b/src/AIS/AIS_InteractiveContext_1.cxx index 4c535c3cfc..48eb874e0e 100644 --- a/src/AIS/AIS_InteractiveContext_1.cxx +++ b/src/AIS/AIS_InteractiveContext_1.cxx @@ -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 index 0000000000..87bd4bffcf --- /dev/null +++ b/src/AIS/AIS_NArray1OfEntityOwner.hxx @@ -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 +#include + +typedef NCollection_Array1 AIS_NArray1OfEntityOwner; + +#endif diff --git a/src/AIS/AIS_Selection.cxx b/src/AIS/AIS_Selection.cxx index e310e8df96..659b67d0d9 100644 --- a/src/AIS/AIS_Selection.cxx +++ b/src/AIS/AIS_Selection.cxx @@ -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; - } } } diff --git a/src/AIS/AIS_Selection.hxx b/src/AIS/AIS_Selection.hxx index 2e0bca8380..d6b481f587 100644 --- a/src/AIS/AIS_Selection.hxx +++ b/src/AIS/AIS_Selection.hxx @@ -18,6 +18,7 @@ #define _AIS_Selection_HeaderFile #include +#include #include #include #include @@ -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); diff --git a/src/AIS/AIS_ViewController.cxx b/src/AIS/AIS_ViewController.cxx index 4f3d19e0b2..71f543a015 100644 --- a/src/AIS/AIS_ViewController.cxx +++ b/src/AIS/AIS_ViewController.cxx @@ -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) diff --git a/src/AIS/FILES b/src/AIS/FILES index e26ea6ae8b..c863075e7b 100644 --- a/src/AIS/FILES +++ b/src/AIS/FILES @@ -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 -- 2.39.5