-// File: DDocStd_ApplicationCommands.cxx
-// Created: Wed Mar 1 14:06:03 2000
-// Author: Denis PASCAL
-// <dp@dingox.paris1.matra-dtv.fr>
-
+// Created on: 2000-03-01
+// Created by: Denis PASCAL
+// Copyright (c) 2000-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
#include <DDocStd.hxx>
#include <Draw.hxx>
#include <TDF_Tool.hxx>
#include <OSD_Path.hxx>
+#include <OSD_OpenFile.hxx>
#include <TDocStd_PathParser.hxx>
-//#include <TPrsStd_AISViewer.hxx>
-//#include <AIS_InteractiveContext.hxx>
+#include <XmlLDrivers.hxx>
+
+#include <AIS_InteractiveContext.hxx>
+#include <TPrsStd_AISViewer.hxx>
+#include <ViewerTest.hxx>
+#include <V3d_Viewer.hxx>
-#ifndef WNT
+#ifndef _WIN32
extern Draw_Viewer dout;
#else
Standard_IMPORT Draw_Viewer dout;
#endif
-extern int ViewerMainLoop (Standard_Integer, const char**);
-#include <ViewerTest_Tool.hxx>
-
//=======================================================================
//function : ListDocuments
//purpose :
const char** /*a*/)
{
if (nb == 1) {
- Handle(TDocStd_Application) A;
- if (!DDocStd::Find(A)) return 1;
+ Handle(TDocStd_Application) A = DDocStd::GetApplication();
Handle(TDocStd_Document) D;
Standard_Integer nbdoc = A->NbDocuments();
for (Standard_Integer i = 1; i <= nbdoc; i++) {
}
return 0;
}
- di << "DDocStd_ListDocuments : Error" << "\n";
+ di << "DDocStd_ListDocuments : Error\n";
return 1;
}
D = new TDocStd_Document("dummy");
DD = new DDocStd_DrawDocument(D);
Draw::Set(a[1],DD);
- di << "document (not handled by application) " << a[1] << " created" << "\n";
+ di << "document (not handled by application) " << a[1] << " created\n";
DDocStd::ReturnLabel(di,D->Main());
}
- else di << a[1] << " is already a document" << "\n";
+ else di << a[1] << " is already a document\n";
return 0;
}
if (nb == 3) {
if (!DDocStd::GetDocument(a[1],D,Standard_False)) {
- Handle(TDocStd_Application) A;
- if (!DDocStd::Find(A)) return 1;
+ Handle(TDocStd_Application) A = DDocStd::GetApplication();
A->NewDocument(a[2],D);
DD = new DDocStd_DrawDocument(D);
TDataStd_Name::Set(D->GetData()->Root(),a[1]);
Draw::Set(a[1],DD);
- di << "document " << a[1] << " created" << "\n";
+ di << "document " << a[1] << " created\n";
DDocStd::ReturnLabel(di,D->Main());
}
- else di << a[1] << " is already a document" << "\n";
+ else di << a[1] << " is already a document\n";
return 0;
}
- di << "DDocStd_NewDocument : Error" << "\n";
+ di << "DDocStd_NewDocument : Error\n";
return 1;
}
-//=======================================================================
-//function : InitViewer
-//purpose :
-//=======================================================================
-
-// static Standard_Integer DDocStd_InitViewer (Draw_Interpretor& di,
-// Standard_Integer nb,
-// const char** arg)
-// {
-// if (nb == 2) {
-// Handle(TDocStd_Application) A;
-// if (!DDocStd::Find(A)) return 1;
-// Handle(TDocStd_Document) D;
-// if (!DDocStd::GetDocument(arg[1],D)) return 1;
-// Handle(TPrsStd_AISViewer) viewer;
-// if (!TPrsStd_AISViewer::Find (D->Main(),viewer)) {
-// TCollection_AsciiString title;
-// title.Prepend(arg[1]);
-// title.Prepend("_");
-// title.Prepend("Document");
-// Handle(V3d_Viewer) vw = ViewerTest_Tool::MakeViewer (title.ToCString());
-// Handle(AIS_InteractiveContext) IC = new AIS_InteractiveContext(vw);
-// A->SetViewer (D,IC);
-// }
-// ViewerTest_Tool::InitViewerTest (viewer->GetInteractiveContext());
-// return 0;
-// }
-// cout << "DDocStd_InitViewer : Error" << endl;
-// return 1;
-// }
-
-
//=======================================================================
//function : Open
//purpose :
Standard_Integer nb,
const char** a)
{
- if (nb == 3) {
+ if (nb >= 3) {
TCollection_ExtendedString path (a[1]);
- Handle(TDocStd_Application) A;
- if (!DDocStd::Find(A)) return 1;
+ Handle(TDocStd_Application) A = DDocStd::GetApplication();
Handle(TDocStd_Document) D;
Standard_Integer insession = A->IsInSession(path);
if (insession > 0) {
- di <<"document " << insession << " is already in session" << "\n";
+ di <<"document " << insession << " is already in session\n";
return 0;
}
- PCDM_ReaderStatus theStatus = A->Open(path,D);
+ PCDM_ReaderStatus theStatus;
+
+ Standard_Boolean anUseStream = Standard_False;
+ for ( Standard_Integer i = 3; i < nb; i++ )
+ {
+ if (!strcmp (a[i], "-stream"))
+ {
+ di << "standard SEEKABLE stream is used\n";
+ anUseStream = Standard_True;
+ break;
+ }
+ }
+
+ if (anUseStream)
+ {
+ std::ifstream aFileStream;
+ OSD_OpenStream (aFileStream, path, std::ios::in | std::ios::binary);
+
+ theStatus = A->Open (aFileStream, D);
+ }
+ else
+ {
+ theStatus = A->Open(path,D);
+ }
if (theStatus == PCDM_RS_OK && !D.IsNull()) {
Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(D);
TDataStd_Name::Set(D->GetData()->Root(),a[2]);
switch ( theStatus ) {
case PCDM_RS_AlreadyRetrieved:
case PCDM_RS_AlreadyRetrievedAndModified: {
- di << " already retrieved " << "\n" ;
+ di << " already retrieved \n" ;
break;
}
case PCDM_RS_NoDriver: {
- di << " could not retrieve , no Driver to make it " <<"\n" ;
+ di << " could not retrieve , no Driver to make it \n" ;
break ;
}
case PCDM_RS_UnknownDocument:
case PCDM_RS_NoModel: {
- di << " could not retrieve , Unknown Document or No Model " <<"\n";
+ di << " could not retrieve , Unknown Document or No Model \n";
break ;
}
case PCDM_RS_TypeNotFoundInSchema:
case PCDM_RS_UnrecognizedFileFormat: {
- di << " could not retrieve , Type not found or Unrecognized File Format" <<"\n";
+ di << " could not retrieve , Type not found or Unrecognized File Format\n";
break ;
}
case PCDM_RS_PermissionDenied: {
- di << " could not retrieve , permission denied " << "\n" ;
+ di << " could not retrieve , permission denied \n" ;
break;
}
default:
- di << " could not retrieve " << "\n" ;
+ di << " could not retrieve \n" ;
break;
}
- di << "DDocStd_Open : Error" << "\n";
+ di << "DDocStd_Open : Error\n";
}
}
return 1;
if (nb == 2) {
Handle(TDocStd_Document) D;
if (!DDocStd::GetDocument(a[1],D)) return 1;
- Handle(TDocStd_Application) A;
- if (!DDocStd::Find(A)) return 1;
+ Handle(TDocStd_Application) A = DDocStd::GetApplication();
if (!D->IsSaved()) {
- di << "this document has never been saved" << "\n";
+ di << "this document has never been saved\n";
return 0;
}
A->Save(D);
return 0;
}
- di << "DDocStd_Save : Error" << "\n";
+ di << "DDocStd_Save : Error\n";
return 1;
}
Standard_Integer nb,
const char** a)
{
- if (nb == 3) {
+ if (nb >= 3) {
Handle(TDocStd_Document) D;
if (!DDocStd::GetDocument(a[1],D)) return 1;
TCollection_ExtendedString path (a[2]);
- Handle(TDocStd_Application) A;
- if (!DDocStd::Find(A)) return 1;
- PCDM_StoreStatus theStatus = A->SaveAs(D,path);
+ Handle(TDocStd_Application) A = DDocStd::GetApplication();
+ PCDM_StoreStatus theStatus;
+
+ Standard_Boolean anUseStream = Standard_False;
+ for ( Standard_Integer i = 3; i < nb; i++ )
+ {
+ if (!strcmp (a[i], "-stream"))
+ {
+ di << "standard SEEKABLE stream is used\n";
+ anUseStream = Standard_True;
+ break;
+ }
+ }
+
+ if (anUseStream)
+ {
+ std::ofstream aFileStream;
+ OSD_OpenStream (aFileStream, path, std::ios::out | std::ios::binary);
+ theStatus = A->SaveAs (D, aFileStream);
+ }
+ else
+ {
+ theStatus = A->SaveAs(D,path);
+ }
+
if (theStatus != PCDM_SS_OK ) {
switch ( theStatus ) {
- case PCDM_SS_DriverFailure: {
- di << " could not store , no driver found to make it " <<"\n" ;
- break ;
- }
- case PCDM_SS_WriteFailure: {
- di << " Write access failure " << "\n" ;
- break;
- }
- case PCDM_SS_Failure: {
- di << " Write failure " << "\n" ;
- }
+ case PCDM_SS_DriverFailure: {
+ di << "Error saving document: Could not store , no driver found to make it\n";
+ break ;
+ }
+ case PCDM_SS_WriteFailure: {
+ di << "Error saving document: Write access failure\n";
+ break;
+ }
+ case PCDM_SS_Failure: {
+ di << "Error saving document: Write failure\n" ;
+ break;
+ }
+ case PCDM_SS_Doc_IsNull: {
+ di << "Error saving document: No document to save\n";
+ break ;
+ }
+ case PCDM_SS_No_Obj: {
+ di << "Error saving document: No objects written\n";
+ break;
+ }
+ case PCDM_SS_Info_Section_Error: {
+ di << "Error saving document: Write info section failure\n" ;
+ break;
+ }
+ default:
+ break;
}
return 1;
} else {
return 0;
}
}
- di << "DDocStd_SaveAs : Error not enough argument" << "\n";
+ di << "DDocStd_SaveAs : Error not enough argument\n";
return 1;
}
//purpose :
//=======================================================================
-static Standard_Integer DDocStd_Close (Draw_Interpretor& di,
- Standard_Integer nb,
- const char** a)
+static Standard_Integer DDocStd_Close (Draw_Interpretor& /*theDI*/,
+ Standard_Integer theArgNb,
+ const char** theArgVec)
{
- if (nb == 2) {
- Handle(TDocStd_Document) D;
- if (!DDocStd::GetDocument(a[1],D)) return 1;
- Handle(TDocStd_Application) A;
- if (!DDocStd::Find(A)) return 1;
- A->Close(D);
- Handle(Draw_Drawable3D) DD = Draw::Get(a[1],Standard_False);
- dout.RemoveDrawable (DD);
- return 0;
+ if (theArgNb != 2)
+ {
+ std::cout << "DDocStd_Close : Error\n";
+ return 1;
}
- di << "DDocStd_Close : Error" << "\n";
- return 1;
+
+ Handle(TDocStd_Document) aDoc;
+ Standard_CString aDocName = theArgVec[1];
+ if (!DDocStd::GetDocument (aDocName, aDoc))
+ {
+ return 1;
+ }
+
+ TDF_Label aRoot = aDoc->GetData()->Root();
+ Handle(TPrsStd_AISViewer) aDocViewer;
+ if (TPrsStd_AISViewer::Find (aRoot, aDocViewer)
+ && !aDocViewer->GetInteractiveContext().IsNull())
+ {
+ Handle(V3d_Viewer) aViewer = aDocViewer->GetInteractiveContext()->CurrentViewer();
+ V3d_ListOfView aViews;
+ for (V3d_ListOfViewIterator aViewIter (aDocViewer->GetInteractiveContext()->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
+ {
+ aViews.Append (aViewIter.Value());
+ }
+ for (V3d_ListOfViewIterator aViewIter (aViews); aViewIter.More(); aViewIter.Next())
+ {
+ Handle(V3d_View) aView = aViewIter.Value();
+ ViewerTest::RemoveView (aView);
+ }
+ }
+
+ Handle(TDocStd_Application) aDocApp = DDocStd::GetApplication();
+
+ aDocApp->Close (aDoc);
+
+ Handle(Draw_Drawable3D) aDrawable = Draw::Get (aDocName, Standard_False);
+ dout.RemoveDrawable (aDrawable);
+ Draw::Set (theArgVec[1], Handle(Draw_Drawable3D)());
+ return 0;
}
//=======================================================================
const char** a)
{
if (nb == 2) {
- Handle(TDocStd_Application) A;
- if (!DDocStd::Find(A)) return 1;
+ Handle(TDocStd_Application) A = DDocStd::GetApplication();
di << A->IsInSession(a[1]);
return 0;
}
- di << "DDocStd_IsInSession : Error" << "\n";
+ di << "DDocStd_IsInSession : Error\n";
return 1;
}
di << "Extension : " << path.Extension().ToCString() << "\n";
return 0;
}
- di << "DDocStd_OSDPath : Error" << "\n";
+ di << "DDocStd_OSDPath : Error\n";
return 1;
}
di << "Path : " << PathAsciiString.ToCString() << "\n";
return 0;
}
- di << "DDocStd_Path : Error" << "\n";
+ di << "DDocStd_Path : Error\n";
return 1;
}
Handle(TDocStd_Document) D;
if (!DDocStd::GetDocument(a[1],D)) return 1;
TCollection_ExtendedString comment (a[2]);
-// Handle(TDocStd_Application) A;
-// if (!DDocStd::Find(A)) return 1;
+// Handle(TDocStd_Application) A = DDocStd::GetApplication();
// A->AddComment(D,comment);
D->AddComment(comment);
return 0;
}
- di << "DDocStd_AddComment : Wrong arguments number" << "\n";
+ di << "DDocStd_AddComment : Wrong arguments number\n";
return 1;
}
return 0;
}
- di << "DDocStd_PrintComments : Wrong arguments number" << "\n";
+ di << "DDocStd_PrintComments : Wrong arguments number\n";
return 1;
}
+//=======================================================================
+//function : SetStorageVerison
+//purpose :
+//=======================================================================
+static Standard_Integer DDocStd_SetStorageVersion (Draw_Interpretor& ,
+ Standard_Integer nb,
+ const char** a)
+{
+ if (nb == 2)
+ {
+ const int version = atoi(a[1]);
+ XmlLDrivers::SetStorageVersion(version);
+ return 0;
+ }
+ return 1;
+}
+
+//=======================================================================
+//function : GetStorageVerison
+//purpose :
+//=======================================================================
+static Standard_Integer DDocStd_GetStorageVersion (Draw_Interpretor& di,
+ Standard_Integer ,
+ const char** )
+{
+ di << XmlLDrivers::StorageVersion() << "\n" ;
+ return 0;
+}
+
//=======================================================================
//function : ApplicationCommands
//purpose :
const char* g = "DDocStd application commands";
// user application commands
-
-
theCommands.Add("ListDocuments",
"ListDocuments",
__FILE__, DDocStd_ListDocuments, g);
"NewDocument docname format",
__FILE__, DDocStd_NewDocument, g);
- //theCommands.Add("InitViewer",
- // "InitViewer DOC",
- // __FILE__, DDocStd_InitViewer, g);
-
theCommands.Add("Open",
- "Open path docname",
+ "Open path docname [-stream]",
__FILE__, DDocStd_Open, g);
theCommands.Add("SaveAs",
- "SaveAs DOC path",
+ "SaveAs DOC path [-stream]",
__FILE__, DDocStd_SaveAs, g);
theCommands.Add("Save",
"PrintComments Doc",
__FILE__, DDocStd_PrintComments, g);
- // active document
-
- //theCommands.Add("Active",
- // "Active [D]",
- // __FILE__, DDocStd_Active, g);
-
+ theCommands.Add("GetStorageVersion",
+ "GetStorageVersion",
+ __FILE__, DDocStd_GetStorageVersion, g);
+ theCommands.Add("SetStorageVersion",
+ "SetStorageVersion Version",
+ __FILE__, DDocStd_SetStorageVersion, g);
}