b311480e |
1 | // Created by: DAUTRY Philippe |
2 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
3 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
b311480e |
15 | |
7fd59977 |
16 | // --------------------- |
7fd59977 |
17 | // Version: 0.0 |
b311480e |
18 | //Version Date Purpose |
7fd59977 |
19 | // 0.0 May 26 1997 Creation |
20 | |
42cf5bc1 |
21 | #include <Standard_GUID.hxx> |
22 | #include <TDF_Attribute.hxx> |
23 | #include <TDF_IDFilter.hxx> |
7fd59977 |
24 | #include <TDF_IDList.hxx> |
25 | #include <TDF_ListIteratorOfIDList.hxx> |
26 | #include <TDF_MapIteratorOfIDMap.hxx> |
27 | |
28 | // To avoid too much resizing actions, et 23 est un nombre premier. |
29 | #define TDF_IDFilterMapSize 23 |
30 | |
31 | //======================================================================= |
32 | //function : TDF_IDFilter |
33 | //purpose : |
34 | //======================================================================= |
35 | |
36 | TDF_IDFilter::TDF_IDFilter(const Standard_Boolean ignoreMode) : |
37 | myIgnore(ignoreMode) |
38 | {} |
39 | |
7fd59977 |
40 | //======================================================================= |
41 | //function : IgnoreAll |
42 | //purpose : |
43 | //======================================================================= |
44 | |
45 | void TDF_IDFilter::IgnoreAll(const Standard_Boolean ignore) |
46 | { |
47 | myIgnore = ignore; |
48 | myIDMap.Clear(); myIDMap.ReSize(TDF_IDFilterMapSize); |
49 | } |
50 | |
51 | |
52 | //======================================================================= |
53 | //function : Keep |
54 | //purpose : Keeps an ID. |
55 | //======================================================================= |
56 | |
57 | void TDF_IDFilter::Keep(const Standard_GUID& anID) |
58 | { |
59 | if (myIgnore) myIDMap.Add(anID); |
60 | else myIDMap.Remove(anID); |
61 | } |
62 | |
63 | |
64 | //======================================================================= |
65 | //function : Keep |
66 | //purpose : Keeps a list of ID. |
67 | //======================================================================= |
68 | |
69 | void TDF_IDFilter::Keep(const TDF_IDList& anIDList) |
70 | { |
71 | if (!anIDList.IsEmpty()) { |
72 | TDF_ListIteratorOfIDList itr(anIDList); |
73 | if (myIgnore) { |
74 | Standard_Integer n = anIDList.Extent() + myIDMap.NbBuckets() + 1; |
75 | myIDMap.ReSize(n); |
76 | for (; itr.More(); itr.Next()) myIDMap.Add(itr.Value()); |
77 | } |
78 | else { |
79 | for (; itr.More(); itr.Next()) myIDMap.Remove(itr.Value()); |
80 | } |
81 | } |
82 | } |
83 | |
84 | |
85 | //======================================================================= |
86 | //function : Ignore |
87 | //purpose : Ignores an ID. |
88 | //======================================================================= |
89 | |
90 | void TDF_IDFilter::Ignore(const Standard_GUID& anID) |
91 | { |
92 | if (myIgnore) myIDMap.Remove(anID); |
93 | else myIDMap.Add(anID); |
94 | } |
95 | |
96 | |
97 | //======================================================================= |
98 | //function : Ignore |
99 | //purpose : Ignores a list of ID. |
100 | //======================================================================= |
101 | |
102 | void TDF_IDFilter::Ignore(const TDF_IDList& anIDList) |
103 | { |
104 | if (!anIDList.IsEmpty()) { |
105 | TDF_ListIteratorOfIDList itr(anIDList); |
106 | if (myIgnore) { |
107 | for (; itr.More(); itr.Next()) myIDMap.Remove(itr.Value()); |
108 | } |
109 | else { |
110 | Standard_Integer n = anIDList.Extent() + myIDMap.NbBuckets() + 1; |
111 | myIDMap.ReSize(n); |
112 | for (; itr.More(); itr.Next()) myIDMap.Add(itr.Value()); |
113 | } |
114 | } |
115 | } |
116 | |
117 | |
118 | //======================================================================= |
119 | //function : IDList |
120 | //purpose : |
121 | //======================================================================= |
122 | |
123 | void TDF_IDFilter::IDList(TDF_IDList& anIDList) const |
124 | { |
125 | anIDList.Clear(); |
126 | for (TDF_MapIteratorOfIDMap itr(myIDMap); itr.More(); itr.Next()) |
127 | anIDList.Append(itr.Key()); |
128 | } |
129 | |
130 | |
131 | //======================================================================= |
132 | //function : Copy |
133 | //purpose : |
134 | //======================================================================= |
135 | |
136 | void TDF_IDFilter::Copy(const TDF_IDFilter& fromFilter) |
137 | { |
138 | myIgnore = fromFilter.IgnoreAll(); |
139 | TDF_IDList idl; |
140 | fromFilter.IDList(idl); |
141 | if (myIgnore) Keep(idl); |
142 | else Ignore(idl); |
143 | } |
144 | |
145 | |
146 | //======================================================================= |
147 | //function : Dump |
148 | //purpose : |
149 | //======================================================================= |
150 | |
151 | void TDF_IDFilter::Dump(Standard_OStream& anOS) const |
152 | { |
153 | if (myIgnore) anOS<<"EX"; else anOS<<"IN"; anOS<<"CLUSIVE filter: "; |
154 | if (myIgnore) anOS<<"ignores"; else anOS<<"keeps "; anOS<<" all IDs"; |
155 | TDF_MapIteratorOfIDMap itr(myIDMap); |
156 | if (itr.More()) { |
04232180 |
157 | anOS<<" BUT:"<<std::endl; |
7fd59977 |
158 | for (; itr.More(); itr.Next()) { |
159 | const Standard_GUID& guid = itr.Key(); |
160 | guid.ShallowDump(anOS); |
04232180 |
161 | anOS<<std::endl; |
7fd59977 |
162 | } |
163 | } |
164 | } |