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 Oct 1 1997 Creation
21 #include <Standard_DomainError.hxx>
22 #include <Standard_Dump.hxx>
23 #include <Standard_NullObject.hxx>
24 #include <TCollection_AsciiString.hxx>
25 #include <TDF_Data.hxx>
26 #include <TDF_Delta.hxx>
27 #include <TDF_Transaction.hxx>
29 #undef DEB_TRANSACTION
31 #define DEB_TRANSACTION
33 #undef DEB_TRANSACTION_DUMP
35 #include <TDF_Tool.hxx>
37 //=======================================================================
38 //function : TDF_Transaction
40 //=======================================================================
42 TDF_Transaction::TDF_Transaction
43 (const TCollection_AsciiString& aName)
48 //=======================================================================
49 //function : TDF_Transaction
51 //=======================================================================
53 TDF_Transaction::TDF_Transaction
54 (const Handle(TDF_Data)& aDF,
55 const TCollection_AsciiString& aName)
64 //=======================================================================
65 //function : Initialize
66 //purpose : Initializes a transaction ready to be opened.
67 //=======================================================================
69 void TDF_Transaction::Initialize(const Handle(TDF_Data)& aDF)
71 if (IsOpen()) myDF->AbortUntilTransaction(myUntilTransaction);
73 myUntilTransaction = 0;
77 //=======================================================================
80 //=======================================================================
82 Standard_Integer TDF_Transaction::Open()
84 #ifdef OCCT_DEBUG_TRANSACTION
85 std::cout<<"Transaction "<<myName<<" opens #"<<myDF->Transaction()+1<<std::endl;
88 throw Standard_DomainError("This transaction is already open.");
90 throw Standard_NullObject("Null TDF_Data.");
91 return myUntilTransaction = myDF->OpenTransaction();
95 //=======================================================================
98 //=======================================================================
100 Handle(TDF_Delta) TDF_Transaction::Commit(const Standard_Boolean withDelta)
102 #ifdef OCCT_DEBUG_TRANSACTION
103 std::cout<<"Transaction "<<myName<<" commits ";
105 Handle(TDF_Delta) delta;
107 #ifdef OCCT_DEBUG_TRANSACTION
108 std::cout<<"from #"<<myDF->Transaction()<<" until #"<<myUntilTransaction<<" while current is #"<<myDF->Transaction()<<std::endl;
110 #ifdef OCCT_DEBUG_TRANSACTION_DUMP
111 std::cout<<"DF before commit"<<std::endl;
112 TDF_Tool::DeepDump(std::cout,myDF);
114 Standard_Integer until = myUntilTransaction;
115 myUntilTransaction = 0;
116 delta = myDF->CommitUntilTransaction(until, withDelta);
117 #ifdef OCCT_DEBUG_TRANSACTION_DUMP
118 std::cout<<"DF after commit"<<std::endl;
119 TDF_Tool::DeepDump(std::cout,myDF);
122 #ifdef OCCT_DEBUG_TRANSACTION
123 else std::cout<<"but this transaction is not open!"<<std::endl;
129 //=======================================================================
132 //=======================================================================
134 void TDF_Transaction::Abort()
137 #ifdef OCCT_DEBUG_TRANSACTION
138 std::cout<<"Transaction "<<myName<<" aborts from #"<<myDF->Transaction()<<" until #"<<myUntilTransaction<<" while current is #"<<myDF->Transaction()<<std::endl;
140 #ifdef OCCT_DEBUG_TRANSACTION_DUMP
141 std::cout<<"DF before abort"<<std::endl;
142 TDF_Tool::DeepDump(std::cout,myDF);
144 myDF->AbortUntilTransaction(myUntilTransaction);
145 myUntilTransaction = 0;
146 #ifdef OCCT_DEBUG_TRANSACTION_DUMP
147 std::cout<<"DF after abort"<<std::endl;
148 TDF_Tool::DeepDump(std::cout,myDF);
153 //=======================================================================
154 //function : DumpJson
156 //=======================================================================
157 void TDF_Transaction::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
159 OCCT_DUMP_CLASS_BEGIN (theOStream, TDF_Transaction)
161 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myDF.get())
162 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myUntilTransaction)
163 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myName)