mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-09-03 14:10:33 +03:00
0029217: Application Framework - nonsense API method XmlLDrivers::SetStorageVersion()
1. Unification of usage of a storage version of an OCAF document by XML and binary file formats. 2. A new format version enumeration in TDocStd package: TDocStd_FormatVersion. 3. Removal of unnecessary methods for storage version like XmlLDrivers::StorageVersion() and BinLDrivers::StorageVersion(). 4. Support of old documents (storage version <= 9) in binary file format (came from ESA). New files: - TDocStd_FormatVersion.hxx: a new storage format version enumeration for an OCAF document. Modified files: - CDM_Document.hxx and cxx: removal of storage format version property (moved to TDocStd_Document). - TDocStd_Document.hxx and cxx: a storage format version property (moved from CDM_Document). - BinLDrivers_DocumentSection.hxx and cxx: support of old document storage version in binary file format. - BinDrivers_DocumentStorageDriver.hxx and cxx, - BinLDrivers_DocumentStorageDriver.hxx and cxx, - BinLDrivers_DocumentRetrievalDriver.cxx, - XmlLDrivers_DocumentRetrievalDriver.cxx, - XmlLDrivers_DocumentStorageDriver.cxx: usage of document storage version from TDocStd_Document in storage and retrieval drivers. - DDocStd_ApplicationCommands.cxx: draw-command name StorageVersion is replaced by StorageFormatVersion (to be the same everywhere). A corresponding script is corrected too. New test: - bugs caf bug29217: a test case for old document storage version in binary file format. It checks several attributes saved by the version TDocStd_FormatVersion_VERSION_7 (old) and the latest version. Modified test: - caf presentation M1: the test used a file in the current folder, not in {imagedir} like all other tests. - bugs caf bug28691 Documentation: - dox/upgrade/upgrade.md // All remarks are fixed.
This commit is contained in:
@@ -33,7 +33,6 @@
|
||||
//#include <BinMNaming.hxx>
|
||||
static Standard_GUID BinLStorageDriver ("13a56835-8269-11d5-aab2-0050044b1af1");
|
||||
static Standard_GUID BinLRetrievalDriver("13a56836-8269-11d5-aab2-0050044b1af1");
|
||||
#define CURRENT_DOCUMENT_VERSION 10
|
||||
|
||||
//=======================================================================
|
||||
//function : Factory
|
||||
@@ -93,15 +92,4 @@ Handle(BinMDF_ADriverTable) BinLDrivers::AttributeDrivers
|
||||
return aTable;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : StorageVersion
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TCollection_AsciiString BinLDrivers::StorageVersion()
|
||||
{
|
||||
TCollection_AsciiString aVersionStr (CURRENT_DOCUMENT_VERSION);
|
||||
return aVersionStr;
|
||||
}
|
||||
|
||||
PLUGIN(BinLDrivers)
|
||||
|
@@ -40,9 +40,6 @@ public:
|
||||
|
||||
//! Creates a table of the supported drivers' types
|
||||
Standard_EXPORT static Handle(BinMDF_ADriverTable) AttributeDrivers (const Handle(Message_Messenger)& MsgDrv);
|
||||
|
||||
//! returns last storage version
|
||||
Standard_EXPORT static TCollection_AsciiString StorageVersion();
|
||||
};
|
||||
|
||||
#endif // _BinLDrivers_HeaderFile
|
||||
|
@@ -168,14 +168,14 @@ void BinLDrivers_DocumentRetrievalDriver::Read (Standard_IStream&
|
||||
return;
|
||||
}
|
||||
Standard_Integer aFileVer = aHeaderData->StorageVersion().IntegerValue();
|
||||
Standard_Integer aCurrVer = BinLDrivers::StorageVersion().IntegerValue();
|
||||
Standard_Integer aCurrVer = TDocStd_Document::CurrentStorageFormatVersion();
|
||||
// maintain one-way compatibility starting from version 2+
|
||||
if (!CheckDocumentVersion(aFileVer, aCurrVer)) {
|
||||
myReaderStatus = PCDM_RS_NoVersion;
|
||||
// file was written with another version
|
||||
myMsgDriver->Send (aMethStr + "error: wrong file version: " +
|
||||
aHeaderData->StorageVersion() + " while current is " +
|
||||
BinLDrivers::StorageVersion(), Message_Fail);
|
||||
TDocStd_Document::CurrentStorageFormatVersion(), Message_Fail);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -14,6 +14,7 @@
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <BinLDrivers_DocumentSection.hxx>
|
||||
#include <TDocStd_FormatVersion.hxx>
|
||||
#include <FSD_FileHeader.hxx>
|
||||
#include <BinMDataStd.hxx>
|
||||
|
||||
@@ -109,7 +110,8 @@ void BinLDrivers_DocumentSection::SetLength (const uint64_t theLength)
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void BinLDrivers_DocumentSection::WriteTOC (Standard_OStream& theStream)
|
||||
void BinLDrivers_DocumentSection::WriteTOC (Standard_OStream& theStream,
|
||||
const Standard_Integer theDocFormatVersion)
|
||||
{
|
||||
char aBuf[512];
|
||||
|
||||
@@ -147,7 +149,14 @@ void BinLDrivers_DocumentSection::WriteTOC (Standard_OStream& theStream)
|
||||
aBufSz[0] = 0;
|
||||
aBufSz[1] = 0;
|
||||
aBufSz[2] = 0;
|
||||
theStream.write (&aBuf[0], 3*sizeof(uint64_t));
|
||||
if (theDocFormatVersion <= TDocStd_FormatVersion_VERSION_9)
|
||||
{
|
||||
theStream.write(&aBuf[0], 3*sizeof(Standard_Integer));
|
||||
}
|
||||
else
|
||||
{
|
||||
theStream.write(&aBuf[0], 3*sizeof(uint64_t));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,24 +166,47 @@ void BinLDrivers_DocumentSection::WriteTOC (Standard_OStream& theStream)
|
||||
//=======================================================================
|
||||
|
||||
void BinLDrivers_DocumentSection::Write (Standard_OStream& theStream,
|
||||
const uint64_t theOffset)
|
||||
const uint64_t theOffset,
|
||||
const Standard_Integer theDocFormatVersion)
|
||||
{
|
||||
const uint64_t aSectionEnd = (uint64_t) theStream.tellp();
|
||||
theStream.seekp((std::streamsize)myValue[0]);
|
||||
myValue[0] = theOffset;
|
||||
myValue[1] = aSectionEnd - theOffset;
|
||||
uint64_t aVal[3] = {
|
||||
myValue[0],
|
||||
myValue[1],
|
||||
uint64_t(myIsPostRead ? 1 : 0)
|
||||
};
|
||||
#if DO_INVERSE
|
||||
aVal[0] = InverseUint64(aVal[0]);
|
||||
aVal[1] = InverseUint64(aVal[1]);
|
||||
aVal[2] = InverseUint64(aVal[2]);
|
||||
#endif
|
||||
if (theDocFormatVersion <= TDocStd_FormatVersion_VERSION_9)
|
||||
{
|
||||
// Check the limits for a 4-bytes integer.
|
||||
if (myValue[0] > INT_MAX || myValue[1] > INT_MAX)
|
||||
throw Standard_OutOfRange("BinLDrivers_DocumentSection::Write : file size is too big, needs int64.");
|
||||
|
||||
// Old documents stored file position as 4-bytes values.
|
||||
int32_t aValInt[3] = {
|
||||
int32_t(myValue[0]),
|
||||
int32_t(myValue[1]),
|
||||
int32_t(myIsPostRead ? 1 : 0)
|
||||
};
|
||||
#if DO_INVERSE
|
||||
aValInt[0] = InverseInt(aValInt[0]);
|
||||
aValInt[1] = InverseInt(aValInt[1]);
|
||||
aValInt[2] = InverseInt(aValInt[2]);
|
||||
#endif
|
||||
theStream.write((char *)&aValInt[0], 3*sizeof(int32_t));
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t aVal[3] = {
|
||||
myValue[0],
|
||||
myValue[1],
|
||||
uint64_t(myIsPostRead ? 1 : 0)
|
||||
};
|
||||
#if DO_INVERSE
|
||||
aVal[0] = InverseUint64(aVal[0]);
|
||||
aVal[1] = InverseUint64(aVal[1]);
|
||||
aVal[2] = InverseUint64(aVal[2]);
|
||||
#endif
|
||||
theStream.write((char *)&aVal[0], 3*sizeof(uint64_t));
|
||||
}
|
||||
|
||||
theStream.write((char *)&aVal[0], 3*sizeof(uint64_t));
|
||||
theStream.seekp((std::streamsize)aSectionEnd);
|
||||
}
|
||||
|
||||
@@ -186,7 +218,7 @@ void BinLDrivers_DocumentSection::Write (Standard_OStream& theStream,
|
||||
void BinLDrivers_DocumentSection::ReadTOC
|
||||
(BinLDrivers_DocumentSection& theSection,
|
||||
Standard_IStream& theStream,
|
||||
const Standard_Integer theDocFormatVersion)
|
||||
const Standard_Integer theDocFormatVersion)
|
||||
{
|
||||
char aBuf[512];
|
||||
Standard_Integer aNameBufferSize;
|
||||
@@ -199,11 +231,11 @@ void BinLDrivers_DocumentSection::ReadTOC
|
||||
theSection.myName = (Standard_CString)&aBuf[0];
|
||||
|
||||
uint64_t aValue[3];
|
||||
if (theDocFormatVersion <= 9)
|
||||
if (theDocFormatVersion <= TDocStd_FormatVersion_VERSION_9)
|
||||
{
|
||||
// Old documents stored file position as 4-bytes values.
|
||||
Standard_Integer aValInt[3];
|
||||
theStream.read ((char *)&aValInt[0], 3*sizeof(Standard_Integer));
|
||||
int32_t aValInt[3];
|
||||
theStream.read ((char *)&aValInt[0], 3*sizeof(int32_t));
|
||||
#if DO_INVERSE
|
||||
aValue[0] = InverseInt (aValInt[0]);
|
||||
aValue[1] = InverseInt (aValInt[1]);
|
||||
|
@@ -66,11 +66,13 @@ public:
|
||||
Standard_EXPORT void SetLength (const uint64_t theLength);
|
||||
|
||||
//! Create a Section entry in the Document TOC (list of sections)
|
||||
Standard_EXPORT void WriteTOC (Standard_OStream& theOS);
|
||||
Standard_EXPORT void WriteTOC (Standard_OStream& theOS,
|
||||
const Standard_Integer theDocFormatVersion);
|
||||
|
||||
//! Save Offset and Length data into the Section entry
|
||||
//! in the Document TOC (list of sections)
|
||||
Standard_EXPORT void Write (Standard_OStream& theOS, const uint64_t theOffset);
|
||||
Standard_EXPORT void Write (Standard_OStream& theOS, const uint64_t theOffset,
|
||||
const Standard_Integer theDocFormatVersion);
|
||||
|
||||
//! Fill a DocumentSection instance from the data that are read
|
||||
//! from TOC.
|
||||
|
@@ -123,17 +123,16 @@ void BinLDrivers_DocumentStorageDriver::Write (const Handle(CDM_Document)& theD
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 2. Write the Table of Contents of Sections
|
||||
const Standard_Integer aDocVer = aDoc->StorageFormatVersion();
|
||||
BinLDrivers_VectorOfDocumentSection::Iterator anIterS (mySections);
|
||||
for (; anIterS.More(); anIterS.Next())
|
||||
anIterS.ChangeValue().WriteTOC (theOStream);
|
||||
anIterS.ChangeValue().WriteTOC (theOStream, aDocVer);
|
||||
|
||||
// Shapes Section is the last one, it indicates the end of the table.
|
||||
BinLDrivers_DocumentSection aShapesSection (SHAPESECTION_POS,
|
||||
Standard_False);
|
||||
aShapesSection.WriteTOC (theOStream);
|
||||
aShapesSection.WriteTOC (theOStream, aDocVer);
|
||||
|
||||
// 3. Write document contents
|
||||
// (Storage data to the stream)
|
||||
@@ -152,7 +151,7 @@ void BinLDrivers_DocumentStorageDriver::Write (const Handle(CDM_Document)& theD
|
||||
}
|
||||
|
||||
// 4. Write Shapes section
|
||||
WriteShapeSection (aShapesSection, theOStream, aPS.Next());
|
||||
WriteShapeSection (aShapesSection, theOStream, aDocVer, aPS.Next());
|
||||
if (!aPS.More())
|
||||
{
|
||||
SetIsError(Standard_True);
|
||||
@@ -165,7 +164,7 @@ void BinLDrivers_DocumentStorageDriver::Write (const Handle(CDM_Document)& theD
|
||||
BinLDrivers_DocumentSection& aSection = anIterS.ChangeValue();
|
||||
const Standard_Size aSectionOffset = (Standard_Size) theOStream.tellp();
|
||||
WriteSection (aSection.Name(), aDoc, theOStream);
|
||||
aSection.Write (theOStream, aSectionOffset);
|
||||
aSection.Write (theOStream, aSectionOffset, aDocVer);
|
||||
}
|
||||
|
||||
// End of processing: close structures and check the status
|
||||
@@ -469,9 +468,11 @@ void BinLDrivers_DocumentStorageDriver::WriteInfoSection
|
||||
theData->SetApplicationVersion(theDoc->Application()->Version());
|
||||
theData->SetApplicationName(theDoc->Application()->Name());
|
||||
|
||||
Handle(TDocStd_Document) aDoc = Handle(TDocStd_Document)::DownCast(theDoc);
|
||||
const Standard_Integer aDocVer = aDoc->StorageFormatVersion();
|
||||
aHeader.einfo += FSD_BinaryFile::WriteInfo (theOStream,
|
||||
aObjNb,
|
||||
BinLDrivers::StorageVersion(),
|
||||
aDocVer,
|
||||
Storage_Schema::ICreationDate(),
|
||||
"", // schema name
|
||||
aShemaVer,
|
||||
@@ -500,7 +501,7 @@ void BinLDrivers_DocumentStorageDriver::WriteInfoSection
|
||||
// write info section
|
||||
FSD_BinaryFile::WriteInfo (theOStream,
|
||||
aObjNb,
|
||||
BinLDrivers::StorageVersion(),
|
||||
aDocVer,
|
||||
Storage_Schema::ICreationDate(),
|
||||
"", // schema name
|
||||
aShemaVer,
|
||||
@@ -546,8 +547,9 @@ void BinLDrivers_DocumentStorageDriver::WriteSection
|
||||
void BinLDrivers_DocumentStorageDriver::WriteShapeSection
|
||||
(BinLDrivers_DocumentSection& theSection,
|
||||
Standard_OStream& theOS,
|
||||
const Standard_Integer theDocVer,
|
||||
const Message_ProgressRange& /*theRange*/)
|
||||
{
|
||||
const Standard_Size aShapesSectionOffset = (Standard_Size) theOS.tellp();
|
||||
theSection.Write (theOS, aShapesSectionOffset);
|
||||
theSection.Write (theOS, aShapesSectionOffset, theDocVer);
|
||||
}
|
||||
|
@@ -80,13 +80,14 @@ protected:
|
||||
const Message_ProgressRange& theRange = Message_ProgressRange());
|
||||
|
||||
//! define the procedure of writing a section to file.
|
||||
Standard_EXPORT virtual void WriteSection (const TCollection_AsciiString& theName,
|
||||
const Handle(CDM_Document)& theDoc,
|
||||
Standard_OStream& theOS);
|
||||
Standard_EXPORT virtual void WriteSection (const TCollection_AsciiString& /*theName*/,
|
||||
const Handle(CDM_Document)& /*theDoc*/,
|
||||
Standard_OStream& /*theOS*/);
|
||||
|
||||
//! defines the procedure of writing a shape section to file
|
||||
Standard_EXPORT virtual void WriteShapeSection (BinLDrivers_DocumentSection& theDocSection,
|
||||
Standard_OStream& theOS,
|
||||
const Standard_Integer theDocVer,
|
||||
const Message_ProgressRange& theRange = Message_ProgressRange());
|
||||
|
||||
Handle(BinMDF_ADriverTable) myDrivers;
|
||||
|
Reference in New Issue
Block a user