0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / XmlMDataStd / XmlMDataStd_NameDriver.cxx
1 // Created on: 2001-08-01
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16
17 #include <Message_Messenger.hxx>
18 #include <Standard_Type.hxx>
19 #include <TDataStd_Name.hxx>
20 #include <TDF_Attribute.hxx>
21 #include <XmlMDataStd_NameDriver.hxx>
22 #include <XmlObjMgt.hxx>
23 #include <XmlObjMgt_Persistent.hxx>
24 #include <XmlObjMgt_RRelocationTable.hxx>
25 #include <XmlObjMgt_SRelocationTable.hxx>
26
27 IMPLEMENT_STANDARD_RTTIEXT(XmlMDataStd_NameDriver,XmlMDF_ADriver)
28 IMPLEMENT_DOMSTRING (AttributeIDString, "nameguid")
29 //=======================================================================
30 //function : XmlMDataStd_NameDriver
31 //purpose  : Constructor
32 //=======================================================================
33 XmlMDataStd_NameDriver::XmlMDataStd_NameDriver
34                         (const Handle(Message_Messenger)& theMsgDriver)
35       : XmlMDF_ADriver (theMsgDriver, NULL)
36 {}
37
38 //=======================================================================
39 //function : NewEmpty()
40 //purpose  : 
41 //=======================================================================
42 Handle(TDF_Attribute) XmlMDataStd_NameDriver::NewEmpty () const
43 {
44   return (new TDataStd_Name());
45 }
46
47 //=======================================================================
48 //function : Paste()
49 //purpose  : 
50 //=======================================================================
51 Standard_Boolean XmlMDataStd_NameDriver::Paste
52                                (const XmlObjMgt_Persistent&  theSource,
53                                 const Handle(TDF_Attribute)& theTarget,
54                                 XmlObjMgt_RRelocationTable&  ) const
55 {
56   if(!theTarget.IsNull()) {
57     TCollection_ExtendedString aString;
58     if (XmlObjMgt::GetExtendedString (theSource, aString))
59     {
60       Handle(TDataStd_Name)::DownCast(theTarget) -> Set (aString);
61       // attribute id
62       Standard_GUID aGUID;
63       const XmlObjMgt_Element& anElement = theSource;
64       XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString());
65       if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL)
66         aGUID = TDataStd_Name::GetID(); //default case
67       else
68         aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
69
70       Handle(TDataStd_Name)::DownCast(theTarget)->SetID(aGUID);
71       return Standard_True;
72     }
73   }
74   myMessageDriver->Send("error retrieving ExtendedString for type TDataStd_Name", Message_Fail);
75   return Standard_False;
76 }
77
78 //=======================================================================
79 //function : Paste()
80 //purpose  : store
81 //=======================================================================
82 void XmlMDataStd_NameDriver::Paste (const Handle(TDF_Attribute)& theSource,
83                                     XmlObjMgt_Persistent&        theTarget,
84                                     XmlObjMgt_SRelocationTable&  ) const
85 {
86   Handle(TDataStd_Name) aName = Handle(TDataStd_Name)::DownCast(theSource);
87   if (aName.IsNull()) return;
88   XmlObjMgt::SetExtendedString (theTarget, aName -> Get());
89   if(aName->ID() != TDataStd_Name::GetID()) {
90     //convert GUID
91     Standard_Character aGuidStr [Standard_GUID_SIZE_ALLOC];
92     Standard_PCharacter pGuidStr = aGuidStr;
93     aName->ID().ToCString (pGuidStr);
94     theTarget.Element().setAttribute (::AttributeIDString(), aGuidStr);
95   }
96 }