7fd59977 |
1 | // File: AIS_ExclusionFilter.cxx |
2 | // Created: Fri Nov 28 14:20:52 1997 |
3 | // Author: Robert COUBLANC |
4 | // <rob@robox.paris1.matra-dtv.fr> |
5 | |
6 | |
7 | #include <AIS_ExclusionFilter.ixx> |
8 | #include <TColStd_ListOfInteger.hxx> |
9 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
10 | #include <TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger.hxx> |
11 | #include <AIS_InteractiveObject.hxx> |
12 | |
13 | //======================================================================= |
14 | //function : AIS_ExclusionFilter |
15 | //purpose : Constructors |
16 | //======================================================================= |
17 | |
18 | AIS_ExclusionFilter::AIS_ExclusionFilter(const Standard_Boolean ExclusionFlagOn): |
19 | myIsExclusionFlagOn(ExclusionFlagOn) |
20 | { |
21 | } |
22 | |
23 | AIS_ExclusionFilter::AIS_ExclusionFilter(const AIS_KindOfInteractive TypeToExclude, |
24 | const Standard_Boolean ExclusionFlagOn): |
25 | myIsExclusionFlagOn(ExclusionFlagOn) |
26 | { |
27 | TColStd_ListOfInteger L; |
28 | myStoredTypes.Bind((Standard_Integer)TypeToExclude,L); |
29 | } |
30 | |
31 | AIS_ExclusionFilter::AIS_ExclusionFilter(const AIS_KindOfInteractive TypeToExclude, |
32 | const Standard_Integer SignatureInType, |
33 | const Standard_Boolean ExclusionFlagOn): |
34 | myIsExclusionFlagOn(ExclusionFlagOn) |
35 | { |
36 | TColStd_ListOfInteger L; |
37 | L.Append(SignatureInType); |
38 | myStoredTypes.Bind((Standard_Integer)TypeToExclude,L); |
39 | } |
40 | |
41 | //======================================================================= |
42 | //function : Add |
43 | //purpose : |
44 | //======================================================================= |
45 | Standard_Boolean AIS_ExclusionFilter::Add(const AIS_KindOfInteractive TypeToExclude) |
46 | { |
47 | if(IsStored(TypeToExclude)) |
48 | return Standard_False; |
49 | TColStd_ListOfInteger L; |
50 | myStoredTypes.Bind((Standard_Integer)TypeToExclude,L); |
51 | return Standard_True; |
52 | } |
53 | |
54 | Standard_Boolean AIS_ExclusionFilter::Add(const AIS_KindOfInteractive TypeToExclude, |
55 | const Standard_Integer SignatureInType) |
56 | { |
57 | if(!IsStored(TypeToExclude)){ |
58 | TColStd_ListOfInteger L; |
59 | L.Append(SignatureInType); |
60 | myStoredTypes.Bind((Standard_Integer)TypeToExclude,L); |
61 | return Standard_True; |
62 | } |
63 | |
64 | myStoredTypes((Standard_Integer)TypeToExclude).Append(SignatureInType); |
65 | return Standard_True; |
66 | } |
67 | |
68 | //======================================================================= |
69 | //function : Remove |
70 | //purpose : |
71 | //======================================================================= |
72 | |
73 | Standard_Boolean AIS_ExclusionFilter::Remove(const AIS_KindOfInteractive TypeToExclude) |
74 | { |
75 | if(!IsStored(TypeToExclude)) return Standard_False; |
76 | myStoredTypes((Standard_Integer)TypeToExclude).Clear(); |
77 | myStoredTypes.UnBind((Standard_Integer)TypeToExclude); |
78 | return Standard_True; |
79 | } |
80 | |
81 | Standard_Boolean AIS_ExclusionFilter::Remove(const AIS_KindOfInteractive TypeToExclude, |
82 | const Standard_Integer SignatureInType) |
83 | { |
84 | if(!IsStored(TypeToExclude)) return Standard_False; |
85 | TColStd_ListOfInteger& LL = myStoredTypes.ChangeFind((Standard_Integer)TypeToExclude); |
86 | for(TColStd_ListIteratorOfListOfInteger it(LL);it.More();it.Next()){ |
87 | if(it.Value()==SignatureInType){ |
88 | LL.Remove(it); |
89 | return Standard_True; |
90 | } |
91 | } |
92 | return Standard_False; |
93 | } |
94 | |
95 | |
96 | //======================================================================= |
97 | //function : Clear |
98 | //purpose : |
99 | //======================================================================= |
100 | |
101 | void AIS_ExclusionFilter::Clear() |
102 | { |
103 | TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger Mit(myStoredTypes); |
104 | for(;Mit.More();Mit.Next()) |
105 | myStoredTypes.ChangeFind(Mit.Key()).Clear(); |
106 | myStoredTypes.Clear(); |
107 | } |
108 | |
109 | //======================================================================= |
110 | //function : IsStored |
111 | //purpose : |
112 | //======================================================================= |
113 | |
114 | Standard_Boolean AIS_ExclusionFilter::IsStored(const AIS_KindOfInteractive aType) const |
115 | { |
116 | return myStoredTypes.IsBound(Standard_Integer(aType)); |
117 | } |
118 | |
119 | //======================================================================= |
120 | //function : IsSignatureIn |
121 | //purpose : |
122 | //======================================================================= |
123 | Standard_Boolean AIS_ExclusionFilter::IsSignatureIn(const AIS_KindOfInteractive aType, |
124 | const Standard_Integer SignatureInType) const |
125 | { |
126 | if(!myStoredTypes.IsBound(aType)) return Standard_False; |
127 | for(TColStd_ListIteratorOfListOfInteger Lit(myStoredTypes((Standard_Integer)aType)); |
128 | Lit.More(); |
129 | Lit.Next()){ |
130 | if(Lit.Value()==SignatureInType) |
131 | return Standard_True; |
132 | } |
133 | return Standard_False; |
134 | } |
135 | |
136 | //======================================================================= |
137 | //function : ListOfStoredTypes |
138 | //purpose : |
139 | //======================================================================= |
140 | |
141 | void AIS_ExclusionFilter::ListOfStoredTypes(TColStd_ListOfInteger& TheList) const |
142 | { |
143 | TheList.Clear(); |
144 | TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger MIT(myStoredTypes); |
145 | for(;MIT.More();MIT.Next()) |
146 | TheList.Append(MIT.Key()); |
147 | } |
148 | |
149 | //======================================================================= |
150 | //function : ListOfSignature |
151 | //purpose : |
152 | //======================================================================= |
153 | |
154 | void AIS_ExclusionFilter::ListOfSignature(const AIS_KindOfInteractive aType,TColStd_ListOfInteger& TheStoredList) const |
155 | { |
156 | TheStoredList.Clear(); |
157 | if(IsStored(aType)) |
158 | for(TColStd_ListIteratorOfListOfInteger it(myStoredTypes(aType));it.More();it.Next()) |
159 | TheStoredList.Append(it.Value()); |
160 | } |
161 | |
162 | //======================================================================= |
163 | //function : IsOk |
164 | //purpose : |
165 | //======================================================================= |
166 | |
167 | Standard_Boolean AIS_ExclusionFilter::IsOk(const Handle(SelectMgr_EntityOwner)& EO) const |
168 | { |
169 | if(myStoredTypes.IsEmpty()) |
170 | return myIsExclusionFlagOn; |
171 | |
172 | if(EO.IsNull()) |
173 | return Standard_False; |
174 | Handle(AIS_InteractiveObject) IO = Handle(AIS_InteractiveObject)::DownCast(EO->Selectable()); |
175 | if(IO.IsNull()) |
176 | return Standard_False; |
177 | |
178 | // le type de l'ais n'est pas dans la map... |
179 | if(!myStoredTypes.IsBound(IO->Type())) |
180 | return myIsExclusionFlagOn ; |
181 | // le type de l'ais est dans la map et il n'y a pas de signature precisee |
182 | if(myStoredTypes(IO->Type()).IsEmpty()) |
183 | return !myIsExclusionFlagOn ; |
184 | // il y a une ou des signatures precisees... |
185 | if(IsSignatureIn(IO->Type(),IO->Signature())) |
186 | return !myIsExclusionFlagOn; |
187 | |
188 | return myIsExclusionFlagOn; |
189 | } |
190 | |
191 | |
192 | |
193 | |
194 | |
195 | |
196 | |