0030686: Visualization, SelectMgr_ViewerSelector - sorting issues of transformation...
[occt.git] / src / XmlMDataStd / XmlMDataStd_RealDriver.cxx
1 // Created on: 2001-08-24
2 // Created by: Alexnder 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 //AGV 150202: Changed prototype XmlObjMgt::SetStringValue()
17
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>
25
26 #include <stdio.h>
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)
36 {}
37
38 //=======================================================================
39 //function : NewEmpty
40 //purpose  : 
41 //=======================================================================
42 Handle(TDF_Attribute) XmlMDataStd_RealDriver::NewEmpty() const
43 {
44   return (new TDataStd_Real());
45 }
46
47 //=======================================================================
48 //function : Paste
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
55 {
56   // attribute id
57   Standard_GUID aGUID;
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
62   else
63     aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
64
65   Handle(TDataStd_Real)::DownCast(theTarget)->SetID(aGUID);
66
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 \"")
73       + aValueStr + "\"";
74     myMessageDriver->Send (aMessageString, Message_Warning);
75   }
76   Handle(TDataStd_Real) anAtt = Handle(TDataStd_Real)::DownCast(theTarget);
77   anAtt->Set(aValue);
78
79   return Standard_True;
80 }
81
82 //=======================================================================
83 //function : Paste
84 //purpose  : transient -> persistent (store)
85 //=======================================================================
86 void XmlMDataStd_RealDriver::Paste (const Handle(TDF_Attribute)& theSource,
87                                     XmlObjMgt_Persistent&        theTarget,
88                                     XmlObjMgt_SRelocationTable&  ) const
89 {
90   Handle(TDataStd_Real) anAtt = Handle(TDataStd_Real)::DownCast(theSource);
91   char aValueChar[32];
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()) {
97     //convert GUID
98     Standard_Character aGuidStr [Standard_GUID_SIZE_ALLOC];
99     Standard_PCharacter pGuidStr = aGuidStr;
100     anAtt->ID().ToCString (pGuidStr);
101     theTarget.Element().setAttribute (::AttributeIDString(), aGuidStr);
102   }
103 }