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