- 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
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),
#include <Prs3d_Drawer.hxx>
#include <Prs3d_TypeOfHighlight.hxx>
#include <PrsMgr_PresentationManager3d.hxx>
+#include <SelectMgr_AndOrFilter.hxx>
#include <SelectMgr_IndexedMapOfOwner.hxx>
#include <SelectMgr_ListOfFilter.hxx>
#include <SelectMgr_PickingStrategy.hxx>
class SelectMgr_SelectionManager;
class V3d_Viewer;
-class SelectMgr_OrFilter;
class V3d_View;
class TopLoc_Location;
class TCollection_ExtendedString;
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;
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;
#include <Quantity_Color.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Filter.hxx>
-#include <SelectMgr_OrFilter.hxx>
#include <SelectMgr_SelectionManager.hxx>
#include <Standard_Transient.hxx>
#include <TCollection_AsciiString.hxx>
SelectMgr.hxx
SelectMgr_AndFilter.cxx
SelectMgr_AndFilter.hxx
+SelectMgr_AndOrFilter.cxx
+SelectMgr_AndOrFilter.hxx
SelectMgr_BaseFrustum.cxx
SelectMgr_BaseFrustum.hxx
SelectMgr_CompositionFilter.cxx
SelectMgr_EntityOwner.hxx
SelectMgr_Filter.cxx
SelectMgr_Filter.hxx
+SelectMgr_FilterType.hxx
SelectMgr_Frustum.hxx
SelectMgr_Frustum.lxx
SelectMgr_FrustumBuilder.cxx
--- /dev/null
+// 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 <SelectMgr_AndOrFilter.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+#include <SelectMgr_Filter.hxx>
+#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
+#include <SelectMgr_SelectableObject.hxx>
+#include <Standard_Type.hxx>
+
+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;
+}
--- /dev/null
+// 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 <Standard.hxx>
+#include <Standard_Type.hxx>
+
+#include <Graphic3d_NMapOfTransient.hxx>
+#include <Standard_Boolean.hxx>
+#include <SelectMgr_CompositionFilter.hxx>
+#include <SelectMgr_FilterType.hxx>
+
+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
--- /dev/null
+// 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
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Filter.hxx>
-#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
#include <SelectMgr_OrFilter.hxx>
-#include <SelectMgr_SelectableObject.hxx>
#include <Standard_Type.hxx>
IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_OrFilter,SelectMgr_CompositionFilter)
{
}
-//=============================================================================
-//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;
}
#include <Standard.hxx>
#include <Standard_Type.hxx>
-#include <Graphic3d_NMapOfTransient.hxx>
#include <SelectMgr_CompositionFilter.hxx>
#include <Standard_Boolean.hxx>
class SelectMgr_EntityOwner;
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;
-
-
};
{
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)
{
}
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] << "'";
__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);
--- /dev/null
+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