1 // Created on: 2001-09-04
2 // Created by: Julia DOROVSKIKH
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 #include <XmlMDataXtd_PositionDriver.hxx>
18 #include <CDM_MessageDriver.hxx>
20 #include <Standard_Type.hxx>
21 #include <TDataXtd_Position.hxx>
22 #include <TDF_Attribute.hxx>
23 #include <XmlObjMgt.hxx>
24 #include <XmlObjMgt_Persistent.hxx>
28 IMPLEMENT_STANDARD_RTTIEXT(XmlMDataXtd_PositionDriver,XmlMDF_ADriver)
30 //=======================================================================
31 //function : XmlMDataXtd_PositionDriver
32 //purpose : Constructor
33 //=======================================================================
34 XmlMDataXtd_PositionDriver::XmlMDataXtd_PositionDriver
35 (const Handle(CDM_MessageDriver)& theMsgDriver)
36 : XmlMDF_ADriver (theMsgDriver, NULL)
39 //=======================================================================
42 //=======================================================================
43 Handle(TDF_Attribute) XmlMDataXtd_PositionDriver::NewEmpty() const
45 return (new TDataXtd_Position());
48 //=======================================================================
50 //purpose : persistent -> transient (retrieve)
51 //=======================================================================
52 Standard_Boolean XmlMDataXtd_PositionDriver::Paste
53 (const XmlObjMgt_Persistent& theSource,
54 const Handle(TDF_Attribute)& theTarget,
55 XmlObjMgt_RRelocationTable& ) const
57 Handle(TDataXtd_Position) aTPos = Handle(TDataXtd_Position)::DownCast(theTarget);
60 XmlObjMgt_DOMString aPosStr = XmlObjMgt::GetStringValue(theSource.Element());
63 WriteMessage ("Cannot retrieve position string from element");
64 return Standard_False;
69 Standard_CString aValueStr = Standard_CString(aPosStr.GetString());
72 if (!XmlObjMgt::GetReal(aValueStr, aValue))
74 TCollection_ExtendedString aMessageString =
75 TCollection_ExtendedString
76 ("Cannot retrieve X coordinate for TDataXtd_Position attribute as \"")
78 WriteMessage (aMessageString);
79 return Standard_False;
84 if (!XmlObjMgt::GetReal(aValueStr, aValue))
86 TCollection_ExtendedString aMessageString =
87 TCollection_ExtendedString
88 ("Cannot retrieve Y coordinate for TDataXtd_Position attribute as \"")
90 WriteMessage (aMessageString);
91 return Standard_False;
96 if (!XmlObjMgt::GetReal(aValueStr, aValue))
98 TCollection_ExtendedString aMessageString =
99 TCollection_ExtendedString
100 ("Cannot retrieve Z coordinate for TDataXtd_Position attribute as \"")
102 WriteMessage (aMessageString);
103 return Standard_False;
107 aTPos->SetPosition(aPos);
109 return Standard_True;
112 //=======================================================================
114 //purpose : transient -> persistent (store)
115 //=======================================================================
116 void XmlMDataXtd_PositionDriver::Paste
117 (const Handle(TDF_Attribute)& theSource,
118 XmlObjMgt_Persistent& theTarget,
119 XmlObjMgt_SRelocationTable& ) const
121 Handle(TDataXtd_Position) aTPos = Handle(TDataXtd_Position)::DownCast(theSource);
124 gp_Pnt aPos = aTPos->GetPosition();
126 Sprintf (buf, "%.17g %.17g %.17g", aPos.X(), aPos.Y(), aPos.Z());
127 XmlObjMgt::SetStringValue(theTarget.Element(), buf);