1 // Created on: 2000-03-01
2 // Created by: Denis PASCAL
3 // Copyright (c) 2000-2012 OPEN CASCADE SAS
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.
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.
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.
22 #include <DDocStd.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>
40 #include <Draw_Interpretor.hxx>
41 #include <TDF_MapIteratorOfLabelMap.hxx>
43 #include <TCollection_ExtendedString.hxx>
44 #include <TDF_Tool.hxx>
45 #include <TDF_ChildIterator.hxx>
46 #include <TDF_Tool.hxx>
48 #include <TDocStd_XLinkTool.hxx>
50 #include <OSD_Function.hxx>
51 #include <OSD_SharedLibrary.hxx>
52 #include <OSD_LoadMode.hxx>
54 //typedef Standard_Integer (* DFBROWSER_CALL)(const Handle(TDocStd_Document)&);
55 //static DFBROWSER_CALL gDFunc = 0;
57 //=======================================================================
59 //purpose : Main (DOC)
60 //=======================================================================
62 static Standard_Integer DDocStd_Main (Draw_Interpretor& di,Standard_Integer nb, const char** a)
65 Handle(TDocStd_Document) DOC;
66 if (!DDocStd::GetDocument(a[1],DOC)) return 1;
67 DDocStd::ReturnLabel(di,DOC->Main());
70 di << "DDocStd_Main : Error" << "\n";
75 //=======================================================================
78 //=======================================================================
80 static Standard_Integer DDocStd_Format (Draw_Interpretor& di,Standard_Integer n, const char** a)
82 Handle(TDocStd_Document) D;
84 if (!DDocStd::GetDocument(a[1],D)) return 1;
85 //cout << "FORMAT : " << D->StorageFormat() << endl;
87 Standard_SStream aStream;
88 D->StorageFormat().Print(aStream);
94 if (!DDocStd::GetDocument(a[1],D)) return 1;
95 D->ChangeStorageFormat(a[2]);
98 di << "DDocStd_Format : Error" << "\n";
102 //=======================================================================
103 //function : Copy "Copy DOC entry XDOC xentry",
104 //=======================================================================
106 static Standard_Integer DDocStd_Copy (Draw_Interpretor& di,Standard_Integer n, const char** a)
109 Handle(TDocStd_Document) DOC, XDOC;
110 if (!DDocStd::GetDocument(a[1],DOC)) return 1;
111 if (!DDocStd::GetDocument(a[3],XDOC)) return 1;
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";
122 di << "DDocStd_XLinkTool : Error" << "\n";
127 //=======================================================================
128 //function : CopyWithLink "Copy DOC entry XDOC xentry",
129 //=======================================================================
131 static Standard_Integer DDocStd_CopyWithLink (Draw_Interpretor& di,Standard_Integer n, const char** a)
134 Handle(TDocStd_Document) DOC, XDOC;
135 if (!DDocStd::GetDocument(a[1],DOC)) return 1;
136 if (!DDocStd::GetDocument(a[3],XDOC)) return 1;
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";
147 di << "DDocStd_CopyWithLink : Error" << "\n";
151 //=======================================================================
152 //function : UpdateLink (D,[xrefentry])
153 //=======================================================================
155 static Standard_Integer DDocStd_UpdateLink (Draw_Interpretor& di,Standard_Integer nb, const char** a)
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;
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";
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";
179 di << "DDocStd_UpdateXLink : Error" << "\n";
183 //=======================================================================
184 //function : UndoLimit
186 //=======================================================================
188 static Standard_Integer DDocStd_UndoLimit (Draw_Interpretor& di,Standard_Integer n, const char** a)
192 Handle(TDocStd_Document) D;
193 if (!DDocStd::GetDocument(a[1],D)) return 1;
196 Standard_Integer lim = atoi(a[2]);
197 D->SetUndoLimit(lim);
200 // display current values
201 di << D->GetUndoLimit() << " ";
202 di << D->GetAvailableUndos() << " ";
203 di << D->GetAvailableRedos();
207 //=======================================================================
208 //function : Undo, Redo
209 //purpose : Undo (DOC)
210 //=======================================================================
212 static Standard_Integer DDocStd_Undo (Draw_Interpretor& di,Standard_Integer n, const char** a)
216 Handle(TDocStd_Document) D;
217 if (!DDocStd::GetDocument(a[1],D)) return 1;
219 Standard_Integer i,step = 1;
224 // test if the command was undo or redo
225 Standard_Boolean undo = a[0][0] == 'U';
227 for (i = 1; i <= step; i++) {
229 if (!D->Undo()) di << "Undo not done" << "\n";
232 if (!D->Redo()) di << "Redo not done" << "\n";
239 //=======================================================================
240 //function : NewCommand
242 //=======================================================================
244 static Standard_Integer DDocStd_NewCommand(Draw_Interpretor& /*di*/,Standard_Integer n, const char** a)
247 Handle(TDocStd_Document) D;
248 if (!DDocStd::GetDocument(a[1],D)) return 1;
253 //=======================================================================
254 //function : OpenCommand
256 //=======================================================================
258 static Standard_Integer DDocStd_OpenCommand(Draw_Interpretor& /*di*/,Standard_Integer n, const char** a)
262 Handle(TDocStd_Document) D;
263 if (!DDocStd::GetDocument(a[1],D)) return 1;
268 //=======================================================================
269 //function : AbortCommand
271 //=======================================================================
273 static Standard_Integer DDocStd_AbortCommand(Draw_Interpretor& /*di*/,Standard_Integer n, const char** a)
276 Handle(TDocStd_Document) D;
277 if (!DDocStd::GetDocument(a[1],D)) return 1;
282 //=======================================================================
283 //function : CommitCommand
285 //=======================================================================
287 static Standard_Integer DDocStd_CommitCommand(Draw_Interpretor& /*di*/,Standard_Integer n, const char** a)
290 Handle(TDocStd_Document) D;
291 if (!DDocStd::GetDocument(a[1],D)) return 1;
297 //=======================================================================
298 //function : DDocStd_DumpDocument
299 //purpose : DumpDocument (DOC)
300 //=======================================================================
302 static Standard_Integer DDocStd_DumpDocument (Draw_Interpretor& di,
307 Handle(TDocStd_Document) D;
308 if (!DDocStd::GetDocument(arg[1],D)) return 1;
312 di << "DOCUMENT : " << TCollection_AsciiString(D->GetName(),'?').ToCString();
314 di << "DOCUMENT : " << "not saved";
317 //cout << "FORMAT : " << D->StorageFormat();
319 Standard_SStream aStream;
320 D->StorageFormat().Print(aStream);
325 if (D->HasOpenCommand()) di << " Is Open";
327 else di << " Is Not Open";
329 else " Is Not Open"; // ???
333 di << " limit :" << D->GetUndoLimit();
334 di << " undos :" << D->GetAvailableUndos() << " ";
335 di << " redos :" << D->GetAvailableRedos();
337 // cout << "CURRENT :";
338 // TCollection_AsciiString string;
339 // TDF_Tool::Entry(D->CurrentLabel(),string);
344 if (D->IsModified()) di << "true";
347 if (!TDocStd_Modified::IsEmpty(D->Main())) {
348 di << "MODIFICATIONS : ";
349 TDF_MapIteratorOfLabelMap it (D->GetModified());
350 if (!it.More()) di << "VALID" << "\n";
352 TCollection_AsciiString string;
353 for (;it.More();it.Next()) {
354 TDF_Tool::Entry(it.Key(),string);
355 di << string.ToCString() << " ";
362 di << "DDocStd_DumpDocument : Error" << "\n";
366 //=======================================================================
367 //function : SetModified
368 //purpose : Set modifications in a document
369 //=======================================================================
371 static Standard_Integer DDocStd_SetModified (Draw_Interpretor& di,Standard_Integer n, const char** a)
374 Handle(TDocStd_Document) D;
375 if (!DDocStd::GetDocument(a[1],D)) return 1;
377 for (Standard_Integer i = 2; i < n; i++) {
378 if (DDocStd::Find(D,a[i],L)) D->SetModified(L);
382 di << "DDocStd_SetModified : Error" << "\n";
386 //=======================================================================
387 //function : Propagate
389 //=======================================================================
391 static Standard_Integer DDocStd_Propagate (Draw_Interpretor& di,Standard_Integer /*n*/, const char** /*a*/)
394 // Handle(TDocStd_Document) D;
395 // if (!DDocStd::GetDocument(a[1],D)) return 1;
396 // if (D->IsValid()) {
397 // cout << "the document is valid" << endl;
400 // Handle(TDesign_Function) F;
401 // if (!D->Main().FindAttribute(TDesign_Function::GetID(),F)) {
402 // cout << "no function found at main" << endl;
405 // TFunction_Logbook mdf (Standard_True);
406 // for (TDF_MapIteratorOfLabelMap it (D->GetModified());it.More();it.Next()) {
407 // mdf.SetTouched(it.Key());
410 // D->PurgeModified();
413 di << "DDocStd_Propagate : not implemented" << "\n";
417 //=======================================================================
418 //function : DocumentCommands
420 //=======================================================================
422 void DDocStd::DocumentCommands(Draw_Interpretor& theCommands)
425 static Standard_Boolean done = Standard_False;
427 done = Standard_True;
430 const char* g = "DDocStd commands";
432 // Data Framework Access
434 theCommands.Add("Main","Main (DOC)",
435 __FILE__, DDocStd_Main, g);
440 theCommands.Add ("Format",
441 "Format (DOC, [format])",
442 __FILE__, DDocStd_Format, g);
444 theCommands.Add ("DumpDocument",
445 "DumpDocument (DOC)",
446 __FILE__, DDocStd_DumpDocument, g);
450 theCommands.Add("Copy","Copy DOC entry XDOC xentry",
451 __FILE__, DDocStd_Copy, g);
453 theCommands.Add("CopyWithLink","CopyWithLink DOC entry XDOC xentry",
454 __FILE__, DDocStd_CopyWithLink, g);
456 theCommands.Add("UpdateLink","UpdateLink DOC [entry]",
457 __FILE__, DDocStd_UpdateLink, g);
462 theCommands.Add("UndoLimit","UndoLimit DOC (Value), return UndoLimit Undos Redos",
463 __FILE__, DDocStd_UndoLimit, g);
465 theCommands.Add("Undo","Undo DOC (steps = 1)",
466 __FILE__, DDocStd_Undo, g);
468 theCommands.Add("Redo","Redo DOC (steps = 1)",
469 __FILE__, DDocStd_Undo, g);
471 theCommands.Add("NewCommand","NewCommand DOC",
472 __FILE__, DDocStd_NewCommand, g);
474 theCommands.Add("OpenCommand","OpenCommand DOC",
475 __FILE__, DDocStd_OpenCommand, g);
477 theCommands.Add("AbortCommand","AbortCommand DOC",
478 __FILE__, DDocStd_AbortCommand, g);
480 theCommands.Add("CommitCommand","CommitCommand DOC",
481 __FILE__, DDocStd_CommitCommand, g);
484 // Modif and Propagation
486 theCommands.Add("SetModified","SetModified DOC Label1 Label2 ....",
487 __FILE__, DDocStd_SetModified, g);
489 theCommands.Add("Propagate","Propagate DOC",
490 __FILE__, DDocStd_Propagate, g);