1 // Created on: 1997-11-28
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <AIS_ExclusionFilter.hxx>
19 #include <AIS_InteractiveObject.hxx>
20 #include <SelectMgr_EntityOwner.hxx>
21 #include <Standard_Type.hxx>
22 #include <TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger.hxx>
23 #include <TColStd_ListOfInteger.hxx>
25 IMPLEMENT_STANDARD_RTTIEXT(AIS_ExclusionFilter,SelectMgr_Filter)
27 //=======================================================================
28 //function : AIS_ExclusionFilter
29 //purpose : Constructors
30 //=======================================================================
31 AIS_ExclusionFilter::AIS_ExclusionFilter(const Standard_Boolean ExclusionFlagOn):
32 myIsExclusionFlagOn(ExclusionFlagOn)
36 AIS_ExclusionFilter::AIS_ExclusionFilter(const AIS_KindOfInteractive TypeToExclude,
37 const Standard_Boolean ExclusionFlagOn):
38 myIsExclusionFlagOn(ExclusionFlagOn)
40 TColStd_ListOfInteger L;
41 myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
44 AIS_ExclusionFilter::AIS_ExclusionFilter(const AIS_KindOfInteractive TypeToExclude,
45 const Standard_Integer SignatureInType,
46 const Standard_Boolean ExclusionFlagOn):
47 myIsExclusionFlagOn(ExclusionFlagOn)
49 TColStd_ListOfInteger L;
50 L.Append(SignatureInType);
51 myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
54 //=======================================================================
57 //=======================================================================
58 Standard_Boolean AIS_ExclusionFilter::Add(const AIS_KindOfInteractive TypeToExclude)
60 if(IsStored(TypeToExclude))
61 return Standard_False;
62 TColStd_ListOfInteger L;
63 myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
67 Standard_Boolean AIS_ExclusionFilter::Add(const AIS_KindOfInteractive TypeToExclude,
68 const Standard_Integer SignatureInType)
70 if(!IsStored(TypeToExclude)){
71 TColStd_ListOfInteger L;
72 L.Append(SignatureInType);
73 myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
77 myStoredTypes((Standard_Integer)TypeToExclude).Append(SignatureInType);
81 //=======================================================================
84 //=======================================================================
86 Standard_Boolean AIS_ExclusionFilter::Remove(const AIS_KindOfInteractive TypeToExclude)
88 if(!IsStored(TypeToExclude)) return Standard_False;
89 myStoredTypes((Standard_Integer)TypeToExclude).Clear();
90 myStoredTypes.UnBind((Standard_Integer)TypeToExclude);
94 Standard_Boolean AIS_ExclusionFilter::Remove(const AIS_KindOfInteractive TypeToExclude,
95 const Standard_Integer SignatureInType)
97 if(!IsStored(TypeToExclude)) return Standard_False;
98 TColStd_ListOfInteger& LL = myStoredTypes.ChangeFind((Standard_Integer)TypeToExclude);
99 for(TColStd_ListIteratorOfListOfInteger it(LL);it.More();it.Next()){
100 if(it.Value()==SignatureInType){
102 return Standard_True;
105 return Standard_False;
109 //=======================================================================
112 //=======================================================================
114 void AIS_ExclusionFilter::Clear()
116 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger Mit(myStoredTypes);
117 for(;Mit.More();Mit.Next())
118 myStoredTypes.ChangeFind(Mit.Key()).Clear();
119 myStoredTypes.Clear();
122 //=======================================================================
123 //function : IsStored
125 //=======================================================================
127 Standard_Boolean AIS_ExclusionFilter::IsStored(const AIS_KindOfInteractive aType) const
129 return myStoredTypes.IsBound(Standard_Integer(aType));
132 //=======================================================================
133 //function : IsSignatureIn
135 //=======================================================================
136 Standard_Boolean AIS_ExclusionFilter::IsSignatureIn(const AIS_KindOfInteractive aType,
137 const Standard_Integer SignatureInType) const
139 if(!myStoredTypes.IsBound(aType)) return Standard_False;
140 for(TColStd_ListIteratorOfListOfInteger Lit(myStoredTypes((Standard_Integer)aType));
143 if(Lit.Value()==SignatureInType)
144 return Standard_True;
146 return Standard_False;
149 //=======================================================================
150 //function : ListOfStoredTypes
152 //=======================================================================
154 void AIS_ExclusionFilter::ListOfStoredTypes(TColStd_ListOfInteger& TheList) const
157 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger MIT(myStoredTypes);
158 for(;MIT.More();MIT.Next())
159 TheList.Append(MIT.Key());
162 //=======================================================================
163 //function : ListOfSignature
165 //=======================================================================
167 void AIS_ExclusionFilter::ListOfSignature(const AIS_KindOfInteractive aType,TColStd_ListOfInteger& TheStoredList) const
169 TheStoredList.Clear();
171 for(TColStd_ListIteratorOfListOfInteger it(myStoredTypes(aType));it.More();it.Next())
172 TheStoredList.Append(it.Value());
175 //=======================================================================
178 //=======================================================================
180 Standard_Boolean AIS_ExclusionFilter::IsOk(const Handle(SelectMgr_EntityOwner)& EO) const
182 if(myStoredTypes.IsEmpty())
183 return myIsExclusionFlagOn;
186 return Standard_False;
187 Handle(AIS_InteractiveObject) IO = Handle(AIS_InteractiveObject)::DownCast(EO->Selectable());
189 return Standard_False;
191 // type of AIS is not in the map...
192 if(!myStoredTypes.IsBound(IO->Type()))
193 return myIsExclusionFlagOn ;
194 // type of AIS is not in the map and there is no signature indicated
195 if(myStoredTypes(IO->Type()).IsEmpty())
196 return !myIsExclusionFlagOn ;
197 // one or several signatures are indicated...
198 if(IsSignatureIn(IO->Type(),IO->Signature()))
199 return !myIsExclusionFlagOn;
201 return myIsExclusionFlagOn;