0025418: Debug output to be limited to OCC development environment
[occt.git] / src / TDF / TDF_Transaction.cxx
1 // Created by: DAUTRY Philippe
2 // Copyright (c) 1997-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 //              -------------------
17
18 // Version:     0.0
19 //Version       Date            Purpose
20 //              0.0     Oct  1 1997     Creation
21
22
23
24 #include <TDF_Transaction.ixx>
25
26 #undef DEB_TRANSACTION
27 #ifdef OCCT_DEBUG
28 #define DEB_TRANSACTION
29 #endif
30 #undef DEB_TRANSACTION_DUMP
31
32 #include <TDF_Tool.hxx>
33
34 //=======================================================================
35 //function : TDF_Transaction
36 //purpose  : 
37 //=======================================================================
38
39 TDF_Transaction::TDF_Transaction
40 (const TCollection_AsciiString& aName)
41 : myUntilTransaction(0),
42   myName(aName)
43 {}
44
45
46 //=======================================================================
47 //function : TDF_Transaction
48 //purpose  : Private copy constructor.
49 //=======================================================================
50
51 TDF_Transaction::TDF_Transaction(const TDF_Transaction& /*aTrans*/)
52 {}
53
54
55 //=======================================================================
56 //function : TDF_Transaction
57 //purpose  : 
58 //=======================================================================
59
60 TDF_Transaction::TDF_Transaction
61 (const Handle(TDF_Data)& aDF,
62  const TCollection_AsciiString& aName)
63 : myDF(aDF),
64   myUntilTransaction(0),
65   myName(aName)
66 {}
67
68
69
70
71 //=======================================================================
72 //function : Initialize
73 //purpose  : Initializes a transaction ready to be opened.
74 //=======================================================================
75
76 void TDF_Transaction::Initialize(const Handle(TDF_Data)& aDF)
77 {
78   if (IsOpen()) myDF->AbortUntilTransaction(myUntilTransaction);
79   myDF = aDF;
80   myUntilTransaction = 0;
81 }
82
83
84 //=======================================================================
85 //function : Open
86 //purpose  : 
87 //=======================================================================
88
89 Standard_Integer TDF_Transaction::Open()
90 {
91 #ifdef OCCT_DEBUG_TRANSACTION
92   cout<<"Transaction "<<myName<<" opens #"<<myDF->Transaction()+1<<endl;
93 #endif
94   if (IsOpen())
95     Standard_DomainError::Raise("This transaction is already open.");
96   if (myDF.IsNull())
97     Standard_NullObject::Raise("Null TDF_Data.");
98   return myUntilTransaction = myDF->OpenTransaction();
99 }
100
101
102 //=======================================================================
103 //function : Commit
104 //purpose  : 
105 //=======================================================================
106
107 Handle(TDF_Delta) TDF_Transaction::Commit(const Standard_Boolean withDelta)
108 {
109 #ifdef OCCT_DEBUG_TRANSACTION
110   cout<<"Transaction "<<myName<<" commits ";
111 #endif
112   Handle(TDF_Delta) delta;
113   if (IsOpen()) {
114 #ifdef OCCT_DEBUG_TRANSACTION
115     cout<<"from #"<<myDF->Transaction()<<" until #"<<myUntilTransaction<<" while current is #"<<myDF->Transaction()<<endl;
116 #endif
117 #ifdef OCCT_DEBUG_TRANSACTION_DUMP
118     cout<<"DF before commit"<<endl;
119     TDF_Tool::DeepDump(cout,myDF);
120 #endif
121     Standard_Integer until = myUntilTransaction;
122     myUntilTransaction = 0;
123     delta = myDF->CommitUntilTransaction(until, withDelta);
124 #ifdef OCCT_DEBUG_TRANSACTION_DUMP
125     cout<<"DF after commit"<<endl;
126     TDF_Tool::DeepDump(cout,myDF);
127 #endif
128   }
129 #ifdef OCCT_DEBUG_TRANSACTION
130   else cout<<"but this transaction is not open!"<<endl;
131 #endif
132   return delta;
133 }
134
135
136 //=======================================================================
137 //function : Abort
138 //purpose  : alias ~
139 //=======================================================================
140
141 void TDF_Transaction::Abort()
142 {
143   if (IsOpen()) {
144 #ifdef OCCT_DEBUG_TRANSACTION
145     cout<<"Transaction "<<myName<<" aborts from #"<<myDF->Transaction()<<" until #"<<myUntilTransaction<<" while current is #"<<myDF->Transaction()<<endl;
146 #endif
147 #ifdef OCCT_DEBUG_TRANSACTION_DUMP
148     cout<<"DF before abort"<<endl;
149     TDF_Tool::DeepDump(cout,myDF);
150 #endif
151     myDF->AbortUntilTransaction(myUntilTransaction);
152     myUntilTransaction = 0;
153 #ifdef OCCT_DEBUG_TRANSACTION_DUMP
154     cout<<"DF after abort"<<endl;
155     TDF_Tool::DeepDump(cout,myDF);
156 #endif
157   }
158 }
159