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>
24 #include <Draw_Interpretor.hxx>
25 #include <Draw_Viewer.hxx>
26 #include <DDocStd_DrawDocument.hxx>
27 #include <TDocStd_Application.hxx>
28 #include <TDocStd_Document.hxx>
29 #include <TDataStd_Name.hxx>
31 #include <Standard_GUID.hxx>
32 #include <Standard_ExtString.hxx>
33 #include <TCollection_AsciiString.hxx>
34 #include <TCollection_ExtendedString.hxx>
36 #include <TDF_Data.hxx>
37 #include <TDF_ChildIterator.hxx>
38 #include <TDF_Tool.hxx>
40 #include <OSD_Path.hxx>
41 #include <TDocStd_PathParser.hxx>
42 //#include <TPrsStd_AISViewer.hxx>
43 //#include <AIS_InteractiveContext.hxx>
46 extern Draw_Viewer dout;
48 Standard_IMPORT Draw_Viewer dout;
51 extern int ViewerMainLoop (Standard_Integer, const char**);
52 #include <ViewerTest_Tool.hxx>
54 //=======================================================================
55 //function : ListDocuments
57 //=======================================================================
59 static Standard_Integer DDocStd_ListDocuments (Draw_Interpretor& di,
64 Handle(TDocStd_Application) A;
65 if (!DDocStd::Find(A)) return 1;
66 Handle(TDocStd_Document) D;
67 Standard_Integer nbdoc = A->NbDocuments();
68 for (Standard_Integer i = 1; i <= nbdoc; i++) {
70 di <<"document " << i;
72 TCollection_AsciiString GetNameAsciiString(D->GetName().ToExtString(),'?');
73 TCollection_AsciiString GetPathAsciiString(D->GetPath().ToExtString(),'?');
74 //cout << " name : " << D->GetName();
75 //cout << " path : " << D->GetPath();
76 di << " name : " << GetNameAsciiString.ToCString();
77 di << " path : " << GetPathAsciiString.ToCString();
79 else di << " not saved";
84 di << "DDocStd_ListDocuments : Error" << "\n";
89 //=======================================================================
90 //function : NewDocument
92 //=======================================================================
94 static Standard_Integer DDocStd_NewDocument (Draw_Interpretor& di,
98 Handle(TDocStd_Document) D;
99 Handle(DDocStd_DrawDocument) DD;
101 if (!DDocStd::GetDocument(a[1],D,Standard_False)) {
102 D = new TDocStd_Document("dummy");
103 DD = new DDocStd_DrawDocument(D);
105 di << "document (not handled by application) " << a[1] << " created" << "\n";
106 DDocStd::ReturnLabel(di,D->Main());
108 else di << a[1] << " is already a document" << "\n";
112 if (!DDocStd::GetDocument(a[1],D,Standard_False)) {
113 Handle(TDocStd_Application) A;
114 if (!DDocStd::Find(A)) return 1;
115 A->NewDocument(a[2],D);
116 DD = new DDocStd_DrawDocument(D);
117 TDataStd_Name::Set(D->GetData()->Root(),a[1]);
119 di << "document " << a[1] << " created" << "\n";
120 DDocStd::ReturnLabel(di,D->Main());
122 else di << a[1] << " is already a document" << "\n";
125 di << "DDocStd_NewDocument : Error" << "\n";
129 //=======================================================================
130 //function : InitViewer
132 //=======================================================================
134 // static Standard_Integer DDocStd_InitViewer (Draw_Interpretor& di,
135 // Standard_Integer nb,
139 // Handle(TDocStd_Application) A;
140 // if (!DDocStd::Find(A)) return 1;
141 // Handle(TDocStd_Document) D;
142 // if (!DDocStd::GetDocument(arg[1],D)) return 1;
143 // Handle(TPrsStd_AISViewer) viewer;
144 // if (!TPrsStd_AISViewer::Find (D->Main(),viewer)) {
145 // TCollection_AsciiString title;
146 // title.Prepend(arg[1]);
147 // title.Prepend("_");
148 // title.Prepend("Document");
149 // Handle(V3d_Viewer) vw = ViewerTest_Tool::MakeViewer (title.ToCString());
150 // Handle(AIS_InteractiveContext) IC = new AIS_InteractiveContext(vw);
151 // A->SetViewer (D,IC);
153 // ViewerTest_Tool::InitViewerTest (viewer->GetInteractiveContext());
156 // cout << "DDocStd_InitViewer : Error" << endl;
161 //=======================================================================
164 //=======================================================================
166 static Standard_Integer DDocStd_Open (Draw_Interpretor& di,
171 TCollection_ExtendedString path (a[1]);
172 Handle(TDocStd_Application) A;
173 if (!DDocStd::Find(A)) return 1;
174 Handle(TDocStd_Document) D;
175 Standard_Integer insession = A->IsInSession(path);
177 di <<"document " << insession << " is already in session" << "\n";
180 PCDM_ReaderStatus theStatus = A->Open(path,D);
181 if (theStatus == PCDM_RS_OK && !D.IsNull()) {
182 Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(D);
183 TDataStd_Name::Set(D->GetData()->Root(),a[2]);
187 switch ( theStatus ) {
188 case PCDM_RS_AlreadyRetrieved:
189 case PCDM_RS_AlreadyRetrievedAndModified: {
190 di << " already retrieved " << "\n" ;
193 case PCDM_RS_NoDriver: {
194 di << " could not retrieve , no Driver to make it " <<"\n" ;
197 case PCDM_RS_UnknownDocument:
198 case PCDM_RS_NoModel: {
199 di << " could not retrieve , Unknown Document or No Model " <<"\n";
202 case PCDM_RS_TypeNotFoundInSchema:
203 case PCDM_RS_UnrecognizedFileFormat: {
204 di << " could not retrieve , Type not found or Unrecognized File Format" <<"\n";
207 case PCDM_RS_PermissionDenied: {
208 di << " could not retrieve , permission denied " << "\n" ;
212 di << " could not retrieve " << "\n" ;
215 di << "DDocStd_Open : Error" << "\n";
221 //=======================================================================
224 //=======================================================================
226 static Standard_Integer DDocStd_Save (Draw_Interpretor& di,
231 Handle(TDocStd_Document) D;
232 if (!DDocStd::GetDocument(a[1],D)) return 1;
233 Handle(TDocStd_Application) A;
234 if (!DDocStd::Find(A)) return 1;
236 di << "this document has never been saved" << "\n";
242 di << "DDocStd_Save : Error" << "\n";
246 //=======================================================================
249 //=======================================================================
251 static Standard_Integer DDocStd_SaveAs (Draw_Interpretor& di,
256 Handle(TDocStd_Document) D;
257 if (!DDocStd::GetDocument(a[1],D)) return 1;
258 TCollection_ExtendedString path (a[2]);
259 Handle(TDocStd_Application) A;
260 if (!DDocStd::Find(A)) return 1;
261 PCDM_StoreStatus theStatus = A->SaveAs(D,path);
262 if (theStatus != PCDM_SS_OK ) {
263 switch ( theStatus ) {
264 case PCDM_SS_DriverFailure: {
265 di << " could not store , no driver found to make it " <<"\n" ;
268 case PCDM_SS_WriteFailure: {
269 di << " Write access failure " << "\n" ;
272 case PCDM_SS_Failure: {
273 di << " Write failure " << "\n" ;
281 di << "DDocStd_SaveAs : Error not enough argument" << "\n";
285 //=======================================================================
288 //=======================================================================
290 static Standard_Integer DDocStd_Close (Draw_Interpretor& di,
295 Handle(TDocStd_Document) D;
296 if (!DDocStd::GetDocument(a[1],D)) return 1;
297 Handle(TDocStd_Application) A;
298 if (!DDocStd::Find(A)) return 1;
301 Handle(Draw_Drawable3D) DD = Draw::Get(a[1],Standard_False);
302 dout.RemoveDrawable (DD);
303 Handle(Draw_Drawable3D) aDNull;
304 Draw::Set(a[1], aDNull);
307 di << "DDocStd_Close : Error" << "\n";
311 //=======================================================================
312 //function : IsInSession
314 //=======================================================================
316 static Standard_Integer DDocStd_IsInSession (Draw_Interpretor& di,
321 Handle(TDocStd_Application) A;
322 if (!DDocStd::Find(A)) return 1;
323 di << A->IsInSession(a[1]);
326 di << "DDocStd_IsInSession : Error" << "\n";
331 //=======================================================================
334 //=======================================================================
336 static Standard_Integer DDocStd_OSDPath (Draw_Interpretor& di,
341 OSD_Path path (a[1]);
342 di << "Node : " << path.Node().ToCString() << "\n";
343 di << "UserName : " << path.UserName().ToCString() << "\n";
344 di << "Password : " << path.Password().ToCString() << "\n";
345 di << "Disk : " << path.Disk().ToCString() << "\n";
346 di << "Trek : " << path.Trek().ToCString() << "\n";
347 di << "Name : " << path.Name().ToCString() << "\n";
348 di << "Extension : " << path.Extension().ToCString() << "\n";
351 di << "DDocStd_OSDPath : Error" << "\n";
356 //=======================================================================
359 //=======================================================================
361 static Standard_Integer DDocStd_Path (Draw_Interpretor& di,
366 TDocStd_PathParser path (a[1]);
367 //cout << "Trek : " << path.Trek() << endl;
368 //cout << "Name : " << path.Name() << endl;
369 //cout << "Extension : " << path.Extension() << endl;
370 //cout << "Path : " << path.Path() << endl;
371 TCollection_AsciiString TrekAsciiString(path.Trek().ToExtString(),'?');
372 TCollection_AsciiString NameAsciiString(path.Name().ToExtString(),'?');
373 TCollection_AsciiString ExtensionAsciiString(path.Extension().ToExtString(),'?');
374 TCollection_AsciiString PathAsciiString(path.Path().ToExtString(),'?');
375 di << "Trek : " << TrekAsciiString.ToCString() << "\n";
376 di << "Name : " << NameAsciiString.ToCString() << "\n";
377 di << "Extension : " << ExtensionAsciiString.ToCString() << "\n";
378 di << "Path : " << PathAsciiString.ToCString() << "\n";
381 di << "DDocStd_Path : Error" << "\n";
385 //=======================================================================
386 //function : AddComment
388 //=======================================================================
389 static Standard_Integer DDocStd_AddComment (Draw_Interpretor& di,
394 Handle(TDocStd_Document) D;
395 if (!DDocStd::GetDocument(a[1],D)) return 1;
396 TCollection_ExtendedString comment (a[2]);
397 // Handle(TDocStd_Application) A;
398 // if (!DDocStd::Find(A)) return 1;
399 // A->AddComment(D,comment);
400 D->AddComment(comment);
403 di << "DDocStd_AddComment : Wrong arguments number" << "\n";
407 //=======================================================================
408 //function : PrintComments
410 //=======================================================================
411 static Standard_Integer DDocStd_PrintComments (Draw_Interpretor& di,
416 Handle(TDocStd_Document) D;
417 if (!DDocStd::GetDocument(a[1],D)) return 1;
419 TColStd_SequenceOfExtendedString comments;
420 D->Comments(comments);
422 for (int i = 1; i <= comments.Length(); i++)
424 //cout << comments(i) << endl;
425 TCollection_AsciiString commentAsciiString(comments(i).ToExtString(),'?');
426 di << commentAsciiString.ToCString() << "\n";
431 di << "DDocStd_PrintComments : Wrong arguments number" << "\n";
435 //=======================================================================
436 //function : ApplicationCommands
438 //=======================================================================
440 void DDocStd::ApplicationCommands(Draw_Interpretor& theCommands)
443 static Standard_Boolean done = Standard_False;
445 done = Standard_True;
447 const char* g = "DDocStd application commands";
449 // user application commands
452 theCommands.Add("ListDocuments",
454 __FILE__, DDocStd_ListDocuments, g);
456 theCommands.Add("NewDocument",
457 "NewDocument docname format",
458 __FILE__, DDocStd_NewDocument, g);
460 //theCommands.Add("InitViewer",
462 // __FILE__, DDocStd_InitViewer, g);
464 theCommands.Add("Open",
466 __FILE__, DDocStd_Open, g);
468 theCommands.Add("SaveAs",
470 __FILE__, DDocStd_SaveAs, g);
472 theCommands.Add("Save",
474 __FILE__, DDocStd_Save, g);
476 theCommands.Add("Close",
478 __FILE__, DDocStd_Close, g);
480 theCommands.Add("IsInSession",
482 __FILE__, DDocStd_IsInSession, g);
484 theCommands.Add("OSDPath",
486 __FILE__, DDocStd_OSDPath, g);
488 theCommands.Add("Path",
490 __FILE__, DDocStd_Path, g);
492 theCommands.Add("AddComment",
493 "AddComment Doc string",
494 __FILE__, DDocStd_AddComment, g);
496 theCommands.Add("PrintComments",
498 __FILE__, DDocStd_PrintComments, g);
502 //theCommands.Add("Active",
504 // __FILE__, DDocStd_Active, g);