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 <CDM_MessageDriver.hxx>
18 #include <Standard_Type.hxx>
19 #include <TDF_Attribute.hxx>
20 #include <TDF_Tool.hxx>
21 #include <TFunction_Function.hxx>
22 #include <XmlMFunction_FunctionDriver.hxx>
23 #include <XmlObjMgt.hxx>
24 #include <XmlObjMgt_Persistent.hxx>
26 IMPLEMENT_STANDARD_RTTIEXT(XmlMFunction_FunctionDriver,XmlMDF_ADriver)
27 IMPLEMENT_DOMSTRING (GuidString, "guid")
28 IMPLEMENT_DOMSTRING (FailureString, "failure")
30 //=======================================================================
31 //function : XmlMFunction_FunctionDriver
32 //purpose : Constructor
33 //=======================================================================
34 XmlMFunction_FunctionDriver::XmlMFunction_FunctionDriver
35 (const Handle(CDM_MessageDriver)& theMsgDriver)
36 : XmlMDF_ADriver (theMsgDriver, NULL)
39 //=======================================================================
42 //=======================================================================
43 Handle(TDF_Attribute) XmlMFunction_FunctionDriver::NewEmpty() const
45 return (new TFunction_Function());
48 //=======================================================================
50 //purpose : persistent -> transient (retrieve)
51 //=======================================================================
52 Standard_Boolean XmlMFunction_FunctionDriver::Paste
53 (const XmlObjMgt_Persistent& theSource,
54 const Handle(TDF_Attribute)& theTarget,
55 XmlObjMgt_RRelocationTable& ) const
57 Handle(TFunction_Function) aF = Handle(TFunction_Function)::DownCast(theTarget);
60 XmlObjMgt_DOMString aGuidDomStr =
61 theSource.Element().getAttribute(::GuidString());
62 Standard_CString aGuidStr = (Standard_CString)aGuidDomStr.GetString();
63 if (aGuidStr[0] == '\0')
65 WriteMessage ("error retrieving GUID for type TFunction_Function");
66 return Standard_False;
68 aF->SetDriverGUID(aGuidStr);
71 Standard_Integer aValue;
72 XmlObjMgt_DOMString aFStr = theSource.Element().getAttribute(::FailureString());
73 if (!aFStr.GetInteger(aValue))
75 TCollection_ExtendedString aMessageString =
76 TCollection_ExtendedString
77 ("Cannot retrieve failure number for TFunction_Function attribute from \"")
79 WriteMessage (aMessageString);
80 return Standard_False;
82 aF->SetFailure(aValue);
87 //=======================================================================
89 //purpose : transient -> persistent (store)
90 //=======================================================================
91 void XmlMFunction_FunctionDriver::Paste (const Handle(TDF_Attribute)& theSource,
92 XmlObjMgt_Persistent& theTarget,
93 XmlObjMgt_SRelocationTable& ) const
95 Handle(TFunction_Function) aF =
96 Handle(TFunction_Function)::DownCast(theSource);
99 //convert GUID into attribute value
100 Standard_Character aGuidStr [40];
101 Standard_PCharacter pGuidStr;
104 aF->GetDriverGUID().ToCString(pGuidStr);
105 theTarget.Element().setAttribute(::GuidString(), aGuidStr);
107 //integer value of failure
108 theTarget.Element().setAttribute(::FailureString(), aF->GetFailure());