mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0026229: Add the possibility in OCAF to open/save a document from/to a stream object
TDocStd_Application class extended to open/save a document of XmlOcaf and BinOcaf format from/to standard SEEKABLE stream object which should support SEEK functionality. Open and SaveAs DRAW commands got new additional argument "-stream" to turn on using of stream functionality. The main changes for BinOcaf format applied in: FSD_BinaryFile class (static method using standard stream added) BinLDrivers_DocumentRetrievalDriver and BinLDrivers_DocumentStorageDriver classes use standard stream object as an argument The main changes for XmlOcaf format applied in: LDOMParser and LDOM_XmlWriter classes use standard stream object as an argument Unused class FSD_Archive and its siblings removed from MFC samples.
This commit is contained in:
@@ -103,3 +103,48 @@ PCDM_TypeOfFileDriver PCDM::FileDriverType(const TCollection_AsciiString& aFileN
|
||||
return PCDM_TOFD_Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : FileDriverType
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
PCDM_TypeOfFileDriver PCDM::FileDriverType (Standard_IStream& theIStream, PCDM_BaseDriverPointer& theBaseDriver)
|
||||
{
|
||||
TCollection_AsciiString aReadMagicNumber;
|
||||
|
||||
if (theIStream.good())
|
||||
{
|
||||
streampos aDocumentPos = theIStream.tellg();
|
||||
|
||||
// read magic number from the file
|
||||
aReadMagicNumber = Storage_BaseDriver::ReadMagicNumber (theIStream);
|
||||
|
||||
if (!theIStream.good())
|
||||
{
|
||||
theIStream.clear();
|
||||
}
|
||||
|
||||
theIStream.seekg(aDocumentPos);
|
||||
}
|
||||
|
||||
if(aReadMagicNumber == FSD_CmpFile::MagicNumber())
|
||||
{
|
||||
theBaseDriver = new FSD_CmpFile;
|
||||
return PCDM_TOFD_CmpFile;
|
||||
}
|
||||
else if (aReadMagicNumber == FSD_File::MagicNumber())
|
||||
{
|
||||
theBaseDriver = new FSD_File;
|
||||
return PCDM_TOFD_File;
|
||||
}
|
||||
else if (aReadMagicNumber == FSD_BinaryFile::MagicNumber())
|
||||
{
|
||||
theBaseDriver = new FSD_BinaryFile;
|
||||
return PCDM_TOFD_File;
|
||||
}
|
||||
|
||||
theBaseDriver = NULL;
|
||||
return PCDM_TOFD_Unknown;
|
||||
}
|
||||
|
||||
|
@@ -21,6 +21,8 @@
|
||||
#include <Standard_DefineAlloc.hxx>
|
||||
#include <Standard_Handle.hxx>
|
||||
|
||||
#include <Standard_IStream.hxx>
|
||||
|
||||
#include <Standard_Boolean.hxx>
|
||||
#include <PCDM_TypeOfFileDriver.hxx>
|
||||
#include <PCDM_BaseDriverPointer.hxx>
|
||||
@@ -74,6 +76,8 @@ private:
|
||||
|
||||
|
||||
Standard_EXPORT static PCDM_TypeOfFileDriver FileDriverType (const TCollection_AsciiString& aFileName, PCDM_BaseDriverPointer& aBaseDriver);
|
||||
|
||||
Standard_EXPORT static PCDM_TypeOfFileDriver FileDriverType (Standard_IStream& theIStream, PCDM_BaseDriverPointer& theBaseDriver);
|
||||
|
||||
|
||||
|
||||
|
@@ -40,6 +40,8 @@ IMPLEMENT_STANDARD_RTTIEXT(PCDM_ReadWriter,Standard_Transient)
|
||||
static TCollection_ExtendedString TryXmlDriverType
|
||||
(const TCollection_AsciiString& theFileName);
|
||||
|
||||
static TCollection_ExtendedString TryXmlDriverType (Standard_IStream& theIStream);
|
||||
|
||||
//=======================================================================
|
||||
//function : Open
|
||||
//purpose :
|
||||
@@ -151,6 +153,41 @@ TCollection_ExtendedString PCDM_ReadWriter::FileFormat
|
||||
return theFormat;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : FileFormat
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TCollection_ExtendedString PCDM_ReadWriter::FileFormat (Standard_IStream& theIStream, Handle(Storage_Data)& theData)
|
||||
{
|
||||
TCollection_ExtendedString aFormat;
|
||||
|
||||
Storage_BaseDriver* aFileDriver;
|
||||
if (PCDM::FileDriverType (theIStream, aFileDriver) == PCDM_TOFD_Unknown)
|
||||
{
|
||||
return ::TryXmlDriverType (theIStream);
|
||||
}
|
||||
|
||||
// the stream starts with a magic number, FileDriverType has read
|
||||
// them already but returned the stream pos to initial state,
|
||||
// thus we should read them before reading of info section
|
||||
aFileDriver->ReadMagicNumber(theIStream);
|
||||
|
||||
aFileDriver->ReadCompleteInfo (theIStream, theData);
|
||||
|
||||
for (Standard_Integer i = 1; i <= theData->HeaderData()->UserInfo().Length(); i++)
|
||||
{
|
||||
const TCollection_AsciiString& aLine = theData->HeaderData()->UserInfo().Value(i);
|
||||
|
||||
if(aLine.Search (FILE_FORMAT) != -1)
|
||||
{
|
||||
aFormat = TCollection_ExtendedString (aLine.Token(" ",2).ToCString(), Standard_True);
|
||||
}
|
||||
}
|
||||
|
||||
return aFormat;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ::TryXmlDriverType
|
||||
//purpose : called from FileFormat()
|
||||
@@ -174,3 +211,39 @@ static TCollection_ExtendedString TryXmlDriverType
|
||||
}
|
||||
return theFormat;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ::TryXmlDriverType
|
||||
//purpose : called from FileFormat()
|
||||
//=======================================================================
|
||||
|
||||
static TCollection_ExtendedString TryXmlDriverType (Standard_IStream& theIStream)
|
||||
{
|
||||
TCollection_ExtendedString theFormat;
|
||||
PCDM_DOMHeaderParser aParser;
|
||||
const char * aDocumentElementName = "document";
|
||||
aParser.SetStartElementName (Standard_CString(aDocumentElementName));
|
||||
|
||||
if (theIStream.good())
|
||||
{
|
||||
streampos aDocumentPos = theIStream.tellg();
|
||||
|
||||
// Parse the file; if there is no error or an error appears before retrieval
|
||||
// of the DocumentElement, the XML format cannot be defined
|
||||
if (aParser.parse (theIStream))
|
||||
{
|
||||
LDOM_Element anElement = aParser.GetElement();
|
||||
if (anElement.getTagName().equals (LDOMString(aDocumentElementName)))
|
||||
theFormat = anElement.getAttribute ("format");
|
||||
}
|
||||
|
||||
if (!theIStream.good())
|
||||
{
|
||||
theIStream.clear();
|
||||
}
|
||||
|
||||
theIStream.seekg(aDocumentPos);
|
||||
}
|
||||
|
||||
return theFormat;
|
||||
}
|
||||
|
@@ -76,6 +76,10 @@ public:
|
||||
//! a FileFormat information.
|
||||
Standard_EXPORT static TCollection_ExtendedString FileFormat (const TCollection_ExtendedString& aFileName);
|
||||
|
||||
//! tries to get a format from the stream. returns an empty
|
||||
//! string if the file could not be read or does not have
|
||||
//! a FileFormat information.
|
||||
Standard_EXPORT static TCollection_ExtendedString FileFormat (Standard_IStream& theIStream, Handle(Storage_Data)& theData);
|
||||
|
||||
|
||||
|
||||
|
@@ -22,6 +22,9 @@
|
||||
|
||||
#include <PCDM_ReaderStatus.hxx>
|
||||
#include <Standard_Transient.hxx>
|
||||
#include <Standard_IStream.hxx>
|
||||
#include <Storage_Data.hxx>
|
||||
|
||||
class PCDM_DriverError;
|
||||
class CDM_Document;
|
||||
class TCollection_ExtendedString;
|
||||
@@ -43,6 +46,11 @@ public:
|
||||
|
||||
//! retrieves the content of the file into a new Document.
|
||||
Standard_EXPORT virtual void Read (const TCollection_ExtendedString& aFileName, const Handle(CDM_Document)& aNewDocument, const Handle(CDM_Application)& anApplication) = 0;
|
||||
|
||||
Standard_EXPORT virtual void Read (Standard_IStream& theIStream,
|
||||
const Handle(Storage_Data)& theStorageData,
|
||||
const Handle(CDM_Document)& theDoc,
|
||||
const Handle(CDM_Application)& theApplication) = 0;
|
||||
|
||||
PCDM_ReaderStatus GetStatus() const;
|
||||
|
||||
|
@@ -69,6 +69,18 @@ void PCDM_RetrievalDriver::RaiseIfUnknownTypes(const Handle(Storage_Schema)& aSc
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Read
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void PCDM_RetrievalDriver::Read(Standard_IStream& /*theIStream*/,
|
||||
const Handle(Storage_Data)& /*theStorageData*/,
|
||||
const Handle(CDM_Document)& /*theDoc*/,
|
||||
const Handle(CDM_Application)& /*theApplication*/)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Read
|
||||
//purpose :
|
||||
|
@@ -56,6 +56,11 @@ public:
|
||||
//! into a persistent document. and the Make method to build a
|
||||
//! transient document.
|
||||
Standard_EXPORT virtual void Read (const TCollection_ExtendedString& aFileName, const Handle(CDM_Document)& aNewDocument, const Handle(CDM_Application)& anApplication) Standard_OVERRIDE;
|
||||
|
||||
Standard_EXPORT virtual void Read (Standard_IStream& theIStream,
|
||||
const Handle(Storage_Data)& theStorageData,
|
||||
const Handle(CDM_Document)& theDoc,
|
||||
const Handle(CDM_Application)& theApplication) Standard_OVERRIDE;
|
||||
|
||||
Standard_EXPORT virtual void Make (const Handle(PCDM_Document)& aPCDM, const Handle(CDM_Document)& aNewDocument) = 0;
|
||||
|
||||
|
@@ -105,6 +105,15 @@ void PCDM_StorageDriver::Write(const Handle(CDM_Document)& aDocument, const TCol
|
||||
PCDM_DriverError::Raise(theData->ErrorStatusExtension().ToCString());
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Write
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void PCDM_StorageDriver::Write (const Handle(CDM_Document)& /*aDocument*/, Standard_OStream& /*theOStream*/)
|
||||
{
|
||||
|
||||
}
|
||||
//void PCDM_StorageDriver::LoadExtensions(const Handle(Storage_Schema)& aSchema, const TColStd_SequenceOfExtendedString& Extensions) {}
|
||||
void PCDM_StorageDriver::LoadExtensions(const Handle(Storage_Schema)& , const TColStd_SequenceOfExtendedString& ) {}
|
||||
|
||||
|
@@ -75,6 +75,9 @@ public:
|
||||
//! by default Write will use Make method to build a persistent
|
||||
//! document and the Schema method to write the persistent document.
|
||||
Standard_EXPORT virtual void Write (const Handle(CDM_Document)& aDocument, const TCollection_ExtendedString& aFileName) Standard_OVERRIDE;
|
||||
|
||||
//! Write <theDocument> to theOStream
|
||||
Standard_EXPORT virtual void Write (const Handle(CDM_Document)& theDocument, Standard_OStream& theOStream) Standard_OVERRIDE;
|
||||
|
||||
Standard_EXPORT void SetFormat (const TCollection_ExtendedString& aformat);
|
||||
|
||||
|
@@ -38,6 +38,8 @@ public:
|
||||
|
||||
Standard_EXPORT virtual void Write (const Handle(CDM_Document)& aDocument, const TCollection_ExtendedString& aFileName) = 0;
|
||||
|
||||
//! Write <theDocument> to theOStream
|
||||
Standard_EXPORT virtual void Write (const Handle(CDM_Document)& theDocument, Standard_OStream& theOStream) = 0;
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user