1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0026961: Recover possibility to read files in old persistence format -- preparation

Added basic support for possibility to read filed in old persistent format.
Toolkits TKStd, TKStdL, TKShape added to provide necessary tools (to be done).
Obsolete interfaces are removed from classes in PCDM and Storage.
This commit is contained in:
myn
2015-12-09 20:27:36 +03:00
committed by abv
parent ede9746c21
commit 7ed7467da3
79 changed files with 2010 additions and 1287 deletions

View File

@@ -60,26 +60,6 @@ Standard_Boolean PCDM::FindStorageDriver(const Handle(CDM_Document)& aDocument)
return aDocument->FindStoragePlugin();
}
//=======================================================================
//function : Schema
//purpose : returns a schema to be used during a Store or Retrieve
// operation.
// Schema will plug the schema defined by
// the SchemaName method.
//=======================================================================
Handle(Storage_Schema) PCDM::Schema(const TCollection_ExtendedString& aSchemaName, const Handle(CDM_Application)& anApplication) {
Handle(Resource_Manager) r = anApplication->Resources();
if(!UTL::Find(r,aSchemaName)) {
Standard_SStream aMsg; aMsg << "could not find the plugin resource for the schema: " << TCollection_ExtendedString(aSchemaName) << (char)0;
Standard_NoSuchObject::Raise(aMsg);
}
Handle(Standard_Transient) t = Plugin::Load(UTL::GUID(UTL::Value(r,aSchemaName)));
return Handle(Storage_Schema)::DownCast (t);
}
//=======================================================================
//function : FileDriverType
//purpose :

View File

@@ -28,75 +28,23 @@
#include <PCDM_BaseDriverPointer.hxx>
class CDM_Document;
class PCDM_StorageDriver;
class Storage_Schema;
class TCollection_ExtendedString;
class CDM_Application;
class TCollection_AsciiString;
class PCDM_Document;
class PCDM_Reader;
class PCDM_Writer;
class PCDM_RetrievalDriver;
class PCDM_StorageDriver;
class PCDM_ReferenceIterator;
class PCDM_Reference;
class PCDM_ReadWriter;
class PCDM_ReadWriter_1;
class PCDM
{
public:
DEFINE_STANDARD_ALLOC
Standard_EXPORT static Standard_Boolean FindStorageDriver (const Handle(CDM_Document)& aDocument);
//! gets in the EuclidDesktop resource the plugin
//! identifier of the driver plugs the driver.
Standard_EXPORT static Handle(PCDM_StorageDriver) StorageDriver (const Handle(CDM_Document)& aDocument);
//! returns a schema to be used during a Store or Retrieve
//! operation.
//! Schema will plug the schema defined by
//! the SchemaName method.
Standard_EXPORT static Handle(Storage_Schema) Schema (const TCollection_ExtendedString& aSchemaName, const Handle(CDM_Application)& anApplication);
protected:
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);
friend class PCDM_Document;
friend class PCDM_Reader;
friend class PCDM_Writer;
friend class PCDM_RetrievalDriver;
friend class PCDM_StorageDriver;
friend class PCDM_ReferenceIterator;
friend class PCDM_Reference;
friend class PCDM_ReadWriter;
friend class PCDM_ReadWriter_1;
DEFINE_STANDARD_ALLOC
};
#endif // _PCDM_HeaderFile

View File

@@ -26,7 +26,6 @@
#include <Storage_BaseDriver.hxx>
#include <Storage_Data.hxx>
#include <Storage_HeaderData.hxx>
#include <Storage_Schema.hxx>
#include <Storage_TypeData.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
@@ -130,9 +129,9 @@ TCollection_ExtendedString PCDM_ReadWriter::FileFormat
Open(*theFileDriver,aFileName,Storage_VSRead);
theFileIsOpen=Standard_True;
Handle(Storage_Schema) s = new Storage_Schema;
Handle(Storage_HeaderData) hd = s->ReadHeaderSection(*theFileDriver);
const TColStd_SequenceOfAsciiString &refUserInfo = hd->UserInfo();
Storage_HeaderData hd;
hd.Read (*theFileDriver);
const TColStd_SequenceOfAsciiString &refUserInfo = hd.UserInfo();
Standard_Boolean found=Standard_False;
for (Standard_Integer i =1; !found && i<= refUserInfo.Length() ; i++) {
if(refUserInfo(i).Search(FILE_FORMAT) != -1) {
@@ -141,7 +140,12 @@ TCollection_ExtendedString PCDM_ReadWriter::FileFormat
Standard_True);
}
}
if(!found) theFormat=s->ReadTypeSection(*theFileDriver)->Types()->Value(1);
if (!found)
{
Storage_TypeData td;
td.Read (*theFileDriver);
theFormat = td.Types()->Value(1);
}
}
catch (Standard_Failure) {}

