0024750: Replace instantiations of TCollection generic classes by NCollection templat...
[occt.git] / src / AIS / AIS_ExclusionFilter.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
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>
22
23 //=======================================================================
24 //function : AIS_ExclusionFilter
25 //purpose  : Constructors
26 //=======================================================================
27
28 AIS_ExclusionFilter::AIS_ExclusionFilter(const Standard_Boolean ExclusionFlagOn):
29 myIsExclusionFlagOn(ExclusionFlagOn)
30 {
31 }
32
33 AIS_ExclusionFilter::AIS_ExclusionFilter(const AIS_KindOfInteractive TypeToExclude,
34                                          const Standard_Boolean ExclusionFlagOn):
35 myIsExclusionFlagOn(ExclusionFlagOn)
36 {
37   TColStd_ListOfInteger L;
38   myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
39 }
40
41 AIS_ExclusionFilter::AIS_ExclusionFilter(const AIS_KindOfInteractive TypeToExclude,
42                                          const Standard_Integer SignatureInType,
43                                          const Standard_Boolean ExclusionFlagOn):
44 myIsExclusionFlagOn(ExclusionFlagOn)
45 {
46   TColStd_ListOfInteger L;
47   L.Append(SignatureInType);
48   myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
49 }
50
51 //=======================================================================
52 //function : Add
53 //purpose  : 
54 //=======================================================================
55 Standard_Boolean AIS_ExclusionFilter::Add(const AIS_KindOfInteractive TypeToExclude) 
56 {
57   if(IsStored(TypeToExclude)) 
58     return Standard_False;
59   TColStd_ListOfInteger L;
60   myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
61   return Standard_True;
62 }
63
64 Standard_Boolean AIS_ExclusionFilter::Add(const AIS_KindOfInteractive TypeToExclude,
65                                           const Standard_Integer SignatureInType) 
66 {
67   if(!IsStored(TypeToExclude)){
68     TColStd_ListOfInteger L;
69     L.Append(SignatureInType);
70     myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
71     return Standard_True;
72   }
73
74   myStoredTypes((Standard_Integer)TypeToExclude).Append(SignatureInType);
75   return Standard_True;
76 }
77
78 //=======================================================================
79 //function : Remove
80 //purpose  : 
81 //=======================================================================
82
83 Standard_Boolean AIS_ExclusionFilter::Remove(const AIS_KindOfInteractive TypeToExclude) 
84 {
85   if(!IsStored(TypeToExclude)) return Standard_False;
86   myStoredTypes((Standard_Integer)TypeToExclude).Clear();
87   myStoredTypes.UnBind((Standard_Integer)TypeToExclude);
88   return Standard_True;
89 }
90
91 Standard_Boolean AIS_ExclusionFilter::Remove(const AIS_KindOfInteractive TypeToExclude,
92                                              const Standard_Integer SignatureInType) 
93 {
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){
98       LL.Remove(it);
99       return Standard_True;
100     }
101   }
102   return Standard_False;
103 }
104
105
106 //=======================================================================
107 //function : Clear
108 //purpose  : 
109 //=======================================================================
110
111 void  AIS_ExclusionFilter::Clear()
112 {
113   TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger Mit(myStoredTypes);
114   for(;Mit.More();Mit.Next())
115     myStoredTypes.ChangeFind(Mit.Key()).Clear();
116   myStoredTypes.Clear();
117 }
118
119 //=======================================================================
120 //function : IsStored
121 //purpose  : 
122 //=======================================================================
123
124 Standard_Boolean AIS_ExclusionFilter::IsStored(const AIS_KindOfInteractive aType) const
125 {
126   return myStoredTypes.IsBound(Standard_Integer(aType));
127 }
128
129 //=======================================================================
130 //function : IsSignatureIn
131 //purpose  : 
132 //=======================================================================
133 Standard_Boolean AIS_ExclusionFilter::IsSignatureIn(const AIS_KindOfInteractive aType,
134                                                     const Standard_Integer SignatureInType) const
135 {
136   if(!myStoredTypes.IsBound(aType)) return Standard_False;
137   for(TColStd_ListIteratorOfListOfInteger Lit(myStoredTypes((Standard_Integer)aType));
138       Lit.More();
139       Lit.Next()){
140     if(Lit.Value()==SignatureInType)
141       return Standard_True;
142   }
143   return Standard_False;
144 }
145
146 //=======================================================================
147 //function : ListOfStoredTypes
148 //purpose  : 
149 //=======================================================================
150
151 void AIS_ExclusionFilter::ListOfStoredTypes(TColStd_ListOfInteger& TheList) const
152 {
153   TheList.Clear();
154   TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger MIT(myStoredTypes);
155   for(;MIT.More();MIT.Next())
156     TheList.Append(MIT.Key());
157 }
158
159 //=======================================================================
160 //function : ListOfSignature
161 //purpose  : 
162 //=======================================================================
163
164 void AIS_ExclusionFilter::ListOfSignature(const AIS_KindOfInteractive aType,TColStd_ListOfInteger& TheStoredList) const
165 {
166   TheStoredList.Clear();
167   if(IsStored(aType))
168     for(TColStd_ListIteratorOfListOfInteger it(myStoredTypes(aType));it.More();it.Next())
169       TheStoredList.Append(it.Value());
170 }
171
172 //=======================================================================
173 //function : IsOk
174 //purpose  : 
175 //=======================================================================
176
177 Standard_Boolean AIS_ExclusionFilter::IsOk(const Handle(SelectMgr_EntityOwner)& EO) const
178 {
179   if(myStoredTypes.IsEmpty())
180     return myIsExclusionFlagOn;
181
182   if(EO.IsNull()) 
183     return Standard_False;
184   Handle(AIS_InteractiveObject) IO = Handle(AIS_InteractiveObject)::DownCast(EO->Selectable());
185   if(IO.IsNull()) 
186     return Standard_False;
187
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;
197   
198   return myIsExclusionFlagOn;
199 }
200
201
202
203
204
205
206