7fd59977 |
1 | // File: XmlMXCAFDoc_MaterialDriver.cxx |
2 | // Created: 10.12.08 15:04:13 |
3 | // Author: Pavel TELKOV |
4 | // Copyright: Open CASCADE 2008 |
5 | |
6 | #include <XmlMXCAFDoc_MaterialDriver.ixx> |
7 | #include <XmlObjMgt.hxx> |
8 | #include <XCAFDoc_Material.hxx> |
9 | #include <TCollection_HAsciiString.hxx> |
10 | |
11 | IMPLEMENT_DOMSTRING (NameIndexString, "name") |
12 | IMPLEMENT_DOMSTRING (DescrIndexString, "descr") |
13 | IMPLEMENT_DOMSTRING (DensNameIndexString, "dens_name") |
14 | IMPLEMENT_DOMSTRING (DensTypeIndexString, "dens_type") |
15 | |
16 | //======================================================================= |
17 | //function : XmlMXCAFDoc_MaterialDriver |
18 | //purpose : Constructor |
19 | //======================================================================= |
20 | XmlMXCAFDoc_MaterialDriver::XmlMXCAFDoc_MaterialDriver |
21 | (const Handle(CDM_MessageDriver)& theMsgDriver) |
22 | : XmlMDF_ADriver (theMsgDriver, "xcaf", "Material") |
23 | {} |
24 | |
25 | //======================================================================= |
26 | //function : NewEmpty |
27 | //purpose : |
28 | //======================================================================= |
29 | Handle(TDF_Attribute) XmlMXCAFDoc_MaterialDriver::NewEmpty() const |
30 | { |
31 | return (new XCAFDoc_Material()); |
32 | } |
33 | |
34 | //======================================================================= |
35 | //function : Paste |
36 | //purpose : persistent -> transient (retrieve) |
37 | //======================================================================= |
38 | Standard_Boolean XmlMXCAFDoc_MaterialDriver::Paste |
39 | (const XmlObjMgt_Persistent& theSource, |
40 | const Handle(TDF_Attribute)& theTarget, |
41 | XmlObjMgt_RRelocationTable& ) const |
42 | { |
43 | Standard_Real aDensity; |
44 | XmlObjMgt_DOMString aRealStr = XmlObjMgt::GetStringValue(theSource); |
45 | |
46 | if (XmlObjMgt::GetReal(aRealStr, aDensity) == Standard_False) { |
47 | TCollection_ExtendedString aMessageString = |
48 | TCollection_ExtendedString("Cannot retrieve Material attribute density from \"") |
49 | + aRealStr + "\""; |
50 | WriteMessage (aMessageString); |
51 | return Standard_False; |
52 | } |
53 | |
54 | const XmlObjMgt_Element& anElement = theSource; |
55 | XmlObjMgt_DOMString aNameStr = anElement.getAttribute(::NameIndexString()); |
56 | XmlObjMgt_DOMString aDescrStr = anElement.getAttribute(::DescrIndexString()); |
57 | XmlObjMgt_DOMString aDensNameStr = anElement.getAttribute(::DensNameIndexString()); |
58 | XmlObjMgt_DOMString aDensTypeStr = anElement.getAttribute(::DensTypeIndexString()); |
59 | if ( aNameStr == NULL || aDescrStr == NULL || |
60 | aDensNameStr == NULL ||aDensTypeStr == NULL ) { |
61 | TCollection_ExtendedString aMessageString |
62 | ("Cannot retrieve Material attribute name or description"); |
63 | WriteMessage (aMessageString); |
64 | return Standard_False; |
65 | } |
66 | |
67 | Handle(TCollection_HAsciiString) aName = |
68 | new TCollection_HAsciiString( aNameStr.GetString() ); |
69 | Handle(TCollection_HAsciiString) aDescr = |
70 | new TCollection_HAsciiString( aDescrStr.GetString() ); |
71 | Handle(TCollection_HAsciiString) aDensName = |
72 | new TCollection_HAsciiString( aDensNameStr.GetString() ); |
73 | Handle(TCollection_HAsciiString) aDensType = |
74 | new TCollection_HAsciiString( aDensTypeStr.GetString() ); |
75 | |
76 | Handle(XCAFDoc_Material) anAtt = Handle(XCAFDoc_Material)::DownCast(theTarget); |
77 | anAtt->Set(aName, aDescr, aDensity, aDensName, aDensType); |
78 | |
79 | return Standard_True; |
80 | } |
81 | |
82 | //======================================================================= |
83 | //function : Paste |
84 | //purpose : transient -> persistent (store) |
85 | //======================================================================= |
86 | void XmlMXCAFDoc_MaterialDriver::Paste (const Handle(TDF_Attribute)& theSource, |
87 | XmlObjMgt_Persistent& theTarget, |
88 | XmlObjMgt_SRelocationTable& ) const |
89 | { |
90 | Handle(XCAFDoc_Material) anAtt = Handle(XCAFDoc_Material)::DownCast(theSource); |
91 | |
92 | XmlObjMgt_DOMString aNameString, aDescrString, aDensNameStr, aDensTypeStr; |
93 | if ( !anAtt->GetName().IsNull() ) |
94 | aNameString = anAtt->GetName()->String().ToCString(); |
95 | if ( !anAtt->GetDescription().IsNull() ) |
96 | aDescrString = anAtt->GetDescription()->String().ToCString(); |
97 | if ( !anAtt->GetDensName().IsNull() ) |
98 | aDensNameStr = anAtt->GetDensName()->String().ToCString(); |
99 | if ( !anAtt->GetDensValType().IsNull() ) |
100 | aDensTypeStr = anAtt->GetDensValType()->String().ToCString(); |
101 | |
102 | XmlObjMgt::SetStringValue (theTarget, anAtt->GetDensity()); |
103 | theTarget.Element().setAttribute(::NameIndexString(), aNameString); |
104 | theTarget.Element().setAttribute(::DescrIndexString(),aDescrString); |
105 | theTarget.Element().setAttribute(::DensNameIndexString(),aDensNameStr); |
106 | theTarget.Element().setAttribute(::DensTypeIndexString(),aDensTypeStr); |
107 | } |