0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[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 // Version:     0.0
18 //Version       Date            Purpose
19 //              0.0     Oct  1 1997     Creation
20
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>
28
29 #undef DEB_TRANSACTION
30 #ifdef OCCT_DEBUG
31 #define DEB_TRANSACTION
32 #endif
33 #undef DEB_TRANSACTION_DUMP
34
35 #include <TDF_Tool.hxx>
36
37 //=======================================================================
38 //function : TDF_Transaction
39 //purpose  : 
40 //=======================================================================
41
42 TDF_Transaction::TDF_Transaction
43 (const TCollection_AsciiString& aName)
44 : myName(aName),
45   myUntilTransaction(0)
46 {}
47
48 //=======================================================================
49 //function : TDF_Transaction
50 //purpose  : 
51 //=======================================================================
52
53 TDF_Transaction::TDF_Transaction
54 (const Handle(TDF_Data)& aDF,
55  const TCollection_AsciiString& aName)
56 : myDF(aDF),
57   myName(aName),
58   myUntilTransaction(0)
59 {}
60
61
62
63
64 //=======================================================================
65 //function : Initialize
66 //purpose  : Initializes a transaction ready to be opened.
67 //=======================================================================
68
69 void TDF_Transaction::Initialize(const Handle(TDF_Data)& aDF)
70 {
71   if (IsOpen()) myDF->AbortUntilTransaction(myUntilTransaction);
72   myDF = aDF;
73   myUntilTransaction = 0;
74 }
75
76
77 //=======================================================================
78 //function : Open
79 //purpose  : 
80 //=======================================================================
81
82 Standard_Integer TDF_Transaction::Open()
83 {
84 #ifdef OCCT_DEBUG_TRANSACTION
85   std::cout<<"Transaction "<<myName<<" opens #"<<myDF->Transaction()+1<<std::endl;
86 #endif
87   if (IsOpen())
88     throw Standard_DomainError("This transaction is already open.");
89   if (myDF.IsNull())
90     throw Standard_NullObject("Null TDF_Data.");
91   return myUntilTransaction = myDF->OpenTransaction();
92 }
93
94
95 //=======================================================================
96 //function : Commit
97 //purpose  : 
98 //=======================================================================
99
100 Handle(TDF_Delta) TDF_Transaction::Commit(const Standard_Boolean withDelta)
101 {
102 #ifdef OCCT_DEBUG_TRANSACTION
103   std::cout<<"Transaction "<<myName<<" commits ";
104 #endif
105   Handle(TDF_Delta) delta;
106   if (IsOpen()) {
107 #ifdef OCCT_DEBUG_TRANSACTION
108     std::cout<<"from #"<<myDF->Transaction()<<" until #"<<myUntilTransaction<<" while current is #"<<myDF->Transaction()<<std::endl;
109 #endif
110 #ifdef OCCT_DEBUG_TRANSACTION_DUMP
111     std::cout<<"DF before commit"<<std::endl;
112     TDF_Tool::DeepDump(std::cout,myDF);
113 #endif
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);
120 #endif
121   }
122 #ifdef OCCT_DEBUG_TRANSACTION
123   else std::cout<<"but this transaction is not open!"<<std::endl;
124 #endif
125   return delta;
126 }
127
128
129 //=======================================================================
130 //function : Abort
131 //purpose  : alias ~
132 //=======================================================================
133
134 void TDF_Transaction::Abort()
135 {
136   if (IsOpen()) {
137 #ifdef OCCT_DEBUG_TRANSACTION
138     std::cout<<"Transaction "<<myName<<" aborts from #"<<myDF->Transaction()<<" until #"<<myUntilTransaction<<" while current is #"<<myDF->Transaction()<<std::endl;
139 #endif
140 #ifdef OCCT_DEBUG_TRANSACTION_DUMP
141     std::cout<<"DF before abort"<<std::endl;
142     TDF_Tool::DeepDump(std::cout,myDF);
143 #endif
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);
149 #endif
150   }
151 }
152
153 //=======================================================================
154 //function : DumpJson
155 //purpose  : 
156 //=======================================================================
157 void TDF_Transaction::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
158 {
159   OCCT_DUMP_CLASS_BEGIN (theOStream, TDF_Transaction)
160
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)
164 }