1 // Created by: DAUTRY Philippe
2 // Copyright (c) 1997-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 // ---------------------------
18 //Version Date Purpose
19 // 0.0 Sep 30 1997 Creation
24 #include <DDF_Data.hxx>
25 #include <DDF_Transaction.hxx>
26 #include <DDF_TransactionStack.hxx>
29 #include <Draw_Appli.hxx>
30 #include <Draw_Drawable3D.hxx>
31 #include <Draw_Interpretor.hxx>
33 #include <TDF_Data.hxx>
34 #include <TDF_Delta.hxx>
35 #include <TDF_Transaction.hxx>
37 static DDF_TransactionStack DDF_TStack;
38 static Handle(TDF_Delta) DDF_LastDelta;
40 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41 // Transaction commands
42 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
46 //=======================================================================
48 //purpose : Opens a transaction
49 //=======================================================================
51 static Standard_Integer OpenTran (Draw_Interpretor& di,
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";
61 DDF_TStack.Prepend(tr);
67 //=======================================================================
68 //function : AbortTran
69 //purpose : Aborts a transaction
70 //=======================================================================
72 static Standard_Integer AbortTran (Draw_Interpretor& di,
79 if (DDF::GetDF (a[1], DF)) {
80 if (DF->Transaction () > 0) {
81 Handle(DDF_Transaction) tr = DDF_TStack.First();
82 di<<"Abort transaction # "<<tr->Transaction()<<" # "<<DF->Transaction()<<"\n";
84 DDF_TStack.RemoveFirst();
87 di<<"DDF_BasicCommands::AbortTran - No more transaction to abort\n";
94 //=======================================================================
95 //function : CommitTran
96 //purpose : Commits a transaction
97 //=======================================================================
99 static Standard_Integer CommitTran (Draw_Interpretor& di,
106 if (DDF::GetDF (a[1], DF)) {
107 if (DF->Transaction () > 0) {
108 Handle(DDF_Transaction) tr = DDF_TStack.First();
109 di<<"Commit transaction # "<<tr->Transaction()<<" # "<<DF->Transaction()<<"\n";
110 Standard_Boolean withDelta = Standard_False;
111 if (n > 2) withDelta = (Draw::Atoi(a[2]) != 0);
112 DDF_LastDelta = tr->Commit(withDelta);
113 DDF_TStack.RemoveFirst();
116 di<<"DDF_BasicCommands::CommitTran - No more transaction to commit\n";
123 //=======================================================================
124 //function : CurrentTran
125 //purpose : Current transaction number.
126 //=======================================================================
128 static Standard_Integer CurrentTran (Draw_Interpretor& di,
135 if (DDF::GetDF (a[1], DF)) {
136 di<<"# "<<DF->Transaction()<<"\n";
137 if (!DDF_TStack.IsEmpty())
138 if (DF->Transaction() != DDF_TStack.First()->Transaction())
139 di<<"Transaction object said # "<<DDF_TStack.First()->Transaction()<<"\n";
148 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
150 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
154 //=======================================================================
157 //=======================================================================
159 static Standard_Integer Undo (Draw_Interpretor& di,
166 if (DDF::GetDF (a[1], DF)) {
167 Standard_Boolean withDelta = Standard_False;
168 if (n > 2) withDelta = (Draw::Atoi(a[2]) != 0);
169 if (!DDF_LastDelta.IsNull()) {
170 if (DF->IsApplicable(DDF_LastDelta)) {
171 Handle(TDF_Delta) tmp = DF->Undo(DDF_LastDelta,withDelta);
175 di<<"Undo not applicable HERE and NOW.\n";
180 di<<"No undo to apply.\n";
192 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
197 //=======================================================================
198 //function : TransactionCommands
200 //=======================================================================
202 void DDF::TransactionCommands (Draw_Interpretor& theCommands)
204 static Standard_Boolean done = Standard_False;
206 done = Standard_True;
208 const char* g = "DF transaction and undo commands";
214 "Opens a transaction on a DF: OpenTran dfname",
215 __FILE__, OpenTran, g);
219 "Aborts a transaction on a DF: AbortTran dfname",
220 __FILE__, AbortTran, g);
224 "Commits a transaction on a DF with/without delta generation : CommitTran dfname [withDelta]",
225 __FILE__, CommitTran, g);
229 "Returns the current transaction number on a DF : CurrentTran dfname",
230 __FILE__, CurrentTran, g);
236 " Undos last DF commit modifications: Undo dfname [withDelta]",