0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / XmlMDataStd / XmlMDataStd_AsciiStringDriver.cxx
1 // Created on: 2007-08-21
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2007-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_AsciiString.hxx>
20 #include <TDF_Attribute.hxx>
21 #include <XmlMDataStd_AsciiStringDriver.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_AsciiStringDriver,XmlMDF_ADriver)
28 IMPLEMENT_DOMSTRING (AttributeIDString, "asciiguid")
29 //=======================================================================
30 //function : XmlMDataStd_AsciiStringDriver
31 //purpose  : Constructor
32 //=======================================================================
33 XmlMDataStd_AsciiStringDriver::XmlMDataStd_AsciiStringDriver
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_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()) {
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;
70   }
71   myMessageDriver->Send("error retrieving AsciiString for type TDataStd_AsciiString", Message_Fail);
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);
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   }
94 }