0028314: Application Framework - Display mode is not saved within XML OCAF document
[occt.git] / src / XmlMDataXtd / XmlMDataXtd_PresentationDriver.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
f47afe53 16#include <XmlMDataXtd_PresentationDriver.hxx>
7fd59977 17
42cf5bc1 18#include <CDM_MessageDriver.hxx>
19#include <Standard_Type.hxx>
20#include <TDF_Attribute.hxx>
42cf5bc1 21#include <XmlObjMgt.hxx>
22#include <XmlObjMgt_Persistent.hxx>
7fd59977 23
f47afe53 24#include <TDataXtd_Presentation.hxx>
25
26IMPLEMENT_STANDARD_RTTIEXT(XmlMDataXtd_PresentationDriver,XmlMDF_ADriver)
27
7fd59977 28IMPLEMENT_DOMSTRING (GuidString, "guid")
29IMPLEMENT_DOMSTRING (IsDisplayedString, "isdisplayed")
30IMPLEMENT_DOMSTRING (ColorString, "color")
31IMPLEMENT_DOMSTRING (MaterialString, "material")
32IMPLEMENT_DOMSTRING (TransparencyString,"transparency")
33IMPLEMENT_DOMSTRING (WidthString, "width")
34IMPLEMENT_DOMSTRING (ModeString, "mode")
35
36IMPLEMENT_DOMSTRING (DisplayedString, "true")
37
38//=======================================================================
f47afe53 39//function : XmlMDataXtd_PresentationDriver
7fd59977 40//purpose : Constructor
41//=======================================================================
f47afe53 42XmlMDataXtd_PresentationDriver::XmlMDataXtd_PresentationDriver
43 (const Handle(CDM_MessageDriver)& theMsgDriver)
44 : XmlMDF_ADriver (theMsgDriver, NULL)
7fd59977 45{}
46
47//=======================================================================
48//function : NewEmpty
49//purpose :
50//=======================================================================
f47afe53 51Handle(TDF_Attribute) XmlMDataXtd_PresentationDriver::NewEmpty() const
7fd59977 52{
f47afe53 53 return (new TDataXtd_Presentation());
7fd59977 54}
55
56//=======================================================================
57//function : Paste
58//purpose : persistent -> transient (retrieve)
59//=======================================================================
f47afe53 60Standard_Boolean XmlMDataXtd_PresentationDriver::Paste
61 (const XmlObjMgt_Persistent& theSource,
62 const Handle(TDF_Attribute)& theTarget,
63 XmlObjMgt_RRelocationTable& ) const
7fd59977 64{
65 TCollection_ExtendedString aMessageString;
66 XmlObjMgt_DOMString aDOMStr;
67
f47afe53 68 Handle(TDataXtd_Presentation) aTPrs =
69 Handle(TDataXtd_Presentation)::DownCast(theTarget);
7fd59977 70 const XmlObjMgt_Element& anElem = theSource;
71
72 //convert attribute value into GUID
73 aDOMStr = anElem.getAttribute(::GuidString());
74 if (aDOMStr == NULL)
75 {
76 WriteMessage("Cannot retrieve guid string from attribute");
77 return Standard_False;
78 }
79 Standard_CString aGuidStr = (Standard_CString) aDOMStr.GetString();
80 aTPrs->SetDriverGUID(aGuidStr);
81
82 // is displayed
83 aDOMStr = anElem.getAttribute(::IsDisplayedString());
84 aTPrs->SetDisplayed(aDOMStr != NULL);
85
86 Standard_Integer anIValue;
87
88 // color
89 aDOMStr = anElem.getAttribute(::ColorString());
90 if (aDOMStr != NULL)
91 {
92 if (!aDOMStr.GetInteger(anIValue))
93 {
94 aMessageString = TCollection_ExtendedString
95 ("Cannot retrieve Integer value from \"") + aDOMStr + "\"";
96 WriteMessage (aMessageString);
97 return Standard_False;
98 }
99 aTPrs->SetColor((Quantity_NameOfColor)anIValue);
100 }
101 else
102 {
103 aTPrs->UnsetColor();
104 }
105
106 // material
107 aDOMStr = anElem.getAttribute(::MaterialString());
108 if (aDOMStr != NULL)
109 {
110 if (!aDOMStr.GetInteger(anIValue))
111 {
112 aMessageString = TCollection_ExtendedString
113 ("Cannot retrieve Integer value from \"") + aDOMStr + "\"";
114 WriteMessage (aMessageString);
115 return Standard_False;
116 }
f47afe53 117 aTPrs->SetMaterialIndex(anIValue);
7fd59977 118 }
119 else
120 {
121 aTPrs->UnsetMaterial();
122 }
123
124 Standard_Real aValue;
125
126 // transparency
127 aDOMStr = anElem.getAttribute(::TransparencyString());
128 if (aDOMStr != NULL)
129 {
130 if (!XmlObjMgt::GetReal(aDOMStr, aValue))
131 {
132 aMessageString = TCollection_ExtendedString
133 ("Cannot retrieve Real value from \"") + aDOMStr + "\"";
134 WriteMessage (aMessageString);
135 return Standard_False;
136 }
137 aTPrs->SetTransparency(aValue);
138 }
139 else
140 {
141 aTPrs->UnsetTransparency();
142 }
143
144 // width
145 aDOMStr = anElem.getAttribute(::WidthString());
146 if (aDOMStr != NULL)
147 {
148 if (!XmlObjMgt::GetReal(aDOMStr, aValue))
149 {
150 aMessageString = TCollection_ExtendedString
151 ("Cannot retrieve Real value from \"") + aDOMStr + "\"";
152 WriteMessage (aMessageString);
153 return Standard_False;
154 }
155 aTPrs->SetWidth(aValue);
156 }
157 else
158 {
159 aTPrs->UnsetWidth();
160 }
161
7fd59977 162 // mode
163 aDOMStr = anElem.getAttribute(::ModeString());
164 if (aDOMStr != NULL)
165 {
166 if (!aDOMStr.GetInteger(anIValue))
167 {
168 aMessageString = TCollection_ExtendedString
169 ("Cannot retrieve Integer value from \"") + aDOMStr + "\"";
170 WriteMessage (aMessageString);
171 return Standard_False;
172 }
173 aTPrs->SetMode(anIValue);
174 }
175 else
176 {
177 aTPrs->UnsetMode();
178 }
7fd59977 179
180 return Standard_True;
181}
182
183//=======================================================================
184//function : Paste
185//purpose : transient -> persistent (store)
186//=======================================================================
f47afe53 187void XmlMDataXtd_PresentationDriver::Paste
188 (const Handle(TDF_Attribute)& theSource,
189 XmlObjMgt_Persistent& theTarget,
190 XmlObjMgt_SRelocationTable&) const
7fd59977 191{
f47afe53 192 Handle(TDataXtd_Presentation) aTPrs =
193 Handle(TDataXtd_Presentation)::DownCast(theSource);
7fd59977 194 if (aTPrs.IsNull()) return;
195
196 //convert GUID into attribute value
197 Standard_Character aGuidStr [40];
198 Standard_PCharacter pGuidStr;
199 pGuidStr=aGuidStr;
200 aTPrs->GetDriverGUID().ToCString (pGuidStr);
201 theTarget.Element().setAttribute(::GuidString(), aGuidStr);
202
203 // is displayed
204 if (aTPrs->IsDisplayed())
205 theTarget.Element().setAttribute(::IsDisplayedString(), ::DisplayedString());
206
207 Standard_Integer aNb;
208
209 // color
210 if (aTPrs->HasOwnColor())
211 {
f47afe53 212 aNb = aTPrs->Color();
7fd59977 213 theTarget.Element().setAttribute(::ColorString(), aNb);
214 }
215
216 // material
217 if (aTPrs->HasOwnMaterial())
218 {
f47afe53 219 aNb = aTPrs->MaterialIndex();
7fd59977 220 theTarget.Element().setAttribute(::MaterialString(), aNb);
221 }
222
223 // transparency
224 if (aTPrs->HasOwnTransparency())
225 {
226 TCollection_AsciiString aRNbStr (aTPrs->Transparency());
227 theTarget.Element().setAttribute(::TransparencyString(), aRNbStr.ToCString());
228 }
229
230 // width
231 if (aTPrs->HasOwnWidth())
232 {
233 TCollection_AsciiString aRNbStr (aTPrs->Width());
234 theTarget.Element().setAttribute(::WidthString(), aRNbStr.ToCString());
235 }
236
7fd59977 237 // mode
238 if (aTPrs->HasOwnMode())
239 {
240 aNb = aTPrs->Mode();
241 theTarget.Element().setAttribute(::ModeString(), aNb);
242 }
7fd59977 243}