1 // Created on: 1997-11-28
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <AIS_ExclusionFilter.ixx>
24 #include <TColStd_ListOfInteger.hxx>
25 #include <TColStd_ListIteratorOfListOfInteger.hxx>
26 #include <TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger.hxx>
27 #include <AIS_InteractiveObject.hxx>
29 //=======================================================================
30 //function : AIS_ExclusionFilter
31 //purpose : Constructors
32 //=======================================================================
34 AIS_ExclusionFilter::AIS_ExclusionFilter(const Standard_Boolean ExclusionFlagOn):
35 myIsExclusionFlagOn(ExclusionFlagOn)
39 AIS_ExclusionFilter::AIS_ExclusionFilter(const AIS_KindOfInteractive TypeToExclude,
40 const Standard_Boolean ExclusionFlagOn):
41 myIsExclusionFlagOn(ExclusionFlagOn)
43 TColStd_ListOfInteger L;
44 myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
47 AIS_ExclusionFilter::AIS_ExclusionFilter(const AIS_KindOfInteractive TypeToExclude,
48 const Standard_Integer SignatureInType,
49 const Standard_Boolean ExclusionFlagOn):
50 myIsExclusionFlagOn(ExclusionFlagOn)
52 TColStd_ListOfInteger L;
53 L.Append(SignatureInType);
54 myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
57 //=======================================================================
60 //=======================================================================
61 Standard_Boolean AIS_ExclusionFilter::Add(const AIS_KindOfInteractive TypeToExclude)
63 if(IsStored(TypeToExclude))
64 return Standard_False;
65 TColStd_ListOfInteger L;
66 myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
70 Standard_Boolean AIS_ExclusionFilter::Add(const AIS_KindOfInteractive TypeToExclude,
71 const Standard_Integer SignatureInType)
73 if(!IsStored(TypeToExclude)){
74 TColStd_ListOfInteger L;
75 L.Append(SignatureInType);
76 myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
80 myStoredTypes((Standard_Integer)TypeToExclude).Append(SignatureInType);
84 //=======================================================================
87 //=======================================================================
89 Standard_Boolean AIS_ExclusionFilter::Remove(const AIS_KindOfInteractive TypeToExclude)
91 if(!IsStored(TypeToExclude)) return Standard_False;
92 myStoredTypes((Standard_Integer)TypeToExclude).Clear();
93 myStoredTypes.UnBind((Standard_Integer)TypeToExclude);
97 Standard_Boolean AIS_ExclusionFilter::Remove(const AIS_KindOfInteractive TypeToExclude,
98 const Standard_Integer SignatureInType)
100 if(!IsStored(TypeToExclude)) return Standard_False;
101 TColStd_ListOfInteger& LL = myStoredTypes.ChangeFind((Standard_Integer)TypeToExclude);
102 for(TColStd_ListIteratorOfListOfInteger it(LL);it.More();it.Next()){
103 if(it.Value()==SignatureInType){
105 return Standard_True;
108 return Standard_False;
112 //=======================================================================
115 //=======================================================================
117 void AIS_ExclusionFilter::Clear()
119 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger Mit(myStoredTypes);
120 for(;Mit.More();Mit.Next())
121 myStoredTypes.ChangeFind(Mit.Key()).Clear();
122 myStoredTypes.Clear();
125 //=======================================================================
126 //function : IsStored
128 //=======================================================================
130 Standard_Boolean AIS_ExclusionFilter::IsStored(const AIS_KindOfInteractive aType) const
132 return myStoredTypes.IsBound(Standard_Integer(aType));
135 //=======================================================================
136 //function : IsSignatureIn
138 //=======================================================================
139 Standard_Boolean AIS_ExclusionFilter::IsSignatureIn(const AIS_KindOfInteractive aType,
140 const Standard_Integer SignatureInType) const
142 if(!myStoredTypes.IsBound(aType)) return Standard_False;
143 for(TColStd_ListIteratorOfListOfInteger Lit(myStoredTypes((Standard_Integer)aType));
146 if(Lit.Value()==SignatureInType)
147 return Standard_True;
149 return Standard_False;
152 //=======================================================================
153 //function : ListOfStoredTypes
155 //=======================================================================
157 void AIS_ExclusionFilter::ListOfStoredTypes(TColStd_ListOfInteger& TheList) const
160 TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger MIT(myStoredTypes);
161 for(;MIT.More();MIT.Next())
162 TheList.Append(MIT.Key());
165 //=======================================================================
166 //function : ListOfSignature
168 //=======================================================================
170 void AIS_ExclusionFilter::ListOfSignature(const AIS_KindOfInteractive aType,TColStd_ListOfInteger& TheStoredList) const
172 TheStoredList.Clear();
174 for(TColStd_ListIteratorOfListOfInteger it(myStoredTypes(aType));it.More();it.Next())
175 TheStoredList.Append(it.Value());
178 //=======================================================================
181 //=======================================================================
183 Standard_Boolean AIS_ExclusionFilter::IsOk(const Handle(SelectMgr_EntityOwner)& EO) const
185 if(myStoredTypes.IsEmpty())
186 return myIsExclusionFlagOn;
189 return Standard_False;
190 Handle(AIS_InteractiveObject) IO = Handle(AIS_InteractiveObject)::DownCast(EO->Selectable());
192 return Standard_False;
194 // type of AIS is not in the map...
195 if(!myStoredTypes.IsBound(IO->Type()))
196 return myIsExclusionFlagOn ;
197 // type of AIS is not in the map and there is no signature indicated
198 if(myStoredTypes(IO->Type()).IsEmpty())
199 return !myIsExclusionFlagOn ;
200 // one or several signatures are indicated...
201 if(IsSignatureIn(IO->Type(),IO->Signature()))
202 return !myIsExclusionFlagOn;
204 return myIsExclusionFlagOn;