View File

@@ -244,8 +244,9 @@ Standard_Integer PCDM_ReadWriter_1::ReadReferenceCounter(const TCollection_Exten
theFileIsOpen=Standard_True;
Handle(Storage_Schema) s = new Storage_Schema;
Handle(Storage_HeaderData) hd = s->ReadHeaderSection(*theFileDriver);
const TColStd_SequenceOfAsciiString &refUserInfo = hd->UserInfo();
Storage_HeaderData hd;
hd.Read (*theFileDriver);
const TColStd_SequenceOfAsciiString &refUserInfo = hd.UserInfo();
for ( i =1; i<= refUserInfo.Length() ; i++) {
if(refUserInfo(i).Search(REFERENCE_COUNTER) != -1) {
@@ -347,8 +348,9 @@ void PCDM_ReadWriter_1::ReadUserInfo(const TCollection_ExtendedString& aFileName
PCDM_ReadWriter::Open(*theFileDriver,aFileName,Storage_VSRead);
Handle(Storage_Schema) s = new Storage_Schema;
Handle(Storage_HeaderData) hd = s->ReadHeaderSection(*theFileDriver);
const TColStd_SequenceOfAsciiString &refUserInfo = hd->UserInfo();
Storage_HeaderData hd;
hd.Read (*theFileDriver);
const TColStd_SequenceOfAsciiString &refUserInfo = hd.UserInfo();
Standard_Integer debut=0,fin=0;
@@ -390,8 +392,9 @@ Standard_Integer PCDM_ReadWriter_1::ReadDocumentVersion(const TCollection_Extend
PCDM_ReadWriter::Open(*theFileDriver,aFileName,Storage_VSRead);
theFileIsOpen=Standard_True;
Handle(Storage_Schema) s = new Storage_Schema;
Handle(Storage_HeaderData) hd = s->ReadHeaderSection(*theFileDriver);
const TColStd_SequenceOfAsciiString &refUserInfo = hd->UserInfo();
Storage_HeaderData hd;
hd.Read (*theFileDriver);
const TColStd_SequenceOfAsciiString &refUserInfo = hd.UserInfo();
static Standard_Integer i ;
for ( i =1; i<= refUserInfo.Length() ; i++) {

View File

@@ -31,44 +31,12 @@
#include <Standard_NoSuchObject.hxx>
#include <Standard_Type.hxx>
#include <Standard_TypeMismatch.hxx>
#include <Storage_Data.hxx>
#include <Storage_HeaderData.hxx>
#include <Storage_HSeqOfRoot.hxx>
#include <Storage_Root.hxx>
#include <Storage_Schema.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
#include <TColStd_SequenceOfAsciiString.hxx>
#include <locale.h>
IMPLEMENT_STANDARD_RTTIEXT(PCDM_RetrievalDriver,PCDM_Reader)
void PCDM_RetrievalDriver::RaiseIfUnknownTypes(const Handle(Storage_Schema)& aSchema, const TCollection_ExtendedString& aFileName) {
PCDM_BaseDriverPointer theFileDriver;
TCollection_AsciiString aFileNameU(aFileName);
if(PCDM::FileDriverType(aFileNameU, theFileDriver) == PCDM_TOFD_Unknown)
return;
PCDM_ReadWriter::Open(*theFileDriver,aFileName,Storage_VSRead);
TColStd_SequenceOfAsciiString theUnknownTypes;
Standard_Boolean unknowns = aSchema->HasUnknownType(*theFileDriver,theUnknownTypes);
theFileDriver->Close();
delete theFileDriver;
if(unknowns) {
Standard_SStream aMsg; aMsg << "cannot read: `" << aFileName << "', because the following types: ";
for (Standard_Integer i=1; i <= theUnknownTypes.Length(); i++) {
aMsg << theUnknownTypes(i);
if(i< theUnknownTypes.Length()) aMsg <<",";
}
aMsg << " have been found in it but not in the available Schema: " << aSchema->Name() << (char)0;
Standard_TypeMismatch::Raise(aMsg);
}
}
//=======================================================================
//function : Read
//purpose :
@@ -81,181 +49,17 @@ void PCDM_RetrievalDriver::Read(Standard_IStream& /*theIStream*/,
}
//=======================================================================
//function : Read
//purpose :
//=======================================================================
void PCDM_RetrievalDriver::References(const TCollection_ExtendedString& aFileName, PCDM_SequenceOfReference& theReferences, const Handle(CDM_MessageDriver)& theMsgDriver)
{ PCDM_ReadWriter::Reader(aFileName)->ReadReferences(aFileName, theReferences, theMsgDriver);}
void PCDM_RetrievalDriver::Read(const TCollection_ExtendedString& theFileName,
const Handle(CDM_Document)& aNewDocument,
const Handle(CDM_Application)& theApplication)
{
Standard_SStream aMsg;
Standard_Boolean Failure=Standard_False;
Handle(Storage_Schema) aSchema;
TColStd_SequenceOfExtendedString theExtensions;
myReaderStatus = PCDM_RS_OK;
{
try {
OCC_CATCH_SIGNALS
aSchema=PCDM::Schema(SchemaName(),theApplication);
Extensions(theFileName, theExtensions, theApplication->MessageDriver());
LoadExtensions(aSchema,theExtensions, theApplication->MessageDriver());
}
catch (Standard_NoSuchObject) {
aMsg << Standard_NoSuchObject::Caught() << endl;
myReaderStatus = PCDM_RS_NoSchema;
Failure=Standard_True;
}
catch (Standard_Failure) {
aMsg << Standard_Failure::Caught() << endl;
myReaderStatus = PCDM_RS_ExtensionFailure;
Failure=Standard_True;
}
if(Failure) Standard_Failure::Raise(aMsg);
}
Standard_Integer PCDM_RetrievalDriver::DocumentVersion(const TCollection_ExtendedString& aFileName, const Handle(CDM_MessageDriver)& theMsgDriver)
{ return PCDM_ReadWriter::Reader(aFileName)->ReadDocumentVersion(aFileName, theMsgDriver); }
PCDM_BaseDriverPointer theFileDriver;
TCollection_AsciiString aFileNameU(theFileName);
if(PCDM::FileDriverType(aFileNameU, theFileDriver) == PCDM_TOFD_Unknown) {
myReaderStatus = PCDM_RS_UnknownFileDriver;
return;
}
{
try {
OCC_CATCH_SIGNALS
RaiseIfUnknownTypes(aSchema, theFileName);
PCDM_ReadWriter::Open(*theFileDriver,theFileName,Storage_VSRead);
}
catch (Standard_TypeMismatch) {
aMsg << Standard_TypeMismatch::Caught() << endl;
myReaderStatus = PCDM_RS_TypeNotFoundInSchema;
Failure=Standard_True;
}
catch (Standard_Failure) {
aMsg << Standard_Failure::Caught() << endl;
myReaderStatus = PCDM_RS_OpenError;
Failure=Standard_True;
}
if(Failure) Standard_Failure::Raise(aMsg);
}
Handle(Storage_Data) theData = aSchema->Read(*theFileDriver);
Storage_Error aStatus = theData->ErrorStatus();
if(aStatus != Storage_VSOk) {
switch (aStatus) {
case Storage_VSOpenError:
case Storage_VSNotOpen:
case Storage_VSAlreadyOpen:
myReaderStatus = PCDM_RS_OpenError;
aMsg << "Stream Open Error" << endl;
break;
case Storage_VSModeError:
myReaderStatus = PCDM_RS_WrongStreamMode;
aMsg << "Stream is opened with a wrong mode for operation" << endl;
break;
case Storage_VSSectionNotFound:
aMsg << "Section is not found" << endl;
myReaderStatus = PCDM_RS_FormatFailure;
break;
case Storage_VSFormatError:
myReaderStatus = PCDM_RS_FormatFailure;
aMsg << "Wrong format error" << endl;
break;
case Storage_VSUnknownType:
myReaderStatus = PCDM_RS_TypeFailure;
aMsg << "Try to read an unknown type" << endl;
break;
case Storage_VSTypeMismatch:
myReaderStatus = PCDM_RS_TypeFailure;
aMsg << "Try to read a wrong primitive type" << endl;
break;
default:
myReaderStatus = PCDM_RS_DriverFailure;
aMsg << "Retrieval Driver Failure" << endl;
}
Standard_Failure::Raise(aMsg);
}
theFileDriver->Close();
delete theFileDriver;
Handle(Storage_HSeqOfRoot) theDocuments=theData->Roots();
Handle(Storage_Root) theDocument;
for(Standard_Integer i=1; i<=theDocuments->Length() && theDocument.IsNull(); i++) {
theDocument=theDocuments->Value(i);
}
if(theDocument.IsNull()) {
Standard_SStream anErrorMsg;
anErrorMsg << "could not find any document in this file" << (char) 0;
myReaderStatus = PCDM_RS_NoDocument;
Standard_Failure::Raise(anErrorMsg);
}
Handle(Standard_Persistent) theObject=theDocument->Object();
Handle(PCDM_Document) thePDocument = Handle(PCDM_Document)::DownCast (theObject);
{
try {
OCC_CATCH_SIGNALS
Make(thePDocument,aNewDocument);
}
catch (Standard_Failure) {
aMsg << "Error during Make: ";
aMsg << Standard_Failure::Caught() << (char)0;
myReaderStatus = PCDM_RS_MakeFailure;
Failure=Standard_True;
}
}
// read comments
aNewDocument->SetComments(theData->Comments());
PCDM_DriverError_Raise_if(Failure,aMsg);
}
void PCDM_RetrievalDriver::References(const TCollection_ExtendedString& aFileName, PCDM_SequenceOfReference& theReferences, const Handle(CDM_MessageDriver)& theMsgDriver) {
PCDM_ReadWriter::Reader(aFileName)->ReadReferences(aFileName, theReferences, theMsgDriver);
}
void PCDM_RetrievalDriver::Extensions(const TCollection_ExtendedString& aFileName, TColStd_SequenceOfExtendedString& theExtensions, const Handle(CDM_MessageDriver)& theMsgDriver) {
PCDM_ReadWriter::Reader(aFileName)->ReadExtensions(aFileName,theExtensions, theMsgDriver);
}
Standard_Integer PCDM_RetrievalDriver::DocumentVersion(const TCollection_ExtendedString& aFileName, const Handle(CDM_MessageDriver)& theMsgDriver) {
return PCDM_ReadWriter::Reader(aFileName)->ReadDocumentVersion(aFileName, theMsgDriver);
}
Standard_Integer PCDM_RetrievalDriver::ReferenceCounter(const TCollection_ExtendedString& aFileName, const Handle(CDM_MessageDriver)& theMsgDriver) {
return PCDM_ReadWriter::Reader(aFileName)->ReadReferenceCounter(aFileName, theMsgDriver);
}
void PCDM_RetrievalDriver::LoadExtensions(const Handle(Storage_Schema)& , const TColStd_SequenceOfExtendedString& , const Handle(CDM_MessageDriver)&) {}
//=======================================================================
//function : Format
//purpose :
//=======================================================================
Standard_Integer PCDM_RetrievalDriver::ReferenceCounter(const TCollection_ExtendedString& aFileName, const Handle(CDM_MessageDriver)& theMsgDriver)
{ return PCDM_ReadWriter::Reader(aFileName)->ReadReferenceCounter(aFileName, theMsgDriver); }
void PCDM_RetrievalDriver::SetFormat (const TCollection_ExtendedString& aformat)
{
myFormat = aformat;
}
//=======================================================================
//function : Format
//purpose :
//=======================================================================
{ myFormat = aformat; }
TCollection_ExtendedString PCDM_RetrievalDriver::GetFormat () const
{
return myFormat;
}
{ return myFormat; }

View File

@@ -20,94 +20,49 @@
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <TCollection_ExtendedString.hxx>
#include <PCDM_Reader.hxx>
#include <PCDM_ReferenceIterator.hxx>
#include <TColStd_SequenceOfExtendedString.hxx>
#include <PCDM_SequenceOfReference.hxx>
#include <Standard_Integer.hxx>
class Standard_NoSuchObject;
class PCDM_DriverError;
class CDM_MetaData;
class TCollection_ExtendedString;
class CDM_Document;
class CDM_Application;
class PCDM_Document;
class Storage_Schema;
class CDM_MessageDriver;
class TCollection_AsciiString;
class TCollection_ExtendedString;
class PCDM_RetrievalDriver;
DEFINE_STANDARD_HANDLE(PCDM_RetrievalDriver, PCDM_Reader)
class PCDM_RetrievalDriver : public PCDM_Reader
{
friend Standard_EXPORT void PCDM_ReferenceIterator::Init (const Handle(CDM_MetaData)& aMetaData);
public:
Standard_EXPORT static Standard_Integer DocumentVersion (
const TCollection_ExtendedString& theFileName,
const Handle(CDM_MessageDriver)& theMsgDriver);
//! Warning - raises DriverError if an error occurs during inside the
//! Make method.
//! retrieves the content of the file into a new Document.
//!
//! by default Read will use the Schema method to read the file
//! 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 static Standard_Integer ReferenceCounter (
const TCollection_ExtendedString& theFileName,
const Handle(CDM_MessageDriver)& theMsgDriver);
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;
Standard_EXPORT virtual TCollection_ExtendedString SchemaName() const = 0;
Standard_EXPORT virtual void LoadExtensions (const Handle(Storage_Schema)& aSchema, const TColStd_SequenceOfExtendedString& Extensions, const Handle(CDM_MessageDriver)& theMsgDriver);
Standard_EXPORT static void RaiseIfUnknownTypes (const Handle(Storage_Schema)& aSchema, const TCollection_ExtendedString& aFileName);
Standard_EXPORT static Standard_Integer DocumentVersion (const TCollection_ExtendedString& aFileName, const Handle(CDM_MessageDriver)& theMsgDriver);
Standard_EXPORT static Standard_Integer ReferenceCounter (const TCollection_ExtendedString& aFileName, const Handle(CDM_MessageDriver)& theMsgDriver);
Standard_EXPORT void SetFormat (const TCollection_ExtendedString& aformat);
Standard_EXPORT TCollection_ExtendedString GetFormat() const;
friend
Standard_EXPORT void PCDM_ReferenceIterator::Init (const Handle(CDM_MetaData)& aMetaData);
DEFINE_STANDARD_RTTIEXT(PCDM_RetrievalDriver,PCDM_Reader)
protected:
private:
Standard_EXPORT static void References (const TCollection_ExtendedString& aFileName, PCDM_SequenceOfReference& theReferences, const Handle(CDM_MessageDriver)& theMsgDriver);
Standard_EXPORT static void Extensions (const TCollection_ExtendedString& aFileName, TColStd_SequenceOfExtendedString& theExtensions, const Handle(CDM_MessageDriver)& theMsgDriver);
Standard_EXPORT static void UserInfo (const TCollection_ExtendedString& aFileName, const TCollection_AsciiString& Start, const TCollection_AsciiString& End, TColStd_SequenceOfExtendedString& theUserInfo, const Handle(CDM_MessageDriver)& theMsgDriver);
Standard_EXPORT static void References (
const TCollection_ExtendedString& theFileName,
PCDM_SequenceOfReference& theReferences,
const Handle(CDM_MessageDriver)& theMsgDriver);
TCollection_ExtendedString myFormat;
};
#endif // _PCDM_RetrievalDriver_HeaderFile

View File

@@ -44,7 +44,7 @@ IMPLEMENT_STANDARD_RTTIEXT(PCDM_StorageDriver,PCDM_Writer)
void PCDM_StorageDriver::Write(const Handle(CDM_Document)& aDocument, const TCollection_ExtendedString& aFileName)
{
Handle(Storage_Schema) theSchema=PCDM::Schema(SchemaName(),aDocument->Application());
Handle(Storage_Schema) theSchema = new Storage_Schema;
TColStd_SequenceOfExtendedString theExtensions;
aDocument->Extensions(theExtensions);