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.
16 #include <XmlMDataXtd_PresentationDriver.hxx>
18 #include <CDM_MessageDriver.hxx>
19 #include <Standard_Type.hxx>
20 #include <TDF_Attribute.hxx>
21 #include <XmlObjMgt.hxx>
22 #include <XmlObjMgt_Persistent.hxx>
24 #include <TDataXtd_Presentation.hxx>
26 IMPLEMENT_STANDARD_RTTIEXT(XmlMDataXtd_PresentationDriver,XmlMDF_ADriver)
28 IMPLEMENT_DOMSTRING (GuidString, "guid")
29 IMPLEMENT_DOMSTRING (IsDisplayedString, "isdisplayed")
30 IMPLEMENT_DOMSTRING (ColorString, "color")
31 IMPLEMENT_DOMSTRING (MaterialString, "material")
32 IMPLEMENT_DOMSTRING (TransparencyString,"transparency")
33 IMPLEMENT_DOMSTRING (WidthString, "width")
34 IMPLEMENT_DOMSTRING (ModeString, "mode")
36 IMPLEMENT_DOMSTRING (DisplayedString, "true")
38 //=======================================================================
39 //function : XmlMDataXtd_PresentationDriver
40 //purpose : Constructor
41 //=======================================================================
42 XmlMDataXtd_PresentationDriver::XmlMDataXtd_PresentationDriver
43 (const Handle(CDM_MessageDriver)& theMsgDriver)
44 : XmlMDF_ADriver (theMsgDriver, NULL)
47 //=======================================================================
50 //=======================================================================
51 Handle(TDF_Attribute) XmlMDataXtd_PresentationDriver::NewEmpty() const
53 return (new TDataXtd_Presentation());
56 //=======================================================================
58 //purpose : persistent -> transient (retrieve)
59 //=======================================================================
60 Standard_Boolean XmlMDataXtd_PresentationDriver::Paste
61 (const XmlObjMgt_Persistent& theSource,
62 const Handle(TDF_Attribute)& theTarget,
63 XmlObjMgt_RRelocationTable& ) const
65 TCollection_ExtendedString aMessageString;
66 XmlObjMgt_DOMString aDOMStr;
68 Handle(TDataXtd_Presentation) aTPrs =
69 Handle(TDataXtd_Presentation)::DownCast(theTarget);
70 const XmlObjMgt_Element& anElem = theSource;
72 //convert attribute value into GUID
73 aDOMStr = anElem.getAttribute(::GuidString());
76 WriteMessage("Cannot retrieve guid string from attribute");
77 return Standard_False;
79 Standard_CString aGuidStr = (Standard_CString) aDOMStr.GetString();
80 aTPrs->SetDriverGUID(aGuidStr);
83 aDOMStr = anElem.getAttribute(::IsDisplayedString());
84 aTPrs->SetDisplayed(aDOMStr != NULL);
86 Standard_Integer anIValue;
89 aDOMStr = anElem.getAttribute(::ColorString());
92 if (!aDOMStr.GetInteger(anIValue))
94 aMessageString = TCollection_ExtendedString
95 ("Cannot retrieve Integer value from \"") + aDOMStr + "\"";
96 WriteMessage (aMessageString);
97 return Standard_False;
99 aTPrs->SetColor((Quantity_NameOfColor)anIValue);
107 aDOMStr = anElem.getAttribute(::MaterialString());
110 if (!aDOMStr.GetInteger(anIValue))
112 aMessageString = TCollection_ExtendedString
113 ("Cannot retrieve Integer value from \"") + aDOMStr + "\"";
114 WriteMessage (aMessageString);
115 return Standard_False;
117 aTPrs->SetMaterialIndex(anIValue);
121 aTPrs->UnsetMaterial();
124 Standard_Real aValue;
127 aDOMStr = anElem.getAttribute(::TransparencyString());
130 if (!XmlObjMgt::GetReal(aDOMStr, aValue))
132 aMessageString = TCollection_ExtendedString
133 ("Cannot retrieve Real value from \"") + aDOMStr + "\"";
134 WriteMessage (aMessageString);
135 return Standard_False;
137 aTPrs->SetTransparency(aValue);
141 aTPrs->UnsetTransparency();
145 aDOMStr = anElem.getAttribute(::WidthString());
148 if (!XmlObjMgt::GetReal(aDOMStr, aValue))
150 aMessageString = TCollection_ExtendedString
151 ("Cannot retrieve Real value from \"") + aDOMStr + "\"";
152 WriteMessage (aMessageString);
153 return Standard_False;
155 aTPrs->SetWidth(aValue);
163 aDOMStr = anElem.getAttribute(::ModeString());
166 if (!aDOMStr.GetInteger(anIValue))
168 aMessageString = TCollection_ExtendedString
169 ("Cannot retrieve Integer value from \"") + aDOMStr + "\"";
170 WriteMessage (aMessageString);
171 return Standard_False;
173 aTPrs->SetMode(anIValue);
180 return Standard_True;
183 //=======================================================================
185 //purpose : transient -> persistent (store)
186 //=======================================================================
187 void XmlMDataXtd_PresentationDriver::Paste
188 (const Handle(TDF_Attribute)& theSource,
189 XmlObjMgt_Persistent& theTarget,
190 XmlObjMgt_SRelocationTable&) const
192 Handle(TDataXtd_Presentation) aTPrs =
193 Handle(TDataXtd_Presentation)::DownCast(theSource);
194 if (aTPrs.IsNull()) return;
196 //convert GUID into attribute value
197 Standard_Character aGuidStr [40];
198 Standard_PCharacter pGuidStr;
200 aTPrs->GetDriverGUID().ToCString (pGuidStr);
201 theTarget.Element().setAttribute(::GuidString(), aGuidStr);
204 if (aTPrs->IsDisplayed())
205 theTarget.Element().setAttribute(::IsDisplayedString(), ::DisplayedString());
207 Standard_Integer aNb;
210 if (aTPrs->HasOwnColor())
212 aNb = aTPrs->Color();
213 theTarget.Element().setAttribute(::ColorString(), aNb);
217 if (aTPrs->HasOwnMaterial())
219 aNb = aTPrs->MaterialIndex();
220 theTarget.Element().setAttribute(::MaterialString(), aNb);
224 if (aTPrs->HasOwnTransparency())
226 TCollection_AsciiString aRNbStr (aTPrs->Transparency());
227 theTarget.Element().setAttribute(::TransparencyString(), aRNbStr.ToCString());
231 if (aTPrs->HasOwnWidth())
233 TCollection_AsciiString aRNbStr (aTPrs->Width());
234 theTarget.Element().setAttribute(::WidthString(), aRNbStr.ToCString());
238 if (aTPrs->HasOwnMode())
241 theTarget.Element().setAttribute(::ModeString(), aNb);