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.
19 //Version Date Purpose
20 // 0.0 Feb 7 1997 Creation
24 #include <TDF_Attribute.ixx>
26 #include <TCollection_AsciiString.hxx>
27 #include <TDF_DefaultDeltaOnModification.hxx>
28 #include <TDF_DefaultDeltaOnRemoval.hxx>
29 #include <TDF_DeltaOnForget.hxx>
30 #include <TDF_DeltaOnResume.hxx>
31 #include <TDF_DataSet.hxx>
32 #include <TDF_Label.hxx>
33 #include <TDF_LabelNode.hxx>
34 #include <TDF_Tool.hxx>
36 #include <Standard_DomainError.hxx>
37 #include <Standard_ImmutableObject.hxx>
39 #undef TDF_DATA_COMMIT_OPTIMIZED
43 //=======================================================================
44 //function : TDF_Attribute
45 //purpose : Initializes fields.
46 //=======================================================================
48 TDF_Attribute::TDF_Attribute() :
51 mySavedTransaction(0),
57 //=======================================================================
60 //=======================================================================
62 const TDF_Label TDF_Attribute::Label() const
63 { return TDF_Label(myLabelNode); }
66 //=======================================================================
69 //=======================================================================
71 Standard_Boolean TDF_Attribute::FindAttribute (const Standard_GUID& anID,
72 Handle(TDF_Attribute)& anAttribute) const
74 return Label().FindAttribute(anID,anAttribute);
77 //=======================================================================
78 //function : IsAttribute
80 //=======================================================================
82 Standard_Boolean TDF_Attribute::IsAttribute (const Standard_GUID& anID) const
84 return Label().IsAttribute(anID);
87 //=======================================================================
88 //function : AddAttribute
90 //=======================================================================
92 void TDF_Attribute::AddAttribute (const Handle(TDF_Attribute)& otherAttribute) const
93 { Label().AddAttribute (otherAttribute); }
97 //=======================================================================
98 //function : ForgetAttribute
100 //=======================================================================
102 Standard_Boolean TDF_Attribute::ForgetAttribute (const Standard_GUID& anID) const
103 { return Label().ForgetAttribute (anID); }
107 //=======================================================================
108 //function : ForgetAllAttributes
110 //=======================================================================
112 void TDF_Attribute::ForgetAllAttributes (const Standard_Boolean clearChildren) const
113 { Label().ForgetAllAttributes (clearChildren); }
118 //=======================================================================
121 //=======================================================================
123 void TDF_Attribute::Forget (const Standard_Integer aTransaction)
125 mySavedTransaction = myTransaction;
126 myTransaction = aTransaction;
127 myFlags = (myFlags | TDF_AttributeForgottenMsk);
128 Validate(Standard_False);
132 //=======================================================================
135 //=======================================================================
137 void TDF_Attribute::Resume()
139 myTransaction = mySavedTransaction;
140 mySavedTransaction = -1; // To say "just resumed"!
141 myFlags = (myFlags & ~TDF_AttributeForgottenMsk);
142 Validate(Standard_True);
146 //=======================================================================
147 //function : UntilTransaction
149 //=======================================================================
151 Standard_Integer TDF_Attribute::UntilTransaction() const
153 if (IsForgotten()) return myTransaction;
154 else if (IsBackuped()) return myNext->myTransaction - 1;
155 else if (IsValid()) return myLabelNode->Data()->Transaction();
156 Standard_DomainError::Raise("The attribute structure is wrong.");
161 //=======================================================================
162 //function : AfterAddition
164 //=======================================================================
166 void TDF_Attribute::AfterAddition()
170 //=======================================================================
171 //function : BeforeRemoval
173 //=======================================================================
175 void TDF_Attribute::BeforeRemoval()
178 //=======================================================================
179 //function : BeforeForget
181 //=======================================================================
183 void TDF_Attribute::BeforeForget()
187 //=======================================================================
188 //function : AfterResume
190 //=======================================================================
192 void TDF_Attribute::AfterResume()
196 //=======================================================================
197 //function : BeforeUndo
198 //purpose : Before application of a TDF_Delta.
199 //=======================================================================
201 Standard_Boolean TDF_Attribute::BeforeUndo
202 (const Handle(TDF_AttributeDelta)& /*anAttDelta*/,
203 const Standard_Boolean /*forceIt*/)
204 { return Standard_True; }
207 //=======================================================================
208 //function : AfterUndo
209 //purpose : After application of a TDF_Delta.
210 //=======================================================================
212 Standard_Boolean TDF_Attribute::AfterUndo
213 (const Handle(TDF_AttributeDelta)& /*anAttDelta*/,
214 const Standard_Boolean /*forceIt*/)
215 { return Standard_True; }
218 //=======================================================================
219 //function : AfterRetrieval
221 //=======================================================================
223 Standard_Boolean TDF_Attribute::AfterRetrieval
224 (const Standard_Boolean /*forceIt*/)
225 { return Standard_True; }
228 //=======================================================================
229 //function : BeforeCommitTransaction
231 //=======================================================================
233 void TDF_Attribute::BeforeCommitTransaction() {}
236 //=======================================================================
238 //purpose : Backups the attribute.
239 //=======================================================================
241 void TDF_Attribute::Backup()
243 // The attribute must be valid and attached to a label.
244 if (IsValid() && (myLabelNode != NULL)) {
245 Handle(TDF_Data) aData = myLabelNode->Data();
247 // check that modification is allowed
248 if ( !aData->IsModificationAllowed() ) {
249 TCollection_AsciiString aMess;
250 aMess = "Attribute \"";
251 aMess += DynamicType()->Name();
252 aMess += "\" is changed outside transaction";
253 Standard_ImmutableObject::Raise(aMess.ToCString());
256 const Standard_Integer currentTransaction =
257 aData->Transaction();
258 if (myTransaction < currentTransaction) {//"!=" is less secure.
259 Handle(TDF_Attribute) backup = BackupCopy();
260 #ifdef TDF_DATA_COMMIT_OPTIMIZED
261 myLabelNode->AttributesModified(Standard_True);
263 backup->myLabelNode = myLabelNode;
264 backup->myNext = this; // Back reference;
265 backup->myBackup = myBackup;
266 backup->myTransaction = myTransaction;
267 backup->Backup(Standard_True);
270 myTransaction = currentTransaction;
276 //=======================================================================
277 //function : BackupCopy
278 //purpose : Standard implementation of BackupCopy.
279 //=======================================================================
281 Handle(TDF_Attribute) TDF_Attribute::BackupCopy() const
283 Handle(TDF_Attribute) copy = NewEmpty(); copy->Restore(this);
288 //=======================================================================
289 //function : RemoveBackup
291 //=======================================================================
293 void TDF_Attribute::RemoveBackup()
296 if (myBackup.IsNull())
297 Standard_DomainError::Raise("Impossible to remove a nonexistent backup.");
299 myBackup->BeforeRemoval();
300 myBackup->myLabelNode = NULL; // Absolutly necessary!
301 myBackup->myNext.Nullify(); // Absolutly necessary!
302 myBackup = myBackup->myBackup;
303 if (!myBackup.IsNull()) myBackup->myNext = this; // New back reference.
306 //=======================================================================
307 //function : References
308 //purpose : Adds the referenced attributes or labels.
309 //=======================================================================
311 void TDF_Attribute::References(const Handle(TDF_DataSet)& /*aDataSet*/) const
315 //=======================================================================
316 //function : DeltaOnAddition
317 //purpose : Creates such a delta.
318 //=======================================================================
320 Handle(TDF_DeltaOnAddition) TDF_Attribute::DeltaOnAddition() const
321 { return new TDF_DeltaOnAddition(this); }
324 //=======================================================================
325 //function : DeltaOnForget
326 //purpose : Creates such a delta.
327 //=======================================================================
329 Handle(TDF_DeltaOnForget) TDF_Attribute::DeltaOnForget() const
330 { return new TDF_DeltaOnForget(this); }
333 //=======================================================================
334 //function : DeltaOnResume
335 //purpose : Creates such a delta.
336 //=======================================================================
338 Handle(TDF_DeltaOnResume) TDF_Attribute::DeltaOnResume() const
339 { return new TDF_DeltaOnResume(this); }
342 //=======================================================================
343 //function : DeltaOnModification
344 //purpose : Creates such a delta.
345 //=======================================================================
347 Handle(TDF_DeltaOnModification) TDF_Attribute::DeltaOnModification
348 (const Handle(TDF_Attribute)& anOldAttribute) const
349 { return new TDF_DefaultDeltaOnModification(anOldAttribute); }
352 //=======================================================================
353 //function : DeltaOnModification
354 //purpose : Applies such a delta.
355 //=======================================================================
357 void TDF_Attribute::DeltaOnModification
358 (const Handle(TDF_DeltaOnModification)& aDelta)
361 Restore(aDelta->Attribute());
365 //=======================================================================
366 //function : DeltaOnRemoval
367 //purpose : Creates such a delta.
368 //=======================================================================
370 Handle(TDF_DeltaOnRemoval) TDF_Attribute::DeltaOnRemoval() const
371 { return new TDF_DefaultDeltaOnRemoval(this); } // myBackup
374 //=======================================================================
376 //purpose : This method is equivalent to operator <<
377 //=======================================================================
379 Standard_OStream& TDF_Attribute::Dump(Standard_OStream& anOS) const
381 anOS<<"\t"<<DynamicType()->Name()<<"\tTrans. "<<myTransaction<<";";
382 if (IsValid()) anOS<<" Valid";
383 if (IsBackuped()) anOS<<" Backuped";
384 if (IsForgotten()) anOS<<" Forgotten";
386 Standard_PCharacter pStr;
389 ID().ToCString(pStr);
390 anOS<<";\tID = "<<toto<<endl;
395 //=======================================================================
396 //function :ExtendedDump
398 //=======================================================================
400 void TDF_Attribute::ExtendedDump
401 (Standard_OStream& anOS,
402 const TDF_IDFilter& /*aFilter*/,
403 TDF_AttributeIndexedMap& /*aMap*/) const