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