1 // Created on: 2001-08-24
2 // Created by: Alexnder GRIGORIEV
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 //AGV 150202: Changed prototype XmlObjMgt::SetStringValue()
18 #include <Message_Messenger.hxx>
19 #include <Standard_Type.hxx>
20 #include <TDataStd_Real.hxx>
21 #include <TDF_Attribute.hxx>
22 #include <XmlMDataStd_RealDriver.hxx>
23 #include <XmlObjMgt.hxx>
24 #include <XmlObjMgt_Persistent.hxx>
27 IMPLEMENT_STANDARD_RTTIEXT(XmlMDataStd_RealDriver,XmlMDF_ADriver)
28 IMPLEMENT_DOMSTRING (AttributeIDString, "realattguid")
29 //=======================================================================
30 //function : XmlMDataStd_RealDriver
31 //purpose : Constructor
32 //=======================================================================
33 XmlMDataStd_RealDriver::XmlMDataStd_RealDriver
34 (const Handle(Message_Messenger)& theMsgDriver)
35 : XmlMDF_ADriver (theMsgDriver, NULL)
38 //=======================================================================
41 //=======================================================================
42 Handle(TDF_Attribute) XmlMDataStd_RealDriver::NewEmpty() const
44 return (new TDataStd_Real());
47 //=======================================================================
49 //purpose : persistent -> transient (retrieve)
50 //=======================================================================
51 Standard_Boolean XmlMDataStd_RealDriver::Paste
52 (const XmlObjMgt_Persistent& theSource,
53 const Handle(TDF_Attribute)& theTarget,
54 XmlObjMgt_RRelocationTable& ) const
58 const XmlObjMgt_Element& anElement = theSource;
59 XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString());
60 if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL)
61 aGUID = TDataStd_Real::GetID(); //default case
63 aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
65 Handle(TDataStd_Real)::DownCast(theTarget)->SetID(aGUID);
67 Standard_Real aValue(0.);
68 const XmlObjMgt_DOMString& aRealStr= XmlObjMgt::GetStringValue (theSource);
69 Standard_CString aValueStr = Standard_CString (aRealStr.GetString());
70 if(XmlObjMgt::GetReal(aRealStr, aValue) == Standard_False) {
71 TCollection_ExtendedString aMessageString =
72 TCollection_ExtendedString("Cannot retrieve Real attribute from \"")
74 myMessageDriver->Send (aMessageString, Message_Warning);
76 Handle(TDataStd_Real) anAtt = Handle(TDataStd_Real)::DownCast(theTarget);
82 //=======================================================================
84 //purpose : transient -> persistent (store)
85 //=======================================================================
86 void XmlMDataStd_RealDriver::Paste (const Handle(TDF_Attribute)& theSource,
87 XmlObjMgt_Persistent& theTarget,
88 XmlObjMgt_SRelocationTable& ) const
90 Handle(TDataStd_Real) anAtt = Handle(TDataStd_Real)::DownCast(theSource);
92 Sprintf(aValueChar, "%.17g", anAtt->Get());
93 TCollection_AsciiString aValueStr(aValueChar);
94 // No occurrence of '&', '<' and other irregular XML characters
95 XmlObjMgt::SetStringValue (theTarget, aValueStr.ToCString(), Standard_True);
96 if(anAtt->ID() != TDataStd_Real::GetID()) {
98 Standard_Character aGuidStr [Standard_GUID_SIZE_ALLOC];
99 Standard_PCharacter pGuidStr = aGuidStr;
100 anAtt->ID().ToCString (pGuidStr);
101 theTarget.Element().setAttribute (::AttributeIDString(), aGuidStr);