0027957: Visualization, AIS_InteractiveContext - protect from displaying the same...
[occt.git] / src / AIS / AIS_ExclusionFilter.cxx
CommitLineData
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
92efcf78 26IMPLEMENT_STANDARD_RTTIEXT(AIS_ExclusionFilter,SelectMgr_Filter)
27
7fd59977 28//=======================================================================
29//function : AIS_ExclusionFilter
30//purpose : Constructors
31//=======================================================================
7fd59977 32AIS_ExclusionFilter::AIS_ExclusionFilter(const Standard_Boolean ExclusionFlagOn):
33myIsExclusionFlagOn(ExclusionFlagOn)
34{
35}
36
37AIS_ExclusionFilter::AIS_ExclusionFilter(const AIS_KindOfInteractive TypeToExclude,
38 const Standard_Boolean ExclusionFlagOn):
39myIsExclusionFlagOn(ExclusionFlagOn)
40{
41 TColStd_ListOfInteger L;
42 myStoredTypes.Bind((Standard_Integer)TypeToExclude,L);
43}
44
45AIS_ExclusionFilter::AIS_ExclusionFilter(const AIS_KindOfInteractive TypeToExclude,
46 const Standard_Integer SignatureInType,
47 const Standard_Boolean ExclusionFlagOn):
48myIsExclusionFlagOn(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//=======================================================================
59Standard_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
68Standard_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
87Standard_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
95Standard_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
115void 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
128Standard_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//=======================================================================
137Standard_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
155void 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
168void 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
181Standard_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
81bba717 192 // type of AIS is not in the map...
7fd59977 193 if(!myStoredTypes.IsBound(IO->Type()))
194 return myIsExclusionFlagOn ;
81bba717 195 // type of AIS is not in the map and there is no signature indicated
7fd59977 196 if(myStoredTypes(IO->Type()).IsEmpty())
197 return !myIsExclusionFlagOn ;
81bba717 198 // one or several signatures are indicated...
7fd59977 199 if(IsSignatureIn(IO->Type(),IO->Signature()))
200 return !myIsExclusionFlagOn;
201
202 return myIsExclusionFlagOn;
203}
204
205
206
207
208
209
210