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.
17 #include <AIS_ExclusionFilter.ixx>
18 #include <TColStd_ListOfInteger.hxx>
19 #include <TColStd_ListIteratorOfListOfInteger.hxx>
20 #include <TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger.hxx>
21 #include <AIS_InteractiveObject.hxx>
23 //=======================================================================
24 //function : AIS_ExclusionFilter
25 //purpose : Constructors
26 //=======================================================================
28 AIS_ExclusionFilter::AIS_ExclusionFilter(const Standard_Boolean ExclusionFlagOn):
29 myIsExclusionFlagOn(ExclusionFlagOn)
33 AIS_ExclusionFilter::AIS_ExclusionFilter(const AIS_KindOfInteractive TypeToExclude,
34 const Standard_Boolean ExclusionFlagOn):
35 myIsExclusionFlagOn(ExclusionFlagOn)
37 TColStd_ListOfInteger L;
38 myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
41 AIS_ExclusionFilter::AIS_ExclusionFilter(const AIS_KindOfInteractive TypeToExclude,
42 const Standard_Integer SignatureInType,
43 const Standard_Boolean ExclusionFlagOn):
44 myIsExclusionFlagOn(ExclusionFlagOn)
46 TColStd_ListOfInteger L;
47 L.Append(SignatureInType);
48 myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
51 //=======================================================================
54 //=======================================================================
55 Standard_Boolean AIS_ExclusionFilter::Add(const AIS_KindOfInteractive TypeToExclude)
57 if(IsStored(TypeToExclude))
58 return Standard_False;
59 TColStd_ListOfInteger L;
60 myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
64 Standard_Boolean AIS_ExclusionFilter::Add(const AIS_KindOfInteractive TypeToExclude,
65 const Standard_Integer SignatureInType)
67 if(!IsStored(TypeToExclude)){
68 TColStd_ListOfInteger L;
69 L.Append(SignatureInType);
70 myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
74 myStoredTypes((Standard_Integer)TypeToExclude).Append(SignatureInType);
78 //=======================================================================
81 //=======================================================================
83 Standard_Boolean AIS_ExclusionFilter::Remove(const AIS_KindOfInteractive TypeToExclude)
85 if(!IsStored(TypeToExclude)) return Standard_False;
86 myStoredTypes((Standard_Integer)TypeToExclude).Clear();
87 myStoredTypes.UnBind((Standard_Integer)TypeToExclude);
91 Standard_Boolean AIS_ExclusionFilter::Remove(const AIS_KindOfInteractive TypeToExclude,
92 const Standard_Integer SignatureInType)
94 if(!IsStored(TypeToExclude)) return Standard_False;
95 TColStd_ListOfInteger& LL = myStoredTypes.ChangeFind((Standard_Integer)TypeToExclude);
96 for(TColStd_ListIteratorOfListOfInteger it(LL);it.More();it.Next()){
97 if(it.Value()==SignatureInType){
102 return Standard_False;
106 //=======================================================================
109 //=======================================================================
111 void AIS_ExclusionFilter::Clear()
113 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger Mit(myStoredTypes);
114 for(;Mit.More();Mit.Next())
115 myStoredTypes.ChangeFind(Mit.Key()).Clear();
116 myStoredTypes.Clear();
119 //=======================================================================
120 //function : IsStored
122 //=======================================================================
124 Standard_Boolean AIS_ExclusionFilter::IsStored(const AIS_KindOfInteractive aType) const
126 return myStoredTypes.IsBound(Standard_Integer(aType));
129 //=======================================================================
130 //function : IsSignatureIn
132 //=======================================================================
133 Standard_Boolean AIS_ExclusionFilter::IsSignatureIn(const AIS_KindOfInteractive aType,
134 const Standard_Integer SignatureInType) const
136 if(!myStoredTypes.IsBound(aType)) return Standard_False;
137 for(TColStd_ListIteratorOfListOfInteger Lit(myStoredTypes((Standard_Integer)aType));
140 if(Lit.Value()==SignatureInType)
141 return Standard_True;
143 return Standard_False;
146 //=======================================================================
147 //function : ListOfStoredTypes
149 //=======================================================================
151 void AIS_ExclusionFilter::ListOfStoredTypes(TColStd_ListOfInteger& TheList) const
154 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger MIT(myStoredTypes);
155 for(;MIT.More();MIT.Next())
156 TheList.Append(MIT.Key());
159 //=======================================================================
160 //function : ListOfSignature
162 //=======================================================================
164 void AIS_ExclusionFilter::ListOfSignature(const AIS_KindOfInteractive aType,TColStd_ListOfInteger& TheStoredList) const
166 TheStoredList.Clear();
168 for(TColStd_ListIteratorOfListOfInteger it(myStoredTypes(aType));it.More();it.Next())
169 TheStoredList.Append(it.Value());
172 //=======================================================================
175 //=======================================================================
177 Standard_Boolean AIS_ExclusionFilter::IsOk(const Handle(SelectMgr_EntityOwner)& EO) const
179 if(myStoredTypes.IsEmpty())
180 return myIsExclusionFlagOn;
183 return Standard_False;
184 Handle(AIS_InteractiveObject) IO = Handle(AIS_InteractiveObject)::DownCast(EO->Selectable());
186 return Standard_False;
188 // type of AIS is not in the map...
189 if(!myStoredTypes.IsBound(IO->Type()))
190 return myIsExclusionFlagOn ;
191 // type of AIS is not in the map and there is no signature indicated
192 if(myStoredTypes(IO->Type()).IsEmpty())
193 return !myIsExclusionFlagOn ;
194 // one or several signatures are indicated...
195 if(IsSignatureIn(IO->Type(),IO->Signature()))
196 return !myIsExclusionFlagOn;
198 return myIsExclusionFlagOn;