// Created on: 2001-09-04 // Created by: Julia DOROVSKIKH // Copyright (c) 2001-2012 OPEN CASCADE SAS // // The content of this file is subject to the Open CASCADE Technology Public // License Version 6.5 (the "License"). You may not use the content of this file // except in compliance with the License. Please obtain a copy of the License // at http://www.opencascade.org and read it completely before using this file. // // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. // // The Original Code and all software distributed under the License is // distributed on an "AS IS" basis, without warranty of any kind, and the // Initial Developer hereby disclaims all such warranties, including without // limitation, any warranties of merchantability, fitness for a particular // purpose or non-infringement. Please see the License for the specific terms // and conditions governing the rights and limitations under the License. #include #include #include #include #include //======================================================================= //function : XmlMXCAFDoc_CentroidDriver //purpose : Constructor //======================================================================= XmlMXCAFDoc_CentroidDriver::XmlMXCAFDoc_CentroidDriver (const Handle(CDM_MessageDriver)& theMsgDriver) : XmlMDF_ADriver (theMsgDriver, "xcaf", "Centroid") {} //======================================================================= //function : NewEmpty //purpose : //======================================================================= Handle(TDF_Attribute) XmlMXCAFDoc_CentroidDriver::NewEmpty() const { return (new XCAFDoc_Centroid()); } //======================================================================= //function : Paste //purpose : persistent -> transient (retrieve) //======================================================================= Standard_Boolean XmlMXCAFDoc_CentroidDriver::Paste (const XmlObjMgt_Persistent& theSource, const Handle(TDF_Attribute)& theTarget, XmlObjMgt_RRelocationTable& ) const { Handle(XCAFDoc_Centroid) aTPos = Handle(XCAFDoc_Centroid)::DownCast(theTarget); // position XmlObjMgt_DOMString aPosStr = XmlObjMgt::GetStringValue(theSource.Element()); if (aPosStr == NULL) { WriteMessage ("Cannot retrieve position string from element"); return Standard_False; } gp_Pnt aPos; Standard_Real aValue; Standard_CString aValueStr = Standard_CString(aPosStr.GetString()); // X if (!XmlObjMgt::GetReal(aValueStr, aValue)) { TCollection_ExtendedString aMessageString = TCollection_ExtendedString ("Cannot retrieve X coordinate for XCAFDoc_Centroid attribute as \"") + aValueStr + "\""; WriteMessage (aMessageString); return Standard_False; } aPos.SetX(aValue); // Y if (!XmlObjMgt::GetReal(aValueStr, aValue)) { TCollection_ExtendedString aMessageString = TCollection_ExtendedString ("Cannot retrieve Y coordinate for XCAFDoc_Centroid attribute as \"") + aValueStr + "\""; WriteMessage (aMessageString); return Standard_False; } aPos.SetY(aValue); // Z if (!XmlObjMgt::GetReal(aValueStr, aValue)) { TCollection_ExtendedString aMessageString = TCollection_ExtendedString ("Cannot retrieve Z coordinate for XCAFDoc_Centroid attribute as \"") + aValueStr + "\""; WriteMessage (aMessageString); return Standard_False; } aPos.SetZ(aValue); aTPos->Set(aPos); return Standard_True; } //======================================================================= //function : Paste //purpose : transient -> persistent (store) //======================================================================= void XmlMXCAFDoc_CentroidDriver::Paste (const Handle(TDF_Attribute)& theSource, XmlObjMgt_Persistent& theTarget, XmlObjMgt_SRelocationTable& ) const { Handle(XCAFDoc_Centroid) aTPos = Handle(XCAFDoc_Centroid)::DownCast(theSource); if (!aTPos.IsNull()) { gp_Pnt aPos = aTPos->Get(); char buf [64]; sprintf (buf, "%.17g %.17g %.17g", aPos.X(), aPos.Y(), aPos.Z()); XmlObjMgt::SetStringValue(theTarget.Element(), buf); } }