0027932: Improvement of standard attributes usability.
[occt.git] / src / XmlMDataStd / XmlMDataStd_NameDriver.cxx
index 4880fef..5745223 100644 (file)
@@ -25,7 +25,7 @@
 #include <XmlObjMgt_SRelocationTable.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(XmlMDataStd_NameDriver,XmlMDF_ADriver)
-
+IMPLEMENT_DOMSTRING (AttributeIDString, "nameguid")
 //=======================================================================
 //function : XmlMDataStd_NameDriver
 //purpose  : Constructor
@@ -53,11 +53,23 @@ Standard_Boolean XmlMDataStd_NameDriver::Paste
                                 const Handle(TDF_Attribute)& theTarget,
                                 XmlObjMgt_RRelocationTable&  ) const
 {
-  TCollection_ExtendedString aString;
-  if (XmlObjMgt::GetExtendedString (theSource, aString))
-  {
-    Handle(TDataStd_Name)::DownCast(theTarget) -> Set (aString);
-    return Standard_True;
+  if(!theTarget.IsNull()) {    
+    TCollection_ExtendedString aString;
+    if (XmlObjMgt::GetExtendedString (theSource, aString))
+    {
+      Handle(TDataStd_Name)::DownCast(theTarget) -> Set (aString);    
+      // attribute id
+      Standard_GUID aGUID;
+      const XmlObjMgt_Element& anElement = theSource;
+      XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString());
+      if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL)
+        aGUID = TDataStd_Name::GetID(); //default case
+      else
+        aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
+
+      Handle(TDataStd_Name)::DownCast(theTarget)->SetID(aGUID);
+         return Standard_True;
+    }
   }
   WriteMessage("error retrieving ExtendedString for type TDataStd_Name");
   return Standard_False;
@@ -65,12 +77,20 @@ Standard_Boolean XmlMDataStd_NameDriver::Paste
 
 //=======================================================================
 //function : Paste()
-//purpose  : 
+//purpose  : store
 //=======================================================================
 void XmlMDataStd_NameDriver::Paste (const Handle(TDF_Attribute)& theSource,
                                     XmlObjMgt_Persistent&        theTarget,
                                     XmlObjMgt_SRelocationTable&  ) const
 {
   Handle(TDataStd_Name) aName = Handle(TDataStd_Name)::DownCast(theSource);
+  if (aName.IsNull()) return;
   XmlObjMgt::SetExtendedString (theTarget, aName -> Get());
+  if(aName->ID() != TDataStd_Name::GetID()) {
+    //convert GUID
+    Standard_Character aGuidStr [Standard_GUID_SIZE_ALLOC];
+    Standard_PCharacter pGuidStr = aGuidStr;
+    aName->ID().ToCString (pGuidStr);
+    theTarget.Element().setAttribute (::AttributeIDString(), aGuidStr);
+  }
 }