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

Integration of OCCT 6.5.0 from SVN

This commit is contained in:
bugmaster
2011-03-16 07:30:28 +00:00
committed by bugmaster
parent 4903637061
commit 7fd59977df
16375 changed files with 3882564 additions and 0 deletions

2
src/PCDM/FILES Executable file
View File

@@ -0,0 +1,2 @@
PCDM_DOMHeaderParser.hxx
PCDM_DOMHeaderParser.cxx

87
src/PCDM/PCDM.cdl Executable file
View File

@@ -0,0 +1,87 @@
-- File: PCDM.cdl
-- Created: Fri Aug 1 15:22:57 1997
-- Author: Jean-Louis Frenkel
-- <rmi@frilox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1997
package PCDM
uses
CDM,TColStd,TCollection,Storage
is
enumeration ReaderStatus is
RS_OK,
RS_NoDriver,
RS_UnknownFileDriver,
RS_OpenError,
RS_NoVersion,
RS_NoSchema,
RS_NoDocument,
RS_ExtensionFailure,
RS_WrongStreamMode,
RS_FormatFailure,
RS_TypeFailure,
RS_TypeNotFoundInSchema,
RS_UnrecognizedFileFormat,
RS_MakeFailure,
RS_PermissionDenied,
RS_DriverFailure
end ReaderStatus;
deferred class Document;
class SequenceOfDocument instantiates Sequence from TCollection(Document from PCDM);
deferred class Reader;
deferred class Writer;
deferred class RetrievalDriver;
deferred class StorageDriver;
class ReferenceIterator;
---Category: exceptions
exception DriverError inherits Failure from Standard;
---Category: classes for versioning reading/writing og the headers.
private class Reference;
private class SequenceOfReference instantiates Sequence from TCollection(Reference from PCDM);
private deferred class ReadWriter;
private class ReadWriter_1;
---Category: type of FileDriver;
--
private enumeration TypeOfFileDriver is TOFD_File, TOFD_CmpFile, TOFD_Unknown
end TypeOfFileDriver from PCDM;
private pointer BaseDriverPointer to BaseDriver from Storage;
---Category: drivers plugin.
--
FindStorageDriver(aDocument: Document from CDM)
returns Boolean from Standard;
StorageDriver(aDocument: Document from CDM)
returns StorageDriver from PCDM
raises NoSuchObject from Standard;
---Purpose: gets in the EuclidDesktop resource the plugin
-- identifier of the driver plugs the driver.
--
Schema(aSchemaName: ExtendedString from TCollection;
anApplication: Application from CDM)
---Purpose: returns a schema to be used during a Store or Retrieve
-- operation.
-- Schema will plug the schema defined by
-- the SchemaName method.
returns Schema from Storage;
FileDriverType(aFileName: AsciiString from TCollection; aBaseDriver: out BaseDriverPointer from PCDM)
returns TypeOfFileDriver from PCDM
is private;
end PCDM;

89
src/PCDM/PCDM.cxx Executable file
View File

@@ -0,0 +1,89 @@
// File: PCDM.cxx
// Created: Wed Nov 5 11:53:15 1997
// Author: Jean-Louis Frenkel
// <rmi@frilox.paris1.matra-dtv.fr>
#include <PCDM.ixx>
#include <Plugin.hxx>
#include <Standard_SStream.hxx>
#include <Standard_NoSuchObject.hxx>
#include <Resource_Manager.hxx>
#include <Standard_GUID.hxx>
#include <UTL.hxx>
#include <FSD_CmpFile.hxx>
#include <FSD_File.hxx>
#include <FSD_BinaryFile.hxx>
//=======================================================================
//function : StorageDriver
//purpose : gets in the EuclidDesktop resource the plugin
// identifier of the driver plugs the driver.
//=======================================================================
Handle(PCDM_StorageDriver) PCDM::StorageDriver(const Handle(CDM_Document)& aDocument) {
if(!PCDM::FindStorageDriver(aDocument)) {
Standard_SStream aMsg; aMsg << "could not find the storage driver plugin resource for the format: " << aDocument->StorageFormat()<<(char) 0;
Standard_NoSuchObject::Raise(aMsg);
}
//return Handle(PCDM_StorageDriver)::DownCast(Plugin::Load(aDocument->StoragePlugin()));
Handle(PCDM_StorageDriver) DRIVER =
Handle(PCDM_StorageDriver)::DownCast(Plugin::Load(aDocument->StoragePlugin()));
if (!DRIVER.IsNull()) DRIVER->SetFormat(aDocument->StorageFormat());
return DRIVER;
}
//=======================================================================
//function : FindStorageDriver
//purpose :
//=======================================================================
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)*)&t);
}
//=======================================================================
//function : FileDriverType
//purpose :
//=======================================================================
PCDM_TypeOfFileDriver PCDM::FileDriverType(const TCollection_AsciiString& aFileName, PCDM_BaseDriverPointer& aBaseDriver) {
if(FSD_CmpFile::IsGoodFileType(aFileName) == Storage_VSOk) {
aBaseDriver=new FSD_CmpFile;
return PCDM_TOFD_CmpFile;
}
else if(FSD_File::IsGoodFileType(aFileName) == Storage_VSOk) {
aBaseDriver=new FSD_File;
return PCDM_TOFD_File;
}
else if(FSD_BinaryFile::IsGoodFileType(aFileName) == Storage_VSOk) {
aBaseDriver=new FSD_BinaryFile;
return PCDM_TOFD_File;
}
else {
aBaseDriver=NULL;
return PCDM_TOFD_Unknown;
}
}

View File

@@ -0,0 +1,56 @@
// File: PCDM_DOMHeaderParser.cxx
// Created: 30.07.01 12:51:01
// Author: Alexander GRIGORIEV
// Copyright: OpenCascade 2001
// History:
#include <PCDM_DOMHeaderParser.hxx>
//=======================================================================
//function : SetStartElementName
//purpose : set the name of the element which would stop parsing when detected
//=======================================================================
void PCDM_DOMHeaderParser::SetStartElementName
(const TCollection_AsciiString& aStartElementName)
{
myStartElementName = LDOMString (aStartElementName.ToCString());
}
//=======================================================================
//function : SetEndElementName
//purpose : set the name of the element which would stop parsing when parsed
//=======================================================================
void PCDM_DOMHeaderParser::SetEndElementName
(const TCollection_AsciiString& anEndElementName)
{
myEndElementName = LDOMString (anEndElementName.ToCString());
}
//=======================================================================
//function : PCDM_DOMHeaderParser()
//purpose : Constructor
//=======================================================================
Standard_Boolean PCDM_DOMHeaderParser::startElement ()
{
if (myStartElementName == NULL)
return Standard_False;
myElement = getCurrentElement ();
return (myElement.getTagName().equals (myStartElementName));
}
//=======================================================================
//function : endElement
//purpose :
//=======================================================================
Standard_Boolean PCDM_DOMHeaderParser::endElement ()
{
if (myEndElementName == NULL)
return Standard_False;
myElement = getCurrentElement ();
return (myElement.getTagName().equals (myEndElementName));
}

View File

