0025266: Debug statements in the source are getting flushed on to the console
[occt.git] / src / DDF / DDF_TransactionCommands.cxx
CommitLineData
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 Sep 30 1997 Creation
20
21
22
23#include <DDF.hxx>
24#include <DDF_Data.hxx>
25#include <DDF_Transaction.hxx>
26#include <DDF_TransactionStack.hxx>
27
28#include <Draw.hxx>
29#include <Draw_Appli.hxx>
30#include <Draw_Drawable3D.hxx>
31#include <Draw_Interpretor.hxx>
32
33#include <TDF_Data.hxx>
34#include <TDF_Delta.hxx>
35#include <TDF_Transaction.hxx>
36
37static DDF_TransactionStack DDF_TStack;
38static Handle(TDF_Delta) DDF_LastDelta;
39
40// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41// Transaction commands
42// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
43
44
45
46//=======================================================================
47//function : OpenTran
48//purpose : Opens a transaction
49//=======================================================================
50
51static Standard_Integer OpenTran (Draw_Interpretor& di,
52 Standard_Integer n,
53 const char** a)
54{
55 if (n < 2) return 1;
56
57 Handle(TDF_Data) DF;
58 if (DDF::GetDF (a[1], DF)) {
59 Handle(DDF_Transaction) tr = new DDF_Transaction(DF);
60 di<<"Open transaction # "<<tr->Open()<<" # "<<DF->Transaction()<<"\n";
6af4fe1c 61 DDF_TStack.Prepend(tr);
7fd59977 62 }
63 return 0;
64}
65
66
67//=======================================================================
68//function : AbortTran
69//purpose : Aborts a transaction
70//=======================================================================
71
72static Standard_Integer AbortTran (Draw_Interpretor& di,
73 Standard_Integer n,
74 const char** a)
75{
76 if (n < 2) return 1;
77
78 Handle(TDF_Data) DF;
79 if (DDF::GetDF (a[1], DF)) {
80 if (DF->Transaction () > 0) {
6af4fe1c 81 Handle(DDF_Transaction) tr = DDF_TStack.First();
7fd59977 82 di<<"Abort transaction # "<<tr->Transaction()<<" # "<<DF->Transaction()<<"\n";
83 tr->Abort();
6af4fe1c 84 DDF_TStack.RemoveFirst();
7fd59977 85 }
86 else {
87 di<<"DDF_BasicCommands::AbortTran - No more transaction to abort"<<"\n";
88 }
89 }
90 return 0;
91}
92
93
94//=======================================================================
95//function : CommitTran
96//purpose : Commits a transaction
97//=======================================================================
98
99static Standard_Integer CommitTran (Draw_Interpretor& di,
100 Standard_Integer n,
101 const char** a)
102{
103 if (n < 2) return 1;
104
105 Handle(TDF_Data) DF;
106 if (DDF::GetDF (a[1], DF)) {
107 if (DF->Transaction () > 0) {
6af4fe1c 108 Handle(DDF_Transaction) tr = DDF_TStack.First();
7fd59977 109 di<<"Commit transaction # "<<tr->Transaction()<<" # "<<DF->Transaction()<<"\n";
110 Standard_Boolean withDelta = Standard_False;
91322f44 111 if (n > 2) withDelta = (Draw::Atoi(a[2]) != 0);
7fd59977 112 DDF_LastDelta = tr->Commit(withDelta);
6af4fe1c 113 DDF_TStack.RemoveFirst();
7fd59977 114 }
115 else {
116 di<<"DDF_BasicCommands::CommitTran - No more transaction to commit"<<"\n";
117 }
118 }
119 return 0;
120}
121
122
123//=======================================================================
124//function : CurrentTran
125//purpose : Current transaction number.
126//=======================================================================
127
128static Standard_Integer CurrentTran (Draw_Interpretor& di,
129 Standard_Integer n,
130 const char** a)
131{
132 if (n < 2) return 1;
133
134 Handle(TDF_Data) DF;
135 if (DDF::GetDF (a[1], DF)) {
136 di<<"# "<<DF->Transaction()<<"\n";
137 if (!DDF_TStack.IsEmpty())
6af4fe1c 138 if (DF->Transaction() != DDF_TStack.First()->Transaction())
139 di<<"Transaction object said # "<<DDF_TStack.First()->Transaction()<<"\n";
7fd59977 140 }
141 return 0;
142
143}
144
145
146
147
148// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
149// Delta commands
150// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
151
152
153
154//=======================================================================
155//function : Undo
156//purpose : Undo
157//=======================================================================
158
159static Standard_Integer Undo (Draw_Interpretor& di,
160 Standard_Integer n,
161 const char** a)
162{
163 if (n < 2) return 1;
164
165 Handle(TDF_Data) DF;
166 if (DDF::GetDF (a[1], DF)) {
167 Standard_Boolean withDelta = Standard_False;
91322f44 168 if (n > 2) withDelta = (Draw::Atoi(a[2]) != 0);
7fd59977 169 if (!DDF_LastDelta.IsNull()) {
170 if (DF->IsApplicable(DDF_LastDelta)) {
171 Handle(TDF_Delta) tmp = DF->Undo(DDF_LastDelta,withDelta);
172 DDF_LastDelta = tmp;
173 }
174 else {
175 di<<"Undo not applicable HERE and NOW."<<"\n";
176 return 1;
177 }
178 }
179 else {
180 di<<"No undo to apply."<<"\n";
181 return 1;
182 }
183 }
184 else {
185 di<<"Unknown DF."<<"\n";
186 return 1;
187 }
188 return 0;
189}
190
191
192// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
193
194
195
196
197//=======================================================================
198//function : TransactionCommands
199//purpose :
200//=======================================================================
201
202void DDF::TransactionCommands (Draw_Interpretor& theCommands)
203{
204 static Standard_Boolean done = Standard_False;
205 if (done) return;
206 done = Standard_True;
207
208 const char* g = "DF transaction and undo commands";
209
210 // Transaction :
211 // +++++++++++++
212 theCommands.Add
213 ("OpenTran",
214 "Opens a transaction on a DF: OpenTran dfname",
215 __FILE__, OpenTran, g);
216
217 theCommands.Add
218 ("AbortTran",
219 "Aborts a transaction on a DF: AbortTran dfname",
220 __FILE__, AbortTran, g);
221
222 theCommands.Add
223 ("CommitTran",
224 "Commits a transaction on a DF with/without delta generation : CommitTran dfname [withDelta]",
225 __FILE__, CommitTran, g);
226
227 theCommands.Add
228 ("CurrentTran",
229 "Returns the current transaction number on a DF : CurrentTran dfname",
230 __FILE__, CurrentTran, g);
231
232 // Undo :
233 // ++++++
234 theCommands.Add
235 ("DFUndo",
236 " Undos last DF commit modifications: Undo dfname [withDelta]",
237 __FILE__, Undo, g);
238
239
240}