b311480e |
1 | // Created on: 2007-08-21 |
2 | // Created by: Sergey ZARITCHNY |
973c2be1 |
3 | // Copyright (c) 2007-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
42cf5bc1 |
16 | |
17 | #include <CDM_MessageDriver.hxx> |
18 | #include <Standard_Type.hxx> |
19 | #include <TDataStd_AsciiString.hxx> |
20 | #include <TDF_Attribute.hxx> |
21 | #include <XmlMDataStd_AsciiStringDriver.hxx> |
7fd59977 |
22 | #include <XmlObjMgt.hxx> |
42cf5bc1 |
23 | #include <XmlObjMgt_Persistent.hxx> |
7fd59977 |
24 | #include <XmlObjMgt_RRelocationTable.hxx> |
25 | #include <XmlObjMgt_SRelocationTable.hxx> |
7fd59977 |
26 | |
92efcf78 |
27 | IMPLEMENT_STANDARD_RTTIEXT(XmlMDataStd_AsciiStringDriver,XmlMDF_ADriver) |
fa53efef |
28 | IMPLEMENT_DOMSTRING (AttributeIDString, "asciiguid") |
7fd59977 |
29 | //======================================================================= |
30 | //function : XmlMDataStd_AsciiStringDriver |
31 | //purpose : Constructor |
32 | //======================================================================= |
7fd59977 |
33 | XmlMDataStd_AsciiStringDriver::XmlMDataStd_AsciiStringDriver |
34 | (const Handle(CDM_MessageDriver)& theMsgDriver) |
35 | : XmlMDF_ADriver (theMsgDriver, NULL) |
36 | {} |
37 | |
38 | //======================================================================= |
39 | //function : NewEmpty() |
40 | //purpose : |
41 | //======================================================================= |
42 | Handle(TDF_Attribute) XmlMDataStd_AsciiStringDriver::NewEmpty () const |
43 | { |
44 | return (new TDataStd_AsciiString()); |
45 | } |
46 | |
47 | //======================================================================= |
48 | //function : Paste() |
49 | //purpose : retrieve |
50 | //======================================================================= |
51 | Standard_Boolean XmlMDataStd_AsciiStringDriver::Paste |
52 | (const XmlObjMgt_Persistent& theSource, |
53 | const Handle(TDF_Attribute)& theTarget, |
54 | XmlObjMgt_RRelocationTable& ) const |
55 | { |
56 | if(!theTarget.IsNull()) { |
fa53efef |
57 | const TCollection_AsciiString aString = XmlObjMgt::GetStringValue (theSource); |
58 | Handle(TDataStd_AsciiString)::DownCast(theTarget) -> Set (aString); |
59 | // attribute id |
60 | Standard_GUID aGUID; |
61 | const XmlObjMgt_Element& anElement = theSource; |
62 | XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString()); |
63 | if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL) |
64 | aGUID = TDataStd_AsciiString::GetID(); //default case |
65 | else |
66 | aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case |
67 | |
68 | Handle(TDataStd_AsciiString)::DownCast(theTarget)->SetID(aGUID); |
69 | return Standard_True; |
7fd59977 |
70 | } |
71 | WriteMessage("error retrieving AsciiString for type TDataStd_AsciiString"); |
72 | return Standard_False; |
73 | } |
74 | |
75 | //======================================================================= |
76 | //function : Paste() |
77 | //purpose : store |
78 | //======================================================================= |
79 | void XmlMDataStd_AsciiStringDriver::Paste (const Handle(TDF_Attribute)& theSource, |
80 | XmlObjMgt_Persistent& theTarget, |
81 | XmlObjMgt_SRelocationTable& ) const |
82 | { |
83 | Handle(TDataStd_AsciiString) aS = Handle(TDataStd_AsciiString)::DownCast(theSource); |
84 | if (aS.IsNull()) return; |
85 | XmlObjMgt_DOMString aString = aS->Get().ToCString(); |
86 | XmlObjMgt::SetStringValue (theTarget, aString); |
fa53efef |
87 | if(aS->ID() != TDataStd_AsciiString::GetID()) { |
88 | //convert GUID |
89 | Standard_Character aGuidStr [Standard_GUID_SIZE_ALLOC]; |
90 | Standard_PCharacter pGuidStr = aGuidStr; |
91 | aS->ID().ToCString (pGuidStr); |
92 | theTarget.Element().setAttribute (::AttributeIDString(), aGuidStr); |
93 | } |
7fd59977 |
94 | } |