1 // Created by: DAUTRY Philippe
2 // Copyright (c) 1997-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 // -----------------------
18 //Version Date Purpose
19 // 0.0 Mar 7 1997 Creation
21 #include <Standard_Transient.hxx>
22 #include <Standard_Type.hxx>
23 #include <TDF_Attribute.hxx>
24 #include <TDF_DataMapIteratorOfAttributeDataMap.hxx>
25 #include <TDF_DataMapIteratorOfLabelDataMap.hxx>
26 #include <TDF_Label.hxx>
27 #include <TDF_RelocationTable.hxx>
29 IMPLEMENT_STANDARD_RTTIEXT(TDF_RelocationTable,Standard_Transient)
31 //=======================================================================
32 //function : TDF_RelocationTable
34 //=======================================================================
35 TDF_RelocationTable::TDF_RelocationTable(const Standard_Boolean selfRelocate)
36 : mySelfRelocate(selfRelocate),myAfterRelocate(Standard_False)
40 //=======================================================================
41 //function : SelfRelocate
43 //=======================================================================
45 void TDF_RelocationTable::SelfRelocate(const Standard_Boolean selfRelocate)
46 { mySelfRelocate = selfRelocate; }
49 //=======================================================================
50 //function : SelfRelocate
52 //=======================================================================
54 Standard_Boolean TDF_RelocationTable::SelfRelocate() const
55 { return mySelfRelocate; }
57 //=======================================================================
58 //function : SelfRelocate
60 //=======================================================================
62 void TDF_RelocationTable::AfterRelocate(const Standard_Boolean afterRelocate)
63 { myAfterRelocate = afterRelocate; }
66 //=======================================================================
67 //function : SelfRelocate
69 //=======================================================================
71 Standard_Boolean TDF_RelocationTable::AfterRelocate() const
72 { return myAfterRelocate; }
75 //=======================================================================
76 //function : SetRelocation
77 //purpose : Sets the relocation value of <aSourceLabel>
79 //=======================================================================
81 void TDF_RelocationTable::SetRelocation
82 (const TDF_Label& aSourceLabel,
83 const TDF_Label& aTargetLabel)
85 if (!myLabelTable.IsBound(aSourceLabel))
86 myLabelTable.Bind(aSourceLabel,aTargetLabel);
90 //=======================================================================
91 //function : HasRelocation
92 //purpose : Finds the relocation value of <aSourceLabel>
93 // and returns it into <aTargetLabel>.
94 //=======================================================================
96 Standard_Boolean TDF_RelocationTable::HasRelocation
97 (const TDF_Label& aSourceLabel,
98 TDF_Label& aTargetLabel) const
100 aTargetLabel.Nullify();
101 if (myLabelTable.IsBound(aSourceLabel)) {
102 aTargetLabel = myLabelTable.Find(aSourceLabel);
103 return Standard_True;
105 if (mySelfRelocate) {
106 aTargetLabel = aSourceLabel;
107 return !myAfterRelocate;
109 return Standard_False;
113 //=======================================================================
114 //function : SetRelocation
115 //purpose : Sets the relocation value of <aSourceAttribute>
116 // to <aTargetAttribute>.
117 //=======================================================================
119 void TDF_RelocationTable::SetRelocation
120 (const Handle(TDF_Attribute)& aSourceAttribute,
121 const Handle(TDF_Attribute)& aTargetAttribute)
123 if (!myAttributeTable.IsBound(aSourceAttribute))
124 myAttributeTable.Bind(aSourceAttribute,aTargetAttribute);
128 //=======================================================================
129 //function : HasRelocation
130 //purpose : Finds the relocation value of <aSourceAttribute>
131 // and returns it into <aTargetAttribute>.
132 //=======================================================================
134 Standard_Boolean TDF_RelocationTable::HasRelocation
135 (const Handle(TDF_Attribute)& aSourceAttribute,
136 Handle(TDF_Attribute)& aTargetAttribute) const
138 aTargetAttribute.Nullify();
139 if (myAttributeTable.IsBound(aSourceAttribute)) {
140 aTargetAttribute = myAttributeTable.Find(aSourceAttribute);
141 return Standard_True;
143 if (mySelfRelocate) {
144 aTargetAttribute = aSourceAttribute;
145 return !myAfterRelocate;
147 return Standard_False;
151 //=======================================================================
152 //function : SetTransientRelocation
153 //purpose : Sets the relocation value of <aSourceTransient>
154 // to <aTargetTransient>.
155 //=======================================================================
157 void TDF_RelocationTable::SetTransientRelocation
158 (const Handle(Standard_Transient)& aSourceTransient,
159 const Handle(Standard_Transient)& aTargetTransient)
161 if (!myTransientTable.Contains(aSourceTransient))
162 myTransientTable.Add(aSourceTransient,aTargetTransient);
166 //=======================================================================
167 //function : HasTransientRelocation
168 //purpose : Finds the relocation value of <aSourceTransient>
169 // and returns it into <aTargetTransient>.
170 //=======================================================================
172 Standard_Boolean TDF_RelocationTable::HasTransientRelocation
173 (const Handle(Standard_Transient)& aSourceTransient,
174 Handle(Standard_Transient)& aTargetTransient) const
176 aTargetTransient.Nullify();
177 if (myTransientTable.Contains(aSourceTransient)) {
178 aTargetTransient = myTransientTable.FindFromKey(aSourceTransient);
179 return Standard_True;
181 if (mySelfRelocate) {
182 aTargetTransient = aSourceTransient;
183 return !myAfterRelocate;
185 return Standard_False;
189 //=======================================================================
191 //purpose : Clears the relocation dictonnary.
192 //=======================================================================
194 void TDF_RelocationTable::Clear()
196 myLabelTable.Clear();
197 myAttributeTable.Clear();
198 myTransientTable.Clear();
202 //=======================================================================
203 //function : TargetLabelMap
205 //=======================================================================
207 void TDF_RelocationTable::TargetLabelMap(TDF_LabelMap& aLabelMap) const
209 for (TDF_DataMapIteratorOfLabelDataMap itr(myLabelTable);
210 itr.More(); itr.Next())
211 aLabelMap.Add(itr.Value());
215 //=======================================================================
216 //function : TargetAttributeMap
218 //=======================================================================
220 void TDF_RelocationTable::TargetAttributeMap(TDF_AttributeMap& anAttributeMap) const
222 for (TDF_DataMapIteratorOfAttributeDataMap itr(myAttributeTable);
223 itr.More(); itr.Next())
224 anAttributeMap.Add(itr.Value());
228 //=======================================================================
229 //function : LabelTable
231 //=======================================================================
233 TDF_LabelDataMap& TDF_RelocationTable::LabelTable()
234 { return myLabelTable; }
237 //=======================================================================
238 //function : AttributeTable
240 //=======================================================================
242 TDF_AttributeDataMap& TDF_RelocationTable::AttributeTable()
243 { return myAttributeTable; }
246 //=======================================================================
247 //function : TransientTable
249 //=======================================================================
251 TColStd_IndexedDataMapOfTransientTransient& TDF_RelocationTable::TransientTable()
252 { return myTransientTable; }
255 //=======================================================================
258 //=======================================================================
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
266 anOS<<"Relocation Table ";
267 if (mySelfRelocate) anOS<<"IS"; else anOS<<"NOT";
268 anOS<<" self relocate ";
269 if (myAfterRelocate) anOS<<"WITH"; else anOS<<"WITHOUT";
270 anOS<<" after relocate"<<endl;
271 anOS<<"Nb labels="<<myLabelTable.Extent();
272 anOS<<" Nb attributes="<<myAttributeTable.Extent();
273 anOS<<" Nb transients="<<myTransientTable.Extent()<<endl;
275 Standard_Integer nb = 0;
277 anOS<<"Label Table:"<<endl;
278 for (TDF_DataMapIteratorOfLabelDataMap itr(myLabelTable);
279 itr.More(); itr.Next()) {
282 itr.Key().EntryDump(anOS);
284 itr.Value().EntryDump(anOS);
291 if (dumpAttributes) {
292 anOS<<"Attribute Table:"<<endl;
293 for (TDF_DataMapIteratorOfAttributeDataMap itr(myAttributeTable);
294 itr.More(); itr.Next()) {
297 itr.Key()->Dump(anOS);
299 itr.Value()->Dump(anOS);
305 if (dumpTransients) {
306 anOS<<"Transient Table:"<<myTransientTable.Extent()<<" transient(s) in table."<<endl;