1 // File: DDF_TransactionCommands.cxx
2 // ---------------------------
3 // Author: DAUTRY Philippe
4 // <fid@fox.paris1.matra-dtv.fr>
5 // Copyright: Matra Datavision 1997
7 // History: Version Date Purpose
8 // 0.0 Sep 30 1997 Creation
13 #include <DDF_Data.hxx>
14 #include <DDF_Transaction.hxx>
15 #include <DDF_TransactionStack.hxx>
18 #include <Draw_Appli.hxx>
19 #include <Draw_Drawable3D.hxx>
20 #include <Draw_Interpretor.hxx>
22 #include <TDF_Data.hxx>
23 #include <TDF_Delta.hxx>
24 #include <TDF_Transaction.hxx>
26 static DDF_TransactionStack DDF_TStack;
27 static Handle(TDF_Delta) DDF_LastDelta;
29 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30 // Transaction commands
31 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
35 //=======================================================================
37 //purpose : Opens a transaction
38 //=======================================================================
40 static Standard_Integer OpenTran (Draw_Interpretor& di,
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";
56 //=======================================================================
57 //function : AbortTran
58 //purpose : Aborts a transaction
59 //=======================================================================
61 static Standard_Integer AbortTran (Draw_Interpretor& di,
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";
76 di<<"DDF_BasicCommands::AbortTran - No more transaction to abort"<<"\n";
83 //=======================================================================
84 //function : CommitTran
85 //purpose : Commits a transaction
86 //=======================================================================
88 static Standard_Integer CommitTran (Draw_Interpretor& di,
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);
105 di<<"DDF_BasicCommands::CommitTran - No more transaction to commit"<<"\n";
112 //=======================================================================
113 //function : CurrentTran
114 //purpose : Current transaction number.
115 //=======================================================================
117 static Standard_Integer CurrentTran (Draw_Interpretor& di,
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";
137 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
139 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
143 //=======================================================================
146 //=======================================================================
148 static Standard_Integer Undo (Draw_Interpretor& di,
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);
164 di<<"Undo not applicable HERE and NOW."<<"\n";
169 di<<"No undo to apply."<<"\n";
174 di<<"Unknown DF."<<"\n";
181 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
186 //=======================================================================
187 //function : TransactionCommands
189 //=======================================================================
191 void DDF::TransactionCommands (Draw_Interpretor& theCommands)
193 static Standard_Boolean done = Standard_False;
195 done = Standard_True;
197 const char* g = "DF transaction and undo commands";
203 "Opens a transaction on a DF: OpenTran dfname",
204 __FILE__, OpenTran, g);
208 "Aborts a transaction on a DF: AbortTran dfname",
209 __FILE__, AbortTran, g);
213 "Commits a transaction on a DF with/without delta generation : CommitTran dfname [withDelta]",
214 __FILE__, CommitTran, g);
218 "Returns the current transaction number on a DF : CurrentTran dfname",
219 __FILE__, CurrentTran, g);
225 " Undos last DF commit modifications: Undo dfname [withDelta]",