1 // Created on: 2001-09-04
2 // Created by: Julia DOROVSKIKH
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <XmlMXCAFDoc_CentroidDriver.ixx>
23 #include <XmlObjMgt.hxx>
24 #include <XCAFDoc_Centroid.hxx>
29 //=======================================================================
30 //function : XmlMXCAFDoc_CentroidDriver
31 //purpose : Constructor
32 //=======================================================================
33 XmlMXCAFDoc_CentroidDriver::XmlMXCAFDoc_CentroidDriver
34 (const Handle(CDM_MessageDriver)& 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 WriteMessage ("Cannot retrieve position string from element");
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 WriteMessage (aMessageString);
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 WriteMessage (aMessageString);
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 WriteMessage (aMessageString);
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();
125 sprintf (buf, "%.17g %.17g %.17g", aPos.X(), aPos.Y(), aPos.Z());
126 XmlObjMgt::SetStringValue(theTarget.Element(), buf);