1 // Created on: 2000-03-01
2 // Created by: Denis PASCAL
3 // Copyright (c) 2000-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 #include <DDocStd.hxx>
20 #include <Draw_Interpretor.hxx>
21 #include <TDocStd_XLinkTool.hxx>
22 #include <TDF_Reference.hxx>
23 #include <TDocStd_Document.hxx>
24 #include <CDM_Document.hxx>
25 #include <TDocStd_Modified.hxx>
26 #include <TDF_Label.hxx>
27 #include <DDocStd_DrawDocument.hxx>
28 #include <TDocStd_Document.hxx>
29 #include <TDocStd_XLink.hxx>
30 #include <TDocStd_XLinkRoot.hxx>
31 #include <TDocStd_XLinkIterator.hxx>
32 #include <TDocStd_Application.hxx>
34 #include <Draw_Interpretor.hxx>
35 #include <TDF_MapIteratorOfLabelMap.hxx>
37 #include <TCollection_ExtendedString.hxx>
38 #include <TDF_Tool.hxx>
39 #include <TDF_ChildIterator.hxx>
40 #include <TDF_Tool.hxx>
42 #include <TDocStd_XLinkTool.hxx>
44 #include <OSD_Function.hxx>
45 #include <OSD_SharedLibrary.hxx>
46 #include <OSD_LoadMode.hxx>
48 //typedef Standard_Integer (* DFBROWSER_CALL)(const Handle(TDocStd_Document)&);
49 //static DFBROWSER_CALL gDFunc = 0;
51 //=======================================================================
53 //purpose : Main (DOC)
54 //=======================================================================
56 static Standard_Integer DDocStd_Main (Draw_Interpretor& di,Standard_Integer nb, const char** a)
59 Handle(TDocStd_Document) DOC;
60 if (!DDocStd::GetDocument(a[1],DOC)) return 1;
61 DDocStd::ReturnLabel(di,DOC->Main());
64 di << "DDocStd_Main : Error\n";
69 //=======================================================================
72 //=======================================================================
74 static Standard_Integer DDocStd_Format (Draw_Interpretor& di,Standard_Integer n, const char** a)
76 Handle(TDocStd_Document) D;
78 if (!DDocStd::GetDocument(a[1],D)) return 1;
79 //cout << "FORMAT : " << D->StorageFormat() << endl;
81 Standard_SStream aStream;
82 D->StorageFormat().Print(aStream);
88 if (!DDocStd::GetDocument(a[1],D)) return 1;
89 D->ChangeStorageFormat(a[2]);
92 di << "DDocStd_Format : Error\n";
96 //=======================================================================
97 //function : Copy "Copy DOC entry XDOC xentry",
98 //=======================================================================
100 static Standard_Integer DDocStd_Copy (Draw_Interpretor& di,Standard_Integer n, const char** a)
103 Handle(TDocStd_Document) DOC, XDOC;
104 if (!DDocStd::GetDocument(a[1],DOC)) return 1;
105 if (!DDocStd::GetDocument(a[3],XDOC)) return 1;
107 if (!DDocStd::Find(DOC,a[2],L)) return 1;
108 if (!DDocStd::Find(XDOC,a[4],XL)) return 1;
109 TDocStd_XLinkTool XLinkTool;
110 XLinkTool.Copy(L,XL);
111 if (!XLinkTool.IsDone()) {
112 di << "DDocStd_XLinkTool : not done\n";
116 di << "DDocStd_XLinkTool : Error\n";
121 //=======================================================================
122 //function : CopyWithLink "Copy DOC entry XDOC xentry",
123 //=======================================================================
125 static Standard_Integer DDocStd_CopyWithLink (Draw_Interpretor& di,Standard_Integer n, const char** a)
128 Handle(TDocStd_Document) DOC, XDOC;
129 if (!DDocStd::GetDocument(a[1],DOC)) return 1;
130 if (!DDocStd::GetDocument(a[3],XDOC)) return 1;
132 if (!DDocStd::Find(DOC,a[2],L)) return 1;
133 if (!DDocStd::Find(XDOC,a[4],XL)) return 1;
134 TDocStd_XLinkTool XLinkTool;
135 XLinkTool.CopyWithLink(L,XL);
136 if (!XLinkTool.IsDone()) {
137 di << "DDocStd_CopyWithLink : not done\n";
141 di << "DDocStd_CopyWithLink : Error\n";
145 //=======================================================================
146 //function : UpdateLink (D,[xrefentry])
147 //=======================================================================
149 static Standard_Integer DDocStd_UpdateLink (Draw_Interpretor& di,Standard_Integer nb, const char** a)
151 if (nb == 2 || nb == 3) {
152 Handle(TDocStd_Document) DOC;
153 if (!DDocStd::GetDocument(a[1],DOC)) return 1;
154 Handle(TDF_Reference) REF;
155 TDocStd_XLinkTool XLinkTool;
157 if (!DDocStd::Find(DOC,a[2],TDF_Reference::GetID(),REF)) return 1;
158 XLinkTool.UpdateLink(REF->Label());
159 if (!XLinkTool.IsDone()) {
160 di << "DDocStd_UpdateXLink : not done\n";
164 for (TDocStd_XLinkIterator xit (DOC); xit.More(); xit.Next()) {
165 XLinkTool.UpdateLink(xit.Value()->Label());
166 if (!XLinkTool.IsDone()) {
167 di << "DDocStd_UpdateXLink : not done\n";
173 di << "DDocStd_UpdateXLink : Error\n";
177 //=======================================================================
178 //function : UndoLimit
180 //=======================================================================
182 static Standard_Integer DDocStd_UndoLimit (Draw_Interpretor& di,Standard_Integer n, const char** a)
186 Handle(TDocStd_Document) D;
187 if (!DDocStd::GetDocument(a[1],D)) return 1;
190 Standard_Integer lim = Draw::Atoi(a[2]);
191 D->SetUndoLimit(lim);
194 // display current values
195 di << D->GetUndoLimit() << " ";
196 di << D->GetAvailableUndos() << " ";
197 di << D->GetAvailableRedos();
201 //=======================================================================
202 //function : Undo, Redo
203 //purpose : Undo (DOC)
204 //=======================================================================
206 static Standard_Integer DDocStd_Undo (Draw_Interpretor& di,Standard_Integer n, const char** a)
210 Handle(TDocStd_Document) D;
211 if (!DDocStd::GetDocument(a[1],D)) return 1;
213 Standard_Integer i,step = 1;
215 step = Draw::Atoi(a[2]);
218 // test if the command was undo or redo
219 Standard_Boolean undo = a[0][0] == 'U';
221 for (i = 1; i <= step; i++) {
223 if (!D->Undo()) di << "Undo not done\n";
226 if (!D->Redo()) di << "Redo not done\n";
233 //=======================================================================
234 //function : NewCommand
236 //=======================================================================
238 static Standard_Integer DDocStd_NewCommand(Draw_Interpretor& /*di*/,Standard_Integer n, const char** a)
241 Handle(TDocStd_Document) D;
242 if (!DDocStd::GetDocument(a[1],D)) return 1;
247 //=======================================================================
248 //function : OpenCommand
250 //=======================================================================
252 static Standard_Integer DDocStd_OpenCommand(Draw_Interpretor& /*di*/,Standard_Integer n, const char** a)
256 Handle(TDocStd_Document) D;
257 if (!DDocStd::GetDocument(a[1],D)) return 1;
262 //=======================================================================
263 //function : AbortCommand
265 //=======================================================================
267 static Standard_Integer DDocStd_AbortCommand(Draw_Interpretor& /*di*/,Standard_Integer n, const char** a)
270 Handle(TDocStd_Document) D;
271 if (!DDocStd::GetDocument(a[1],D)) return 1;
276 //=======================================================================
277 //function : CommitCommand
279 //=======================================================================
281 static Standard_Integer DDocStd_CommitCommand(Draw_Interpretor& /*di*/,Standard_Integer n, const char** a)
284 Handle(TDocStd_Document) D;
285 if (!DDocStd::GetDocument(a[1],D)) return 1;
291 //=======================================================================
292 //function : DDocStd_DumpDocument
293 //purpose : DumpDocument (DOC)
294 //=======================================================================
296 static Standard_Integer DDocStd_DumpDocument (Draw_Interpretor& di,
301 Handle(TDocStd_Document) D;
302 if (!DDocStd::GetDocument(arg[1],D)) return 1;
306 di << "DOCUMENT : " << TCollection_AsciiString(D->GetName(),'?').ToCString();
308 di << "DOCUMENT : not saved";
311 //cout << "FORMAT : " << D->StorageFormat();
313 Standard_SStream aStream;
314 D->StorageFormat().Print(aStream);
319 if (D->HasOpenCommand()) di << " Is Open";
320 else di << " Is Not Open";
323 di << " limit :" << D->GetUndoLimit();
324 di << " undos :" << D->GetAvailableUndos() << " ";
325 di << " redos :" << D->GetAvailableRedos();
327 // cout << "CURRENT :";
328 // TCollection_AsciiString string;
329 // TDF_Tool::Entry(D->CurrentLabel(),string);
334 if (D->IsModified()) di << "true";
337 if (!TDocStd_Modified::IsEmpty(D->Main())) {
338 di << "MODIFICATIONS : ";
339 TDF_MapIteratorOfLabelMap it (D->GetModified());
340 if (!it.More()) di << "VALID\n";
342 TCollection_AsciiString string;
343 for (;it.More();it.Next()) {
344 TDF_Tool::Entry(it.Key(),string);
345 di << string.ToCString() << " ";
352 di << "DDocStd_DumpDocument : Error\n";
356 //=======================================================================
357 //function : SetModified
358 //purpose : Set modifications in a document
359 //=======================================================================
361 static Standard_Integer DDocStd_SetModified (Draw_Interpretor& di,Standard_Integer n, const char** a)
364 Handle(TDocStd_Document) D;
365 if (!DDocStd::GetDocument(a[1],D)) return 1;
367 for (Standard_Integer i = 2; i < n; i++) {
368 if (DDocStd::Find(D,a[i],L)) D->SetModified(L);
372 di << "DDocStd_SetModified : Error\n";
376 //=======================================================================
377 //function : Propagate
379 //=======================================================================
381 static Standard_Integer DDocStd_Propagate (Draw_Interpretor& di,Standard_Integer /*n*/, const char** /*a*/)
384 // Handle(TDocStd_Document) D;
385 // if (!DDocStd::GetDocument(a[1],D)) return 1;
386 // if (D->IsValid()) {
387 // cout << "the document is valid" << endl;
390 // Handle(TDesign_Function) F;
391 // if (!D->Main().FindAttribute(TDesign_Function::GetID(),F)) {
392 // cout << "no function found at main" << endl;
395 // TFunction_Logbook mdf (Standard_True);
396 // for (TDF_MapIteratorOfLabelMap it (D->GetModified());it.More();it.Next()) {
397 // mdf.SetTouched(it.Key());
400 // D->PurgeModified();
403 di << "DDocStd_Propagate : not implemented\n";
407 //=======================================================================
408 //function : DocumentCommands
410 //=======================================================================
412 void DDocStd::DocumentCommands(Draw_Interpretor& theCommands)
415 static Standard_Boolean done = Standard_False;
417 done = Standard_True;
420 const char* g = "DDocStd commands";
422 // Data Framework Access
424 theCommands.Add("Main","Main (DOC)",
425 __FILE__, DDocStd_Main, g);
430 theCommands.Add ("Format",
431 "Format (DOC, [format])",
432 __FILE__, DDocStd_Format, g);
434 theCommands.Add ("DumpDocument",
435 "DumpDocument (DOC)",
436 __FILE__, DDocStd_DumpDocument, g);
440 theCommands.Add("Copy","Copy DOC entry XDOC xentry",
441 __FILE__, DDocStd_Copy, g);
443 theCommands.Add("CopyWithLink","CopyWithLink DOC entry XDOC xentry",
444 __FILE__, DDocStd_CopyWithLink, g);
446 theCommands.Add("UpdateLink","UpdateLink DOC [entry]",
447 __FILE__, DDocStd_UpdateLink, g);
452 theCommands.Add("UndoLimit","UndoLimit DOC (Value), return UndoLimit Undos Redos",
453 __FILE__, DDocStd_UndoLimit, g);
455 theCommands.Add("Undo","Undo DOC (steps = 1)",
456 __FILE__, DDocStd_Undo, g);
458 theCommands.Add("Redo","Redo DOC (steps = 1)",
459 __FILE__, DDocStd_Undo, g);
461 theCommands.Add("NewCommand","NewCommand DOC",
462 __FILE__, DDocStd_NewCommand, g);
464 theCommands.Add("OpenCommand","OpenCommand DOC",
465 __FILE__, DDocStd_OpenCommand, g);
467 theCommands.Add("AbortCommand","AbortCommand DOC",
468 __FILE__, DDocStd_AbortCommand, g);
470 theCommands.Add("CommitCommand","CommitCommand DOC",
471 __FILE__, DDocStd_CommitCommand, g);
474 // Modif and Propagation
476 theCommands.Add("SetModified","SetModified DOC Label1 Label2 ....",
477 __FILE__, DDocStd_SetModified, g);
479 theCommands.Add("Propagate","Propagate DOC",
480 __FILE__, DDocStd_Propagate, g);