Test for 0022778: Bug in BRepMesh
[occt.git] / src / XmlMXCAFDoc / XmlMXCAFDoc_CentroidDriver.cxx
1 // Created on: 2001-09-04
2 // Created by: Julia DOROVSKIKH
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
4 //
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.
9 //
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.
12 //
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.
19
20
21 #include <XmlMXCAFDoc_CentroidDriver.ixx>
22
23 #include <XmlObjMgt.hxx>
24 #include <XCAFDoc_Centroid.hxx>
25 #include <gp_XYZ.hxx>
26
27 #include <stdio.h>
28
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")
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     WriteMessage ("Cannot retrieve position string from element");
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     WriteMessage (aMessageString);
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     WriteMessage (aMessageString);
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     WriteMessage (aMessageString);
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 [64];
125     sprintf (buf, "%.17g %.17g %.17g", aPos.X(), aPos.Y(), aPos.Z());
126     XmlObjMgt::SetStringValue(theTarget.Element(), buf);
127   }
128 }