@@ -0,0 +1,45 @@
// File: PCDM_DOMHeaderParser.hxx
// Created: 30.07.01 12:45:51
// Author: Alexander GRIGORIEV
// Copyright: OpenCascade 2001
#ifndef PCDM_DOMHeaderParser_HeaderFile
#define PCDM_DOMHeaderParser_HeaderFile
#include <LDOMParser.hxx>
// Block of comments describing class PCDM_DOMHeaderParser
//
class PCDM_DOMHeaderParser : public LDOMParser
{
public:
// ---------- PUBLIC METHODS ----------
void SetStartElementName (const TCollection_AsciiString& aStartElementName);
// set the name of the element which would stop parsing when detected
void SetEndElementName (const TCollection_AsciiString& anEndElementName);
// set the name of the element which would stop parsing when parsed
Standard_Boolean startElement ();
// redefined method from LDOMParser
// stops parsing when the attributes of header element have been read
Standard_Boolean endElement ();
// redefined method from LDOMParser
// stops parsing when the info element with all sub-elements has been read
const LDOM_Element& GetElement () const { return myElement; }
// returns the LDOM_Element containing data about file format
private:
// ---------- PRIVATE FIELDS ----------
LDOM_Element myElement;
LDOMString myStartElementName;
LDOMString myEndElementName;
};
#endif

13
src/PCDM/PCDM_Document.cdl Executable file
View File

@@ -0,0 +1,13 @@
-- File: PCDM_PCDM.cdl
-- Created: Fri Aug 1 15:26:17 1997
-- Author: Jean-Louis Frenkel
-- <rmi@frilox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1997
deferred class Document from PCDM inherits Persistent from Standard
uses Document from CDM
is
end Document from PCDM;

8
src/PCDM/PCDM_Document.cxx Executable file
View File

@@ -0,0 +1,8 @@
// File: PCDM_Document.cxx
// Created: Fri Aug 1 16:08:32 1997
// Author: Jean-Louis Frenkel
// <rmi@frilox.paris1.matra-dtv.fr>
#include <PCDM_Document.ixx>

78
src/PCDM/PCDM_ReadWriter.cdl Executable file
View File

@@ -0,0 +1,78 @@
-- File: PCDM_ReadWriter.cdl
-- Created: Tue Dec 9 08:28:48 1997
-- Author: Jean-Louis Frenkel
-- <rmi@frilox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1997
private deferred class ReadWriter from PCDM inherits Transient from Standard
uses
ExtendedString from TCollection,
AsciiString from TCollection,
Data from Storage,
Document from CDM,
MessageDriver from CDM,
SequenceOfExtendedString from TColStd,
BaseDriver from Storage,
OpenMode from Storage,
SequenceOfReference from PCDM
is
Version(me) returns AsciiString from TCollection
is deferred;
---Purpose: returns PCDM_ReadWriter_1.
WriteReferenceCounter(me; aData: mutable Data from Storage; aDocument: Document from CDM)
is deferred;
WriteReferences(me; aData: mutable Data from Storage; aDocument: Document from CDM; theReferencerFileName: ExtendedString from TCollection)
is deferred;
WriteExtensions(me; aData: mutable Data from Storage; aDocument: Document from CDM)
is deferred;
WriteVersion(me; aData: mutable Data from Storage; aDocument: Document from CDM)
is deferred;
ReadReferenceCounter(me; theFileName: ExtendedString from TCollection;
theMsgDriver: MessageDriver from CDM)
returns Integer from Standard
is deferred;
ReadReferences(me; aFileName: ExtendedString from TCollection; theReferences: in out SequenceOfReference from PCDM; theMsgDriver: MessageDriver from CDM)
is deferred;
ReadExtensions(me; aFileName: ExtendedString from TCollection; theExtensions: in out SequenceOfExtendedString from TColStd; theMsgDriver: MessageDriver from CDM)
is deferred;
ReadDocumentVersion(me; aFileName: ExtendedString from TCollection; theMsgDriver: MessageDriver from CDM)
returns Integer from Standard
is deferred;
---Category: commom methods
Open(myclass; aDriver: in out BaseDriver from Storage; aFileName: ExtendedString from TCollection; anOpenMode: OpenMode from Storage);
Reader(myclass; aFileName: ExtendedString from TCollection)
returns ReadWriter from PCDM;
---Purpose: returns the convenient Reader for a File.
--
Writer(myclass)
returns ReadWriter from PCDM;
WriteFileFormat(myclass; aData: mutable Data from Storage; aDocument: Document from CDM);
FileFormat(myclass; aFileName: ExtendedString from TCollection)
returns ExtendedString from TCollection;
---Purpose: tries to get a format in the file. returns an empty
-- string if the file could not be read or does not have
-- a FileFormat information.
end ReadWriter from PCDM;

155
src/PCDM/PCDM_ReadWriter.cxx Executable file
View File

@@ -0,0 +1,155 @@
// File: PCDM_ReadWriter.cxx
// Created: Tue Dec 9 08:32:51 1997
// Author: Jean-Louis Frenkel
// <rmi@frilox.paris1.matra-dtv.fr>
#include <PCDM_ReadWriter.ixx>
#include <UTL.hxx>
#include <PCDM_ReadWriter_1.hxx>
#include <Storage_Schema.hxx>
#include <Standard_ErrorHandler.hxx>
#include <Storage_HeaderData.hxx>
#include <Storage_TypeData.hxx>
#include <UTL.hxx>
#include <TColStd_HSequenceOfAsciiString.hxx>
#include <PCDM.hxx>
#include <PCDM_DOMHeaderParser.hxx>
#define FILE_FORMAT "FILE_FORMAT: "
static TCollection_ExtendedString TryXmlDriverType
(const TCollection_AsciiString& theFileName);
//=======================================================================
//function : Open
//purpose :
//=======================================================================
void PCDM_ReadWriter::Open (Storage_BaseDriver& aDriver,
const TCollection_ExtendedString& aFileName,
const Storage_OpenMode aMode)
{
Storage_Error error = UTL::OpenFile(aDriver,aFileName,aMode);
if(error != Storage_VSOk) {
Standard_SStream aMsg; aMsg << "could not open the file: ";
aMsg << aFileName;
switch (error) {
case Storage_VSOpenError: aMsg << "; file was not found or permission denied"; break;
case Storage_VSAlreadyOpen: aMsg<< "; file was already opened";
default:
break;
}
aMsg << (char)0;
Standard_Failure::Raise(aMsg);
}
}
//=======================================================================
//function : Reader
//purpose :
//=======================================================================
//Handle(PCDM_ReadWriter) PCDM_ReadWriter::Reader(const TCollection_ExtendedString& aFileName) {
Handle(PCDM_ReadWriter) PCDM_ReadWriter::Reader
(const TCollection_ExtendedString&)
{
static Handle(PCDM_ReadWriter_1) theReader=new PCDM_ReadWriter_1;
return theReader;
}
//=======================================================================
//function : Writer
//purpose :
//=======================================================================
Handle(PCDM_ReadWriter) PCDM_ReadWriter::Writer ()
{
static Handle(PCDM_ReadWriter_1) theWriter=new PCDM_ReadWriter_1;
return theWriter;
}
//=======================================================================
//function : WriteFileFormat
//purpose :
//=======================================================================
void PCDM_ReadWriter::WriteFileFormat (const Handle(Storage_Data)& aData,
const Handle(CDM_Document)& aDocument)
{
TCollection_AsciiString ligne(FILE_FORMAT);
ligne += TCollection_AsciiString(aDocument->StorageFormat(),'?');
aData->AddToUserInfo(ligne);
}
//=======================================================================
//function : FileFormat
//purpose :
//=======================================================================
TCollection_ExtendedString PCDM_ReadWriter::FileFormat
(const TCollection_ExtendedString& aFileName)
{
TCollection_ExtendedString theFormat;
PCDM_BaseDriverPointer theFileDriver;
TCollection_AsciiString theFileName (UTL::CString(aFileName));
if (PCDM::FileDriverType (theFileName, theFileDriver) == PCDM_TOFD_Unknown)
return ::TryXmlDriverType (theFileName);
static Standard_Boolean theFileIsOpen;
theFileIsOpen=Standard_False;
try {
OCC_CATCH_SIGNALS
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();
Standard_Boolean found=Standard_False;
for (Standard_Integer i =1; !found && i<= refUserInfo.Length() ; i++) {
if(refUserInfo(i).Search(FILE_FORMAT) != -1) {
found=Standard_True;
theFormat=UTL::ExtendedString(refUserInfo(i).Token(" ",2));
}
}
if(!found) theFormat=s->ReadTypeSection(*theFileDriver)->Types()->Value(1);
}
catch (Standard_Failure) {}
if(theFileIsOpen)theFileDriver->Close();
delete theFileDriver;
return theFormat;
}
//=======================================================================
//function : ::TryXmlDriverType
//purpose : called from FileFormat()
//=======================================================================
static TCollection_ExtendedString TryXmlDriverType
(const TCollection_AsciiString& theFileName)
{
TCollection_ExtendedString theFormat;
PCDM_DOMHeaderParser aParser;
const char * aDocumentElementName = "document";
aParser.SetStartElementName (Standard_CString(aDocumentElementName));
// 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 (theFileName.ToCString()))
{
LDOM_Element anElement = aParser.GetElement();
if (anElement.getTagName().equals (LDOMString(aDocumentElementName)))
theFormat = anElement.getAttribute ("format");
}
return theFormat;
}

