0030675: Visualization - remove redundant proxy classes in hierarchy of PrsMgr_Presen...
[occt.git] / src / XmlMXCAFDoc / XmlMXCAFDoc_CentroidDriver.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
17 #include <Message_Messenger.hxx>
18 #include <gp_XYZ.hxx>
19 #include <Standard_Type.hxx>
20 #include <TDF_Attribute.hxx>
21 #include <XCAFDoc_Centroid.hxx>
22 #include <XmlMXCAFDoc_CentroidDriver.hxx>
23 #include <XmlObjMgt.hxx>
24 #include <XmlObjMgt_Persistent.hxx>
25
26 #include <stdio.h>
27 IMPLEMENT_STANDARD_RTTIEXT(XmlMXCAFDoc_CentroidDriver,XmlMDF_ADriver)
28
29 //=======================================================================
30 //function : XmlMXCAFDoc_CentroidDriver
31 //purpose  : Constructor
32 //=======================================================================
33 XmlMXCAFDoc_CentroidDriver::XmlMXCAFDoc_CentroidDriver
34                         (const Handle(Message_Messenger)& theMsgDriver)
35       : XmlMDF_ADriver (theMsgDriver, "xcaf", "Centroid")
36 {}
37
38 //=======================================================================
39 //function : NewEmpty
40 //purpose  : 
41 //=======================================================================
42 Handle(TDF_Attribute) XmlMXCAFDoc_CentroidDriver::NewEmpty() const
43 {
44   return (new XCAFDoc_Centroid());
45 }
46
47 //=======================================================================
48 //function : Paste
49 //purpose  : persistent -> transient (retrieve)
50 //=======================================================================
51 Standard_Boolean XmlMXCAFDoc_CentroidDriver::Paste
52                 (const XmlObjMgt_Persistent&  theSource,
53                  const Handle(TDF_Attribute)& theTarget,
54                  XmlObjMgt_RRelocationTable&  ) const
55 {
56   Handle(XCAFDoc_Centroid) aTPos = Handle(XCAFDoc_Centroid)::DownCast(theTarget);
57
58   // position
59   XmlObjMgt_DOMString aPosStr = XmlObjMgt::GetStringValue(theSource.Element());
60   if (aPosStr == NULL)
61   {
62     myMessageDriver->Send ("Cannot retrieve position string from element", Message_Fail);
63     return Standard_False;
64   }
65
66   gp_Pnt aPos;
67   Standard_Real aValue;
68   Standard_CString aValueStr = Standard_CString(aPosStr.GetString());
69
70   // X
71   if (!XmlObjMgt::GetReal(aValueStr, aValue))
72   {
73     TCollection_ExtendedString aMessageString =
74       TCollection_ExtendedString
75         ("Cannot retrieve X coordinate for XCAFDoc_Centroid attribute as \"")
76           + aValueStr + "\"";
77     myMessageDriver->Send (aMessageString, Message_Fail);
78     return Standard_False;
79   }
80   aPos.SetX(aValue);
81
82   // Y
83   if (!XmlObjMgt::GetReal(aValueStr, aValue))
84   {
85     TCollection_ExtendedString aMessageString =
86       TCollection_ExtendedString
87         ("Cannot retrieve Y coordinate for XCAFDoc_Centroid attribute as \"")
88           + aValueStr + "\"";
89     myMessageDriver->Send (aMessageString, Message_Fail);
90     return Standard_False;
91   }
92   aPos.SetY(aValue);
93
94   // Z
95   if (!XmlObjMgt::GetReal(aValueStr, aValue))
96   {
97     TCollection_ExtendedString aMessageString =
98       TCollection_ExtendedString
99         ("Cannot retrieve Z coordinate for XCAFDoc_Centroid attribute as \"")
100           + aValueStr + "\"";
101     myMessageDriver->Send (aMessageString, Message_Fail);
102     return Standard_False;
103   }
104   aPos.SetZ(aValue);
105
106   aTPos->Set(aPos);
107
108   return Standard_True;
109 }
110
111 //=======================================================================
112 //function : Paste
113 //purpose  : transient -> persistent (store)
114 //=======================================================================
115 void XmlMXCAFDoc_CentroidDriver::Paste
116                 (const Handle(TDF_Attribute)& theSource,
117                  XmlObjMgt_Persistent&        theTarget,
118                  XmlObjMgt_SRelocationTable&  ) const
119 {
120   Handle(XCAFDoc_Centroid) aTPos = Handle(XCAFDoc_Centroid)::DownCast(theSource);
121   if (!aTPos.IsNull())
122   {
123     gp_Pnt aPos = aTPos->Get();
124     char buf[75]; // (24 + 1) * 3
125     Sprintf (buf, "%.17g %.17g %.17g", aPos.X(), aPos.Y(), aPos.Z());
126     XmlObjMgt::SetStringValue(theTarget.Element(), buf);
127   }
128 }