0030674: Visualization, AIS_InteractiveObject - fix accessibility of several properties
[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
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>
25
26 IMPLEMENT_STANDARD_RTTIEXT(AIS_ExclusionFilter,SelectMgr_Filter)
27
28 //=======================================================================
29 //function : AIS_ExclusionFilter
30 //purpose  : Constructors
31 //=======================================================================
32 AIS_ExclusionFilter::AIS_ExclusionFilter(const Standard_Boolean ExclusionFlagOn):
33 myIsExclusionFlagOn(ExclusionFlagOn)
34 {
35 }
36
37 AIS_ExclusionFilter::AIS_ExclusionFilter(const AIS_KindOfInteractive TypeToExclude,
38                                          const Standard_Boolean ExclusionFlagOn):
39 myIsExclusionFlagOn(ExclusionFlagOn)
40 {
41   TColStd_ListOfInteger L;
42   myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
43 }
44
45 AIS_ExclusionFilter::AIS_ExclusionFilter(const AIS_KindOfInteractive TypeToExclude,
46                                          const Standard_Integer SignatureInType,
47                                          const Standard_Boolean ExclusionFlagOn):
48 myIsExclusionFlagOn(ExclusionFlagOn)
49 {
50   TColStd_ListOfInteger L;
51   L.Append(SignatureInType);
52   myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
53 }
54
55 //=======================================================================
56 //function : Add
57 //purpose  : 
58 //=======================================================================
59 Standard_Boolean AIS_ExclusionFilter::Add(const AIS_KindOfInteractive TypeToExclude) 
60 {
61   if(IsStored(TypeToExclude)) 
62     return Standard_False;
63   TColStd_ListOfInteger L;
64   myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
65   return Standard_True;
66 }
67
68 Standard_Boolean AIS_ExclusionFilter::Add(const AIS_KindOfInteractive TypeToExclude,
69                                           const Standard_Integer SignatureInType) 
70 {
71   if(!IsStored(TypeToExclude)){
72     TColStd_ListOfInteger L;
73     L.Append(SignatureInType);
74     myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
75     return Standard_True;
76   }
77
78   myStoredTypes((Standard_Integer)TypeToExclude).Append(SignatureInType);
79   return Standard_True;
80 }
81
82 //=======================================================================
83 //function : Remove
84 //purpose  : 
85 //=======================================================================
86
87 Standard_Boolean AIS_ExclusionFilter::Remove(const AIS_KindOfInteractive TypeToExclude) 
88 {
89   if(!IsStored(TypeToExclude)) return Standard_False;
90   myStoredTypes((Standard_Integer)TypeToExclude).Clear();
91   myStoredTypes.UnBind((Standard_Integer)TypeToExclude);
92   return Standard_True;
93 }
94
95 Standard_Boolean AIS_ExclusionFilter::Remove(const AIS_KindOfInteractive TypeToExclude,
96                                              const Standard_Integer SignatureInType) 
97 {
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){
102       LL.Remove(it);
103       return Standard_True;
104     }
105   }
106   return Standard_False;
107 }
108
109
110 //=======================================================================
111 //function : Clear
112 //purpose  : 
113 //=======================================================================
114
115 void  AIS_ExclusionFilter::Clear()
116 {
117   TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger Mit(myStoredTypes);
118   for(;Mit.More();Mit.Next())
119     myStoredTypes.ChangeFind(Mit.Key()).Clear();
120   myStoredTypes.Clear();
121 }
122
123 //=======================================================================
124 //function : IsStored
125 //purpose  : 
126 //=======================================================================
127
128 Standard_Boolean AIS_ExclusionFilter::IsStored(const AIS_KindOfInteractive aType) const
129 {
130   return myStoredTypes.IsBound(Standard_Integer(aType));
131 }
132
133 //=======================================================================
134 //function : IsSignatureIn
135 //purpose  : 
136 //=======================================================================
137 Standard_Boolean AIS_ExclusionFilter::IsSignatureIn(const AIS_KindOfInteractive aType,
138                                                     const Standard_Integer SignatureInType) const
139 {
140   if(!myStoredTypes.IsBound(aType)) return Standard_False;
141   for(TColStd_ListIteratorOfListOfInteger Lit(myStoredTypes((Standard_Integer)aType));
142       Lit.More();
143       Lit.Next()){
144     if(Lit.Value()==SignatureInType)
145       return Standard_True;
146   }
147   return Standard_False;
148 }
149
150 //=======================================================================
151 //function : ListOfStoredTypes
152 //purpose  : 
153 //=======================================================================
154
155 void AIS_ExclusionFilter::ListOfStoredTypes(TColStd_ListOfInteger& TheList) const
156 {
157   TheList.Clear();
158   TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger MIT(myStoredTypes);
159   for(;MIT.More();MIT.Next())
160     TheList.Append(MIT.Key());
161 }
162
163 //=======================================================================
164 //function : ListOfSignature
165 //purpose  : 
166 //=======================================================================
167
168 void AIS_ExclusionFilter::ListOfSignature(const AIS_KindOfInteractive aType,TColStd_ListOfInteger& TheStoredList) const
169 {
170   TheStoredList.Clear();
171   if(IsStored(aType))
172     for(TColStd_ListIteratorOfListOfInteger it(myStoredTypes(aType));it.More();it.Next())
173       TheStoredList.Append(it.Value());
174 }
175
176 //=======================================================================
177 //function : IsOk
178 //purpose  : 
179 //=======================================================================
180
181 Standard_Boolean AIS_ExclusionFilter::IsOk(const Handle(SelectMgr_EntityOwner)& EO) const
182 {
183   if(myStoredTypes.IsEmpty())
184     return myIsExclusionFlagOn;
185
186   if(EO.IsNull()) 
187     return Standard_False;
188   Handle(AIS_InteractiveObject) IO = Handle(AIS_InteractiveObject)::DownCast(EO->Selectable());
189   if(IO.IsNull()) 
190     return Standard_False;
191
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;
201   
202   return myIsExclusionFlagOn;
203 }
204
205
206
207
208
209
210