From: kgv Date: Tue, 11 Apr 2017 07:25:21 +0000 (+0300) Subject: 0028390: Visualization, AIS_InteractiveContext - add topmost-only picking strategy X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=59df732aaafbd4012fea134aa7d5a0b816512b7d;p=occt-copy.git 0028390: Visualization, AIS_InteractiveContext - add topmost-only picking strategy AIS_InteractiveContext::PickingStrategy(), added new property defining picking strategy SelectMgr_PickingStrategy. Strategy SelectMgr_PickingStrategy_OnlyTopmost allows picking only topmost detected entity not rejected by Selection Filters. --- diff --git a/src/AIS/AIS_InteractiveContext.cxx b/src/AIS/AIS_InteractiveContext.cxx index 99e6efbb2c..74e541f416 100644 --- a/src/AIS/AIS_InteractiveContext.cxx +++ b/src/AIS/AIS_InteractiveContext.cxx @@ -95,6 +95,7 @@ myCurLocalIndex(0), myCurDetected(0), myCurHighlighted(0), myZDetectionFlag(0), +myPickingStrategy (SelectMgr_PickingStrategy_FirstAcceptable), myIsAutoActivateSelMode(Standard_True) { InitAttributes(); diff --git a/src/AIS/AIS_InteractiveContext.hxx b/src/AIS/AIS_InteractiveContext.hxx index 6b2d261929..137d4364aa 100644 --- a/src/AIS/AIS_InteractiveContext.hxx +++ b/src/AIS/AIS_InteractiveContext.hxx @@ -17,33 +17,32 @@ #ifndef _AIS_InteractiveContext_HeaderFile #define _AIS_InteractiveContext_HeaderFile -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include #include +#include +#include #include +#include #include -#include +#include +#include +#include +#include +#include #include #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include #include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -144,6 +143,26 @@ public: Standard_EXPORT Standard_Boolean GetAutoActivateSelection() const; + //! Setup picking strategy - which entities detected by picking line will be accepted, considering Selection Filters. + //! By default (SelectMgr_PickingStrategy_FirstAcceptable), Selection Filters reduce the list of entities + //! so that the context accepts topmost in remaining. + //! + //! This means that entities behind non-selectable (by filters) parts can be picked by user. + //! If this behavior is undesirable, and user wants that non-selectable (by filters) parts + //! should remain an obstacle for picking, SelectMgr_PickingStrategy_OnlyTopmost can be set instead. + //! + //! Notice, that since Selection Manager operates only objects registered in it, + //! SelectMgr_PickingStrategy_OnlyTopmost will NOT prevent picking entities behind + //! visible by unregistered in Selection Manager presentations (e.g. deactivated). + //! Hence, SelectMgr_PickingStrategy_OnlyTopmost changes behavior only with Selection Filters enabled. + void SetPickingStrategy (const SelectMgr_PickingStrategy theStrategy) + { + myPickingStrategy = theStrategy; + } + + //! Return picking strategy; SelectMgr_PickingStrategy_FirstAcceptable by default. + SelectMgr_PickingStrategy PickingStrategy() const { return myPickingStrategy; } + //! Controls the choice between the using the display //! and selection modes of open local context which you //! have defined and activating those available by default. @@ -1719,6 +1738,7 @@ protected: Standard_Integer myCurDetected; Standard_Integer myCurHighlighted; Standard_Boolean myZDetectionFlag; + SelectMgr_PickingStrategy myPickingStrategy; //!< picking strategy to be applied within MoveTo() Standard_Boolean myIsAutoActivateSelMode; }; diff --git a/src/AIS/AIS_InteractiveContext_1.cxx b/src/AIS/AIS_InteractiveContext_1.cxx index 0af8ae068a..ef1f417a68 100644 --- a/src/AIS/AIS_InteractiveContext_1.cxx +++ b/src/AIS/AIS_InteractiveContext_1.cxx @@ -329,16 +329,22 @@ AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer th // (the objects must be AIS_Shapes) const Standard_Integer aDetectedNb = myMainSel->NbPicked(); Standard_Integer aNewDetected = 0; + Standard_Boolean toIgnoreDetTop = Standard_False; for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter) { Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aDetIter); if (anOwner.IsNull() || !myFilters->IsOk (anOwner)) { + if (myPickingStrategy == SelectMgr_PickingStrategy_OnlyTopmost) + { + toIgnoreDetTop = Standard_True; + } continue; } - if (aNewDetected < 1) + if (aNewDetected < 1 + && !toIgnoreDetTop) { aNewDetected = aDetIter; } diff --git a/src/SelectMgr/FILES b/src/SelectMgr/FILES index 6997ac27cd..ece37a2250 100755 --- a/src/SelectMgr/FILES +++ b/src/SelectMgr/FILES @@ -22,6 +22,7 @@ SelectMgr_ListIteratorOfListOfFilter.hxx SelectMgr_ListOfFilter.hxx SelectMgr_OrFilter.cxx SelectMgr_OrFilter.hxx +SelectMgr_PickingStrategy.hxx SelectMgr_RectangularFrustum.cxx SelectMgr_RectangularFrustum.hxx SelectMgr_SelectableObject.cxx diff --git a/src/SelectMgr/SelectMgr_PickingStrategy.hxx b/src/SelectMgr/SelectMgr_PickingStrategy.hxx new file mode 100644 index 0000000000..303ce6e368 --- /dev/null +++ b/src/SelectMgr/SelectMgr_PickingStrategy.hxx @@ -0,0 +1,24 @@ +// Copyright (c) 2017 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 _SelectMgr_PickingStrategy_HeaderFile +#define _SelectMgr_PickingStrategy_HeaderFile + +//! Enumeration defines picking strategy - which entities detected by picking line will be accepted, considering selection filters. +enum SelectMgr_PickingStrategy +{ + SelectMgr_PickingStrategy_FirstAcceptable, //!< the first detected entity passing selection filter is accepted (e.g. any) + SelectMgr_PickingStrategy_OnlyTopmost //!< only topmost detected entity passing selection filter is accepted +}; + +#endif // _SelectMgr_PickingStrategy_HeaderFile diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index a50ffc7ad2..c5301546a1 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -10059,6 +10059,30 @@ static int VSelectionProperties (Draw_Interpretor& theDi, { aHiStyle->SetTransparency (aCmd.ArgFloat ("hiTransp")); } + if (aCmd.HasOption ("pickStrategy")) + { + SelectMgr_PickingStrategy aStrategy = SelectMgr_PickingStrategy_FirstAcceptable; + TCollection_AsciiString aVal (aCmd.Arg ("pickStrategy", 0).c_str()); + aVal.LowerCase(); + if (aVal == "first" + || aVal == "firstaccepted" + || aVal == "firstacceptable") + { + aStrategy = SelectMgr_PickingStrategy_FirstAcceptable; + } + else if (aVal == "topmost" + || aVal == "onlyTopmost") + { + aStrategy = SelectMgr_PickingStrategy_OnlyTopmost; + } + else + { + std::cout << "Syntax error: unknwon picking strategy '" << aVal << "'\n"; + return 1; + } + + aCtx->SetPickingStrategy (aStrategy); + } if (aCmd.HasOption ("print") || theArgsNb == 1) { @@ -10687,6 +10711,9 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) "\n vselprops [options]" "\n Customizes selection and dynamic highlight parameters for the whole interactive context:" "\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode" + "\n -pickStrategy {first|topmost} : defines picking strategy" + "\n 'first' to pick first acceptable (default)" + "\n 'topmost' to pick only topmost (and nothing, if topmost is rejected by filters)" "\n -pixTol value : sets up pixel tolerance" "\n -selColor {name|r g b} : sets selection color" "\n -hiColor {name|r g b} : sets dynamic highlight color"