0023604: Uninitialized variables in debug mode
[occt.git] / src / DDocStd / DDocStd_DocumentCommands.cxx
CommitLineData
b311480e 1// Created on: 2000-03-01
2// Created by: Denis PASCAL
3// Copyright (c) 2000-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
21
22#include <DDocStd.hxx>
23
24#include <DDF.hxx>
25#include <Draw.hxx>
26#include <Draw_Interpretor.hxx>
27#include <TDocStd_XLinkTool.hxx>
28#include <TDF_Reference.hxx>
29#include <TDocStd_Document.hxx>
30#include <CDM_Document.hxx>
31#include <TDocStd_Modified.hxx>
32#include <TDF_Label.hxx>
33#include <DDocStd_DrawDocument.hxx>
34#include <TDocStd_Document.hxx>
35#include <TDocStd_XLink.hxx>
36#include <TDocStd_XLinkRoot.hxx>
37#include <TDocStd_XLinkIterator.hxx>
38#include <TDocStd_Application.hxx>
39#include <Draw.hxx>
40#include <Draw_Interpretor.hxx>
41#include <TDF_MapIteratorOfLabelMap.hxx>
42#include <Plugin.hxx>
43#include <TCollection_ExtendedString.hxx>
44#include <TDF_Tool.hxx>
45#include <TDF_ChildIterator.hxx>
46#include <TDF_Tool.hxx>
7fd59977 47// pour propagate
7fd59977 48#include <TDocStd_XLinkTool.hxx>
49
50#include <OSD_Function.hxx>
51#include <OSD_SharedLibrary.hxx>
52#include <OSD_LoadMode.hxx>
53
54//typedef Standard_Integer (* DFBROWSER_CALL)(const Handle(TDocStd_Document)&);
55//static DFBROWSER_CALL gDFunc = 0;
56
57//=======================================================================
58//function : Main
59//purpose : Main (DOC)
60//=======================================================================
61
62static Standard_Integer DDocStd_Main (Draw_Interpretor& di,Standard_Integer nb, const char** a)
63{
64 if (nb == 2) {
65 Handle(TDocStd_Document) DOC;
66 if (!DDocStd::GetDocument(a[1],DOC)) return 1;
67 DDocStd::ReturnLabel(di,DOC->Main());
68 return 0;
69 }
70 di << "DDocStd_Main : Error" << "\n";
71 return 1;
72}
73
74
75//=======================================================================
76//function : Format
77//purpose :
78//=======================================================================
79
80static Standard_Integer DDocStd_Format (Draw_Interpretor& di,Standard_Integer n, const char** a)
81{
82 Handle(TDocStd_Document) D;
83 if (n == 2) {
84 if (!DDocStd::GetDocument(a[1],D)) return 1;
85 //cout << "FORMAT : " << D->StorageFormat() << endl;
86 di << "FORMAT : ";
87 Standard_SStream aStream;
88 D->StorageFormat().Print(aStream);
89 di << aStream;
90 di << "\n";
91 return 0;
92 }
93 if (n == 3) {
94 if (!DDocStd::GetDocument(a[1],D)) return 1;
95 D->ChangeStorageFormat(a[2]);
96 return 0;
97 }
98 di << "DDocStd_Format : Error" << "\n";
99 return 1;
100}
101
102//=======================================================================
103//function : Copy "Copy DOC entry XDOC xentry",
104//=======================================================================
105
106static Standard_Integer DDocStd_Copy (Draw_Interpretor& di,Standard_Integer n, const char** a)
107{
108 if (n == 5) {
109 Handle(TDocStd_Document) DOC, XDOC;
110 if (!DDocStd::GetDocument(a[1],DOC)) return 1;
111 if (!DDocStd::GetDocument(a[3],XDOC)) return 1;
112 TDF_Label L,XL;
113 if (!DDocStd::Find(DOC,a[2],L)) return 1;
114 if (!DDocStd::Find(XDOC,a[4],XL)) return 1;
115 TDocStd_XLinkTool XLinkTool;
116 XLinkTool.Copy(L,XL);
117 if (!XLinkTool.IsDone()) {
118 di << "DDocStd_XLinkTool : not done" << "\n";
119 }
120 return 0;
121 }
122 di << "DDocStd_XLinkTool : Error" << "\n";
123 return 1;
124}
125
126
127//=======================================================================
128//function : CopyWithLink "Copy DOC entry XDOC xentry",
129//=======================================================================
130
131static Standard_Integer DDocStd_CopyWithLink (Draw_Interpretor& di,Standard_Integer n, const char** a)
132{
133 if (n == 5) {
134 Handle(TDocStd_Document) DOC, XDOC;
135 if (!DDocStd::GetDocument(a[1],DOC)) return 1;
136 if (!DDocStd::GetDocument(a[3],XDOC)) return 1;
137 TDF_Label L,XL;
138 if (!DDocStd::Find(DOC,a[2],L)) return 1;
139 if (!DDocStd::Find(XDOC,a[4],XL)) return 1;
140 TDocStd_XLinkTool XLinkTool;
141 XLinkTool.CopyWithLink(L,XL);
142 if (!XLinkTool.IsDone()) {
143 di << "DDocStd_CopyWithLink : not done" << "\n";
144 }
145 return 0;
146 }
147 di << "DDocStd_CopyWithLink : Error" << "\n";
148 return 1;
149}
150
151//=======================================================================
152//function : UpdateLink (D,[xrefentry])
153//=======================================================================
154
155static Standard_Integer DDocStd_UpdateLink (Draw_Interpretor& di,Standard_Integer nb, const char** a)
156{
157 if (nb == 2 || nb == 3) {
158 Handle(TDocStd_Document) DOC;
159 if (!DDocStd::GetDocument(a[1],DOC)) return 1;
160 Handle(TDF_Reference) REF;
161 TDocStd_XLinkTool XLinkTool;
162 if (nb == 3) {
163 if (!DDocStd::Find(DOC,a[2],TDF_Reference::GetID(),REF)) return 1;
164 XLinkTool.UpdateLink(REF->Label());
165 if (!XLinkTool.IsDone()) {
166 di << "DDocStd_UpdateXLink : not done" << "\n";
167 }
168 }
169 else {
170 for (TDocStd_XLinkIterator xit (DOC); xit.More(); xit.Next()) {
171 XLinkTool.UpdateLink(xit.Value()->Label());
172 if (!XLinkTool.IsDone()) {
173 di << "DDocStd_UpdateXLink : not done" << "\n";
174 }
175 }
176 }
177 return 0;
178 }
179 di << "DDocStd_UpdateXLink : Error" << "\n";
180 return 1;
181}
182
183//=======================================================================
184//function : UndoLimit
185//purpose :
186//=======================================================================
187
188static Standard_Integer DDocStd_UndoLimit (Draw_Interpretor& di,Standard_Integer n, const char** a)
189{
190 if (n < 2) return 1;
191
192 Handle(TDocStd_Document) D;
193 if (!DDocStd::GetDocument(a[1],D)) return 1;
194
195 if (n > 2) {
196 Standard_Integer lim = atoi(a[2]);
197 D->SetUndoLimit(lim);
198 }
199
200 // display current values
201 di << D->GetUndoLimit() << " ";
202 di << D->GetAvailableUndos() << " ";
203 di << D->GetAvailableRedos();
204 return 0;
205}
206
207//=======================================================================
208//function : Undo, Redo
209//purpose : Undo (DOC)
210//=======================================================================
211
212static Standard_Integer DDocStd_Undo (Draw_Interpretor& di,Standard_Integer n, const char** a)
213{
214 if (n < 2) return 1;
215
216 Handle(TDocStd_Document) D;
217 if (!DDocStd::GetDocument(a[1],D)) return 1;
218
219 Standard_Integer i,step = 1;
220 if (n > 2) {
221 step = atoi(a[2]);
222 }
223
224 // test if the command was undo or redo
225 Standard_Boolean undo = a[0][0] == 'U';
226
227 for (i = 1; i <= step; i++) {
228 if (undo) {
229 if (!D->Undo()) di << "Undo not done" << "\n";
230 }
231 else {
232 if (!D->Redo()) di << "Redo not done" << "\n";
233 }
234 }
235
236 return 0;
237}
238
239//=======================================================================
240//function : NewCommand
241//purpose :
242//=======================================================================
243
244static Standard_Integer DDocStd_NewCommand(Draw_Interpretor& /*di*/,Standard_Integer n, const char** a)
245{
246 if (n < 2) return 1;
247 Handle(TDocStd_Document) D;
248 if (!DDocStd::GetDocument(a[1],D)) return 1;
249 D->NewCommand();
250 return 0;
251}
252
253//=======================================================================
254//function : OpenCommand
255//purpose :
256//=======================================================================
257
258static Standard_Integer DDocStd_OpenCommand(Draw_Interpretor& /*di*/,Standard_Integer n, const char** a)
259{
260 if (n < 2) return 1;
261
262 Handle(TDocStd_Document) D;
263 if (!DDocStd::GetDocument(a[1],D)) return 1;
264 D->OpenCommand();
265 return 0;
266}
267
268//=======================================================================
269//function : AbortCommand
270//purpose :
271//=======================================================================
272
273static Standard_Integer DDocStd_AbortCommand(Draw_Interpretor& /*di*/,Standard_Integer n, const char** a)
274{
275 if (n < 2) return 1;
276 Handle(TDocStd_Document) D;
277 if (!DDocStd::GetDocument(a[1],D)) return 1;
278 D->AbortCommand();
279 return 0;
280}
281
282//=======================================================================
283//function : CommitCommand
284//purpose :
285//=======================================================================
286
287static Standard_Integer DDocStd_CommitCommand(Draw_Interpretor& /*di*/,Standard_Integer n, const char** a)
288{
289 if (n < 2) return 1;
290 Handle(TDocStd_Document) D;
291 if (!DDocStd::GetDocument(a[1],D)) return 1;
292 D->CommitCommand();
293 return 0;
294}
295
296
297//=======================================================================
298//function : DDocStd_DumpDocument
299//purpose : DumpDocument (DOC)
300//=======================================================================
301
302static Standard_Integer DDocStd_DumpDocument (Draw_Interpretor& di,
303 Standard_Integer nb,
304 const char** arg)
305{
306 if (nb == 2) {
307 Handle(TDocStd_Document) D;
308 if (!DDocStd::GetDocument(arg[1],D)) return 1;
309 di << "\n";
310 // document name
311 if (D->IsSaved())
312 di << "DOCUMENT : " << TCollection_AsciiString(D->GetName(),'?').ToCString();
313 else
314 di << "DOCUMENT : " << "not saved";
315 di << "\n";
316 // format
317 //cout << "FORMAT : " << D->StorageFormat();
318 di << "FORMAT : ";
319 Standard_SStream aStream;
320 D->StorageFormat().Print(aStream);
321 di << aStream;
322 di << "\n";
323 // command
324 di << "COMMAND : ";
325 if (D->HasOpenCommand()) di << " Is Open";
7fd59977 326 else di << " Is Not Open";
7fd59977 327 // undo
328 di << "UNDO :";
329 di << " limit :" << D->GetUndoLimit();
330 di << " undos :" << D->GetAvailableUndos() << " ";
331 di << " redos :" << D->GetAvailableRedos();
332 di << "\n";
333 // cout << "CURRENT :";
334 // TCollection_AsciiString string;
335 // TDF_Tool::Entry(D->CurrentLabel(),string);
336 // cout << string;
337 // cout << endl;
338 // modified
339 di << "MODIFIED : ";
340 if (D->IsModified()) di << "true";
341 else di << "false";
342 di << "\n";
343 if (!TDocStd_Modified::IsEmpty(D->Main())) {
344 di << "MODIFICATIONS : ";
345 TDF_MapIteratorOfLabelMap it (D->GetModified());
346 if (!it.More()) di << "VALID" << "\n";
347 else {
348 TCollection_AsciiString string;
349 for (;it.More();it.Next()) {
350 TDF_Tool::Entry(it.Key(),string);
351 di << string.ToCString() << " ";
352 }
353 di << "\n";
354 }
355 }
356 return 0;
357 }
358 di << "DDocStd_DumpDocument : Error" << "\n";
359 return 1;
360}
361
362//=======================================================================
363//function : SetModified
364//purpose : Set modifications in a document
365//=======================================================================
366
367static Standard_Integer DDocStd_SetModified (Draw_Interpretor& di,Standard_Integer n, const char** a)
368{
369 if (n > 2) {
370 Handle(TDocStd_Document) D;
371 if (!DDocStd::GetDocument(a[1],D)) return 1;
372 TDF_Label L;
373 for (Standard_Integer i = 2; i < n; i++) {
374 if (DDocStd::Find(D,a[i],L)) D->SetModified(L);
375 }
376 return 0;
377 }
378 di << "DDocStd_SetModified : Error" << "\n";
379 return 1;
380}
381
382//=======================================================================
383//function : Propagate
384//purpose :
385//=======================================================================
386
387static Standard_Integer DDocStd_Propagate (Draw_Interpretor& di,Standard_Integer /*n*/, const char** /*a*/)
388{
389// if (n == 2) {
390// Handle(TDocStd_Document) D;
391// if (!DDocStd::GetDocument(a[1],D)) return 1;
392// if (D->IsValid()) {
393// cout << "the document is valid" << endl;
394// return 0;
395// }
396// Handle(TDesign_Function) F;
397// if (!D->Main().FindAttribute(TDesign_Function::GetID(),F)) {
398// cout << "no function found at main" << endl;
399// return 0;
400// }
401// TFunction_Logbook mdf (Standard_True);
402// for (TDF_MapIteratorOfLabelMap it (D->GetModified());it.More();it.Next()) {
403// mdf.SetTouched(it.Key());
404// }
405// F->Execute(mdf);
406// D->PurgeModified();
407// return 0;
408// }
409 di << "DDocStd_Propagate : not implemented" << "\n";
410 return 1;
411}
412
413//=======================================================================
414//function : DocumentCommands
415//purpose :
416//=======================================================================
417
418void DDocStd::DocumentCommands(Draw_Interpretor& theCommands)
419{
420
421 static Standard_Boolean done = Standard_False;
422 if (done) return;
423 done = Standard_True;
424
425
426 const char* g = "DDocStd commands";
427
428 // Data Framework Access
429
430 theCommands.Add("Main","Main (DOC)",
431 __FILE__, DDocStd_Main, g);
432
433
434 // DUMP
435
436 theCommands.Add ("Format",
437 "Format (DOC, [format])",
438 __FILE__, DDocStd_Format, g);
439
440 theCommands.Add ("DumpDocument",
441 "DumpDocument (DOC)",
442 __FILE__, DDocStd_DumpDocument, g);
443
444 // XREF
445
446 theCommands.Add("Copy","Copy DOC entry XDOC xentry",
447 __FILE__, DDocStd_Copy, g);
448
449 theCommands.Add("CopyWithLink","CopyWithLink DOC entry XDOC xentry",
450 __FILE__, DDocStd_CopyWithLink, g);
451
452 theCommands.Add("UpdateLink","UpdateLink DOC [entry]",
453 __FILE__, DDocStd_UpdateLink, g);
454
455
456 // UNDO/REDO
457
458 theCommands.Add("UndoLimit","UndoLimit DOC (Value), return UndoLimit Undos Redos",
459 __FILE__, DDocStd_UndoLimit, g);
460
461 theCommands.Add("Undo","Undo DOC (steps = 1)",
462 __FILE__, DDocStd_Undo, g);
463
464 theCommands.Add("Redo","Redo DOC (steps = 1)",
465 __FILE__, DDocStd_Undo, g);
466
467 theCommands.Add("NewCommand","NewCommand DOC",
468 __FILE__, DDocStd_NewCommand, g);
469
470 theCommands.Add("OpenCommand","OpenCommand DOC",
471 __FILE__, DDocStd_OpenCommand, g);
472
473 theCommands.Add("AbortCommand","AbortCommand DOC",
474 __FILE__, DDocStd_AbortCommand, g);
475
476 theCommands.Add("CommitCommand","CommitCommand DOC",
477 __FILE__, DDocStd_CommitCommand, g);
478
479
480 // Modif and Propagation
481
482 theCommands.Add("SetModified","SetModified DOC Label1 Label2 ....",
483 __FILE__, DDocStd_SetModified, g);
484
485 theCommands.Add("Propagate","Propagate DOC",
486 __FILE__, DDocStd_Propagate, g);
487
488}
489