#include <OSD_Path.hxx>
#include <OSD_OpenFile.hxx>
#include <TDocStd_PathParser.hxx>
+#include <XmlLDrivers.hxx>
#include <AIS_InteractiveContext.hxx>
#include <TPrsStd_AISViewer.hxx>
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 :
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);
}
#include <time.h>
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
//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
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
// 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: ") +
// 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;
#include <XmlObjMgt_Document.hxx>
#include <XmlObjMgt_DOMString.hxx>
#include <XmlObjMgt_Persistent.hxx>
+#include <XmlLDrivers.hxx>
IMPLEMENT_DOMSTRING (TagString, "tag")
IMPLEMENT_DOMSTRING (LabelString, "label")
// 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);
#include <XmlObjMgt.hxx>
#include <XmlObjMgt_Document.hxx>
#include <XmlObjMgt_Persistent.hxx>
+#include <XmlLDrivers.hxx>
IMPLEMENT_STANDARD_RTTIEXT(XmlMDataStd_ExtStringArrayDriver,XmlMDF_ADriver)
IMPLEMENT_DOMSTRING (FirstIndexString, "first")
// 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)
{
#include <XmlMDataStd_TreeNodeDriver.hxx>
#include <XmlObjMgt.hxx>
#include <XmlObjMgt_Persistent.hxx>
+#include <XmlLDrivers.hxx>
IMPLEMENT_STANDARD_RTTIEXT(XmlMDataStd_TreeNodeDriver,XmlMDF_ADriver)
IMPLEMENT_DOMSTRING (TreeIdString, "treeid")
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;
--- /dev/null
+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"
+}