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.
17 #include <Message_Messenger.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>
27 IMPLEMENT_STANDARD_RTTIEXT(XmlMXCAFDoc_CentroidDriver,XmlMDF_ADriver)
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")
38 //=======================================================================
41 //=======================================================================
42 Handle(TDF_Attribute) XmlMXCAFDoc_CentroidDriver::NewEmpty() const
44 return (new XCAFDoc_Centroid());
47 //=======================================================================
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
56 Handle(XCAFDoc_Centroid) aTPos = Handle(XCAFDoc_Centroid)::DownCast(theTarget);
59 XmlObjMgt_DOMString aPosStr = XmlObjMgt::GetStringValue(theSource.Element());
62 myMessageDriver->Send ("Cannot retrieve position string from element", Message_Fail);
63 return Standard_False;
68 Standard_CString aValueStr = Standard_CString(aPosStr.GetString());
71 if (!XmlObjMgt::GetReal(aValueStr, aValue))
73 TCollection_ExtendedString aMessageString =
74 TCollection_ExtendedString
75 ("Cannot retrieve X coordinate for XCAFDoc_Centroid attribute as \"")
77 myMessageDriver->Send (aMessageString, Message_Fail);
78 return Standard_False;
83 if (!XmlObjMgt::GetReal(aValueStr, aValue))
85 TCollection_ExtendedString aMessageString =
86 TCollection_ExtendedString
87 ("Cannot retrieve Y coordinate for XCAFDoc_Centroid attribute as \"")
89 myMessageDriver->Send (aMessageString, Message_Fail);
90 return Standard_False;
95 if (!XmlObjMgt::GetReal(aValueStr, aValue))
97 TCollection_ExtendedString aMessageString =
98 TCollection_ExtendedString
99 ("Cannot retrieve Z coordinate for XCAFDoc_Centroid attribute as \"")
101 myMessageDriver->Send (aMessageString, Message_Fail);
102 return Standard_False;
108 return Standard_True;
111 //=======================================================================
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
120 Handle(XCAFDoc_Centroid) aTPos = Handle(XCAFDoc_Centroid)::DownCast(theSource);
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);