Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2000-03-01 |
2 | // Created by: Denis PASCAL | |
973c2be1 | 3 | // Copyright (c) 2000-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
7fd59977 | 15 | |
16 | #include <DDocStd.hxx> | |
7fd59977 | 17 | #include <Draw_Interpretor.hxx> |
18 | #include <Draw_Viewer.hxx> | |
6d8f9f4a | 19 | #include <Draw_ProgressIndicator.hxx> |
7fd59977 | 20 | #include <DDocStd_DrawDocument.hxx> |
21 | #include <TDocStd_Application.hxx> | |
22 | #include <TDocStd_Document.hxx> | |
23 | #include <TDataStd_Name.hxx> | |
24 | #include <Draw.hxx> | |
7fd59977 | 25 | #include <TCollection_AsciiString.hxx> |
26 | #include <TCollection_ExtendedString.hxx> | |
7fd59977 | 27 | #include <TDF_Data.hxx> |
28 | #include <TDF_ChildIterator.hxx> | |
d5c71e20 | 29 | #include <PCDM_ReaderFilter.hxx> |
7fd59977 | 30 | |
ad3f20c6 | 31 | #include <OSD_FileSystem.hxx> |
7fd59977 | 32 | #include <TDocStd_PathParser.hxx> |
7fd59977 | 33 | |
0e93d9e5 | 34 | #include <AIS_InteractiveContext.hxx> |
35 | #include <TPrsStd_AISViewer.hxx> | |
36 | #include <ViewerTest.hxx> | |
37 | #include <V3d_Viewer.hxx> | |
38 | ||
39 | #ifndef _WIN32 | |
7fd59977 | 40 | extern Draw_Viewer dout; |
41 | #else | |
42 | Standard_IMPORT Draw_Viewer dout; | |
43 | #endif | |
44 | ||
7fd59977 | 45 | //======================================================================= |
46 | //function : ListDocuments | |
47 | //purpose : | |
48 | //======================================================================= | |
49 | ||
50 | static Standard_Integer DDocStd_ListDocuments (Draw_Interpretor& di, | |
51 | Standard_Integer nb, | |
52 | const char** /*a*/) | |
53 | { | |
54 | if (nb == 1) { | |
6fe96f84 | 55 | Handle(TDocStd_Application) A = DDocStd::GetApplication(); |
7fd59977 | 56 | Handle(TDocStd_Document) D; |
57 | Standard_Integer nbdoc = A->NbDocuments(); | |
58 | for (Standard_Integer i = 1; i <= nbdoc; i++) { | |
59 | A->GetDocument(i,D); | |
60 | di <<"document " << i; | |
61 | if (D->IsSaved()) { | |
ae9f4b64 | 62 | di << " name : " << D->GetName(); |
63 | di << " path : " << D->GetPath(); | |
7fd59977 | 64 | } |
65 | else di << " not saved"; | |
66 | di << "\n"; | |
67 | } | |
68 | return 0; | |
69 | } | |
586db386 | 70 | di << "DDocStd_ListDocuments : Error\n"; |
7fd59977 | 71 | return 1; |
72 | } | |
73 | ||
74 | ||
75 | //======================================================================= | |
76 | //function : NewDocument | |
77 | //purpose : | |
78 | //======================================================================= | |
79 | ||
80 | static Standard_Integer DDocStd_NewDocument (Draw_Interpretor& di, | |
81 | Standard_Integer nb, | |
82 | const char** a) | |
83 | { | |
84 | Handle(TDocStd_Document) D; | |
85 | Handle(DDocStd_DrawDocument) DD; | |
86 | if (nb == 2) { | |
87 | if (!DDocStd::GetDocument(a[1],D,Standard_False)) { | |
88 | D = new TDocStd_Document("dummy"); | |
89 | DD = new DDocStd_DrawDocument(D); | |
90 | Draw::Set(a[1],DD); | |
586db386 | 91 | di << "document (not handled by application) " << a[1] << " created\n"; |
7fd59977 | 92 | DDocStd::ReturnLabel(di,D->Main()); |
93 | } | |
586db386 | 94 | else di << a[1] << " is already a document\n"; |
7fd59977 | 95 | return 0; |
96 | } | |
97 | if (nb == 3) { | |
98 | if (!DDocStd::GetDocument(a[1],D,Standard_False)) { | |
6fe96f84 | 99 | Handle(TDocStd_Application) A = DDocStd::GetApplication(); |
7fd59977 | 100 | A->NewDocument(a[2],D); |
101 | DD = new DDocStd_DrawDocument(D); | |
102 | TDataStd_Name::Set(D->GetData()->Root(),a[1]); | |
103 | Draw::Set(a[1],DD); | |
586db386 | 104 | di << "document " << a[1] << " created\n"; |
7fd59977 | 105 | DDocStd::ReturnLabel(di,D->Main()); |
106 | } | |
586db386 | 107 | else di << a[1] << " is already a document\n"; |
7fd59977 | 108 | return 0; |
109 | } | |
586db386 | 110 | di << "DDocStd_NewDocument : Error\n"; |
7fd59977 | 111 | return 1; |
112 | } | |
113 | ||
7fd59977 | 114 | //======================================================================= |
115 | //function : Open | |
116 | //purpose : | |
117 | //======================================================================= | |
118 | ||
119 | static Standard_Integer DDocStd_Open (Draw_Interpretor& di, | |
6d8f9f4a | 120 | Standard_Integer nb, |
121 | const char** a) | |
7fd59977 | 122 | { |
4ff92abe | 123 | if (nb >= 3) { |
94f16a89 | 124 | TCollection_ExtendedString path (a[1], Standard_True); |
d5c71e20 | 125 | Standard_CString DocName = a[2]; |
6fe96f84 | 126 | Handle(TDocStd_Application) A = DDocStd::GetApplication(); |
7fd59977 | 127 | Handle(TDocStd_Document) D; |
4ff92abe | 128 | PCDM_ReaderStatus theStatus; |
129 | ||
130 | Standard_Boolean anUseStream = Standard_False; | |
d5c71e20 | 131 | Handle(PCDM_ReaderFilter) aFilter = new PCDM_ReaderFilter; |
4ff92abe | 132 | for ( Standard_Integer i = 3; i < nb; i++ ) |
133 | { | |
d5c71e20 | 134 | TCollection_AsciiString anArg(a[i]); |
135 | if (anArg == "-append") | |
136 | { | |
137 | aFilter->Mode() = PCDM_ReaderFilter::AppendMode_Protect; | |
138 | } | |
139 | else if (anArg == "-overwrite") | |
140 | { | |
141 | aFilter->Mode() = PCDM_ReaderFilter::AppendMode_Overwrite; | |
142 | } | |
143 | else if (anArg == "-stream") | |
4ff92abe | 144 | { |
145 | di << "standard SEEKABLE stream is used\n"; | |
146 | anUseStream = Standard_True; | |
d5c71e20 | 147 | } |
148 | else if (anArg.StartsWith("-skip")) | |
149 | { | |
150 | TCollection_AsciiString anAttrType = anArg.SubString(6, anArg.Length()); | |
151 | aFilter->AddSkipped(anAttrType); | |
152 | } | |
153 | else if (anArg.StartsWith("-read")) | |
154 | { | |
155 | TCollection_AsciiString aValue = anArg.SubString(6, anArg.Length()); | |
156 | if (aValue.Value(1) == '0') // path | |
157 | { | |
158 | aFilter->AddPath(aValue); | |
159 | } | |
160 | else // attribute to read | |
161 | { | |
162 | aFilter->AddRead(aValue); | |
163 | } | |
4ff92abe | 164 | } |
165 | } | |
166 | ||
d5c71e20 | 167 | if (aFilter->IsAppendMode() && !DDocStd::GetDocument(DocName, D, Standard_False)) |
168 | { | |
169 | di << "for append mode document " << DocName << " must be already created\n"; | |
170 | return 1; | |
171 | } | |
6d8f9f4a | 172 | Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(di, 1); |
4ff92abe | 173 | if (anUseStream) |
174 | { | |
ad3f20c6 | 175 | const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); |
65acdce5 | 176 | std::shared_ptr<std::istream> aFileStream = aFileSystem->OpenIStream (path, std::ios::in | std::ios::binary); |
4ff92abe | 177 | |
ad3f20c6 | 178 | theStatus = A->Open (*aFileStream, D, aFilter, aProgress->Start()); |
4ff92abe | 179 | } |
180 | else | |
181 | { | |
d5c71e20 | 182 | theStatus = A->Open (path, D, aFilter , aProgress->Start()); |
4ff92abe | 183 | } |
6d8f9f4a | 184 | if (theStatus == PCDM_RS_OK && !D.IsNull()) |
185 | { | |
d5c71e20 | 186 | if (!aFilter->IsAppendMode()) |
187 | { | |
188 | Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument (D); | |
189 | TDataStd_Name::Set (D->GetData()->Root(), DocName); | |
190 | Draw::Set (DocName, DD); | |
191 | } | |
7fd59977 | 192 | return 0; |
6d8f9f4a | 193 | } |
194 | else | |
195 | { | |
7fd59977 | 196 | switch ( theStatus ) { |
6d8f9f4a | 197 | case PCDM_RS_UserBreak: { |
198 | di << " could not retrieve , user break \n"; | |
199 | break; | |
200 | } | |
15e8b082 M |
201 | case PCDM_RS_AlreadyRetrieved: |
202 | case PCDM_RS_AlreadyRetrievedAndModified: { | |
6d8f9f4a | 203 | di << " already retrieved \n" ; |
204 | break; | |
7fd59977 | 205 | } |
15e8b082 | 206 | case PCDM_RS_NoDriver: { |
6d8f9f4a | 207 | di << " could not retrieve , no Driver to make it \n" ; |
208 | break ; | |
7fd59977 | 209 | } |
15e8b082 M |
210 | case PCDM_RS_UnknownDocument: |
211 | case PCDM_RS_NoModel: { | |
6d8f9f4a | 212 | di << " could not retrieve , Unknown Document or No Model \n"; |
213 | break ; | |
7fd59977 | 214 | } |
15e8b082 M |
215 | case PCDM_RS_TypeNotFoundInSchema: |
216 | case PCDM_RS_UnrecognizedFileFormat: { | |
6d8f9f4a | 217 | di << " could not retrieve , Type not found or Unrecognized File Format\n"; |
218 | break ; | |
7fd59977 | 219 | } |
15e8b082 | 220 | case PCDM_RS_PermissionDenied: { |
6d8f9f4a | 221 | di << " could not retrieve , permission denied \n" ; |
222 | break; | |
7fd59977 | 223 | } |
15e8b082 | 224 | default: |
6d8f9f4a | 225 | di << " could not retrieve \n" ; |
226 | break; | |
7fd59977 | 227 | } |
586db386 | 228 | di << "DDocStd_Open : Error\n"; |
6d8f9f4a | 229 | } |
7fd59977 | 230 | } |
231 | return 1; | |
232 | } | |
233 | ||
234 | //======================================================================= | |
235 | //function : Save | |
236 | //purpose : | |
237 | //======================================================================= | |
238 | ||
239 | static Standard_Integer DDocStd_Save (Draw_Interpretor& di, | |
6d8f9f4a | 240 | Standard_Integer nb, |
241 | const char** a) | |
7fd59977 | 242 | { |
243 | if (nb == 2) { | |
244 | Handle(TDocStd_Document) D; | |
245 | if (!DDocStd::GetDocument(a[1],D)) return 1; | |
6fe96f84 | 246 | Handle(TDocStd_Application) A = DDocStd::GetApplication(); |
7fd59977 | 247 | if (!D->IsSaved()) { |
586db386 | 248 | di << "this document has never been saved\n"; |
7fd59977 | 249 | return 0; |
250 | } | |
6d8f9f4a | 251 | |
252 | Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(di, 1); | |
7e785937 | 253 | A->Save (D, aProgress->Start()); |
7fd59977 | 254 | return 0; |
255 | } | |
586db386 | 256 | di << "DDocStd_Save : Error\n"; |
7fd59977 | 257 | return 1; |
258 | } | |
259 | ||
260 | //======================================================================= | |
261 | //function : SaveAs | |
262 | //purpose : | |
263 | //======================================================================= | |
264 | ||
265 | static Standard_Integer DDocStd_SaveAs (Draw_Interpretor& di, | |
030ba648 | 266 | Standard_Integer nb, |
267 | const char** a) | |
268 | { | |
4ff92abe | 269 | if (nb >= 3) { |
7fd59977 | 270 | Handle(TDocStd_Document) D; |
271 | if (!DDocStd::GetDocument(a[1],D)) return 1; | |
94f16a89 | 272 | TCollection_ExtendedString path (a[2], Standard_True); |
6fe96f84 | 273 | Handle(TDocStd_Application) A = DDocStd::GetApplication(); |
4ff92abe | 274 | PCDM_StoreStatus theStatus; |
030ba648 | 275 | |
276 | Standard_Boolean anUseStream(Standard_False), isSaveEmptyLabels(Standard_False); | |
4ff92abe | 277 | for ( Standard_Integer i = 3; i < nb; i++ ) |
278 | { | |
279 | if (!strcmp (a[i], "-stream")) | |
280 | { | |
281 | di << "standard SEEKABLE stream is used\n"; | |
282 | anUseStream = Standard_True; | |
283 | break; | |
030ba648 | 284 | } else { |
285 | isSaveEmptyLabels = ((atoi (a[3])) != 0); | |
286 | D->SetEmptyLabelsSavingMode(isSaveEmptyLabels); | |
4ff92abe | 287 | } |
288 | } | |
6d8f9f4a | 289 | |
290 | Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(di, 1); | |
4ff92abe | 291 | if (anUseStream) |
292 | { | |
27e64adb | 293 | const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem(); |
65acdce5 | 294 | std::shared_ptr<std::ostream> aFileStream = aFileSystem->OpenOStream (path, std::ios::out | std::ios::binary); |
27e64adb | 295 | theStatus = A->SaveAs (D, *aFileStream, aProgress->Start()); |
4ff92abe | 296 | } |
297 | else | |
298 | { | |
7e785937 | 299 | theStatus = A->SaveAs(D,path, aProgress->Start()); |
4ff92abe | 300 | } |
030ba648 | 301 | |
15e8b082 | 302 | if (theStatus != PCDM_SS_OK ) { |
7fd59977 | 303 | switch ( theStatus ) { |
030ba648 | 304 | case PCDM_SS_DriverFailure: { |
305 | di << "Error saving document: Could not store , no driver found to make it\n"; | |
306 | break ; | |
307 | } | |
308 | case PCDM_SS_WriteFailure: { | |
309 | di << "Error saving document: Write access failure\n"; | |
310 | break; | |
311 | } | |
312 | case PCDM_SS_Failure: { | |
313 | di << "Error saving document: Write failure\n" ; | |
314 | break; | |
315 | } | |
316 | case PCDM_SS_Doc_IsNull: { | |
317 | di << "Error saving document: No document to save\n"; | |
318 | break ; | |
319 | } | |
320 | case PCDM_SS_No_Obj: { | |
321 | di << "Error saving document: No objects written\n"; | |
322 | break; | |
323 | } | |
324 | case PCDM_SS_Info_Section_Error: { | |
325 | di << "Error saving document: Write info section failure\n" ; | |
326 | break; | |
327 | } | |
6d8f9f4a | 328 | case PCDM_SS_UserBreak: { |
329 | di << "Error saving document: User break \n" ; | |
330 | break; | |
331 | } | |
030ba648 | 332 | default: |
333 | break; | |
7fd59977 | 334 | } |
335 | return 1; | |
336 | } else { | |
337 | return 0; | |
338 | } | |
339 | } | |
586db386 | 340 | di << "DDocStd_SaveAs : Error not enough argument\n"; |
7fd59977 | 341 | return 1; |
342 | } | |
343 | ||
344 | //======================================================================= | |
345 | //function : Close | |
346 | //purpose : | |
347 | //======================================================================= | |
348 | ||
d99f0355 | 349 | static Standard_Integer DDocStd_Close (Draw_Interpretor& theDI, |
0e93d9e5 | 350 | Standard_Integer theArgNb, |
351 | const char** theArgVec) | |
7fd59977 | 352 | { |
395d00e0 | 353 | bool toComplain = true; |
354 | NCollection_List<TCollection_AsciiString> aDocNames; | |
355 | for (Standard_Integer anArgIt = 1; anArgIt < theArgNb; ++anArgIt) | |
0e93d9e5 | 356 | { |
395d00e0 | 357 | const TCollection_AsciiString anArg (theArgVec[anArgIt]); |
358 | TCollection_AsciiString anArgCase (anArg); | |
359 | anArgCase.LowerCase(); | |
360 | if (anArgCase == "*" | |
361 | || anArgCase == "-all" | |
362 | || anArgCase == "all") | |
363 | { | |
364 | for (NCollection_Map<Handle(Draw_Drawable3D)>::Iterator anIter (Draw::Drawables()); | |
365 | anIter.More(); anIter.Next()) | |
366 | { | |
367 | if (Handle(DDocStd_DrawDocument) aDrawDocument = Handle(DDocStd_DrawDocument)::DownCast (anIter.Value())) | |
368 | { | |
369 | aDocNames.Append (aDrawDocument->Name()); | |
370 | } | |
371 | } | |
372 | if (aDocNames.IsEmpty()) | |
373 | { | |
374 | return 0; | |
375 | } | |
376 | } | |
377 | else if (anArgCase == "-silent") | |
378 | { | |
379 | toComplain = false; | |
380 | } | |
381 | else | |
382 | { | |
383 | aDocNames.Append (anArg); | |
384 | } | |
0e93d9e5 | 385 | } |
24de79c3 | 386 | |
395d00e0 | 387 | if (aDocNames.IsEmpty()) |
0e93d9e5 | 388 | { |
395d00e0 | 389 | theDI << "Syntax error: wrong number of arguments"; |
0e93d9e5 | 390 | return 1; |
7fd59977 | 391 | } |
0e93d9e5 | 392 | |
395d00e0 | 393 | Handle(TDocStd_Application) aDocApp = DDocStd::GetApplication(); |
394 | for (NCollection_List<TCollection_AsciiString>::Iterator aDocNameIter (aDocNames); | |
395 | aDocNameIter.More(); aDocNameIter.Next()) | |
0e93d9e5 | 396 | { |
395d00e0 | 397 | Standard_CString aDocName = aDocNameIter.Value().ToCString(); |
398 | Handle(TDocStd_Document) aDoc; | |
399 | if (DDocStd::GetDocument (aDocName, aDoc, toComplain)) | |
0e93d9e5 | 400 | { |
395d00e0 | 401 | TDF_Label aRoot = aDoc->GetData()->Root(); |
402 | Handle(TPrsStd_AISViewer) aDocViewer; | |
403 | if (TPrsStd_AISViewer::Find (aRoot, aDocViewer) | |
404 | && !aDocViewer->GetInteractiveContext().IsNull()) | |
405 | { | |
406 | Handle(V3d_Viewer) aViewer = aDocViewer->GetInteractiveContext()->CurrentViewer(); | |
407 | V3d_ListOfView aViews; | |
408 | for (V3d_ListOfViewIterator aViewIter (aDocViewer->GetInteractiveContext()->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next()) | |
409 | { | |
410 | aViews.Append (aViewIter.Value()); | |
411 | } | |
412 | for (V3d_ListOfViewIterator aViewIter (aViews); aViewIter.More(); aViewIter.Next()) | |
413 | { | |
414 | Handle(V3d_View) aView = aViewIter.Value(); | |
415 | ViewerTest::RemoveView (aView); | |
416 | } | |
417 | } | |
418 | aDocApp->Close (aDoc); | |
6a24c6de | 419 | } |
395d00e0 | 420 | else if (toComplain) |
6a24c6de | 421 | { |
395d00e0 | 422 | return 1; |
0e93d9e5 | 423 | } |
0e93d9e5 | 424 | |
395d00e0 | 425 | if (Handle(Draw_Drawable3D) aDrawable = Draw::GetExisting (aDocName)) |
426 | { | |
427 | dout.RemoveDrawable (aDrawable); | |
428 | } | |
429 | Draw::Set (aDocName, Handle(Draw_Drawable3D)()); | |
1c8fc6be | 430 | } |
0e93d9e5 | 431 | return 0; |
7fd59977 | 432 | } |
433 | ||
434 | //======================================================================= | |
435 | //function : IsInSession | |
436 | //purpose : | |
437 | //======================================================================= | |
438 | ||
439 | static Standard_Integer DDocStd_IsInSession (Draw_Interpretor& di, | |
440 | Standard_Integer nb, | |
441 | const char** a) | |
442 | { | |
443 | if (nb == 2) { | |
6fe96f84 | 444 | Handle(TDocStd_Application) A = DDocStd::GetApplication(); |
7fd59977 | 445 | di << A->IsInSession(a[1]); |
446 | return 0; | |
447 | } | |
586db386 | 448 | di << "DDocStd_IsInSession : Error\n"; |
7fd59977 | 449 | return 1; |
450 | } | |
451 | ||
452 | ||
453 | //======================================================================= | |
454 | //function : OSDPath | |
455 | //purpose : | |
456 | //======================================================================= | |
457 | ||
458 | static Standard_Integer DDocStd_OSDPath (Draw_Interpretor& di, | |
459 | Standard_Integer nb, | |
460 | const char** a) | |
461 | { | |
462 | if (nb == 2) { | |
463 | OSD_Path path (a[1]); | |
464 | di << "Node : " << path.Node().ToCString() << "\n"; | |
465 | di << "UserName : " << path.UserName().ToCString() << "\n"; | |
466 | di << "Password : " << path.Password().ToCString() << "\n"; | |
467 | di << "Disk : " << path.Disk().ToCString() << "\n"; | |
468 | di << "Trek : " << path.Trek().ToCString() << "\n"; | |
469 | di << "Name : " << path.Name().ToCString() << "\n"; | |
470 | di << "Extension : " << path.Extension().ToCString() << "\n"; | |
471 | return 0; | |
472 | } | |
586db386 | 473 | di << "DDocStd_OSDPath : Error\n"; |
7fd59977 | 474 | return 1; |
475 | } | |
476 | ||
477 | ||
478 | //======================================================================= | |
479 | //function : Path | |
480 | //purpose : | |
481 | //======================================================================= | |
482 | ||
483 | static Standard_Integer DDocStd_Path (Draw_Interpretor& di, | |
484 | Standard_Integer nb, | |
485 | const char** a) | |
486 | { | |
487 | if (nb == 2) { | |
94f16a89 | 488 | TDocStd_PathParser path (TCollection_ExtendedString (a[1], Standard_True)); |
ae9f4b64 | 489 | di << "Trek : " << path.Trek() << "\n"; |
490 | di << "Name : " << path.Name() << "\n"; | |
491 | di << "Extension : " << path.Extension() << "\n"; | |
492 | di << "Path : " << path.Path() << "\n"; | |
7fd59977 | 493 | return 0; |
494 | } | |
586db386 | 495 | di << "DDocStd_Path : Error\n"; |
7fd59977 | 496 | return 1; |
497 | } | |
498 | ||
499 | //======================================================================= | |
500 | //function : AddComment | |
501 | //purpose : | |
502 | //======================================================================= | |
503 | static Standard_Integer DDocStd_AddComment (Draw_Interpretor& di, | |
504 | Standard_Integer nb, | |
505 | const char** a) | |
506 | { | |
507 | if (nb == 3) { | |
508 | Handle(TDocStd_Document) D; | |
509 | if (!DDocStd::GetDocument(a[1],D)) return 1; | |
94f16a89 | 510 | TCollection_ExtendedString comment (a[2], Standard_True); |
6fe96f84 | 511 | // Handle(TDocStd_Application) A = DDocStd::GetApplication(); |
7fd59977 | 512 | // A->AddComment(D,comment); |
513 | D->AddComment(comment); | |
514 | return 0; | |
515 | } | |
586db386 | 516 | di << "DDocStd_AddComment : Wrong arguments number\n"; |
7fd59977 | 517 | return 1; |
518 | } | |
519 | ||
520 | //======================================================================= | |
521 | //function : PrintComments | |
522 | //purpose : | |
523 | //======================================================================= | |
524 | static Standard_Integer DDocStd_PrintComments (Draw_Interpretor& di, | |
525 | Standard_Integer nb, | |
526 | const char** a) | |
527 | { | |
528 | if (nb == 2) { | |
529 | Handle(TDocStd_Document) D; | |
530 | if (!DDocStd::GetDocument(a[1],D)) return 1; | |
531 | ||
532 | TColStd_SequenceOfExtendedString comments; | |
533 | D->Comments(comments); | |
534 | ||
535 | for (int i = 1; i <= comments.Length(); i++) | |
536 | { | |
ae9f4b64 | 537 | di << comments(i) << "\n"; |
7fd59977 | 538 | } |
539 | ||
540 | return 0; | |
541 | } | |
586db386 | 542 | di << "DDocStd_PrintComments : Wrong arguments number\n"; |
7fd59977 | 543 | return 1; |
544 | } | |
545 | ||
c2f5b821 | 546 | //======================================================================= |
c1638a8d | 547 | //function : DDocStd_StorageFormatVersion |
548 | //purpose : | |
c2f5b821 | 549 | //======================================================================= |
c1638a8d | 550 | static Standard_Integer DDocStd_StorageFormatVersion (Draw_Interpretor& theDI, |
551 | Standard_Integer theNbArgs, | |
552 | const char** theArgVec) | |
c2f5b821 | 553 | { |
c1638a8d | 554 | if (theNbArgs != 2 |
555 | && theNbArgs != 3) | |
c2f5b821 | 556 | { |
c1638a8d | 557 | theDI << "Syntax error: wrong number of arguments"; |
558 | return 1; | |
c2f5b821 | 559 | } |
c2f5b821 | 560 | |
c1638a8d | 561 | Handle(TDocStd_Document) aDoc; |
562 | if (!DDocStd::GetDocument (theArgVec[1], aDoc)) | |
563 | { | |
564 | theDI << "Syntax error: " << theArgVec[1] << " is not a document"; | |
565 | return 1; | |
566 | } | |
567 | ||
568 | if (theNbArgs == 2) | |
569 | { | |
570 | theDI << aDoc->StorageFormatVersion() << "\n"; | |
b34d86cb | 571 | return 0; |
572 | } | |
c1638a8d | 573 | |
574 | Standard_Integer aVerInt = 0; | |
575 | if (!Draw::ParseInteger (theArgVec[2], aVerInt) | |
576 | || aVerInt < TDocStd_FormatVersion_LOWER | |
577 | || aVerInt > TDocStd_FormatVersion_UPPER) | |
578 | { | |
579 | theDI << "Syntax error: unknown version '" << theArgVec[2] << "' (valid range is " << TDocStd_FormatVersion_LOWER << ".." << TDocStd_FormatVersion_UPPER << ")"; | |
580 | return 1; | |
581 | } | |
582 | ||
583 | aDoc->ChangeStorageFormatVersion ((TDocStd_FormatVersion )aVerInt); | |
584 | return 0; | |
c2f5b821 | 585 | } |
586 | ||
7fd59977 | 587 | //======================================================================= |
588 | //function : ApplicationCommands | |
589 | //purpose : | |
590 | //======================================================================= | |
591 | ||
592 | void DDocStd::ApplicationCommands(Draw_Interpretor& theCommands) | |
593 | { | |
594 | ||
595 | static Standard_Boolean done = Standard_False; | |
596 | if (done) return; | |
597 | done = Standard_True; | |
598 | ||
599 | const char* g = "DDocStd application commands"; | |
600 | ||
601 | // user application commands | |
7fd59977 | 602 | theCommands.Add("ListDocuments", |
603 | "ListDocuments", | |
604 | __FILE__, DDocStd_ListDocuments, g); | |
605 | ||
606 | theCommands.Add("NewDocument", | |
607 | "NewDocument docname format", | |
608 | __FILE__, DDocStd_NewDocument, g); | |
609 | ||
7fd59977 | 610 | theCommands.Add("Open", |
d5c71e20 | 611 | "Open path docname [-stream] [-skipAttribute] [-readAttribute] [-readPath] [-append|-overwrite]" |
612 | "\n\t\t The options are:" | |
613 | "\n\t\t -stream : opens path as a stream" | |
614 | "\n\t\t -skipAttribute : class name of the attribute to skip during open, for example -skipTDF_Reference" | |
615 | "\n\t\t -readAttribute : class name of the attribute to read only during open, for example -readTDataStd_Name loads only such attributes" | |
616 | "\n\t\t -append : to read file into already existing document once again, append new attributes and don't touch existing" | |
617 | "\n\t\t -overwrite : to read file into already existing document once again, overwriting existing attributes", | |
7fd59977 | 618 | __FILE__, DDocStd_Open, g); |
619 | ||
620 | theCommands.Add("SaveAs", | |
030ba648 | 621 | "SaveAs DOC path [saveEmptyLabels: 0|1] [-stream]", |
7fd59977 | 622 | __FILE__, DDocStd_SaveAs, g); |
623 | ||
624 | theCommands.Add("Save", | |
625 | "Save", | |
626 | __FILE__, DDocStd_Save, g); | |
627 | ||
628 | theCommands.Add("Close", | |
395d00e0 | 629 | "Close the specific document or all documents\n" |
630 | "Close DOC [-silent]" | |
631 | "\n\t\t: Close the specific document." | |
632 | "\n\t\t: -silent not raise an exception or print error message for an empty document \n" | |
633 | "Close *" | |
634 | "\n\t\t: Close all open documents.", | |
7fd59977 | 635 | __FILE__, DDocStd_Close, g); |
636 | ||
637 | theCommands.Add("IsInSession", | |
638 | "IsInSession path", | |
639 | __FILE__, DDocStd_IsInSession, g); | |
640 | ||
641 | theCommands.Add("OSDPath", | |
642 | "OSDPath string", | |
643 | __FILE__, DDocStd_OSDPath, g); | |
644 | ||
645 | theCommands.Add("Path", | |
646 | "Path string", | |
647 | __FILE__, DDocStd_Path, g); | |
648 | ||
649 | theCommands.Add("AddComment", | |
650 | "AddComment Doc string", | |
651 | __FILE__, DDocStd_AddComment, g); | |
652 | ||
653 | theCommands.Add("PrintComments", | |
654 | "PrintComments Doc", | |
655 | __FILE__, DDocStd_PrintComments, g); | |
c2f5b821 | 656 | |
c1638a8d | 657 | static const TCollection_AsciiString THE_SET_VER_HELP = TCollection_AsciiString() + |
658 | "StorageFormatVersion Doc [Version]" | |
659 | "\n\t\t: Print or set storage format version within range " + int(TDocStd_FormatVersion_LOWER) + ".." + int(TDocStd_FormatVersion_UPPER) + | |
660 | "\n\t\t: defined by TDocStd_FormatVersion enumeration."; | |
661 | theCommands.Add("StorageFormatVersion", THE_SET_VER_HELP.ToCString(), | |
662 | __FILE__, DDocStd_StorageFormatVersion, g); | |
716cf4d9 | 663 | theCommands.Add("GetStorageFormatVersion", |
c1638a8d | 664 | "GetStorageFormatVersion Doc" |
665 | "\n\t\t: Alias to StorageFormatVersion", | |
666 | __FILE__, DDocStd_StorageFormatVersion, g); | |
716cf4d9 | 667 | theCommands.Add("SetStorageFormatVersion", |
c1638a8d | 668 | "\n\t\t: Alias to StorageFormatVersion", |
669 | __FILE__, DDocStd_StorageFormatVersion, g); | |
7fd59977 | 670 | } |