b311480e |
1 | // Created on: 2001-08-24 |
2 | // Created by: Alexnder GRIGORIEV |
973c2be1 |
3 | // Copyright (c) 2001-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. |
b311480e |
15 | |
16 | //AGV 150202: Changed prototype XmlObjMgt::SetStringValue() |
7fd59977 |
17 | |
83ae3591 |
18 | #include <Message_Messenger.hxx> |
42cf5bc1 |
19 | #include <Standard_Type.hxx> |
7fd59977 |
20 | #include <TDataStd_Real.hxx> |
42cf5bc1 |
21 | #include <TDF_Attribute.hxx> |
22 | #include <XmlMDataStd_RealDriver.hxx> |
7fd59977 |
23 | #include <XmlObjMgt.hxx> |
42cf5bc1 |
24 | #include <XmlObjMgt_Persistent.hxx> |
7fd59977 |
25 | |
42cf5bc1 |
26 | #include <stdio.h> |
92efcf78 |
27 | IMPLEMENT_STANDARD_RTTIEXT(XmlMDataStd_RealDriver,XmlMDF_ADriver) |
fa53efef |
28 | IMPLEMENT_DOMSTRING (AttributeIDString, "realattguid") |
7fd59977 |
29 | //======================================================================= |
30 | //function : XmlMDataStd_RealDriver |
31 | //purpose : Constructor |
32 | //======================================================================= |
7fd59977 |
33 | XmlMDataStd_RealDriver::XmlMDataStd_RealDriver |
83ae3591 |
34 | (const Handle(Message_Messenger)& theMsgDriver) |
7fd59977 |
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 | { |
fa53efef |
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); |
7fd59977 |
66 | |
e13b9464 |
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 | |
7fd59977 |
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 | { |
fa53efef |
90 | Handle(TDataStd_Real) anAtt = Handle(TDataStd_Real)::DownCast(theSource); |
7fd59977 |
91 | char aValueChar[32]; |
fa53efef |
92 | Sprintf(aValueChar, "%.17g", anAtt->Get()); |
7fd59977 |
93 | TCollection_AsciiString aValueStr(aValueChar); |
7fd59977 |
94 | // No occurrence of '&', '<' and other irregular XML characters |
95 | XmlObjMgt::SetStringValue (theTarget, aValueStr.ToCString(), Standard_True); |
fa53efef |
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 | } |
7fd59977 |
103 | } |