mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-10 18:51:21 +03:00
0028691: Storage of Ocaf documents in XML file format in old document version
This commit is contained in:
parent
a1073ae267
commit
c2f5b8211b
@ -34,6 +34,7 @@
|
|||||||
#include <OSD_Path.hxx>
|
#include <OSD_Path.hxx>
|
||||||
#include <OSD_OpenFile.hxx>
|
#include <OSD_OpenFile.hxx>
|
||||||
#include <TDocStd_PathParser.hxx>
|
#include <TDocStd_PathParser.hxx>
|
||||||
|
#include <XmlLDrivers.hxx>
|
||||||
|
|
||||||
#include <AIS_InteractiveContext.hxx>
|
#include <AIS_InteractiveContext.hxx>
|
||||||
#include <TPrsStd_AISViewer.hxx>
|
#include <TPrsStd_AISViewer.hxx>
|
||||||
@ -473,6 +474,35 @@ static Standard_Integer DDocStd_PrintComments (Draw_Interpretor& di,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : SetStorageVerison
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
|
static Standard_Integer DDocStd_SetStorageVersion (Draw_Interpretor& ,
|
||||||
|
Standard_Integer nb,
|
||||||
|
const char** a)
|
||||||
|
{
|
||||||
|
if (nb == 2)
|
||||||
|
{
|
||||||
|
const int version = atoi(a[1]);
|
||||||
|
XmlLDrivers::SetStorageVersion(version);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : GetStorageVerison
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
|
static Standard_Integer DDocStd_GetStorageVersion (Draw_Interpretor& di,
|
||||||
|
Standard_Integer ,
|
||||||
|
const char** )
|
||||||
|
{
|
||||||
|
di << XmlLDrivers::StorageVersion() << "\n" ;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
//function : ApplicationCommands
|
//function : ApplicationCommands
|
||||||
//purpose :
|
//purpose :
|
||||||
@ -531,4 +561,11 @@ void DDocStd::ApplicationCommands(Draw_Interpretor& theCommands)
|
|||||||
theCommands.Add("PrintComments",
|
theCommands.Add("PrintComments",
|
||||||
"PrintComments Doc",
|
"PrintComments Doc",
|
||||||
__FILE__, DDocStd_PrintComments, g);
|
__FILE__, DDocStd_PrintComments, g);
|
||||||
|
|
||||||
|
theCommands.Add("GetStorageVersion",
|
||||||
|
"GetStorageVersion",
|
||||||
|
__FILE__, DDocStd_GetStorageVersion, g);
|
||||||
|
theCommands.Add("SetStorageVersion",
|
||||||
|
"SetStorageVersion Version",
|
||||||
|
__FILE__, DDocStd_SetStorageVersion, g);
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,8 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
static Standard_GUID XmlLStorageDriver ("13a56820-8269-11d5-aab2-0050044b1af1");
|
static Standard_GUID XmlLStorageDriver ("13a56820-8269-11d5-aab2-0050044b1af1");
|
||||||
static Standard_GUID XmlLRetrievalDriver("13a56822-8269-11d5-aab2-0050044b1af1");
|
static Standard_GUID XmlLRetrievalDriver("13a56822-8269-11d5-aab2-0050044b1af1");
|
||||||
#define CURRENT_DOCUMENT_VERSION 8
|
|
||||||
|
static int CURRENT_DOCUMENT_VERSION(9);
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
//function : Factory
|
//function : Factory
|
||||||
@ -127,10 +128,13 @@ Handle(XmlMDF_ADriverTable) XmlLDrivers::AttributeDrivers
|
|||||||
//purpose : Document storage version
|
//purpose : Document storage version
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
|
||||||
TCollection_AsciiString XmlLDrivers::StorageVersion()
|
int XmlLDrivers::StorageVersion()
|
||||||
{
|
{
|
||||||
TCollection_AsciiString aVersionStr (CURRENT_DOCUMENT_VERSION);
|
return CURRENT_DOCUMENT_VERSION;
|
||||||
return aVersionStr;
|
}
|
||||||
|
void XmlLDrivers::SetStorageVersion(const int version)
|
||||||
|
{
|
||||||
|
CURRENT_DOCUMENT_VERSION = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Declare entry point PLUGINFACTORY
|
// Declare entry point PLUGINFACTORY
|
||||||
|
@ -42,7 +42,8 @@ public:
|
|||||||
|
|
||||||
Standard_EXPORT static Handle(XmlMDF_ADriverTable) AttributeDrivers (const Handle(CDM_MessageDriver)& theMsgDriver);
|
Standard_EXPORT static Handle(XmlMDF_ADriverTable) AttributeDrivers (const Handle(CDM_MessageDriver)& theMsgDriver);
|
||||||
|
|
||||||
Standard_EXPORT static TCollection_AsciiString StorageVersion();
|
Standard_EXPORT static int StorageVersion();
|
||||||
|
Standard_EXPORT static void SetStorageVersion (const int version);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _XmlLDrivers_HeaderFile
|
#endif // _XmlLDrivers_HeaderFile
|
||||||
|
@ -267,7 +267,7 @@ void XmlLDrivers_DocumentRetrievalDriver::ReadFromDomDocument
|
|||||||
|
|
||||||
// oan: OCC22305 - check a document verison and if it's greater than
|
// oan: OCC22305 - check a document verison and if it's greater than
|
||||||
// current version of storage driver set an error status and return
|
// current version of storage driver set an error status and return
|
||||||
if( aCurDocVersion > XmlLDrivers::StorageVersion().IntegerValue() )
|
if( aCurDocVersion > XmlLDrivers::StorageVersion() )
|
||||||
{
|
{
|
||||||
TCollection_ExtendedString aMsg =
|
TCollection_ExtendedString aMsg =
|
||||||
TCollection_ExtendedString ("error: wrong file version: ") +
|
TCollection_ExtendedString ("error: wrong file version: ") +
|
||||||
|
@ -264,7 +264,7 @@ Standard_Boolean XmlLDrivers_DocumentStorageDriver::WriteToDomDocument (const Ha
|
|||||||
// anInfoElem.setAttribute("appv", anAppVersion.ToCString());
|
// anInfoElem.setAttribute("appv", anAppVersion.ToCString());
|
||||||
|
|
||||||
// Document version
|
// Document version
|
||||||
anInfoElem.setAttribute("DocVersion", XmlLDrivers::StorageVersion().ToCString());
|
anInfoElem.setAttribute("DocVersion", XmlLDrivers::StorageVersion());
|
||||||
|
|
||||||
// User info with Copyright
|
// User info with Copyright
|
||||||
TColStd_SequenceOfAsciiString aUserInfo;
|
TColStd_SequenceOfAsciiString aUserInfo;
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include <XmlObjMgt_Document.hxx>
|
#include <XmlObjMgt_Document.hxx>
|
||||||
#include <XmlObjMgt_DOMString.hxx>
|
#include <XmlObjMgt_DOMString.hxx>
|
||||||
#include <XmlObjMgt_Persistent.hxx>
|
#include <XmlObjMgt_Persistent.hxx>
|
||||||
|
#include <XmlLDrivers.hxx>
|
||||||
|
|
||||||
IMPLEMENT_DOMSTRING (TagString, "tag")
|
IMPLEMENT_DOMSTRING (TagString, "tag")
|
||||||
IMPLEMENT_DOMSTRING (LabelString, "label")
|
IMPLEMENT_DOMSTRING (LabelString, "label")
|
||||||
@ -99,7 +100,16 @@ Standard_Integer XmlMDF::WriteSubTree
|
|||||||
|
|
||||||
// Create DOM data item
|
// Create DOM data item
|
||||||
XmlObjMgt_Persistent pAtt;
|
XmlObjMgt_Persistent pAtt;
|
||||||
pAtt.CreateElement (aLabElem, aDriver->TypeName().ToCString(), anId);
|
// In the document version 8 the attribute TPrsStd_AISPresentation
|
||||||
|
// was replaced by TDataXtd_Presentation. Therefore, for old versions
|
||||||
|
// we write old name of the attribute (TPrsStd_AISPresentation).
|
||||||
|
Standard_CString typeName = aDriver->TypeName().ToCString();
|
||||||
|
if (XmlLDrivers::StorageVersion() < 8 &&
|
||||||
|
strcmp(typeName, "TDataXtd_Presentation") == 0)
|
||||||
|
{
|
||||||
|
typeName = "TPrsStd_AISPresentation";
|
||||||
|
}
|
||||||
|
pAtt.CreateElement (aLabElem, typeName, anId);
|
||||||
|
|
||||||
// Paste
|
// Paste
|
||||||
aDriver -> Paste (tAtt, pAtt, theRelocTable);
|
aDriver -> Paste (tAtt, pAtt, theRelocTable);
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <XmlObjMgt.hxx>
|
#include <XmlObjMgt.hxx>
|
||||||
#include <XmlObjMgt_Document.hxx>
|
#include <XmlObjMgt_Document.hxx>
|
||||||
#include <XmlObjMgt_Persistent.hxx>
|
#include <XmlObjMgt_Persistent.hxx>
|
||||||
|
#include <XmlLDrivers.hxx>
|
||||||
|
|
||||||
IMPLEMENT_STANDARD_RTTIEXT(XmlMDataStd_ExtStringArrayDriver,XmlMDF_ADriver)
|
IMPLEMENT_STANDARD_RTTIEXT(XmlMDataStd_ExtStringArrayDriver,XmlMDF_ADriver)
|
||||||
IMPLEMENT_DOMSTRING (FirstIndexString, "first")
|
IMPLEMENT_DOMSTRING (FirstIndexString, "first")
|
||||||
@ -227,39 +228,44 @@ void XmlMDataStd_ExtStringArrayDriver::Paste (const Handle(TDF_Attribute)& theSo
|
|||||||
|
|
||||||
// Find a separator.
|
// Find a separator.
|
||||||
Standard_Boolean found(Standard_True);
|
Standard_Boolean found(Standard_True);
|
||||||
// Preferrable symbols for the separator: - _ . : ^ ~
|
// Optimization of storage of string array elements.
|
||||||
// Don't use a space as a separator: XML low-level parser sometimes "eats" it.
|
// It is applied since the storage version 8 and newer.
|
||||||
Standard_Character c = '-';
|
Standard_Character c = '-';
|
||||||
static Standard_Character aPreferable[] = "-_.:^~";
|
if (XmlLDrivers::StorageVersion() > 7)
|
||||||
for (i = 0; found && aPreferable[i]; i++)
|
|
||||||
{
|
{
|
||||||
c = aPreferable[i];
|
// Preferrable symbols for the separator: - _ . : ^ ~
|
||||||
found = Contains(aExtStringArray, TCollection_ExtendedString(c));
|
// Don't use a space as a separator: XML low-level parser sometimes "eats" it.
|
||||||
}
|
static Standard_Character aPreferable[] = "-_.:^~";
|
||||||
// If all prefferable symbols exist in the array,
|
for (i = 0; found && aPreferable[i]; i++)
|
||||||
// try to use any other simple symbols.
|
|
||||||
if (found)
|
|
||||||
{
|
|
||||||
c = '!';
|
|
||||||
while (found && c < '~')
|
|
||||||
{
|
{
|
||||||
found = Standard_False;
|
c = aPreferable[i];
|
||||||
#ifdef _DEBUG
|
found = Contains(aExtStringArray, TCollection_ExtendedString(c));
|
||||||
TCollection_AsciiString cseparator(c); // deb
|
}
|
||||||
#endif
|
// If all prefferable symbols exist in the array,
|
||||||
TCollection_ExtendedString separator(c);
|
// try to use any other simple symbols.
|
||||||
found = Contains(aExtStringArray, separator);
|
if (found)
|
||||||
if (found)
|
{
|
||||||
|
c = '!';
|
||||||
|
while (found && c < '~')
|
||||||
{
|
{
|
||||||
c++;
|
found = Standard_False;
|
||||||
// Skip forbidden symbols for XML.
|
#ifdef _DEBUG
|
||||||
while (c < '~' && (c == '&' || c == '<'))
|
TCollection_AsciiString cseparator(c); // deb
|
||||||
|
#endif
|
||||||
|
TCollection_ExtendedString separator(c);
|
||||||
|
found = Contains(aExtStringArray, separator);
|
||||||
|
if (found)
|
||||||
{
|
{
|
||||||
c++;
|
c++;
|
||||||
|
// Skip forbidden symbols for XML.
|
||||||
|
while (c < '~' && (c == '&' || c == '<'))
|
||||||
|
{
|
||||||
|
c++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}// check doc version
|
||||||
|
|
||||||
if (found)
|
if (found)
|
||||||
{
|
{
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <XmlMDataStd_TreeNodeDriver.hxx>
|
#include <XmlMDataStd_TreeNodeDriver.hxx>
|
||||||
#include <XmlObjMgt.hxx>
|
#include <XmlObjMgt.hxx>
|
||||||
#include <XmlObjMgt_Persistent.hxx>
|
#include <XmlObjMgt_Persistent.hxx>
|
||||||
|
#include <XmlLDrivers.hxx>
|
||||||
|
|
||||||
IMPLEMENT_STANDARD_RTTIEXT(XmlMDataStd_TreeNodeDriver,XmlMDF_ADriver)
|
IMPLEMENT_STANDARD_RTTIEXT(XmlMDataStd_TreeNodeDriver,XmlMDF_ADriver)
|
||||||
IMPLEMENT_DOMSTRING (TreeIdString, "treeid")
|
IMPLEMENT_DOMSTRING (TreeIdString, "treeid")
|
||||||
@ -115,7 +116,9 @@ void XmlMDataStd_TreeNodeDriver::Paste
|
|||||||
Handle(TDataStd_TreeNode) aS = Handle(TDataStd_TreeNode)::DownCast(theSource);
|
Handle(TDataStd_TreeNode) aS = Handle(TDataStd_TreeNode)::DownCast(theSource);
|
||||||
|
|
||||||
// tree id
|
// tree id
|
||||||
if (aS->ID() != TDataStd_TreeNode::GetDefaultTreeID())
|
// A not default ID is skipped for storage version 8 and newer.
|
||||||
|
if (aS->ID() != TDataStd_TreeNode::GetDefaultTreeID() ||
|
||||||
|
XmlLDrivers::StorageVersion() < 8)
|
||||||
{
|
{
|
||||||
Standard_Character aGuidStr [40];
|
Standard_Character aGuidStr [40];
|
||||||
Standard_PCharacter pGuidStr=aGuidStr;
|
Standard_PCharacter pGuidStr=aGuidStr;
|
||||||
|
94
tests/bugs/caf/bug28691
Normal file
94
tests/bugs/caf/bug28691
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
puts "============"
|
||||||
|
puts "OCC28691"
|
||||||
|
puts "============"
|
||||||
|
puts ""
|
||||||
|
###################################################################################################################
|
||||||
|
# Storage of Ocaf documents in XML file format in old document version
|
||||||
|
###################################################################################################################
|
||||||
|
|
||||||
|
NewDocument D XmlOcaf
|
||||||
|
SetExtStringArray D 0:1 0 1 3 Hello hallo Bonjour
|
||||||
|
set FileV7 ${imagedir}/bug28691_doc7.xml
|
||||||
|
set FileV9 ${imagedir}/bug28691_doc9.xml
|
||||||
|
SetNode D 0:1
|
||||||
|
AISSet D 0:1 NS
|
||||||
|
|
||||||
|
SaveAs D ${FileV9}
|
||||||
|
|
||||||
|
SetStorageVersion 7
|
||||||
|
SaveAs D ${FileV7}
|
||||||
|
|
||||||
|
Close D
|
||||||
|
|
||||||
|
puts "Testing for XML file format in new version document"
|
||||||
|
SetStorageVersion 9
|
||||||
|
Open ${FileV9} D9
|
||||||
|
|
||||||
|
set info [Attributes D9 0:1]
|
||||||
|
if { [regexp "TDataStd_ExtStringArray" ${info}] != 1 } {
|
||||||
|
puts "Error : there is not TDataStd_ExtStringArray attribute in new version document"
|
||||||
|
} else {
|
||||||
|
puts "OK : there is TDataStd_ExtStringArray attribute in new version document"
|
||||||
|
}
|
||||||
|
if { [regexp "TDataStd_TreeNode" ${info}] != 1 } {
|
||||||
|
puts "Error : there is not TDataStd_TreeNode attribute in new version document"
|
||||||
|
} else {
|
||||||
|
puts "OK : there is TDataStd_TreeNode attribute in new version document"
|
||||||
|
}
|
||||||
|
if { [regexp "TDataXtd_Presentation" ${info}] != 1 } {
|
||||||
|
puts "Error : there is not TDataXtd_Presentation attribute in new version document"
|
||||||
|
} else {
|
||||||
|
puts "OK : there is TDataXtd_Presentation attribute in new version document"
|
||||||
|
}
|
||||||
|
set info [GetExtStringArray D9 0:1]
|
||||||
|
if { [regexp "Hello" ${info}] != 1 } {
|
||||||
|
puts "Error : there is not \"Hello\" word in TDataStd_ExtStringArray attribute in new version document"
|
||||||
|
} else {
|
||||||
|
puts "OK : there is \"Hello\" word in TDataStd_ExtStringArray attribute in new version document"
|
||||||
|
}
|
||||||
|
if { [regexp "hallo" ${info}] != 1 } {
|
||||||
|
puts "Error : there is not \"hallo\" word in TDataStd_ExtStringArray attribute in new version document"
|
||||||
|
} else {
|
||||||
|
puts "OK : there is \"hallo\" word in TDataStd_ExtStringArray attribute in new version document"
|
||||||
|
}
|
||||||
|
if { [regexp "Bonjour" ${info}] != 1 } {
|
||||||
|
puts "Error : there is not \"Bonjour\" word in TDataStd_ExtStringArray attribute in new version document"
|
||||||
|
} else {
|
||||||
|
puts "OK : there is \"Bonjour\" word in TDataStd_ExtStringArray attribute in new version document"
|
||||||
|
}
|
||||||
|
|
||||||
|
puts "\nTesting for XML file format in old version document"
|
||||||
|
Open ${FileV7} D7
|
||||||
|
|
||||||
|
set info [Attributes D7 0:1]
|
||||||
|
if { [regexp "TDataStd_ExtStringArray" ${info}] != 1 } {
|
||||||
|
puts "Error : there is not TDataStd_ExtStringArray attribute in old version document"
|
||||||
|
} else {
|
||||||
|
puts "OK : there is TDataStd_ExtStringArray attribute in old version document"
|
||||||
|
}
|
||||||
|
if { [regexp "TDataStd_TreeNode" ${info}] != 1 } {
|
||||||
|
puts "Error : there is not TDataStd_TreeNode attribute in old version document"
|
||||||
|
} else {
|
||||||
|
puts "OK : there is TDataStd_TreeNode attribute in old version document"
|
||||||
|
}
|
||||||
|
if { [regexp "TDataXtd_Presentation" ${info}] != 1 } {
|
||||||
|
puts "Error : there is not TDataXtd_Presentation attribute in old version document"
|
||||||
|
} else {
|
||||||
|
puts "OK : there is TDataXtd_Presentation attribute in old version document"
|
||||||
|
}
|
||||||
|
set info [GetExtStringArray D7 0:1]
|
||||||
|
if { [regexp "Hello" ${info}] != 1 } {
|
||||||
|
puts "Error : there is not \"Hello\" word in TDataStd_ExtStringArray attribute in old version document"
|
||||||
|
} else {
|
||||||
|
puts "OK : there is \"Hello\" word in TDataStd_ExtStringArray attribute in old version document"
|
||||||
|
}
|
||||||
|
if { [regexp "hallo" ${info}] != 1 } {
|
||||||
|
puts "Error : there is not \"hallo\" word in TDataStd_ExtStringArray attribute in old version document"
|
||||||
|
} else {
|
||||||
|
puts "OK : there is \"hallo\" word in TDataStd_ExtStringArray attribute in old version document"
|
||||||
|
}
|
||||||
|
if { [regexp "Bonjour" ${info}] != 1 } {
|
||||||
|
puts "Error : there is not \"Bonjour\" word in TDataStd_ExtStringArray attribute in old version document"
|
||||||
|
} else {
|
||||||
|
puts "OK : there is \"Bonjour\" word in TDataStd_ExtStringArray attribute in old version document"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user