51
src/PCDM/PCDM_ReadWriter_1.cdl Executable file
View File

@@ -0,0 +1,51 @@
-- File: PCDM_ReadWriter_1.cdl
-- Created: Tue Dec 9 08:20:45 1997
-- Author: Jean-Louis Frenkel
-- <rmi@frilox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1997
private class ReadWriter_1 from PCDM inherits ReadWriter from PCDM
uses
ExtendedString from TCollection,
AsciiString from TCollection,
Data from Storage,
Document from CDM,
MessageDriver from CDM,
SequenceOfExtendedString from TColStd,
SequenceOfReference from PCDM
is
Create returns mutable ReadWriter_1 from PCDM;
Version(me) returns AsciiString from TCollection;
---Purpose: returns PCDM_ReadWriter_1.
WriteReferenceCounter(me; aData: mutable Data from Storage; aDocument: Document from CDM);
WriteReferences(me; aData: mutable Data from Storage; aDocument: Document from CDM; theReferencerFileName: ExtendedString from TCollection);
WriteExtensions(me; aData: mutable Data from Storage; aDocument: Document from CDM);
WriteVersion(me; aData: mutable Data from Storage; aDocument: Document from CDM);
ReadReferenceCounter(me; aFileName: ExtendedString from TCollection; theMsgDriver: MessageDriver from CDM)
returns Integer from Standard;
ReadReferences(me; aFileName: ExtendedString from TCollection; theReferences: in out SequenceOfReference from PCDM; theMsgDriver: MessageDriver from CDM);
ReadExtensions(me; aFileName: ExtendedString from TCollection; theExtensions: in out SequenceOfExtendedString from TColStd; theMsgDriver: MessageDriver from CDM);
ReadUserInfo(myclass; aFileName: ExtendedString from TCollection; Start, End: AsciiString from TCollection; theUserInfo:in out SequenceOfExtendedString from TColStd;theMsgDriver: MessageDriver from CDM)
is private;
ReadDocumentVersion(me; aFileName: ExtendedString from TCollection; theMsgDriver: MessageDriver from CDM)
returns Integer from Standard;
end ReadWriter_1 from PCDM;

394
src/PCDM/PCDM_ReadWriter_1.cxx Executable file
View File

