-// File: TDF_Data.cxx
-// -------------
-// Author: DAUTRY Philippe
-// <fid@fox.paris1.matra-dtv.fr>
-// Copyright: Matra Datavision 1997
-
-// Version: 0.0
-// History: Version Date Purpose
-// 0.0 Feb 6 1997 Creation
-
-
-
-#include <TDF_Data.ixx>
-
+// Created by: DAUTRY Philippe
+// Copyright (c) 1997-1999 Matra Datavision
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+
+#include <NCollection_IncAllocator.hxx>
+#include <Standard_NoMoreObject.hxx>
+#include <Standard_NullObject.hxx>
+#include <Standard_Type.hxx>
+#include <Standard_GUID.hxx>
+#include <NCollection_Array1.hxx>
#include <TCollection_AsciiString.hxx>
-
#include <TDF_Attribute.hxx>
-#include <TDF_AttributeIterator.hxx>
+#include <TDF_AttributeDelta.hxx>
#include <TDF_AttributeIndexedMap.hxx>
+#include <TDF_AttributeIterator.hxx>
#include <TDF_ChildIterator.hxx>
+#include <TDF_Data.hxx>
#include <TDF_Delta.hxx>
-#include <TDF_AttributeDelta.hxx>
#include <TDF_DeltaOnAddition.hxx>
#include <TDF_DeltaOnForget.hxx>
#include <TDF_DeltaOnModification.hxx>
#include <TDF_LabelNode.hxx>
#include <TDF_LabelNodePtr.hxx>
#include <TDF_Tool.hxx>
+#include <TDF_Transaction.hxx>
-#include <Standard_NoMoreObject.hxx>
-#include <Standard_NullObject.hxx>
+typedef NCollection_Array1<Handle(TDF_AttributeDelta)> TDF_Array1OfAttributeIDelta;
+
+IMPLEMENT_STANDARD_RTTIEXT(TDF_Data,Standard_Transient)
#undef DEB_DELTA_CREATION
#undef TDF_DATA_COMMIT_OPTIMIZED
-#define BUC60879
-
-#ifdef DEB_DELTA
+#ifdef OCCT_DEBUG_DELTA
#define TDF_Data_DebugModified(ACTION) \
cout<<"After "<<ACTION<<" #"<<myTransaction+1<<", DF "<<this<<" had "<<myNbTouchedAtt<<" attribute(s) touched. Time = "<<myTime<<endl; \
if (!myTransaction) { \
#define TDF_Data_DebugModified(ACTION)
#endif
-#ifdef DEB_DELTA_CREATION
+#ifdef OCCT_DEBUG_DELTA_CREATION
#define TDF_DataDebugDeltaCreation(DELTATYPE) \
{ \
TCollection_AsciiString entry; \
aDelta->AddAttributeDelta(DELTACREATION); \
}
-#ifdef WNT
-// Disable the warning: "operator new unmatched by delete"
-#pragma warning (disable:4291)
-#endif
-
//=======================================================================
//function : TDF_Data
//purpose : empty constructor
myRoot = new (anIncAllocator) TDF_LabelNode (this);
}
-#ifdef WNT
-#pragma warning (default:4291)
-#endif
-
//=======================================================================
//function : Destroy
//purpose : Used to implement the destructor ~.
void TDF_Data::Destroy()
{
AbortUntilTransaction(1);
- delete myRoot;
+ myRoot->Destroy (myLabelNodeAllocator);
+ myRoot = NULL;
}
Standard_Integer TDF_Data::OpenTransaction()
{
- myTimes.Push(myTime);
+ myTimes.Prepend(myTime);
return ++myTransaction;
}
Handle(TDF_Delta) delta;
if (myTransaction>0) {
if (withDelta) delta = new TDF_Delta();
-#ifdef DEB_DELTA
+#ifdef OCCT_DEBUG_DELTA
cout<<"TDF_Data::Begin Commit #"<<myTransaction<<endl;
#endif
#ifdef TDF_DATA_COMMIT_OPTIMIZED
--myTransaction;
if (withDelta) {
if (!delta->IsEmpty()) {
- delta->Validity(myTimes.Top(),myTime);
-#ifdef DEB_DELTA
+ delta->Validity(myTimes.First(),myTime);
+#ifdef OCCT_DEBUG_DELTA
if (myTransaction == 0) {
cout<<"TDF_Data::Commit generated this delta in t=0:"<<endl;
delta->Dump(cout);
}
#endif
}
-#ifdef DEB_DELTA
+#ifdef OCCT_DEBUG_DELTA
else {
if (myTransaction == 0)
cout<<"TDF_Data::Commit generated NO delta."<<endl;
}
#endif
}
- myTimes.Pop();
+ myTimes.RemoveFirst();
}
TDF_Data_DebugModified("COMMIT");
return delta;
TDF_AttributeIterator itr1(aLabel, Standard_False);
while (itr1.More()) {
- TDF_Attribute * aPtrCurrentAtt = itr1.Value();
+ Handle(TDF_Attribute) aPtrCurrentAtt = itr1.Value();
itr1.Next();
// currentAtt = itr1.Value();
-#ifdef BUC60879
// A callback:
aPtrCurrentAtt->BeforeCommitTransaction();
-#endif
backupAtt = aPtrCurrentAtt->myBackup;
}
// --------------------------------------------------------- Modified.
else {
+ const TDF_Attribute* anAttrPtr = aPtrCurrentAtt.operator->(); // to avoid ambiguity
TDF_Data_DeltaCreation
("Modification",
- aPtrCurrentAtt->DeltaOnModification(backupAtt));
+ anAttrPtr->DeltaOnModification(backupAtt));
if (aPtrCurrentAtt->myTransaction == backupAtt->myTransaction)
aPtrCurrentAtt->RemoveBackup();
attMod = attMod || (aPtrCurrentAtt->myTransaction > 0);
return !aDelta.IsNull() && aDelta->IsApplicable(myTime);
}
-
+//=======================================================================
+//function : FixOrder
+//purpose :
+//=======================================================================
+void TDF_Data::FixOrder(const Handle(TDF_Delta)& theDelta)
+{
+ const TDF_AttributeDeltaList& attList = theDelta->AttributeDeltas();
+ Handle(TDF_AttributeDelta) attDelta;
+ Handle(TDF_Attribute) att;
+ Standard_Integer i, indx1(0), indx2(0);
+ Standard_GUID aGuid;
+ TDF_ListIteratorOfAttributeDeltaList itr(attList) ;
+ for (i=1; itr.More(); itr.Next(), i++) {
+ attDelta = itr.Value();
+ if(indx1) {
+ att = attDelta->Attribute();
+ if((att->ID() == aGuid) && (attDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition)))) {
+ indx2 = i;
+ break;
+ }
+ } else
+ if (attDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnRemoval))) {
+ att = attDelta->Attribute();
+ aGuid = att->ID();
+ indx1 = i;
+ }
+ }
+ if(indx1 && indx2) {
+ TDF_Array1OfAttributeIDelta anArray(1, attList.Extent());
+ itr.Initialize(attList);
+ for (i=1; itr.More(); itr.Next(), i++)
+ anArray.SetValue(i, itr.Value());
+ Handle(TDF_AttributeDelta) attDelta1, attDelta2;
+ attDelta1 = anArray.Value(indx1);
+ attDelta2 = anArray.Value(indx2);
+ anArray.SetValue(indx1, attDelta2);
+ anArray.SetValue(indx2, attDelta1);
+ TDF_AttributeDeltaList attList2;
+ for(i=1; i<= anArray.Upper(); i++)
+ attList2.Append(anArray.Value(i));
+ theDelta->ReplaceDeltaList(attList2);
+ }
+}
//=======================================================================
//function : Undo
//purpose : Applies a delta to undo actions.
//=======================================================================
-Handle(TDF_Delta) TDF_Data::Undo
-(const Handle(TDF_Delta)& aDelta,
- const Standard_Boolean withDelta)
+Handle(TDF_Delta) TDF_Data::Undo(const Handle(TDF_Delta)& aDelta,
+ const Standard_Boolean withDelta)
{
Handle(TDF_Delta) newDelta;
if (!aDelta.IsNull ()) {
if (aDelta->IsApplicable(myTime)) {
if (withDelta) OpenTransaction();
-#ifdef DEB_DELTA
+#ifdef OCCT_DEBUG_DELTA
cout<<"TDF_Data::Undo applies this delta:"<<endl;
aDelta->Dump(cout);
#endif
aDelta->BeforeOrAfterApply(Standard_True);
myNotUndoMode = Standard_False;
+ FixOrder(aDelta);
aDelta->Apply ();
myNotUndoMode = Standard_True;
if (withDelta) {
newDelta = CommitTransaction(Standard_True);
newDelta->Validity(aDelta->EndTime(),aDelta->BeginTime());
-#ifdef DEB_DELTA
+#ifdef OCCT_DEBUG_DELTA
cout<<"TDF_Data::Undo, after validity correction, Delta is now available from time \t#"<<newDelta->BeginTime()<<" to time \t#"<<newDelta->EndTime()<<endl;
#endif
}