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_ListIteratorOfListOfInteger.hxx>
24 #include <TColStd_ListOfInteger.hxx>
26 IMPLEMENT_STANDARD_RTTIEXT(AIS_ExclusionFilter,SelectMgr_Filter)
28 //=======================================================================
29 //function : AIS_ExclusionFilter
30 //purpose : Constructors
31 //=======================================================================
32 AIS_ExclusionFilter::AIS_ExclusionFilter(const Standard_Boolean ExclusionFlagOn):
33 myIsExclusionFlagOn(ExclusionFlagOn)
37 AIS_ExclusionFilter::AIS_ExclusionFilter(const AIS_KindOfInteractive TypeToExclude,
38 const Standard_Boolean ExclusionFlagOn):
39 myIsExclusionFlagOn(ExclusionFlagOn)
41 TColStd_ListOfInteger L;
42 myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
45 AIS_ExclusionFilter::AIS_ExclusionFilter(const AIS_KindOfInteractive TypeToExclude,
46 const Standard_Integer SignatureInType,
47 const Standard_Boolean ExclusionFlagOn):
48 myIsExclusionFlagOn(ExclusionFlagOn)
50 TColStd_ListOfInteger L;
51 L.Append(SignatureInType);
52 myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
55 //=======================================================================
58 //=======================================================================
59 Standard_Boolean AIS_ExclusionFilter::Add(const AIS_KindOfInteractive TypeToExclude)
61 if(IsStored(TypeToExclude))
62 return Standard_False;
63 TColStd_ListOfInteger L;
64 myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
68 Standard_Boolean AIS_ExclusionFilter::Add(const AIS_KindOfInteractive TypeToExclude,
69 const Standard_Integer SignatureInType)
71 if(!IsStored(TypeToExclude)){
72 TColStd_ListOfInteger L;
73 L.Append(SignatureInType);
74 myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
78 myStoredTypes((Standard_Integer)TypeToExclude).Append(SignatureInType);
82 //=======================================================================
85 //=======================================================================
87 Standard_Boolean AIS_ExclusionFilter::Remove(const AIS_KindOfInteractive TypeToExclude)
89 if(!IsStored(TypeToExclude)) return Standard_False;
90 myStoredTypes((Standard_Integer)TypeToExclude).Clear();
91 myStoredTypes.UnBind((Standard_Integer)TypeToExclude);
95 Standard_Boolean AIS_ExclusionFilter::Remove(const AIS_KindOfInteractive TypeToExclude,
96 const Standard_Integer SignatureInType)
98 if(!IsStored(TypeToExclude)) return Standard_False;
99 TColStd_ListOfInteger& LL = myStoredTypes.ChangeFind((Standard_Integer)TypeToExclude);
100 for(TColStd_ListIteratorOfListOfInteger it(LL);it.More();it.Next()){
101 if(it.Value()==SignatureInType){
103 return Standard_True;
106 return Standard_False;
110 //=======================================================================
113 //=======================================================================
115 void AIS_ExclusionFilter::Clear()
117 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger Mit(myStoredTypes);
118 for(;Mit.More();Mit.Next())
119 myStoredTypes.ChangeFind(Mit.Key()).Clear();
120 myStoredTypes.Clear();
123 //=======================================================================
124 //function : IsStored
126 //=======================================================================
128 Standard_Boolean AIS_ExclusionFilter::IsStored(const AIS_KindOfInteractive aType) const
130 return myStoredTypes.IsBound(Standard_Integer(aType));
133 //=======================================================================
134 //function : IsSignatureIn
136 //=======================================================================
137 Standard_Boolean AIS_ExclusionFilter::IsSignatureIn(const AIS_KindOfInteractive aType,
138 const Standard_Integer SignatureInType) const
140 if(!myStoredTypes.IsBound(aType)) return Standard_False;
141 for(TColStd_ListIteratorOfListOfInteger Lit(myStoredTypes((Standard_Integer)aType));
144 if(Lit.Value()==SignatureInType)
145 return Standard_True;
147 return Standard_False;
150 //=======================================================================
151 //function : ListOfStoredTypes
153 //=======================================================================
155 void AIS_ExclusionFilter::ListOfStoredTypes(TColStd_ListOfInteger& TheList) const
158 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger MIT(myStoredTypes);
159 for(;MIT.More();MIT.Next())
160 TheList.Append(MIT.Key());
163 //=======================================================================
164 //function : ListOfSignature
166 //=======================================================================
168 void AIS_ExclusionFilter::ListOfSignature(const AIS_KindOfInteractive aType,TColStd_ListOfInteger& TheStoredList) const
170 TheStoredList.Clear();
172 for(TColStd_ListIteratorOfListOfInteger it(myStoredTypes(aType));it.More();it.Next())
173 TheStoredList.Append(it.Value());
176 //=======================================================================
179 //=======================================================================
181 Standard_Boolean AIS_ExclusionFilter::IsOk(const Handle(SelectMgr_EntityOwner)& EO) const
183 if(myStoredTypes.IsEmpty())
184 return myIsExclusionFlagOn;
187 return Standard_False;
188 Handle(AIS_InteractiveObject) IO = Handle(AIS_InteractiveObject)::DownCast(EO->Selectable());
190 return Standard_False;
192 // type of AIS is not in the map...
193 if(!myStoredTypes.IsBound(IO->Type()))
194 return myIsExclusionFlagOn ;
195 // type of AIS is not in the map and there is no signature indicated
196 if(myStoredTypes(IO->Type()).IsEmpty())
197 return !myIsExclusionFlagOn ;
198 // one or several signatures are indicated...
199 if(IsSignatureIn(IO->Type(),IO->Signature()))
200 return !myIsExclusionFlagOn;
202 return myIsExclusionFlagOn;