From: nds Date: Wed, 28 Oct 2020 18:16:27 +0000 (+0300) Subject: 0030737: Visualization - implementing new selection schemes in context X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FCR0_DMUReviewer_IR-2020-10-23;p=occt-copy.git 0030737: Visualization - implementing new selection schemes in context AIS_SelectionScheme_ReplaceExtra introduce --- diff --git a/dox/user_guides/visualization/images/visualization_selection_scheme_replaceExtra.svg b/dox/user_guides/visualization/images/visualization_selection_scheme_replaceExtra.svg new file mode 100644 index 0000000000..7e82fec688 --- /dev/null +++ b/dox/user_guides/visualization/images/visualization_selection_scheme_replaceExtra.svg @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dox/user_guides/visualization/visualization.md b/dox/user_guides/visualization/visualization.md index 403749d53e..f38f9e483d 100644 --- a/dox/user_guides/visualization/visualization.md +++ b/dox/user_guides/visualization/visualization.md @@ -1040,7 +1040,7 @@ Select* methods of AIS_InteractiveContext accept some selection scheme as parame | :----- | :----- | :----- | :----- | :----- | | AIS_SelectionScheme_Replace | @figure{visualization_selection_scheme_replace.svg, ""} | | AIS_SelectionScheme_XOR | @figure{visualization_selection_scheme_XOR.svg, ""} | | AIS_SelectionScheme_Add | @figure{visualization_selection_scheme_add.svg, ""} | | AIS_SelectionScheme_Clear | @figure{visualization_selection_scheme_clear.svg, ""} | -| AIS_SelectionScheme_Remove | @figure{visualization_selection_scheme_remove.svg, ""} | | | | +| AIS_SelectionScheme_Remove | @figure{visualization_selection_scheme_remove.svg, ""} | | AIS_SelectionScheme_ReplaceExtra | @figure{visualization_selection_scheme_replaceExtra.svg, ""} | @subsection occt_visu_3_5 Standard Interactive Object Classes diff --git a/src/AIS/AIS_Selection.cxx b/src/AIS/AIS_Selection.cxx index c914031b06..10b1410367 100644 --- a/src/AIS/AIS_Selection.cxx +++ b/src/AIS/AIS_Selection.cxx @@ -197,6 +197,35 @@ 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; + } } } @@ -216,3 +245,26 @@ AIS_SelectStatus AIS_Selection::appendOwner (const Handle(SelectMgr_EntityOwner) return AddSelect (theOwner); } + +//======================================================================= +//function : XOROwner +//purpose : +//======================================================================= +AIS_SelectStatus AIS_Selection::XOROwner (const Handle(SelectMgr_EntityOwner)& theOwner, + const AIS_NListOfEntityOwner& thePreviousSelected, + const Handle(SelectMgr_Filter)& theFilter) +{ + if (theOwner.IsNull() || !theOwner->HasSelectable() || !theFilter->IsOk (theOwner)) + return AIS_SS_NotDone; + + if (thePreviousSelected.Contains (theOwner)) // was selected, should not be now + { + if (theOwner->IsSelected()) + return Select (theOwner); // deselect + } + else + { + return AddSelect (theOwner); // was not selected, should be now + } + return AIS_SS_NotDone; +} diff --git a/src/AIS/AIS_Selection.hxx b/src/AIS/AIS_Selection.hxx index d3163ce154..2e0bca8380 100644 --- a/src/AIS/AIS_Selection.hxx +++ b/src/AIS/AIS_Selection.hxx @@ -95,6 +95,15 @@ protected: Standard_EXPORT virtual AIS_SelectStatus appendOwner (const Handle(SelectMgr_EntityOwner)& theOwner, const Handle(SelectMgr_Filter)& theFilter); + //! XOR the owner to the current selection if filter is Ok. + //! \param theOwner element to change selection state + //! \param thePreviousSelected previous selected objects + //! \param theFilter context filter to skip not acceptable owners + //! \return result of selection + Standard_EXPORT virtual AIS_SelectStatus XOROwner (const Handle(SelectMgr_EntityOwner)& theOwner, + const AIS_NListOfEntityOwner& thePreviousSelected, + const Handle(SelectMgr_Filter)& theFilter); + protected: AIS_NListOfEntityOwner myresult; diff --git a/src/AIS/AIS_SelectionScheme.hxx b/src/AIS/AIS_SelectionScheme.hxx index ef5da37a7e..a5de1f3e0f 100644 --- a/src/AIS/AIS_SelectionScheme.hxx +++ b/src/AIS/AIS_SelectionScheme.hxx @@ -22,7 +22,9 @@ enum AIS_SelectionScheme AIS_SelectionScheme_Add, //!< adds detected object to current selection AIS_SelectionScheme_Remove, //!< removes detected object from the current selection AIS_SelectionScheme_XOR, //!< performs XOR for detected objects, other selected not touched - AIS_SelectionScheme_Clear //!< clears current selection + AIS_SelectionScheme_Clear, //!< clears current selection + AIS_SelectionScheme_ReplaceExtra, //!< replace with one difference: if result of replace is an empty, + //!< and current selection contains detected element, it will be selected }; #endif // _AIS_SelectionScheme_HeaderFile