0023948: Wrong intersection between a surface of revolution and a plane.
[occt.git] / src / XmlMXCAFDoc / XmlMXCAFDoc_CentroidDriver.cxx
CommitLineData
b311480e 1// Created on: 2001-09-04
2// Created by: Julia DOROVSKIKH
973c2be1 3// Copyright (c) 2001-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
16#include <XmlMXCAFDoc_CentroidDriver.ixx>
17
18#include <XmlObjMgt.hxx>
19#include <XCAFDoc_Centroid.hxx>
20#include <gp_XYZ.hxx>
21
22#include <stdio.h>
23
24//=======================================================================
25//function : XmlMXCAFDoc_CentroidDriver
26//purpose : Constructor
27//=======================================================================
28XmlMXCAFDoc_CentroidDriver::XmlMXCAFDoc_CentroidDriver
29 (const Handle(CDM_MessageDriver)& theMsgDriver)
30 : XmlMDF_ADriver (theMsgDriver, "xcaf", "Centroid")
31{}
32
33//=======================================================================
34//function : NewEmpty
35//purpose :
36//=======================================================================
37Handle(TDF_Attribute) XmlMXCAFDoc_CentroidDriver::NewEmpty() const
38{
39 return (new XCAFDoc_Centroid());
40}
41
42//=======================================================================
43//function : Paste
44//purpose : persistent -> transient (retrieve)
45//=======================================================================
46Standard_Boolean XmlMXCAFDoc_CentroidDriver::Paste
47 (const XmlObjMgt_Persistent& theSource,
48 const Handle(TDF_Attribute)& theTarget,
49 XmlObjMgt_RRelocationTable& ) const
50{
51 Handle(XCAFDoc_Centroid) aTPos = Handle(XCAFDoc_Centroid)::DownCast(theTarget);
52
53 // position
54 XmlObjMgt_DOMString aPosStr = XmlObjMgt::GetStringValue(theSource.Element());
55 if (aPosStr == NULL)
56 {
57 WriteMessage ("Cannot retrieve position string from element");
58 return Standard_False;
59 }
60
61 gp_Pnt aPos;
62 Standard_Real aValue;
63 Standard_CString aValueStr = Standard_CString(aPosStr.GetString());
64
65 // X
66 if (!XmlObjMgt::GetReal(aValueStr, aValue))
67 {
68 TCollection_ExtendedString aMessageString =
69 TCollection_ExtendedString
70 ("Cannot retrieve X coordinate for XCAFDoc_Centroid attribute as \"")
71 + aValueStr + "\"";
72 WriteMessage (aMessageString);
73 return Standard_False;
74 }
75 aPos.SetX(aValue);
76
77 // Y
78 if (!XmlObjMgt::GetReal(aValueStr, aValue))
79 {
80 TCollection_ExtendedString aMessageString =
81 TCollection_ExtendedString
82 ("Cannot retrieve Y coordinate for XCAFDoc_Centroid attribute as \"")
83 + aValueStr + "\"";
84 WriteMessage (aMessageString);
85 return Standard_False;
86 }
87 aPos.SetY(aValue);
88
89 // Z
90 if (!XmlObjMgt::GetReal(aValueStr, aValue))
91 {
92 TCollection_ExtendedString aMessageString =
93 TCollection_ExtendedString
94 ("Cannot retrieve Z coordinate for XCAFDoc_Centroid attribute as \"")
95 + aValueStr + "\"";
96 WriteMessage (aMessageString);
97 return Standard_False;
98 }
99 aPos.SetZ(aValue);
100
101 aTPos->Set(aPos);
102
103 return Standard_True;
104}
105
106//=======================================================================
107//function : Paste
108//purpose : transient -> persistent (store)
109//=======================================================================
110void XmlMXCAFDoc_CentroidDriver::Paste
111 (const Handle(TDF_Attribute)& theSource,
112 XmlObjMgt_Persistent& theTarget,
113 XmlObjMgt_SRelocationTable& ) const
114{
115 Handle(XCAFDoc_Centroid) aTPos = Handle(XCAFDoc_Centroid)::DownCast(theSource);
116 if (!aTPos.IsNull())
117 {
118 gp_Pnt aPos = aTPos->Get();
119 char buf [64];
91322f44 120 Sprintf (buf, "%.17g %.17g %.17g", aPos.X(), aPos.Y(), aPos.Z());
7fd59977 121 XmlObjMgt::SetStringValue(theTarget.Element(), buf);
122 }
123}