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