From: vro Date: Wed, 3 May 2017 12:22:21 +0000 (+0300) Subject: 0028691: Storage of Ocaf documents in XML file format in old document version X-Git-Tag: V7_2_0_beta~155 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=c2f5b8211bde9daed3c5ea27b795ec8190541d58 0028691: Storage of Ocaf documents in XML file format in old document version --- diff --git a/src/DDocStd/DDocStd_ApplicationCommands.cxx b/src/DDocStd/DDocStd_ApplicationCommands.cxx index dce3786f98..f54d2b6461 100644 --- a/src/DDocStd/DDocStd_ApplicationCommands.cxx +++ b/src/DDocStd/DDocStd_ApplicationCommands.cxx @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -473,6 +474,35 @@ static Standard_Integer DDocStd_PrintComments (Draw_Interpretor& di, 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 //purpose : @@ -531,4 +561,11 @@ void DDocStd::ApplicationCommands(Draw_Interpretor& theCommands) theCommands.Add("PrintComments", "PrintComments Doc", __FILE__, DDocStd_PrintComments, g); + + theCommands.Add("GetStorageVersion", + "GetStorageVersion", + __FILE__, DDocStd_GetStorageVersion, g); + theCommands.Add("SetStorageVersion", + "SetStorageVersion Version", + __FILE__, DDocStd_SetStorageVersion, g); } diff --git a/src/XmlLDrivers/XmlLDrivers.cxx b/src/XmlLDrivers/XmlLDrivers.cxx index 9b381c2bd1..705f524c84 100644 --- a/src/XmlLDrivers/XmlLDrivers.cxx +++ b/src/XmlLDrivers/XmlLDrivers.cxx @@ -32,7 +32,8 @@ #include static Standard_GUID XmlLStorageDriver ("13a56820-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 @@ -127,10 +128,13 @@ Handle(XmlMDF_ADriverTable) XmlLDrivers::AttributeDrivers //purpose : Document storage version //======================================================================= -TCollection_AsciiString XmlLDrivers::StorageVersion() +int XmlLDrivers::StorageVersion() +{ + return CURRENT_DOCUMENT_VERSION; +} +void XmlLDrivers::SetStorageVersion(const int version) { - TCollection_AsciiString aVersionStr (CURRENT_DOCUMENT_VERSION); - return aVersionStr; + CURRENT_DOCUMENT_VERSION = version; } // Declare entry point PLUGINFACTORY diff --git a/src/XmlLDrivers/XmlLDrivers.hxx b/src/XmlLDrivers/XmlLDrivers.hxx index 85775593ea..2fcdad82e1 100644 --- a/src/XmlLDrivers/XmlLDrivers.hxx +++ b/src/XmlLDrivers/XmlLDrivers.hxx @@ -42,7 +42,8 @@ public: 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 diff --git a/src/XmlLDrivers/XmlLDrivers_DocumentRetrievalDriver.cxx b/src/XmlLDrivers/XmlLDrivers_DocumentRetrievalDriver.cxx index 6b677e01b7..d220573fda 100644 --- a/src/XmlLDrivers/XmlLDrivers_DocumentRetrievalDriver.cxx +++ b/src/XmlLDrivers/XmlLDrivers_DocumentRetrievalDriver.cxx @@ -267,7 +267,7 @@ void XmlLDrivers_DocumentRetrievalDriver::ReadFromDomDocument // oan: OCC22305 - check a document verison and if it's greater than // 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 ("error: wrong file version: ") + diff --git a/src/XmlLDrivers/XmlLDrivers_DocumentStorageDriver.cxx b/src/XmlLDrivers/XmlLDrivers_DocumentStorageDriver.cxx index 48d4adabb6..cb210d27bb 100644 --- a/src/XmlLDrivers/XmlLDrivers_DocumentStorageDriver.cxx +++ b/src/XmlLDrivers/XmlLDrivers_DocumentStorageDriver.cxx @@ -264,7 +264,7 @@ Standard_Boolean XmlLDrivers_DocumentStorageDriver::WriteToDomDocument (const Ha // anInfoElem.setAttribute("appv", anAppVersion.ToCString()); // Document version - anInfoElem.setAttribute("DocVersion", XmlLDrivers::StorageVersion().ToCString()); + anInfoElem.setAttribute("DocVersion", XmlLDrivers::StorageVersion()); // User info with Copyright TColStd_SequenceOfAsciiString aUserInfo; diff --git a/src/XmlMDF/XmlMDF.cxx b/src/XmlMDF/XmlMDF.cxx index 6e5477708e..03eee48936 100644 --- a/src/XmlMDF/XmlMDF.cxx +++ b/src/XmlMDF/XmlMDF.cxx @@ -33,6 +33,7 @@ #include #include #include +#include IMPLEMENT_DOMSTRING (TagString, "tag") IMPLEMENT_DOMSTRING (LabelString, "label") @@ -99,7 +100,16 @@ Standard_Integer XmlMDF::WriteSubTree // Create DOM data item 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 aDriver -> Paste (tAtt, pAtt, theRelocTable); diff --git a/src/XmlMDataStd/XmlMDataStd_ExtStringArrayDriver.cxx b/src/XmlMDataStd/XmlMDataStd_ExtStringArrayDriver.cxx index dda5154c6f..0c3599bfa8 100644 --- a/src/XmlMDataStd/XmlMDataStd_ExtStringArrayDriver.cxx +++ b/src/XmlMDataStd/XmlMDataStd_ExtStringArrayDriver.cxx @@ -24,6 +24,7 @@ #include #include #include +#include IMPLEMENT_STANDARD_RTTIEXT(XmlMDataStd_ExtStringArrayDriver,XmlMDF_ADriver) IMPLEMENT_DOMSTRING (FirstIndexString, "first") @@ -227,39 +228,44 @@ void XmlMDataStd_ExtStringArrayDriver::Paste (const Handle(TDF_Attribute)& theSo // Find a separator. Standard_Boolean found(Standard_True); - // Preferrable symbols for the separator: - _ . : ^ ~ - // Don't use a space as a separator: XML low-level parser sometimes "eats" it. + // Optimization of storage of string array elements. + // It is applied since the storage version 8 and newer. Standard_Character c = '-'; - static Standard_Character aPreferable[] = "-_.:^~"; - for (i = 0; found && aPreferable[i]; i++) + if (XmlLDrivers::StorageVersion() > 7) { - c = aPreferable[i]; - found = Contains(aExtStringArray, TCollection_ExtendedString(c)); - } - // If all prefferable symbols exist in the array, - // try to use any other simple symbols. - if (found) - { - c = '!'; - while (found && c < '~') + // Preferrable symbols for the separator: - _ . : ^ ~ + // Don't use a space as a separator: XML low-level parser sometimes "eats" it. + static Standard_Character aPreferable[] = "-_.:^~"; + for (i = 0; found && aPreferable[i]; i++) + { + c = aPreferable[i]; + found = Contains(aExtStringArray, TCollection_ExtendedString(c)); + } + // If all prefferable symbols exist in the array, + // try to use any other simple symbols. + if (found) { - found = Standard_False; + c = '!'; + while (found && c < '~') + { + found = Standard_False; #ifdef _DEBUG - TCollection_AsciiString cseparator(c); // deb + TCollection_AsciiString cseparator(c); // deb #endif - TCollection_ExtendedString separator(c); - found = Contains(aExtStringArray, separator); - if (found) - { - c++; - // Skip forbidden symbols for XML. - while (c < '~' && (c == '&' || c == '<')) + TCollection_ExtendedString separator(c); + found = Contains(aExtStringArray, separator); + if (found) { c++; + // Skip forbidden symbols for XML. + while (c < '~' && (c == '&' || c == '<')) + { + c++; + } } } } - } + }// check doc version if (found) { diff --git a/src/XmlMDataStd/XmlMDataStd_TreeNodeDriver.cxx b/src/XmlMDataStd/XmlMDataStd_TreeNodeDriver.cxx index 3e906b660a..f81b0e5221 100644 --- a/src/XmlMDataStd/XmlMDataStd_TreeNodeDriver.cxx +++ b/src/XmlMDataStd/XmlMDataStd_TreeNodeDriver.cxx @@ -22,6 +22,7 @@ #include #include #include +#include IMPLEMENT_STANDARD_RTTIEXT(XmlMDataStd_TreeNodeDriver,XmlMDF_ADriver) IMPLEMENT_DOMSTRING (TreeIdString, "treeid") @@ -115,7 +116,9 @@ void XmlMDataStd_TreeNodeDriver::Paste Handle(TDataStd_TreeNode) aS = Handle(TDataStd_TreeNode)::DownCast(theSource); // 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_PCharacter pGuidStr=aGuidStr; diff --git a/tests/bugs/caf/bug28691 b/tests/bugs/caf/bug28691 new file mode 100644 index 0000000000..d054d4f4f0 --- /dev/null +++ b/tests/bugs/caf/bug28691 @@ -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" +}