From 897aeb207fcb31e02288a3d9b5fea0ff1a50cbe9 Mon Sep 17 00:00:00 2001 From: sshutina Date: Fri, 11 Sep 2020 12:14:58 +0300 Subject: [PATCH] 0031221: Visualization - selection filter in context - Added the new filter SelectMgr_AndOrFilter which allows to define the context filter. By default OR selection filter is used - Added the enumeration SelectMgr_FilterType provides filter types - To define behavior SelectMgr_AndOrFilter use SetFilterType in AIS_InteractiveContext - Added the test - SelectMgr_OrFilter don't store the disabled objects, it's stored in SelectMgr_AndOrFilter --- src/AIS/AIS_InteractiveContext.cxx | 2 +- src/AIS/AIS_InteractiveContext.hxx | 14 ++++- src/AIS/AIS_InteractiveContext_3.cxx | 1 - src/SelectMgr/FILES | 3 ++ src/SelectMgr/SelectMgr_AndOrFilter.cxx | 71 +++++++++++++++++++++++++ src/SelectMgr/SelectMgr_AndOrFilter.hxx | 61 +++++++++++++++++++++ src/SelectMgr/SelectMgr_FilterType.hxx | 24 +++++++++ src/SelectMgr/SelectMgr_OrFilter.cxx | 19 +------ src/SelectMgr/SelectMgr_OrFilter.hxx | 16 ------ src/ViewerTest/ViewerTest.cxx | 47 +++++++++++++++- tests/bugs/vis/bug31221 | 52 ++++++++++++++++++ 11 files changed, 271 insertions(+), 39 deletions(-) create mode 100644 src/SelectMgr/SelectMgr_AndOrFilter.cxx create mode 100644 src/SelectMgr/SelectMgr_AndOrFilter.hxx create mode 100644 src/SelectMgr/SelectMgr_FilterType.hxx create mode 100644 tests/bugs/vis/bug31221 diff --git a/src/AIS/AIS_InteractiveContext.cxx b/src/AIS/AIS_InteractiveContext.cxx index 04d0076c87..67fece1c1f 100644 --- a/src/AIS/AIS_InteractiveContext.cxx +++ b/src/AIS/AIS_InteractiveContext.cxx @@ -128,7 +128,7 @@ myMainVwr(MainViewer), myMainSel(new StdSelect_ViewerSelector3d()), myToHilightSelected(Standard_True), mySelection(new AIS_Selection()), -myFilters(new SelectMgr_OrFilter()), +myFilters (new SelectMgr_AndOrFilter(SelectMgr_FilterType_OR)), myDefaultDrawer(new Prs3d_Drawer()), myCurDetected(0), myCurHighlighted(0), diff --git a/src/AIS/AIS_InteractiveContext.hxx b/src/AIS/AIS_InteractiveContext.hxx index 52adbfdace..2e4d57b5a0 100644 --- a/src/AIS/AIS_InteractiveContext.hxx +++ b/src/AIS/AIS_InteractiveContext.hxx @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,6 @@ class SelectMgr_SelectionManager; class V3d_Viewer; -class SelectMgr_OrFilter; class V3d_View; class TopLoc_Location; class TCollection_ExtendedString; @@ -736,6 +736,15 @@ public: //! @name management of active Selection Modes public: //! @name Selection Filters management + //! @return the context selection filter type. + SelectMgr_FilterType FilterType() const { return myFilters->FilterType(); } + + //! Sets the context selection filter type. + //! SelectMgr_TypeFilter_OR selection filter is used by default. + //! @param theFilterType the filter type. + void SetFilterType (const SelectMgr_FilterType theFilterType) + { myFilters->SetFilterType (theFilterType); } + //! Returns the list of filters active in a local context. Standard_EXPORT const SelectMgr_ListOfFilter& Filters() const; @@ -1354,7 +1363,8 @@ protected: //! @name internal fields Handle(SelectMgr_EntityOwner) myLastPicked; Standard_Boolean myToHilightSelected; Handle(AIS_Selection) mySelection; - Handle(SelectMgr_OrFilter) myFilters; + Handle(SelectMgr_AndOrFilter) myFilters; //!< context filter (the content active filters + //! can be applied with AND or OR operation) Handle(Prs3d_Drawer) myDefaultDrawer; Handle(Prs3d_Drawer) myStyles[Prs3d_TypeOfHighlight_NB]; TColStd_SequenceOfInteger myDetectedSeq; diff --git a/src/AIS/AIS_InteractiveContext_3.cxx b/src/AIS/AIS_InteractiveContext_3.cxx index b0a070f632..fc52e1aeb5 100644 --- a/src/AIS/AIS_InteractiveContext_3.cxx +++ b/src/AIS/AIS_InteractiveContext_3.cxx @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include diff --git a/src/SelectMgr/FILES b/src/SelectMgr/FILES index 208700b0e9..6166e38470 100755 --- a/src/SelectMgr/FILES +++ b/src/SelectMgr/FILES @@ -2,6 +2,8 @@ SelectMgr.cxx SelectMgr.hxx SelectMgr_AndFilter.cxx SelectMgr_AndFilter.hxx +SelectMgr_AndOrFilter.cxx +SelectMgr_AndOrFilter.hxx SelectMgr_BaseFrustum.cxx SelectMgr_BaseFrustum.hxx SelectMgr_CompositionFilter.cxx @@ -11,6 +13,7 @@ SelectMgr_EntityOwner.cxx SelectMgr_EntityOwner.hxx SelectMgr_Filter.cxx SelectMgr_Filter.hxx +SelectMgr_FilterType.hxx SelectMgr_Frustum.hxx SelectMgr_Frustum.lxx SelectMgr_FrustumBuilder.cxx diff --git a/src/SelectMgr/SelectMgr_AndOrFilter.cxx b/src/SelectMgr/SelectMgr_AndOrFilter.cxx new file mode 100644 index 0000000000..5f2e4384f5 --- /dev/null +++ b/src/SelectMgr/SelectMgr_AndOrFilter.cxx @@ -0,0 +1,71 @@ +// Copyright (c) 2020 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. + +#include +#include +#include +#include +#include +#include + +IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_AndOrFilter, SelectMgr_CompositionFilter) + +//============================================================================= +//function : SelectMgr_AndOrFilter +//purpose : +//============================================================================= +SelectMgr_AndOrFilter::SelectMgr_AndOrFilter (const SelectMgr_FilterType theFilterType): +myFilterType (theFilterType) +{ +} + +//============================================================================= +//function : SetDisabledObjects +//purpose : +//============================================================================= +void SelectMgr_AndOrFilter::SetDisabledObjects (const Handle(Graphic3d_NMapOfTransient)& theObjects) +{ + myDisabledObjects = theObjects; +} + +//============================================================================= +//function : IsOk +//purpose : +//============================================================================= +Standard_Boolean SelectMgr_AndOrFilter::IsOk (const Handle(SelectMgr_EntityOwner)& theObj) const +{ + const SelectMgr_SelectableObject* aSelectable = theObj->Selectable().operator->(); + if (!myDisabledObjects.IsNull() && myDisabledObjects->Contains (aSelectable)) + { + return Standard_False; + } + + for (SelectMgr_ListIteratorOfListOfFilter anIter(myFilters); anIter.More();anIter.Next()) + { + Standard_Boolean isOK = anIter.Value()->IsOk(theObj); + if(isOK && myFilterType == SelectMgr_FilterType_OR) + { + return Standard_True; + } + else if (!isOK && myFilterType == SelectMgr_FilterType_AND) + { + return Standard_False; + } + } + + if (myFilterType == SelectMgr_FilterType_OR && !myFilters.IsEmpty()) + { + return Standard_False; + } + return Standard_True; +} diff --git a/src/SelectMgr/SelectMgr_AndOrFilter.hxx b/src/SelectMgr/SelectMgr_AndOrFilter.hxx new file mode 100644 index 0000000000..1f144bce44 --- /dev/null +++ b/src/SelectMgr/SelectMgr_AndOrFilter.hxx @@ -0,0 +1,61 @@ +// Copyright (c) 2020 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_AndOrFilter_HeaderFile +#define _SelectMgr_AndOrFilter_HeaderFile + +#include +#include + +#include +#include +#include +#include + +DEFINE_STANDARD_HANDLE(SelectMgr_AndOrFilter, SelectMgr_CompositionFilter) + +//! A framework to define an OR or AND selection filter. +//! To use an AND selection filter call SetUseOrFilter with False parameter. +//! By default the OR selection filter is used. +class SelectMgr_AndOrFilter : public SelectMgr_CompositionFilter +{ + +public: + + //! Constructs an empty selection filter. + Standard_EXPORT SelectMgr_AndOrFilter (const SelectMgr_FilterType theFilterType); + + //! Indicates that the selected Interactive Object passes the filter. + Standard_EXPORT virtual Standard_Boolean IsOk (const Handle(SelectMgr_EntityOwner)& theObj) const Standard_OVERRIDE; + + //! Disable selection of specified objects. + Standard_EXPORT void SetDisabledObjects (const Handle(Graphic3d_NMapOfTransient)& theObjects); + + //! @return a selection filter type (@sa SelectMgr_FilterType). + SelectMgr_FilterType FilterType() const { return myFilterType; } + + //! Sets a selection filter type. + //! SelectMgr_FilterType_OR selection filter is used be default. + //! @param theFilterType the filter type. + void SetFilterType (const SelectMgr_FilterType theFilterType) { myFilterType = theFilterType; } + + DEFINE_STANDARD_RTTIEXT(SelectMgr_AndOrFilter, SelectMgr_CompositionFilter) + +private: + + Handle(Graphic3d_NMapOfTransient) myDisabledObjects; //!< disabled objects. + //! Selection isn't applied to these objects. + SelectMgr_FilterType myFilterType; //!< selection filter type. SelectMgr_TypeFilter_OR by default. +}; + +#endif // _SelectMgr_AndOrFilter_HeaderFile diff --git a/src/SelectMgr/SelectMgr_FilterType.hxx b/src/SelectMgr/SelectMgr_FilterType.hxx new file mode 100644 index 0000000000..7c739d17ff --- /dev/null +++ b/src/SelectMgr/SelectMgr_FilterType.hxx @@ -0,0 +1,24 @@ +// Copyright (c) 2020 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_FilterType_HeaderFile +#define _SelectMgr_FilterType_HeaderFile + +//! Enumeration defines the filter type. +enum SelectMgr_FilterType +{ + SelectMgr_FilterType_AND, //!< an object should be suitable for all filters. + SelectMgr_FilterType_OR //!< an object should be suitable at least one filter. +}; + +#endif // _SelectMgr_FilterType_HeaderFile diff --git a/src/SelectMgr/SelectMgr_OrFilter.cxx b/src/SelectMgr/SelectMgr_OrFilter.cxx index fe84f35b7f..cedfb54a99 100644 --- a/src/SelectMgr/SelectMgr_OrFilter.cxx +++ b/src/SelectMgr/SelectMgr_OrFilter.cxx @@ -15,9 +15,7 @@ #include #include -#include #include -#include #include IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_OrFilter,SelectMgr_CompositionFilter) @@ -30,28 +28,13 @@ SelectMgr_OrFilter::SelectMgr_OrFilter() { } -//============================================================================= -//function : SetDisabledObjects -//purpose : -//============================================================================= -void SelectMgr_OrFilter::SetDisabledObjects (const Handle(Graphic3d_NMapOfTransient)& theObjects) -{ - myDisabledObjects = theObjects; -} - //============================================================================= //function : IsOk //purpose : //============================================================================= Standard_Boolean SelectMgr_OrFilter::IsOk (const Handle(SelectMgr_EntityOwner)& theObj) const { - const SelectMgr_SelectableObject* aSelectable = theObj->Selectable().operator->(); - if (!myDisabledObjects.IsNull() - && myDisabledObjects->Contains (aSelectable)) - { - return Standard_False; - } - else if (myFilters.IsEmpty()) + if (myFilters.IsEmpty()) { return Standard_True; } diff --git a/src/SelectMgr/SelectMgr_OrFilter.hxx b/src/SelectMgr/SelectMgr_OrFilter.hxx index f4625740d3..192b7e0c9c 100644 --- a/src/SelectMgr/SelectMgr_OrFilter.hxx +++ b/src/SelectMgr/SelectMgr_OrFilter.hxx @@ -20,7 +20,6 @@ #include #include -#include #include #include class SelectMgr_EntityOwner; @@ -41,26 +40,11 @@ public: Standard_EXPORT SelectMgr_OrFilter(); Standard_EXPORT Standard_Boolean IsOk (const Handle(SelectMgr_EntityOwner)& anobj) const Standard_OVERRIDE; - - //! Disable selection of specified objects. - Standard_EXPORT void SetDisabledObjects (const Handle(Graphic3d_NMapOfTransient)& theObjects); - - - DEFINE_STANDARD_RTTIEXT(SelectMgr_OrFilter,SelectMgr_CompositionFilter) protected: - - - -private: - - - Handle(Graphic3d_NMapOfTransient) myDisabledObjects; - - }; diff --git a/src/ViewerTest/ViewerTest.cxx b/src/ViewerTest/ViewerTest.cxx index 39d4410dbe..dc613f95f7 100644 --- a/src/ViewerTest/ViewerTest.cxx +++ b/src/ViewerTest/ViewerTest.cxx @@ -5815,6 +5815,24 @@ static int VSelFilter(Draw_Interpretor& , Standard_Integer theArgc, { aContext->RemoveFilters(); } + else if (anArg == "-contextfilter" && anArgIter + 1 < theArgc) + { + TCollection_AsciiString aVal (theArgv[++anArgIter]); + aVal.LowerCase(); + if (aVal == "and") + { + aContext->SetFilterType (SelectMgr_FilterType_AND); + } + else if (aVal == "or") + { + aContext->SetFilterType (SelectMgr_FilterType_OR); + } + else + { + Message::SendFail() << "Syntax error: wrong command attribute value '" << aVal << "'"; + return 1; + } + } else if (anArg == "-type" && anArgIter + 1 < theArgc) { @@ -5837,6 +5855,28 @@ static int VSelFilter(Draw_Interpretor& , Standard_Integer theArgc, } aContext->AddFilter (aFilter); } + else if (anArg == "-secondtype" + && anArgIter + 1 < theArgc) + { + TCollection_AsciiString aVal (theArgv[++anArgIter]); + TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND; + if (!TopAbs::ShapeTypeFromString (aVal.ToCString(), aShapeType)) + { + Message::SendFail() << "Syntax error: wrong command attribute value '" << aVal << "'"; + return 1; + } + + Handle(SelectMgr_Filter) aFilter; + if (aShapeType == TopAbs_SHAPE) + { + aFilter = new AIS_TypeFilter (AIS_KOI_Shape); + } + else + { + aFilter = new StdSelect_ShapeTypeFilter (aShapeType); + } + aContext->AddFilter (aFilter); + } else { Message::SendFail() << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'"; @@ -6782,8 +6822,13 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands) __FILE__,vr, group); theCommands.Add("vselfilter", - "vselfilter [-type {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}] [-clear]" + "vselfilter [-contextfilter {AND|OR}]" + "\n [-type {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}]" + "\n [-secondtype {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}]" + "\n [-clear]" "\nSets selection shape type filter in context or remove all filters." + "\n : Option -contextfilter : To define a selection filter for two or more types of entity," + "\n use value AND (OR by default)." "\n : Option -type set type of selection filter. Filters are applyed with Or combination." "\n : Option -clear remove all filters in context", __FILE__,VSelFilter,group); diff --git a/tests/bugs/vis/bug31221 b/tests/bugs/vis/bug31221 new file mode 100644 index 0000000000..2487ae5c91 --- /dev/null +++ b/tests/bugs/vis/bug31221 @@ -0,0 +1,52 @@ +puts "===========" +puts "0031221: Visualization - selection filter in context" +puts "===========" +puts "" + +vertex v 0 0 0 + +vertex v1 1 0 0 +vertex v2 10 0 0 +edge e v1 v2 + +vclear +vinit View1 +vdisplay v +vdisplay e +vfit + +# 1. +# Set composition filter AND to aplly VERTEX and EDGE filter +# the vertex and the edge isn't selected +vselfilter -contextfilter AND -type VERTEX -secondtype EDGE + +vchangeselected e + +set aNbSelected [vnbselected] +if { $aNbSelected != 0 } { puts "Error: combined AND filter was not applied" } + +vchangeselected v + +set aNbSelected [vnbselected] +if { $aNbSelected != 0 } { puts "Error: combined AND filter was not applied" } + +# 2. +# Deselected the edge and the vertex +vchangeselected e +vchangeselected v + +# 3. +# Set composition filter OR to aplly VERTEX and EDGE filter +# the vertex and the edge is selected + +vselfilter -contextfilter OR -type VERTEX -secondtype EDGE + +vchangeselected e + +set aNbSelected [vnbselected] +if { $aNbSelected != 1 } { puts "Error: combined OR filter was not applied" } + +vchangeselected v + +set aNbSelected [vnbselected] +if { $aNbSelected != 2 } { puts "Error: combined OR filter was not applied" } \ No newline at end of file