0024234: occt master is not compiled by VC++ 2005 (vc8 32/64 bit TKBO)
[occt.git] / src / DDF / DDF_TransactionCommands.cxx
CommitLineData
b311480e 1// Created by: DAUTRY Philippe
2// Copyright (c) 1997-1999 Matra Datavision
3// Copyright (c) 1999-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20// ---------------------------
7fd59977 21// Version: 0.0
b311480e 22//Version Date Purpose
7fd59977 23// 0.0 Sep 30 1997 Creation
24
25
26
27#include <DDF.hxx>
28#include <DDF_Data.hxx>
29#include <DDF_Transaction.hxx>
30#include <DDF_TransactionStack.hxx>
31
32#include <Draw.hxx>
33#include <Draw_Appli.hxx>
34#include <Draw_Drawable3D.hxx>
35#include <Draw_Interpretor.hxx>
36
37#include <TDF_Data.hxx>
38#include <TDF_Delta.hxx>
39#include <TDF_Transaction.hxx>
40
41static DDF_TransactionStack DDF_TStack;
42static Handle(TDF_Delta) DDF_LastDelta;
43
44// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
45// Transaction commands
46// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
47
48
49
50//=======================================================================
51//function : OpenTran
52//purpose : Opens a transaction
53//=======================================================================
54
55static Standard_Integer OpenTran (Draw_Interpretor& di,
56 Standard_Integer n,
57 const char** a)
58{
59 if (n < 2) return 1;
60
61 Handle(TDF_Data) DF;
62 if (DDF::GetDF (a[1], DF)) {
63 Handle(DDF_Transaction) tr = new DDF_Transaction(DF);
64 di<<"Open transaction # "<<tr->Open()<<" # "<<DF->Transaction()<<"\n";
65 DDF_TStack.Push(tr);
66 }
67 return 0;
68}
69
70
71//=======================================================================
72//function : AbortTran
73//purpose : Aborts a transaction
74//=======================================================================
75
76static Standard_Integer AbortTran (Draw_Interpretor& di,
77 Standard_Integer n,
78 const char** a)
79{
80 if (n < 2) return 1;
81
82 Handle(TDF_Data) DF;
83 if (DDF::GetDF (a[1], DF)) {
84 if (DF->Transaction () > 0) {
85 Handle(DDF_Transaction) tr = DDF_TStack.Top();
86 di<<"Abort transaction # "<<tr->Transaction()<<" # "<<DF->Transaction()<<"\n";
87 tr->Abort();
88 DDF_TStack.Pop();
89 }
90 else {
91 di<<"DDF_BasicCommands::AbortTran - No more transaction to abort"<<"\n";
92 }
93 }
94 return 0;
95}
96
97
98//=======================================================================
99//function : CommitTran
100//purpose : Commits a transaction
101//=======================================================================
102
103static Standard_Integer CommitTran (Draw_Interpretor& di,
104 Standard_Integer n,
105 const char** a)
106{
107 if (n < 2) return 1;
108
109 Handle(TDF_Data) DF;
110 if (DDF::GetDF (a[1], DF)) {
111 if (DF->Transaction () > 0) {
112 Handle(DDF_Transaction) tr = DDF_TStack.Top();
113 di<<"Commit transaction # "<<tr->Transaction()<<" # "<<DF->Transaction()<<"\n";
114 Standard_Boolean withDelta = Standard_False;
91322f44 115 if (n > 2) withDelta = (Draw::Atoi(a[2]) != 0);
7fd59977 116 DDF_LastDelta = tr->Commit(withDelta);
117 DDF_TStack.Pop();
118 }
119 else {
120 di<<"DDF_BasicCommands::CommitTran - No more transaction to commit"<<"\n";
121 }
122 }
123 return 0;
124}
125
126
127//=======================================================================
128//function : CurrentTran
129//purpose : Current transaction number.
130//=======================================================================
131
132static Standard_Integer CurrentTran (Draw_Interpretor& di,
133 Standard_Integer n,
134 const char** a)
135{
136 if (n < 2) return 1;
137
138 Handle(TDF_Data) DF;
139 if (DDF::GetDF (a[1], DF)) {
140 di<<"# "<<DF->Transaction()<<"\n";
141 if (!DDF_TStack.IsEmpty())
142 if (DF->Transaction() != DDF_TStack.Top()->Transaction())
143 di<<"Transaction object said # "<<DDF_TStack.Top()->Transaction()<<"\n";
144 }
145 return 0;
146
147}
148
149
150
151
152// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
153// Delta commands
154// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
155
156
157
158//=======================================================================
159//function : Undo
160//purpose : Undo
161//=======================================================================
162
163static Standard_Integer Undo (Draw_Interpretor& di,
164 Standard_Integer n,
165 const char** a)
166{
167 if (n < 2) return 1;
168
169 Handle(TDF_Data) DF;
170 if (DDF::GetDF (a[1], DF)) {
171 Standard_Boolean withDelta = Standard_False;
91322f44 172 if (n > 2) withDelta = (Draw::Atoi(a[2]) != 0);
7fd59977 173 if (!DDF_LastDelta.IsNull()) {
174 if (DF->IsApplicable(DDF_LastDelta)) {
175 Handle(TDF_Delta) tmp = DF->Undo(DDF_LastDelta,withDelta);
176 DDF_LastDelta = tmp;
177 }
178 else {
179 di<<"Undo not applicable HERE and NOW."<<"\n";
180 return 1;
181 }
182 }
183 else {
184 di<<"No undo to apply."<<"\n";
185 return 1;
186 }
187 }
188 else {
189 di<<"Unknown DF."<<"\n";
190 return 1;
191 }
192 return 0;
193}
194
195
196// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
197
198
199
200
201//=======================================================================
202//function : TransactionCommands
203//purpose :
204//=======================================================================
205
206void DDF::TransactionCommands (Draw_Interpretor& theCommands)
207{
208 static Standard_Boolean done = Standard_False;
209 if (done) return;
210 done = Standard_True;
211
212 const char* g = "DF transaction and undo commands";
213
214 // Transaction :
215 // +++++++++++++
216 theCommands.Add
217 ("OpenTran",
218 "Opens a transaction on a DF: OpenTran dfname",
219 __FILE__, OpenTran, g);
220
221 theCommands.Add
222 ("AbortTran",
223 "Aborts a transaction on a DF: AbortTran dfname",
224 __FILE__, AbortTran, g);
225
226 theCommands.Add
227 ("CommitTran",
228 "Commits a transaction on a DF with/without delta generation : CommitTran dfname [withDelta]",
229 __FILE__, CommitTran, g);
230
231 theCommands.Add
232 ("CurrentTran",
233 "Returns the current transaction number on a DF : CurrentTran dfname",
234 __FILE__, CurrentTran, g);
235
236 // Undo :
237 // ++++++
238 theCommands.Add
239 ("DFUndo",
240 " Undos last DF commit modifications: Undo dfname [withDelta]",
241 __FILE__, Undo, g);
242
243
244}