60aaa106fd3e1d24750a000057fa4813b9a51c3d
[occt.git] / src / XmlMDataXtd / XmlMDataXtd_PositionDriver.cxx
1 // Created on: 2001-09-04
2 // Created by: Julia DOROVSKIKH
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 #include <XmlMDataXtd_PositionDriver.hxx>
17
18 #include <CDM_MessageDriver.hxx>
19 #include <gp_XYZ.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>
25
26 #include <stdio.h>
27
28 IMPLEMENT_STANDARD_RTTIEXT(XmlMDataXtd_PositionDriver,XmlMDF_ADriver)
29
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)
37 {}
38
39 //=======================================================================
40 //function : NewEmpty
41 //purpose  : 
42 //=======================================================================
43 Handle(TDF_Attribute) XmlMDataXtd_PositionDriver::NewEmpty() const
44 {
45   return (new TDataXtd_Position());
46 }
47
48 //=======================================================================
49 //function : Paste
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
56 {
57   Handle(TDataXtd_Position) aTPos = Handle(TDataXtd_Position)::DownCast(theTarget);
58
59   // position
60   XmlObjMgt_DOMString aPosStr = XmlObjMgt::GetStringValue(theSource.Element());
61   if (aPosStr == NULL)
62   {
63     WriteMessage ("Cannot retrieve position string from element");
64     return Standard_False;
65   }
66
67   gp_Pnt aPos;
68   Standard_Real aValue;
69   Standard_CString aValueStr = Standard_CString(aPosStr.GetString());
70
71   // X
72   if (!XmlObjMgt::GetReal(aValueStr, aValue))
73   {
74     TCollection_ExtendedString aMessageString =
75       TCollection_ExtendedString
76         ("Cannot retrieve X coordinate for TDataXtd_Position attribute as \"")
77           + aValueStr + "\"";
78     WriteMessage (aMessageString);
79     return Standard_False;
80   }
81   aPos.SetX(aValue);
82
83   // Y
84   if (!XmlObjMgt::GetReal(aValueStr, aValue))
85   {
86     TCollection_ExtendedString aMessageString =
87       TCollection_ExtendedString
88         ("Cannot retrieve Y coordinate for TDataXtd_Position attribute as \"")
89           + aValueStr + "\"";
90     WriteMessage (aMessageString);
91     return Standard_False;
92   }
93   aPos.SetY(aValue);
94
95   // Z
96   if (!XmlObjMgt::GetReal(aValueStr, aValue))
97   {
98     TCollection_ExtendedString aMessageString =
99       TCollection_ExtendedString
100         ("Cannot retrieve Z coordinate for TDataXtd_Position attribute as \"")
101           + aValueStr + "\"";
102     WriteMessage (aMessageString);
103     return Standard_False;
104   }
105   aPos.SetZ(aValue);
106
107   aTPos->SetPosition(aPos);
108
109   return Standard_True;
110 }
111
112 //=======================================================================
113 //function : Paste
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
120 {
121   Handle(TDataXtd_Position) aTPos = Handle(TDataXtd_Position)::DownCast(theSource);
122   if (!aTPos.IsNull())
123   {
124     gp_Pnt aPos = aTPos->GetPosition();
125     char buf [64];
126     Sprintf (buf, "%.17g %.17g %.17g", aPos.X(), aPos.Y(), aPos.Z());
127     XmlObjMgt::SetStringValue(theTarget.Element(), buf);
128   }
129 }