@@ -0,0 +1,394 @@
// File: PCDM_ReadWriter_1.cxx
// Created: Tue Dec 9 08:22:39 1997
// Author: Jean-Louis Frenkel
// <rmi@frilox.paris1.matra-dtv.fr>
#include <PCDM_ReadWriter_1.ixx>
#include <UTL.hxx>
#include <Storage_Data.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
#include <CDM_Document.hxx>
#include <CDM_ReferenceIterator.hxx>
#include <CDM_MetaData.hxx>
#include <TColStd_SequenceOfExtendedString.hxx>
#include <Storage_Schema.hxx>
#include <Storage_HeaderData.hxx>
#include <TColStd_SequenceOfAsciiString.hxx>
#include <PCDM_Reference.hxx>
#include <Standard_ErrorHandler.hxx>
#include <OSD_Path.hxx>
#include <PCDM_BaseDriverPointer.hxx>
#include <PCDM.hxx>
#include <PCDM_TypeOfFileDriver.hxx>
#define START_REF "START_REF"
#define END_REF "END_REF"
#define START_EXT "START_EXT"
#define END_EXT "END_EXT"
#define MODIFICATION_COUNTER "MODIFICATION_COUNTER: "
#define REFERENCE_COUNTER "REFERENCE_COUNTER: "
//=======================================================================
//function : PCDM_ReadWriter_1
//purpose :
//=======================================================================
PCDM_ReadWriter_1::PCDM_ReadWriter_1() {}
static Standard_Integer RemoveExtraSeparator(TCollection_AsciiString& aString) {
Standard_Integer i, j, len ;
len = aString.Length() ;
#ifdef WNT
// Case of network path, such as \\MACHINE\dir
for (i = j = 2 ; j <= len ; i++,j++) {
#else
for (i = j = 1 ; j <= len ; i++,j++) {
#endif
Standard_Character c = aString.Value(j) ;
aString.SetValue(i,c) ;
if (c == '/')
while(j < len && aString.Value(j+1) == '/') j++ ;
}
len = i-1 ;
if (aString.Value(len) == '/') len-- ;
aString.Trunc(len) ;
return len ;
}
static TCollection_AsciiString AbsolutePath(
const TCollection_AsciiString& aDirPath,
const TCollection_AsciiString& aRelFilePath)
{
TCollection_AsciiString EmptyString = "" ;
#ifdef WNT
if (aRelFilePath.Search(":") == 2 ||
(aRelFilePath.Search("\\") == 1 && aRelFilePath.Value(2) == '\\'))
#else
if(aRelFilePath.Search("/") == 1)
#endif
return aRelFilePath ;
TCollection_AsciiString DirPath = aDirPath, RelFilePath = aRelFilePath ;
Standard_Integer i,len ;
#ifdef WNT
if(DirPath.Search(":") != 2 &&
(DirPath.Search("\\") != 1 || DirPath.Value(2) != '\\'))
#else
if (DirPath.Search("/") != 1 )
#endif
return EmptyString ;
#ifdef WNT
DirPath.ChangeAll('\\','/') ;
RelFilePath.ChangeAll('\\','/') ;
#endif
RemoveExtraSeparator(DirPath) ;
len = RemoveExtraSeparator(RelFilePath) ;
while (RelFilePath.Search("../") == 1) {
if (len == 3)
return EmptyString ;
RelFilePath = RelFilePath.SubString(4,len) ;
len -= 3 ;
if (DirPath.IsEmpty())
return EmptyString ;
i = DirPath.SearchFromEnd("/") ;
if (i < 0)
return EmptyString ;
DirPath.Trunc(i-1) ;
}
TCollection_AsciiString retx;
retx= DirPath;
retx+= "/";
retx+=RelFilePath ;
return retx;
}
static TCollection_AsciiString GetDirFromFile(const TCollection_ExtendedString& aFileName) {
TCollection_AsciiString theCFile=UTL::CString(aFileName);
TCollection_AsciiString theDirectory;
Standard_Integer i=theCFile.SearchFromEnd("/");
#ifdef WNT
// if(i==-1) i=theCFile.SearchFromEnd("\\");
if(theCFile.SearchFromEnd("\\") > i)
i=theCFile.SearchFromEnd("\\");
#endif
if(i!=-1) theDirectory=theCFile.SubString(1,i);
return theDirectory;
}
//=======================================================================
//function : Version
//purpose :
//=======================================================================
TCollection_AsciiString PCDM_ReadWriter_1::Version() const {
return "PCDM_ReadWriter_1";
}
//=======================================================================
//function : WriteReferenceCounter
//purpose :
//=======================================================================
void PCDM_ReadWriter_1::WriteReferenceCounter(const Handle(Storage_Data)& aData, const Handle(CDM_Document)& aDocument) const {
TCollection_AsciiString ligne(REFERENCE_COUNTER);
ligne+=aDocument->ReferenceCounter();
aData->AddToUserInfo(ligne);
}
//=======================================================================
//function : WriteReferences
//purpose :
//=======================================================================
void PCDM_ReadWriter_1::WriteReferences(const Handle(Storage_Data)& aData, const Handle(CDM_Document)& aDocument,const TCollection_ExtendedString& theReferencerFileName) const {
Standard_Integer theNumber = aDocument->ToReferencesNumber();
if(theNumber > 0) {
aData->AddToUserInfo(START_REF);
CDM_ReferenceIterator it(aDocument);
TCollection_ExtendedString ligne;
TCollection_AsciiString theAbsoluteDirectory=GetDirFromFile(theReferencerFileName);
for (;it.More();it.Next()) {
ligne = TCollection_ExtendedString(it.ReferenceIdentifier());
ligne += " ";
ligne += TCollection_ExtendedString(it.Document()->Modifications());
ligne += " ";
TCollection_AsciiString thePath=UTL::CString(it.Document()->MetaData()->FileName());
TCollection_AsciiString theRelativePath;
if(!theAbsoluteDirectory.IsEmpty()) {
theRelativePath=OSD_Path::RelativePath(theAbsoluteDirectory,thePath);
if(!theRelativePath.IsEmpty()) thePath=theRelativePath;
}
ligne += UTL::ExtendedString(thePath);
UTL::AddToUserInfo(aData,ligne);
}
aData->AddToUserInfo(END_REF);
}
}
//=======================================================================
//function : WriteExtensions
//purpose :
//=======================================================================
void PCDM_ReadWriter_1::WriteExtensions(const Handle(Storage_Data)& aData, const Handle(CDM_Document)& aDocument) const {
TColStd_SequenceOfExtendedString theExtensions;
aDocument->Extensions(theExtensions);
Standard_Integer theNumber = theExtensions.Length();
if(theNumber > 0) {
aData->AddToUserInfo(START_EXT);
for (Standard_Integer i=1; i<=theNumber; i++) {
UTL::AddToUserInfo(aData,theExtensions(i));
}
aData->AddToUserInfo(END_EXT);
}
}
//=======================================================================
//function : WriteVersion
//purpose :
//=======================================================================
void PCDM_ReadWriter_1::WriteVersion(const Handle(Storage_Data)& aData, const Handle(CDM_Document)& aDocument) const {
TCollection_AsciiString ligne(MODIFICATION_COUNTER);
ligne+=aDocument->Modifications();
aData->AddToUserInfo(ligne);
}
//=======================================================================
//function : ReadReferenceCounter
//purpose :
//=======================================================================
Standard_Integer PCDM_ReadWriter_1::ReadReferenceCounter(const TCollection_ExtendedString& aFileName, const Handle(CDM_MessageDriver)& theMsgDriver) const {
static Standard_Integer theReferencesCounter ;
theReferencesCounter=0;
static Standard_Integer i ;
PCDM_BaseDriverPointer theFileDriver;
if(PCDM::FileDriverType(TCollection_AsciiString(UTL::CString(aFileName)), theFileDriver) == PCDM_TOFD_Unknown) return theReferencesCounter;
static Standard_Boolean theFileIsOpen ;
theFileIsOpen=Standard_False;
try {
OCC_CATCH_SIGNALS
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();
for ( i =1; i<= refUserInfo.Length() ; i++) {
if(refUserInfo(i).Search(REFERENCE_COUNTER) != -1) {
try { OCC_CATCH_SIGNALS theReferencesCounter=refUserInfo(i).Token(" ",2).IntegerValue();}
catch (Standard_Failure) {
// cout << "warning: could not read the reference counter in " << aFileName << endl;
TCollection_ExtendedString aMsg("Warning: ");
aMsg = aMsg.Cat("could not read the reference counter in ").Cat(aFileName).Cat("\0");
if(!theMsgDriver.IsNull())
theMsgDriver->Write(aMsg.ToExtString());
}
}
}
}
catch (Standard_Failure) {}
if(theFileIsOpen) theFileDriver->Close();
delete theFileDriver;
return theReferencesCounter;
}
//=======================================================================
//function : ReadReferences
//purpose :
//=======================================================================
void PCDM_ReadWriter_1::ReadReferences(const TCollection_ExtendedString& aFileName, PCDM_SequenceOfReference& theReferences, const Handle(CDM_MessageDriver)& theMsgDriver) const {
TColStd_SequenceOfExtendedString ReadReferences;
ReadUserInfo(aFileName,START_REF,END_REF,ReadReferences, theMsgDriver);
Standard_Integer theReferenceIdentifier;
TCollection_ExtendedString theFileName;
Standard_Integer theDocumentVersion;
TCollection_AsciiString theAbsoluteDirectory=GetDirFromFile(aFileName);
for (Standard_Integer i=1; i<=ReadReferences.Length(); i++) {
Standard_Integer pos=ReadReferences(i).Search(" ");
if(pos != -1) {
TCollection_ExtendedString theRest=ReadReferences(i).Split(pos);
theReferenceIdentifier=UTL::IntegerValue(ReadReferences(i));
Standard_Integer pos2=theRest.Search(" ");
theFileName=theRest.Split(pos2);
theDocumentVersion=UTL::IntegerValue(theRest);
TCollection_AsciiString thePath=UTL::CString(theFileName);
TCollection_AsciiString theAbsolutePath;
if(!theAbsoluteDirectory.IsEmpty()) {
theAbsolutePath=AbsolutePath(theAbsoluteDirectory,thePath);
if(!theAbsolutePath.IsEmpty()) thePath=theAbsolutePath;
}
if(!theMsgDriver.IsNull()) {
// cout << "reference found; ReferenceIdentifier: " << theReferenceIdentifier << "; File:" << thePath << ", version:" << theDocumentVersion;
TCollection_ExtendedString aMsg("Warning: ");
aMsg = aMsg.Cat("reference found; ReferenceIdentifier: ").Cat(theReferenceIdentifier).Cat("; File:").Cat(thePath).Cat(", version:").Cat(theDocumentVersion).Cat("\0");
theMsgDriver->Write(aMsg.ToExtString());
}
theReferences.Append(PCDM_Reference (theReferenceIdentifier,UTL::ExtendedString(thePath),theDocumentVersion));
}
}
}
//=======================================================================
//function : ReadExtensions
//purpose :
//=======================================================================
void PCDM_ReadWriter_1::ReadExtensions(const TCollection_ExtendedString& aFileName, TColStd_SequenceOfExtendedString& theExtensions, const Handle(CDM_MessageDriver)& theMsgDriver) const {
ReadUserInfo(aFileName,START_EXT,END_EXT,theExtensions, theMsgDriver);
}
//=======================================================================
//function : ReadUserInfo
//purpose :
//=======================================================================
void PCDM_ReadWriter_1::ReadUserInfo(const TCollection_ExtendedString& aFileName,
const TCollection_AsciiString& Start,
const TCollection_AsciiString& End,
TColStd_SequenceOfExtendedString& theUserInfo,
const Handle(CDM_MessageDriver)&) {
static Standard_Integer i ;
PCDM_BaseDriverPointer theFileDriver;
if(PCDM::FileDriverType(TCollection_AsciiString(UTL::CString(aFileName)), theFileDriver) == PCDM_TOFD_Unknown) return;
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();
Standard_Integer debut=0,fin=0;
for ( i =1; i<= refUserInfo.Length() ; i++) {
TCollection_ExtendedString theLine=refUserInfo(i);
if(refUserInfo(i)== Start) debut=i;
if(refUserInfo(i)== End) fin=i;
}
if(debut != 0) {
for (i=debut+1 ; i<fin; i++) {
theUserInfo.Append(UTL::ExtendedString(refUserInfo(i)));
}
}
theFileDriver->Close();
delete theFileDriver;
}
//=======================================================================
//function : ReadDocumentVersion
//purpose :
//=======================================================================
Standard_Integer PCDM_ReadWriter_1::ReadDocumentVersion(const TCollection_ExtendedString& aFileName, const Handle(CDM_MessageDriver)& theMsgDriver) const {
static Standard_Integer theVersion ;
theVersion=-1;
PCDM_BaseDriverPointer theFileDriver;
if(PCDM::FileDriverType(TCollection_AsciiString(UTL::CString(aFileName)), theFileDriver) == PCDM_TOFD_Unknown) return theVersion;
static Standard_Boolean theFileIsOpen ;
theFileIsOpen =Standard_False;
try {
OCC_CATCH_SIGNALS
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();
static Standard_Integer i ;
for ( i =1; i<= refUserInfo.Length() ; i++) {
if(refUserInfo(i).Search(MODIFICATION_COUNTER) != -1) {
try { OCC_CATCH_SIGNALS theVersion=refUserInfo(i).Token(" ",2).IntegerValue();}
catch (Standard_Failure) {
// cout << "warning: could not read the version in " << aFileName << endl;
TCollection_ExtendedString aMsg("Warning: ");
aMsg = aMsg.Cat("could not read the version in ").Cat(aFileName).Cat("\0");
if(!theMsgDriver.IsNull())
theMsgDriver->Write(aMsg.ToExtString());
}
}
}
}
catch (Standard_Failure) {}
if(theFileIsOpen) theFileDriver->Close();
delete theFileDriver;
return theVersion;
}

39
src/PCDM/PCDM_Reader.cdl Executable file
View File

@@ -0,0 +1,39 @@
-- File: PCDM_Reader.cdl
-- Created: Thu Dec 18 09:16:27 1997
-- Author: Jean-Louis Frenkel
-- <rmi@frilox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1997
deferred class Reader from PCDM inherits Transient from Standard
uses
Document from CDM,
ExtendedString from TCollection,
Application from CDM,
ReaderStatus from PCDM
raises DriverError from PCDM
is
CreateDocument(me: mutable) returns Document from CDM
is deferred;
---Purpose: this method is called by the framework before the read method.
Read(me: mutable; aFileName: ExtendedString from TCollection;
aNewDocument: mutable Document from CDM;
anApplication: Application from CDM)
raises DriverError from PCDM
is deferred;
---Purpose: retrieves the content of the file into a new Document.
GetStatus(me) returns ReaderStatus from PCDM;
---C++: inline
fields
myReaderStatus : ReaderStatus from PCDM is protected;
end Reader from PCDM;

8
src/PCDM/PCDM_Reader.cxx Executable file
View File

@@ -0,0 +1,8 @@
// File: PCDM_Reader.cxx
// Created: Thu Dec 18 09:19:10 1997
// Author: Jean-Louis Frenkel
// <rmi@frilox.paris1.matra-dtv.fr>
#include <PCDM_Reader.ixx>

34
src/PCDM/PCDM_Reader.lxx Executable file
View File

@@ -0,0 +1,34 @@
// File: PCDM_Reader.lxx
// Created: Wed Jun 25 16:31:02 2003
// Author: Sergey ZARITCHNY <szy@opencascade.com>
// Copyright: Open CASCADE 2003
// const static char sccsid[] = "%Z% 5.0-20-%L%, $Date: 2003-07-17 20:53:39 $%Z%";
//=======================================================================
//function : GetStatus
//purpose :
//=======================================================================
inline PCDM_ReaderStatus PCDM_Reader::GetStatus() const {
return myReaderStatus;
}
// Lastly modified by :
// +---------------------------------------------------------------------------+
// ! szy ! Creation !25-06-2003! 5.0-20-%L%!
// +---------------------------------------------------------------------------+
// @@SDM: begin
// Copyright Open CASCADE......................................Version 5.0-20
// Lastly modified by : szy Date : 25-06-2003
// File history synopsis (creation,modification,correction)
// +---------------------------------------------------------------------------+
// ! Developer ! Comments ! Date ! Version !
// +-----------!-----------------------------------------!----------!----------+
// ! szy ! Creation !25-06-2003! 5.0-20-%L%!
// +---------------------------------------------------------------------------+
// @@SDM: end

26
src/PCDM/PCDM_Reference.cdl Executable file
View File

@@ -0,0 +1,26 @@
-- File: PCDM_Reference.cdl
-- Created: Tue Dec 9 09:20:32 1997
-- Author: Jean-Louis Frenkel
-- <rmi@frilox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1997
private class Reference from PCDM
uses ExtendedString from TCollection
is
Create returns Reference from PCDM;
Create(aReferenceIdentifier: Integer from Standard; aFileName: ExtendedString from TCollection; aDocumentVersion: Integer from Standard)
returns Reference from PCDM;
ReferenceIdentifier(me) returns Integer from Standard;
FileName(me) returns ExtendedString from TCollection;
DocumentVersion(me) returns Integer from Standard;
fields
myReferenceIdentifier: Integer from Standard;
myFileName: ExtendedString from TCollection;
myDocumentVersion: Integer from Standard;
end Reference from PCDM;

23
src/PCDM/PCDM_Reference.cxx Executable file
View File

@@ -0,0 +1,23 @@
// File: PCDM_Reference.cxx
// Created: Tue Dec 9 09:22:54 1997
// Author: Jean-Louis Frenkel
// <rmi@frilox.paris1.matra-dtv.fr>
#include <PCDM_Reference.ixx>
PCDM_Reference::PCDM_Reference(){}
PCDM_Reference::PCDM_Reference(const Standard_Integer aReferenceIdentifier, const TCollection_ExtendedString& aFileName, const Standard_Integer aDocumentVersion):myReferenceIdentifier(aReferenceIdentifier),myFileName(aFileName),myDocumentVersion(aDocumentVersion) {}
Standard_Integer PCDM_Reference::ReferenceIdentifier() const {
return myReferenceIdentifier;
}
TCollection_ExtendedString PCDM_Reference::FileName() const {
return myFileName;
}
Standard_Integer PCDM_Reference::DocumentVersion() const {
return myDocumentVersion;
}

View File

@@ -0,0 +1,48 @@
-- File: PCDM_ReferenceIterator.cdl
-- Created: Mon Dec 1 07:53:35 1997
-- Author: Jean-Louis Frenkel
-- <rmi@frilox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1997
class ReferenceIterator from PCDM inherits Transient from Standard
uses MetaData from CDM,
SequenceOfReference from PCDM,
Document from CDM, Application from CDM,
MessageDriver from CDM
is
Create (theMessageDriver : MessageDriver from CDM)
returns mutable ReferenceIterator from PCDM;
---Purpose: Warning! The constructor does not initialization.
LoadReferences(me: mutable; aDocument: Document from CDM; aMetaData: MetaData from CDM; anApplication: Application from CDM; UseStorageConfiguration: Boolean from Standard);
Init(me: mutable;aMetaData: MetaData from CDM)
is virtual;
More(me) returns Boolean from Standard
is virtual private;
Next(me: mutable)
is virtual private;
MetaData(me;UseStorageConfiguration: Boolean from Standard )
returns MetaData from CDM
is virtual private;
ReferenceIdentifier(me) returns Integer from Standard
is virtual private;
DocumentVersion(me) returns Integer from Standard
---Purpose: returns the version of the document in the reference
is virtual private;
fields
myReferences: SequenceOfReference from PCDM;
myIterator: Integer from Standard;
myMessageDriver : MessageDriver from CDM;
end ReferenceIterator from PCDM;

View File

@@ -0,0 +1,142 @@
// File: PCDM_ReferenceIterator.cxx
// Created: Mon Dec 1 08:07:09 1997
// Author: Jean-Louis Frenkel
// <rmi@frilox.paris1.matra-dtv.fr>
// modified: <szy@opencascade.com>
#include <PCDM_ReferenceIterator.ixx>
#include <Storage_Data.hxx>
#include <UTL.hxx>
#include <CDM_Document.hxx>
#include <CDM_Application.hxx>
#include <PCDM_RetrievalDriver.hxx>
#include <PCDM_Reference.hxx>
#include <OSD_Path.hxx>
#ifdef WNT
# include <tchar.h>
#endif // WNT
//=======================================================================
//function : PCDM_ReferenceIterator
//purpose :
//=======================================================================
PCDM_ReferenceIterator::PCDM_ReferenceIterator (const Handle(CDM_MessageDriver)& theMsgDriver) {
myMessageDriver = theMsgDriver;
}
//=======================================================================
//function : LoadReferences
//purpose :
//=======================================================================
void PCDM_ReferenceIterator::LoadReferences(const Handle(CDM_Document)& aDocument,
const Handle(CDM_MetaData)& aMetaData,
const Handle(CDM_Application)& anApplication,
const Standard_Boolean UseStorageConfiguration) {
for (Init(aMetaData);More();Next()) {
aDocument->CreateReference(MetaData(UseStorageConfiguration),ReferenceIdentifier(),
anApplication,DocumentVersion(),UseStorageConfiguration);
}
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void PCDM_ReferenceIterator::Init(const Handle(CDM_MetaData)& theMetaData) {
myReferences.Clear();
// mod. by szy
PCDM_RetrievalDriver::References(theMetaData->FileName(), myReferences,
myMessageDriver);
myIterator=1;
}
//=======================================================================
//function : More
//purpose :
//=======================================================================
Standard_Boolean PCDM_ReferenceIterator::More() const {
return myIterator <= myReferences.Length();
}
//=======================================================================
//function : Next
//purpose :
//=======================================================================
void PCDM_ReferenceIterator::Next() {
myIterator++;
}
//=======================================================================
//function : MetaData
//purpose :
//=======================================================================
Handle(CDM_MetaData) PCDM_ReferenceIterator::MetaData(const Standard_Boolean ) const {
TCollection_ExtendedString theFolder,theName;
TCollection_ExtendedString theFile=myReferences(myIterator).FileName();
TCollection_ExtendedString f(theFile);
#ifndef WNT
Standard_Integer i= f.SearchFromEnd("/");
TCollection_ExtendedString n = f.Split(i);
f.Trunc(f.Length()-1);
theFolder = f;
theName = n;
#else
OSD_Path p = UTL::Path(f);
Standard_ExtCharacter chr;
TCollection_ExtendedString dir, dirRet, name;
dir = UTL::Disk(p);
dir += UTL::Trek(p);
for ( int i = 1; i <= dir.Length (); ++i ) {
chr = dir.Value ( i );
switch ( chr ) {
case _TEXT( '|' ):
dirRet += _TEXT( "/" );
break;
case _TEXT( '^' ):
dirRet += _TEXT( ".." );
break;
default:
dirRet += chr;
}
}
theFolder = dirRet;
theName = UTL::Name(p); theName+= UTL::Extension(p);
#endif // WNT
return CDM_MetaData::LookUp(theFolder,theName,theFile,theFile,UTL::IsReadOnly(theFile));
}
//=======================================================================
//function : ReferenceIdentifier
//purpose :
//=======================================================================
Standard_Integer PCDM_ReferenceIterator::ReferenceIdentifier() const {
return myReferences(myIterator).ReferenceIdentifier();
}
//=======================================================================
//function : DocumentVersion
//purpose :
//=======================================================================
Standard_Integer PCDM_ReferenceIterator::DocumentVersion() const {
return myReferences(myIterator).DocumentVersion();
}

View File

@@ -0,0 +1,91 @@
-- File: PCDM_RetrievalDriver.cdl
-- Created: Thu Aug 7 13:56:49 1997
-- Author: Jean-Louis Frenkel
-- <rmi@frilox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1997
deferred class RetrievalDriver from PCDM
inherits Reader from PCDM
uses
Document from PCDM,
Document from CDM,
ExtendedString from TCollection,
SequenceOfExtendedString from TColStd,
AsciiString from TCollection,
SequenceOfReference from PCDM,
Schema from Storage,
MessageDriver from CDM,
Application from CDM
raises NoSuchObject from Standard, DriverError from PCDM
is
Read(me: mutable; aFileName: ExtendedString from TCollection;
aNewDocument: mutable Document from CDM;
anApplication: Application from CDM)
raises DriverError from PCDM
---Purpose: Warning - raises DriverError if an error occurs during inside the
-- Make method.
is redefined virtual;
---Purpose: 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.
--
Make(me : mutable; aPCDM: Document from PCDM; aNewDocument: mutable Document from CDM)
raises DriverError from PCDM
is deferred;
SchemaName(me) returns ExtendedString from TCollection
is deferred;
LoadExtensions(me: mutable; aSchema: Schema from Storage; Extensions: SequenceOfExtendedString from TColStd; theMsgDriver: MessageDriver from CDM)
is virtual;
---Category: private methods.
References(myclass; aFileName: ExtendedString from TCollection; theReferences: out SequenceOfReference from PCDM; theMsgDriver: MessageDriver from CDM)
is private;
Extensions(myclass; aFileName: ExtendedString from TCollection; theExtensions: in out SequenceOfExtendedString from TColStd; theMsgDriver: MessageDriver from CDM)
is private;
UserInfo(myclass; aFileName: ExtendedString from TCollection; Start, End: AsciiString from TCollection; theUserInfo:in out SequenceOfExtendedString from TColStd; theMsgDriver: MessageDriver from CDM)
is private;
RaiseIfUnknownTypes(myclass; aSchema: Schema from Storage; aFileName: ExtendedString from TCollection);
DocumentVersion(myclass; aFileName: ExtendedString from TCollection; theMsgDriver: MessageDriver from CDM)
returns Integer from Standard;
ReferenceCounter(myclass; aFileName: ExtendedString from TCollection; theMsgDriver: MessageDriver from CDM)
returns Integer from Standard;
SetFormat (me : mutable; aformat : ExtendedString from TCollection);
GetFormat (me)
returns ExtendedString from TCollection;
--friends Init from class ReferenceIterator from PCDM(me: mutable;aMetaData: MetaData from CDM)
fields
myFormat : ExtendedString from TCollection;
friends
Init from class ReferenceIterator from PCDM(me: mutable;aMetaData: MetaData from CDM)
end RetrievalDriver from PCDM;

237
src/PCDM/PCDM_RetrievalDriver.cxx Executable file
View File

@@ -0,0 +1,237 @@
// File: PCDM_RetrievalDriver.cxx
// Created: Thu Aug 7 14:11:39 1997
// Author: Jean-Louis Frenkel
// <rmi@frilox.paris1.matra-dtv.fr>
#include <PCDM_RetrievalDriver.ixx>
#include <PCDM_BaseDriverPointer.hxx>
#include <PCDM.hxx>
#include <PCDM_TypeOfFileDriver.hxx>
#include <Storage_Data.hxx>
#include <Storage_HeaderData.hxx>
#include <Storage_Schema.hxx>
#include <Storage_Root.hxx>
#include <TCollection_AsciiString.hxx>
#include <TColStd_SequenceOfAsciiString.hxx>
#include <Standard_TypeMismatch.hxx>
#include <PCDM_ReadWriter.hxx>
#include <Resource_Manager.hxx>
#include <Standard_ErrorHandler.hxx>
#include <UTL.hxx>
#include <PCDM.hxx>
#include <Storage_HSeqOfRoot.hxx>
#include <locale.h>
void PCDM_RetrievalDriver::RaiseIfUnknownTypes(const Handle(Storage_Schema)& aSchema, const TCollection_ExtendedString& aFileName) {
PCDM_BaseDriverPointer theFileDriver;
if(PCDM::FileDriverType(TCollection_AsciiString(UTL::CString(aFileName)), 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 :
//=======================================================================
void PCDM_RetrievalDriver::Read(const TCollection_ExtendedString& theFileName,
const Handle(CDM_Document)& aNewDocument,
const Handle(CDM_Application)& theApplication) {
char *oldnum,*plocal ;
plocal = setlocale(LC_NUMERIC, NULL) ;
oldnum = new char[strlen(plocal)+1] ;
strcpy(oldnum,plocal);
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);
}
PCDM_BaseDriverPointer theFileDriver;
if(PCDM::FileDriverType(TCollection_AsciiString(UTL::CString(theFileName)), 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 aMsg;
aMsg << "could not find any document in this file" << (char) 0;
myReaderStatus = PCDM_RS_NoDocument;
Standard_Failure::Raise(aMsg);
}
Handle(Standard_Persistent) theObject=theDocument->Object();
Handle(PCDM_Document) thePDocument = *((Handle(PCDM_Document)*)&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());
// on remet le LC_NUMERIC a la precedente valeur
setlocale(LC_NUMERIC, oldnum) ;
delete[] oldnum;
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 :
//=======================================================================
void PCDM_RetrievalDriver::SetFormat (const TCollection_ExtendedString& aformat)
{
myFormat = aformat;
}
//=======================================================================
//function : Format
//purpose :
//=======================================================================
TCollection_ExtendedString PCDM_RetrievalDriver::GetFormat () const
{
return myFormat;
}

70
src/PCDM/PCDM_StorageDriver.cdl Executable file
View File

@@ -0,0 +1,70 @@
-- File: PCDM_StorageDriver.cdl
-- Created: Mon Nov 3 10:09:25 1997
-- Author: Jean-Louis Frenkel
-- <rmi@frilox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1997
deferred class StorageDriver from PCDM inherits Writer from PCDM
---Purpose: persistent implemention of storage.
--
-- The application must redefine one the two Make()
-- methods. The first one, if the application wants to
-- put only one document in the storage file.
--
-- The second method should be redefined to put
-- additional document that could be used by the
-- retrieval instead of the principal document, depending
-- on the schema used during the retrieval. For example,
-- a second document could be a standard
-- CDMShape_Document. This means that a client
-- application will already be able to extract a CDMShape_Document
-- of the file, if the Shape Schema remains unchanged.
--
---Category: persistent implemention of storage.
uses Document from CDM, Document from PCDM, Data from Storage, ExtendedString from TCollection, Schema from Storage,SequenceOfExtendedString from TColStd, SequenceOfDocument from PCDM
raises NoSuchObject from Standard,DriverError from PCDM
is
Make(me: mutable; aDocument: Document from CDM)
returns Document from PCDM
is virtual;
---Purpose: raises NotImplemented.
Make(me: mutable; aDocument: Document from CDM; Documents: out SequenceOfDocument from PCDM)
is virtual;
---Purpose:By default, puts in the Sequence the document returns
-- by the previous Make method.
--
--
SchemaName(me) returns ExtendedString from TCollection
is deferred;
LoadExtensions(me: mutable; aSchema: Schema from Storage; Extensions: SequenceOfExtendedString from TColStd)
is virtual;
Write(me: mutable; aDocument: Document from CDM; aFileName: ExtendedString from TCollection)
raises DriverError
---Purpose: Warning! raises DriverError if an error occurs during inside the
-- Make method.
is redefined virtual;
---Purpose: stores the content of the Document into a new file.
--
-- by default Write will use Make method to build a persistent
-- document and the Schema method to write the persistent document.
--
SetFormat (me : mutable; aformat : ExtendedString from TCollection);
GetFormat (me)
returns ExtendedString from TCollection;
fields
myFormat : ExtendedString from TCollection;
end StorageDriver from PCDM;

135
src/PCDM/PCDM_StorageDriver.cxx Executable file
View File

@@ -0,0 +1,135 @@
// File: PCDM_StorageDriver.cxx
// Created: Thu Aug 7 14:40:31 1997
// Author: Jean-Louis Frenkel
// <rmi@frilox.paris1.matra-dtv.fr>
#include <PCDM_StorageDriver.ixx>
#include <Storage_Data.hxx>
#include <Storage_OpenMode.hxx>
#include <Storage_Schema.hxx>
#include <TColStd_SequenceOfExtendedString.hxx>
#include <FSD_CmpFile.hxx>
#include <TCollection_AsciiString.hxx>
#include <Standard_ErrorHandler.hxx>
#include <PCDM_ReadWriter.hxx>
#include <Resource_Manager.hxx>
#include <Standard_NotImplemented.hxx>
#include <PCDM_SequenceOfDocument.hxx>
#include <PCDM.hxx>
#include <locale.h>
#define STORAGE_VERSION "STORAGE_VERSION:"
void PCDM_StorageDriver::Write(const Handle(CDM_Document)& aDocument, const TCollection_ExtendedString& aFileName) {
// on sauvegarde l'ancien LC_NUMERIC
char *oldnum,*plocal ;
plocal = setlocale(LC_NUMERIC, NULL) ;
oldnum = new char[strlen(plocal)+1] ;
strcpy(oldnum,plocal);
Handle(Storage_Schema) theSchema=PCDM::Schema(SchemaName(),aDocument->Application());
TColStd_SequenceOfExtendedString theExtensions;
aDocument->Extensions(theExtensions);
LoadExtensions(theSchema,theExtensions);
Handle(Storage_Data) theData = new Storage_Data;
static Standard_Boolean Failure;
Failure=Standard_False;
Standard_SStream aMsg; aMsg << "error during Make:";
PCDM_SequenceOfDocument thePersistentDocuments;
{
try { OCC_CATCH_SIGNALS Make(aDocument,thePersistentDocuments);}
catch (Standard_Failure) {
aMsg << Standard_Failure::Caught()<<(char)0;
Failure=Standard_True;
}
}
if(Failure) PCDM_DriverError::Raise(aMsg);
if(thePersistentDocuments.IsEmpty()) {
aMsg << "the storage driver: " << DynamicType()->Name() << "returned no documents to store" << (char) 0;
PCDM_DriverError::Raise(aMsg);
}
Standard_Integer i=1;
for(; i<=thePersistentDocuments.Length(); i++) {
theData->AddRoot(thePersistentDocuments(i));
}
TCollection_AsciiString ligne(STORAGE_VERSION);
ligne+=PCDM_ReadWriter::Writer()->Version();
theData->AddToUserInfo(ligne);
PCDM_ReadWriter::WriteFileFormat(theData,aDocument);
PCDM_ReadWriter::Writer()->WriteReferenceCounter(theData,aDocument);
PCDM_ReadWriter::Writer()->WriteReferences(theData,aDocument,aFileName);
PCDM_ReadWriter::Writer()->WriteExtensions(theData,aDocument);
PCDM_ReadWriter::Writer()->WriteVersion(theData,aDocument);
// add document comments
TColStd_SequenceOfExtendedString aComments;
aDocument->Comments(aComments);
Standard_Integer aLen = aComments.Length();
for (i = 1; i <= aLen; i++)
{
theData->AddToComments(aComments(i));
}
FSD_CmpFile theFile;
PCDM_ReadWriter::Open(theFile,aFileName,Storage_VSWrite);
theSchema->Write(theFile,theData);
theFile.Close();
// on remet le LC_NUMERIC a la precedente valeur
setlocale(LC_NUMERIC, oldnum) ;
delete[] oldnum;
if ( theData->ErrorStatus() != Storage_VSOk )
PCDM_DriverError::Raise(theData->ErrorStatusExtension().ToCString());
}
//void PCDM_StorageDriver::LoadExtensions(const Handle(Storage_Schema)& aSchema, const TColStd_SequenceOfExtendedString& Extensions) {}
void PCDM_StorageDriver::LoadExtensions(const Handle(Storage_Schema)& , const TColStd_SequenceOfExtendedString& ) {}
//Handle(PCDM_Document) PCDM_StorageDriver::Make(const Handle(CDM_Document)& aDocument) {
Handle(PCDM_Document) PCDM_StorageDriver::Make(const Handle(CDM_Document)& ) {
Handle(PCDM_Document) voidDocument;
Standard_SStream aMsg;
aMsg << "No Make method were implemented in this Driver" << DynamicType()->Name() << (char) 0;
Standard_NotImplemented::Raise(aMsg);
return voidDocument;
}
void PCDM_StorageDriver::Make(const Handle(CDM_Document)& aDocument, PCDM_SequenceOfDocument& Documents) {
Documents.Append(Make(aDocument));
}
//=======================================================================
//function : SetFormat
//purpose :
//=======================================================================
void PCDM_StorageDriver::SetFormat (const TCollection_ExtendedString& aformat)
{
myFormat = aformat;
}
//=======================================================================
//function : GetFormat
//purpose :
//=======================================================================
TCollection_ExtendedString PCDM_StorageDriver::GetFormat () const
{
return myFormat;
}

18
src/PCDM/PCDM_Writer.cdl Executable file
View File

@@ -0,0 +1,18 @@
-- File: PCDM_Writer.cdl
-- Created: Thu Dec 18 09:27:19 1997
-- Author: Jean-Louis Frenkel
-- <rmi@frilox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1997
deferred class Writer from PCDM inherits Transient from Standard
uses Document from CDM, ExtendedString from TCollection
raises DriverError from PCDM
is
Write(me: mutable; aDocument: Document from CDM; aFileName: ExtendedString from TCollection)
raises DriverError
is deferred;
end Writer from PCDM;

7
src/PCDM/PCDM_Writer.cxx Executable file
View File

@@ -0,0 +1,7 @@
// File: PCDM_Writer.cxx
// Created: Thu Dec 18 09:28:26 1997
// Author: Jean-Louis Frenkel
// <rmi@frilox.paris1.matra-dtv.fr>
#include <PCDM_Writer.ixx>