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 Mar 7 1997 Creation |
20 | |
42cf5bc1 |
21 | #include <Standard_Transient.hxx> |
22 | #include <Standard_Type.hxx> |
23 | #include <TDF_Attribute.hxx> |
7fd59977 |
24 | #include <TDF_DataMapIteratorOfAttributeDataMap.hxx> |
25 | #include <TDF_DataMapIteratorOfLabelDataMap.hxx> |
42cf5bc1 |
26 | #include <TDF_Label.hxx> |
27 | #include <TDF_RelocationTable.hxx> |
7fd59977 |
28 | |
25e59720 |
29 | IMPLEMENT_STANDARD_RTTIEXT(TDF_RelocationTable,Standard_Transient) |
92efcf78 |
30 | |
7fd59977 |
31 | //======================================================================= |
32 | //function : TDF_RelocationTable |
33 | //purpose : |
34 | //======================================================================= |
7fd59977 |
35 | TDF_RelocationTable::TDF_RelocationTable(const Standard_Boolean selfRelocate) |
36 | : mySelfRelocate(selfRelocate),myAfterRelocate(Standard_False) |
37 | {} |
38 | |
39 | |
40 | //======================================================================= |
41 | //function : SelfRelocate |
42 | //purpose : |
43 | //======================================================================= |
44 | |
45 | void TDF_RelocationTable::SelfRelocate(const Standard_Boolean selfRelocate) |
46 | { mySelfRelocate = selfRelocate; } |
47 | |
48 | |
49 | //======================================================================= |
50 | //function : SelfRelocate |
51 | //purpose : |
52 | //======================================================================= |
53 | |
54 | Standard_Boolean TDF_RelocationTable::SelfRelocate() const |
55 | { return mySelfRelocate; } |
56 | |
57 | //======================================================================= |
58 | //function : SelfRelocate |
59 | //purpose : |
60 | //======================================================================= |
61 | |
62 | void TDF_RelocationTable::AfterRelocate(const Standard_Boolean afterRelocate) |
63 | { myAfterRelocate = afterRelocate; } |
64 | |
65 | |
66 | //======================================================================= |
67 | //function : SelfRelocate |
68 | //purpose : |
69 | //======================================================================= |
70 | |
71 | Standard_Boolean TDF_RelocationTable::AfterRelocate() const |
72 | { return myAfterRelocate; } |
73 | |
74 | |
75 | //======================================================================= |
76 | //function : SetRelocation |
77 | //purpose : Sets the relocation value of <aSourceLabel> |
78 | // to <aTargetLabel>. |
79 | //======================================================================= |
80 | |
81 | void TDF_RelocationTable::SetRelocation |
82 | (const TDF_Label& aSourceLabel, |
83 | const TDF_Label& aTargetLabel) |
84 | { |
85 | if (!myLabelTable.IsBound(aSourceLabel)) |
86 | myLabelTable.Bind(aSourceLabel,aTargetLabel); |
87 | } |
88 | |
89 | |
90 | //======================================================================= |
91 | //function : HasRelocation |
92 | //purpose : Finds the relocation value of <aSourceLabel> |
93 | // and returns it into <aTargetLabel>. |
94 | //======================================================================= |
95 | |
96 | Standard_Boolean TDF_RelocationTable::HasRelocation |
97 | (const TDF_Label& aSourceLabel, |
98 | TDF_Label& aTargetLabel) const |
99 | { |
100 | aTargetLabel.Nullify(); |
101 | if (myLabelTable.IsBound(aSourceLabel)) { |
102 | aTargetLabel = myLabelTable.Find(aSourceLabel); |
103 | return Standard_True; |
104 | } |
105 | if (mySelfRelocate) { |
106 | aTargetLabel = aSourceLabel; |
107 | return !myAfterRelocate; |
108 | } |
109 | return Standard_False; |
110 | } |
111 | |
112 | |
113 | //======================================================================= |
114 | //function : SetRelocation |
115 | //purpose : Sets the relocation value of <aSourceAttribute> |
116 | // to <aTargetAttribute>. |
117 | //======================================================================= |
118 | |
119 | void TDF_RelocationTable::SetRelocation |
120 | (const Handle(TDF_Attribute)& aSourceAttribute, |
121 | const Handle(TDF_Attribute)& aTargetAttribute) |
122 | { |
123 | if (!myAttributeTable.IsBound(aSourceAttribute)) |
124 | myAttributeTable.Bind(aSourceAttribute,aTargetAttribute); |
125 | } |
126 | |
127 | |
128 | //======================================================================= |
129 | //function : HasRelocation |
130 | //purpose : Finds the relocation value of <aSourceAttribute> |
131 | // and returns it into <aTargetAttribute>. |
132 | //======================================================================= |
133 | |
134 | Standard_Boolean TDF_RelocationTable::HasRelocation |
135 | (const Handle(TDF_Attribute)& aSourceAttribute, |
136 | Handle(TDF_Attribute)& aTargetAttribute) const |
137 | { |
138 | aTargetAttribute.Nullify(); |
139 | if (myAttributeTable.IsBound(aSourceAttribute)) { |
140 | aTargetAttribute = myAttributeTable.Find(aSourceAttribute); |
141 | return Standard_True; |
142 | } |
143 | if (mySelfRelocate) { |
144 | aTargetAttribute = aSourceAttribute; |
145 | return !myAfterRelocate; |
146 | } |
147 | return Standard_False; |
148 | } |
149 | |
150 | |
151 | //======================================================================= |
152 | //function : SetTransientRelocation |
153 | //purpose : Sets the relocation value of <aSourceTransient> |
154 | // to <aTargetTransient>. |
155 | //======================================================================= |
156 | |
157 | void TDF_RelocationTable::SetTransientRelocation |
158 | (const Handle(Standard_Transient)& aSourceTransient, |
159 | const Handle(Standard_Transient)& aTargetTransient) |
160 | { |
161 | if (!myTransientTable.Contains(aSourceTransient)) |
162 | myTransientTable.Add(aSourceTransient,aTargetTransient); |
163 | } |
164 | |
165 | |
166 | //======================================================================= |
167 | //function : HasTransientRelocation |
168 | //purpose : Finds the relocation value of <aSourceTransient> |
169 | // and returns it into <aTargetTransient>. |
170 | //======================================================================= |
171 | |
172 | Standard_Boolean TDF_RelocationTable::HasTransientRelocation |
173 | (const Handle(Standard_Transient)& aSourceTransient, |
174 | Handle(Standard_Transient)& aTargetTransient) const |
175 | { |
176 | aTargetTransient.Nullify(); |
177 | if (myTransientTable.Contains(aSourceTransient)) { |
178 | aTargetTransient = myTransientTable.FindFromKey(aSourceTransient); |
179 | return Standard_True; |
180 | } |
181 | if (mySelfRelocate) { |
182 | aTargetTransient = aSourceTransient; |
183 | return !myAfterRelocate; |
184 | } |
185 | return Standard_False; |
186 | } |
187 | |
188 | |
189 | //======================================================================= |
190 | //function : Clear |
191 | //purpose : Clears the relocation dictonnary. |
192 | //======================================================================= |
193 | |
194 | void TDF_RelocationTable::Clear() |
195 | { |
196 | myLabelTable.Clear(); |
197 | myAttributeTable.Clear(); |
198 | myTransientTable.Clear(); |
199 | } |
200 | |
201 | |
202 | //======================================================================= |
203 | //function : TargetLabelMap |
204 | //purpose : |
205 | //======================================================================= |
206 | |
207 | void TDF_RelocationTable::TargetLabelMap(TDF_LabelMap& aLabelMap) const |
208 | { |
209 | for (TDF_DataMapIteratorOfLabelDataMap itr(myLabelTable); |
210 | itr.More(); itr.Next()) |
211 | aLabelMap.Add(itr.Value()); |
212 | } |
213 | |
214 | |
215 | //======================================================================= |
216 | //function : TargetAttributeMap |
217 | //purpose : |
218 | //======================================================================= |
219 | |
220 | void TDF_RelocationTable::TargetAttributeMap(TDF_AttributeMap& anAttributeMap) const |
221 | { |
222 | for (TDF_DataMapIteratorOfAttributeDataMap itr(myAttributeTable); |
223 | itr.More(); itr.Next()) |
224 | anAttributeMap.Add(itr.Value()); |
225 | } |
226 | |
227 | |
228 | //======================================================================= |
229 | //function : LabelTable |
230 | //purpose : |
231 | //======================================================================= |
232 | |
233 | TDF_LabelDataMap& TDF_RelocationTable::LabelTable() |
234 | { return myLabelTable; } |
235 | |
236 | |
237 | //======================================================================= |
238 | //function : AttributeTable |
239 | //purpose : |
240 | //======================================================================= |
241 | |
242 | TDF_AttributeDataMap& TDF_RelocationTable::AttributeTable() |
243 | { return myAttributeTable; } |
244 | |
245 | |
246 | //======================================================================= |
247 | //function : TransientTable |
248 | //purpose : |
249 | //======================================================================= |
250 | |
251 | TColStd_IndexedDataMapOfTransientTransient& TDF_RelocationTable::TransientTable() |
252 | { return myTransientTable; } |
253 | |
254 | |
255 | //======================================================================= |
256 | //function : Dump |
257 | //purpose : |
258 | //======================================================================= |
259 | |
260 | Standard_OStream& TDF_RelocationTable::Dump |
261 | (const Standard_Boolean dumpLabels, |
262 | const Standard_Boolean dumpAttributes, |
263 | const Standard_Boolean dumpTransients, |
264 | Standard_OStream& anOS) const |
265 | { |
266 | anOS<<"Relocation Table "; |
267 | if (mySelfRelocate) anOS<<"IS"; else anOS<<"NOT"; |
268 | anOS<<" self relocate "; |
269 | if (myAfterRelocate) anOS<<"WITH"; else anOS<<"WITHOUT"; |
04232180 |
270 | anOS<<" after relocate"<<std::endl; |
7fd59977 |
271 | anOS<<"Nb labels="<<myLabelTable.Extent(); |
272 | anOS<<" Nb attributes="<<myAttributeTable.Extent(); |
04232180 |
273 | anOS<<" Nb transients="<<myTransientTable.Extent()<<std::endl; |
7fd59977 |
274 | |
275 | Standard_Integer nb = 0; |
276 | if (dumpLabels) { |
04232180 |
277 | anOS<<"Label Table:"<<std::endl; |
7fd59977 |
278 | for (TDF_DataMapIteratorOfLabelDataMap itr(myLabelTable); |
279 | itr.More(); itr.Next()) { |
280 | ++nb; |
281 | anOS<<nb<<" "; |
282 | itr.Key().EntryDump(anOS); |
283 | anOS<<"<=>"; |
284 | itr.Value().EntryDump(anOS); |
285 | anOS<<"| "; |
286 | } |
04232180 |
287 | std::cout<<std::endl; |
7fd59977 |
288 | } |
289 | |
290 | nb = 0; |
291 | if (dumpAttributes) { |
04232180 |
292 | anOS<<"Attribute Table:"<<std::endl; |
7fd59977 |
293 | for (TDF_DataMapIteratorOfAttributeDataMap itr(myAttributeTable); |
294 | itr.More(); itr.Next()) { |
295 | ++nb; |
296 | anOS<<nb<<" "; |
297 | itr.Key()->Dump(anOS); |
298 | anOS<<"<=>"; |
299 | itr.Value()->Dump(anOS); |
300 | anOS<<"| "; |
04232180 |
301 | anOS<<std::endl; |
7fd59977 |
302 | } |
303 | } |
304 | |
305 | if (dumpTransients) { |
04232180 |
306 | anOS<<"Transient Table:"<<myTransientTable.Extent()<<" transient(s) in table."<<std::endl; |
7fd59977 |
307 | } |
308 | |
309 | return anOS; |
310 | } |