b311480e |
1 | // Created on: 1997-11-28 |
2 | // Created by: Robert COUBLANC |
3 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
42cf5bc1 |
17 | |
18 | #include <AIS_ExclusionFilter.hxx> |
7fd59977 |
19 | #include <AIS_InteractiveObject.hxx> |
42cf5bc1 |
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> |
7fd59977 |
25 | |
26 | //======================================================================= |
27 | //function : AIS_ExclusionFilter |
28 | //purpose : Constructors |
29 | //======================================================================= |
7fd59977 |
30 | AIS_ExclusionFilter::AIS_ExclusionFilter(const Standard_Boolean ExclusionFlagOn): |
31 | myIsExclusionFlagOn(ExclusionFlagOn) |
32 | { |
33 | } |
34 | |
35 | AIS_ExclusionFilter::AIS_ExclusionFilter(const AIS_KindOfInteractive TypeToExclude, |
36 | const Standard_Boolean ExclusionFlagOn): |
37 | myIsExclusionFlagOn(ExclusionFlagOn) |
38 | { |
39 | TColStd_ListOfInteger L; |
40 | myStoredTypes.Bind((Standard_Integer)TypeToExclude,L); |
41 | } |
42 | |
43 | AIS_ExclusionFilter::AIS_ExclusionFilter(const AIS_KindOfInteractive TypeToExclude, |
44 | const Standard_Integer SignatureInType, |
45 | const Standard_Boolean ExclusionFlagOn): |
46 | myIsExclusionFlagOn(ExclusionFlagOn) |
47 | { |
48 | TColStd_ListOfInteger L; |
49 | L.Append(SignatureInType); |
50 | myStoredTypes.Bind((Standard_Integer)TypeToExclude,L); |
51 | } |
52 | |
53 | //======================================================================= |
54 | //function : Add |
55 | //purpose : |
56 | //======================================================================= |
57 | Standard_Boolean AIS_ExclusionFilter::Add(const AIS_KindOfInteractive TypeToExclude) |
58 | { |
59 | if(IsStored(TypeToExclude)) |
60 | return Standard_False; |
61 | TColStd_ListOfInteger L; |
62 | myStoredTypes.Bind((Standard_Integer)TypeToExclude,L); |
63 | return Standard_True; |
64 | } |
65 | |
66 | Standard_Boolean AIS_ExclusionFilter::Add(const AIS_KindOfInteractive TypeToExclude, |
67 | const Standard_Integer SignatureInType) |
68 | { |
69 | if(!IsStored(TypeToExclude)){ |
70 | TColStd_ListOfInteger L; |
71 | L.Append(SignatureInType); |
72 | myStoredTypes.Bind((Standard_Integer)TypeToExclude,L); |
73 | return Standard_True; |
74 | } |
75 | |
76 | myStoredTypes((Standard_Integer)TypeToExclude).Append(SignatureInType); |
77 | return Standard_True; |
78 | } |
79 | |
80 | //======================================================================= |
81 | //function : Remove |
82 | //purpose : |
83 | //======================================================================= |
84 | |
85 | Standard_Boolean AIS_ExclusionFilter::Remove(const AIS_KindOfInteractive TypeToExclude) |
86 | { |
87 | if(!IsStored(TypeToExclude)) return Standard_False; |
88 | myStoredTypes((Standard_Integer)TypeToExclude).Clear(); |
89 | myStoredTypes.UnBind((Standard_Integer)TypeToExclude); |
90 | return Standard_True; |
91 | } |
92 | |
93 | Standard_Boolean AIS_ExclusionFilter::Remove(const AIS_KindOfInteractive TypeToExclude, |
94 | const Standard_Integer SignatureInType) |
95 | { |
96 | if(!IsStored(TypeToExclude)) return Standard_False; |
97 | TColStd_ListOfInteger& LL = myStoredTypes.ChangeFind((Standard_Integer)TypeToExclude); |
98 | for(TColStd_ListIteratorOfListOfInteger it(LL);it.More();it.Next()){ |
99 | if(it.Value()==SignatureInType){ |
100 | LL.Remove(it); |
101 | return Standard_True; |
102 | } |
103 | } |
104 | return Standard_False; |
105 | } |
106 | |
107 | |
108 | //======================================================================= |
109 | //function : Clear |
110 | //purpose : |
111 | //======================================================================= |
112 | |
113 | void AIS_ExclusionFilter::Clear() |
114 | { |
115 | TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger Mit(myStoredTypes); |
116 | for(;Mit.More();Mit.Next()) |
117 | myStoredTypes.ChangeFind(Mit.Key()).Clear(); |
118 | myStoredTypes.Clear(); |
119 | } |
120 | |
121 | //======================================================================= |
122 | //function : IsStored |
123 | //purpose : |
124 | //======================================================================= |
125 | |
126 | Standard_Boolean AIS_ExclusionFilter::IsStored(const AIS_KindOfInteractive aType) const |
127 | { |
128 | return myStoredTypes.IsBound(Standard_Integer(aType)); |
129 | } |
130 | |
131 | //======================================================================= |
132 | //function : IsSignatureIn |
133 | //purpose : |
134 | //======================================================================= |
135 | Standard_Boolean AIS_ExclusionFilter::IsSignatureIn(const AIS_KindOfInteractive aType, |
136 | const Standard_Integer SignatureInType) const |
137 | { |
138 | if(!myStoredTypes.IsBound(aType)) return Standard_False; |
139 | for(TColStd_ListIteratorOfListOfInteger Lit(myStoredTypes((Standard_Integer)aType)); |
140 | Lit.More(); |
141 | Lit.Next()){ |
142 | if(Lit.Value()==SignatureInType) |
143 | return Standard_True; |
144 | } |
145 | return Standard_False; |
146 | } |
147 | |
148 | //======================================================================= |
149 | //function : ListOfStoredTypes |
150 | //purpose : |
151 | //======================================================================= |
152 | |
153 | void AIS_ExclusionFilter::ListOfStoredTypes(TColStd_ListOfInteger& TheList) const |
154 | { |
155 | TheList.Clear(); |
156 | TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger MIT(myStoredTypes); |
157 | for(;MIT.More();MIT.Next()) |
158 | TheList.Append(MIT.Key()); |
159 | } |
160 | |
161 | //======================================================================= |
162 | //function : ListOfSignature |
163 | //purpose : |
164 | //======================================================================= |
165 | |
166 | void AIS_ExclusionFilter::ListOfSignature(const AIS_KindOfInteractive aType,TColStd_ListOfInteger& TheStoredList) const |
167 | { |
168 | TheStoredList.Clear(); |
169 | if(IsStored(aType)) |
170 | for(TColStd_ListIteratorOfListOfInteger it(myStoredTypes(aType));it.More();it.Next()) |
171 | TheStoredList.Append(it.Value()); |
172 | } |
173 | |
174 | //======================================================================= |
175 | //function : IsOk |
176 | //purpose : |
177 | //======================================================================= |
178 | |
179 | Standard_Boolean AIS_ExclusionFilter::IsOk(const Handle(SelectMgr_EntityOwner)& EO) const |
180 | { |
181 | if(myStoredTypes.IsEmpty()) |
182 | return myIsExclusionFlagOn; |
183 | |
184 | if(EO.IsNull()) |
185 | return Standard_False; |
186 | Handle(AIS_InteractiveObject) IO = Handle(AIS_InteractiveObject)::DownCast(EO->Selectable()); |
187 | if(IO.IsNull()) |
188 | return Standard_False; |
189 | |
81bba717 |
190 | // type of AIS is not in the map... |
7fd59977 |
191 | if(!myStoredTypes.IsBound(IO->Type())) |
192 | return myIsExclusionFlagOn ; |
81bba717 |
193 | // type of AIS is not in the map and there is no signature indicated |
7fd59977 |
194 | if(myStoredTypes(IO->Type()).IsEmpty()) |
195 | return !myIsExclusionFlagOn ; |
81bba717 |
196 | // one or several signatures are indicated... |
7fd59977 |
197 | if(IsSignatureIn(IO->Type(),IO->Signature())) |
198 | return !myIsExclusionFlagOn; |
199 | |
200 | return myIsExclusionFlagOn; |
201 | } |
202 | |
203 | |
204 | |
205 | |
206 | |
207 | |
208 | |