1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

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
This commit is contained in:
sshutina
2020-09-11 12:14:58 +03:00
committed by abv
parent b95caec47d
commit 897aeb207f
11 changed files with 271 additions and 39 deletions

View File

@@ -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

View File

@@ -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 <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;
}

View File

@@ -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 <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

View File

@@ -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

View File

@@ -15,9 +15,7 @@
#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)
@@ -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;
}

View File

@@ -20,7 +20,6 @@
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <Graphic3d_NMapOfTransient.hxx>
#include <SelectMgr_CompositionFilter.hxx>
#include <Standard_Boolean.hxx>
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;
};