0031221: Visualization - selection filter in context
[occt.git] / src / SelectMgr / SelectMgr_AndOrFilter.cxx
CommitLineData
897aeb20 1// Copyright (c) 2020 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14#include <SelectMgr_AndOrFilter.hxx>
15#include <SelectMgr_EntityOwner.hxx>
16#include <SelectMgr_Filter.hxx>
17#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
18#include <SelectMgr_SelectableObject.hxx>
19#include <Standard_Type.hxx>
20
21IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_AndOrFilter, SelectMgr_CompositionFilter)
22
23//=============================================================================
24//function : SelectMgr_AndOrFilter
25//purpose :
26//=============================================================================
27SelectMgr_AndOrFilter::SelectMgr_AndOrFilter (const SelectMgr_FilterType theFilterType):
28myFilterType (theFilterType)
29{
30}
31
32//=============================================================================
33//function : SetDisabledObjects
34//purpose :
35//=============================================================================
36void SelectMgr_AndOrFilter::SetDisabledObjects (const Handle(Graphic3d_NMapOfTransient)& theObjects)
37{
38 myDisabledObjects = theObjects;
39}
40
41//=============================================================================
42//function : IsOk
43//purpose :
44//=============================================================================
45Standard_Boolean SelectMgr_AndOrFilter::IsOk (const Handle(SelectMgr_EntityOwner)& theObj) const
46{
47 const SelectMgr_SelectableObject* aSelectable = theObj->Selectable().operator->();
48 if (!myDisabledObjects.IsNull() && myDisabledObjects->Contains (aSelectable))
49 {
50 return Standard_False;
51 }
52
53 for (SelectMgr_ListIteratorOfListOfFilter anIter(myFilters); anIter.More();anIter.Next())
54 {
55 Standard_Boolean isOK = anIter.Value()->IsOk(theObj);
56 if(isOK && myFilterType == SelectMgr_FilterType_OR)
57 {
58 return Standard_True;
59 }
60 else if (!isOK && myFilterType == SelectMgr_FilterType_AND)
61 {
62 return Standard_False;
63 }
64 }
65
66 if (myFilterType == SelectMgr_FilterType_OR && !myFilters.IsEmpty())
67 {
68 return Standard_False;
69 }
70 return Standard_True;
71}