b311480e |
1 | // Created on: 2007-07-03 |
2 | // Created by: Sergey ZARITCHNY |
973c2be1 |
3 | // Copyright (c) 2007-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 | |
42cf5bc1 |
16 | |
83ae3591 |
17 | #include <Message_Messenger.hxx> |
7fd59977 |
18 | #include <LDOM_MemManager.hxx> |
42cf5bc1 |
19 | #include <Standard_Type.hxx> |
7fd59977 |
20 | #include <TCollection_ExtendedString.hxx> |
42cf5bc1 |
21 | #include <TColStd_DataMapIteratorOfDataMapOfStringInteger.hxx> |
22 | #include <TColStd_DataMapOfStringInteger.hxx> |
7fd59977 |
23 | #include <TColStd_HArray1OfInteger.hxx> |
24 | #include <TColStd_HArray1OfReal.hxx> |
7fd59977 |
25 | #include <TDataStd_DataMapIteratorOfDataMapOfStringByte.hxx> |
26 | #include <TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfInteger.hxx> |
27 | #include <TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfReal.hxx> |
42cf5bc1 |
28 | #include <TDataStd_DataMapIteratorOfDataMapOfStringReal.hxx> |
29 | #include <TDataStd_DataMapIteratorOfDataMapOfStringString.hxx> |
30 | #include <TDataStd_DataMapOfStringByte.hxx> |
31 | #include <TDataStd_DataMapOfStringHArray1OfInteger.hxx> |
32 | #include <TDataStd_DataMapOfStringHArray1OfReal.hxx> |
33 | #include <TDataStd_DataMapOfStringReal.hxx> |
34 | #include <TDataStd_DataMapOfStringString.hxx> |
35 | #include <TDataStd_NamedData.hxx> |
36 | #include <TDF_Attribute.hxx> |
37 | #include <XmlMDataStd_NamedDataDriver.hxx> |
38 | #include <XmlObjMgt.hxx> |
39 | #include <XmlObjMgt_Document.hxx> |
40 | #include <XmlObjMgt_Persistent.hxx> |
41 | |
92efcf78 |
42 | IMPLEMENT_STANDARD_RTTIEXT(XmlMDataStd_NamedDataDriver,XmlMDF_ADriver) |
7fd59977 |
43 | IMPLEMENT_DOMSTRING (FirstIntegerIndex, "firstI") |
44 | IMPLEMENT_DOMSTRING (LastIntegerIndex, "lastI") |
45 | IMPLEMENT_DOMSTRING (FirstRealIndex, "firstR") |
46 | IMPLEMENT_DOMSTRING (LastRealIndex, "lastR") |
47 | IMPLEMENT_DOMSTRING (FirstStringIndex, "firstS") |
48 | IMPLEMENT_DOMSTRING (LastStringIndex, "lastS") |
49 | IMPLEMENT_DOMSTRING (FirstByteIndex, "firstB") |
50 | IMPLEMENT_DOMSTRING (LastByteIndex, "lastB") |
51 | IMPLEMENT_DOMSTRING (FirstIntArrIndex, "firstIA") |
52 | IMPLEMENT_DOMSTRING (LastIntArrIndex, "lastIA") |
53 | IMPLEMENT_DOMSTRING (FirstRealArrIndex, "firstRA") |
54 | IMPLEMENT_DOMSTRING (LastRealArrIndex, "lastRA") |
55 | |
56 | IMPLEMENT_DOMSTRING (ExtString, "string") |
57 | IMPLEMENT_DOMSTRING (Value, "value") |
58 | |
57c28b61 |
59 | #ifdef _WIN32 |
7fd59977 |
60 | #define EXCEPTION ... |
61 | #else |
a738b534 |
62 | #define EXCEPTION Standard_Failure const& |
7fd59977 |
63 | #endif |
64 | //======================================================================= |
65 | //function : XmlMDataStd_NamedDataDriver |
66 | //purpose : Constructor |
67 | //======================================================================= |
83ae3591 |
68 | XmlMDataStd_NamedDataDriver::XmlMDataStd_NamedDataDriver(const Handle(Message_Messenger)& theMsgDriver) |
7fd59977 |
69 | : XmlMDF_ADriver (theMsgDriver, NULL) |
70 | { |
71 | |
72 | } |
73 | |
74 | //======================================================================= |
75 | //function : NewEmpty |
76 | //purpose : |
77 | //======================================================================= |
78 | Handle(TDF_Attribute) XmlMDataStd_NamedDataDriver::NewEmpty() const |
79 | { |
80 | return new TDataStd_NamedData(); |
81 | } |
82 | |
83 | //======================================================================= |
84 | static TCollection_ExtendedString SplitItemFromEnd(TCollection_ExtendedString& Key) |
85 | { |
86 | TCollection_ExtendedString aValue; |
87 | const Standard_Integer aPos = Key. SearchFromEnd (" "); |
88 | if(aPos == -1) return aValue; |
89 | aValue = Key.Split(aPos-1); |
90 | aValue.Remove(1,1); |
91 | return aValue; |
92 | } |
93 | //======================================================================= |
94 | static TCollection_ExtendedString SplitItemFromStart(TCollection_ExtendedString& Key) |
95 | { |
96 | TCollection_ExtendedString aValue; |
97 | const Standard_Integer aPos = Key. Search (" "); |
98 | if(aPos == -1) return aValue; |
99 | aValue = Key.Split(aPos); |
100 | Key.Remove(Key.Length(),1); |
101 | return aValue; |
102 | } |
103 | //======================================================================= |
104 | Handle(TColStd_HArray1OfInteger) BuildIntArray(const TCollection_AsciiString& ValString, |
83ae3591 |
105 | const Standard_Integer theLen) |
7fd59977 |
106 | { |
107 | Handle(TColStd_HArray1OfInteger) anArr; |
108 | if(ValString.Length() == 0 || !theLen) return anArr; |
109 | anArr = new TColStd_HArray1OfInteger (1, theLen, 0); |
110 | for(Standard_Integer i = 1;i <= theLen;i++) { |
111 | const TCollection_AsciiString& aSVal = ValString.Token(" ",i); |
112 | if(aSVal.Length()) |
113 | anArr->SetValue(i, aSVal.IntegerValue()); |
114 | } |
115 | return anArr; |
116 | } |
117 | |
118 | //======================================================================= |
119 | Handle(TColStd_HArray1OfReal) BuildRealArray(const TCollection_AsciiString& ValString, |
83ae3591 |
120 | const Standard_Integer theLen) |
7fd59977 |
121 | { |
122 | Handle(TColStd_HArray1OfReal) anArr; |
123 | if(ValString.Length() == 0 || !theLen) return anArr; |
124 | anArr = new TColStd_HArray1OfReal (1, theLen, .0); |
125 | for(Standard_Integer i = 1;i <= theLen;i++) { |
126 | const TCollection_AsciiString& aSVal = ValString.Token(" ",i); |
127 | if(aSVal.Length()) |
128 | anArr->SetValue(i, aSVal.RealValue()); |
129 | } |
130 | return anArr; |
131 | } |
132 | //======================================================================= |
133 | //function : Paste |
134 | //purpose : persistent -> transient (retrieve) |
135 | //======================================================================= |
136 | Standard_Boolean XmlMDataStd_NamedDataDriver::Paste(const XmlObjMgt_Persistent& theSource, |
83ae3591 |
137 | const Handle(TDF_Attribute)& theTarget, |
138 | XmlObjMgt_RRelocationTable& ) const |
7fd59977 |
139 | { |
6e6cd5d9 |
140 | Standard_Integer aFirstInd, aLastInd, ind; |
7fd59977 |
141 | const XmlObjMgt_Element& anElement = theSource; |
142 | |
143 | //DataMapOfStringInteger: Read the FirstIndex; if the attribute is absent initialize to 1 |
144 | XmlObjMgt_DOMString aFirstIndex = anElement.getAttribute(::FirstIntegerIndex()); |
145 | if (aFirstIndex == NULL) |
146 | aFirstInd = 1; |
147 | else if (!aFirstIndex.GetInteger(aFirstInd)) |
148 | { |
149 | TCollection_ExtendedString aMessageString = |
150 | TCollection_ExtendedString("Cannot retrieve the first index for NamedData" |
151 | " attribute (DataMapOfStringInteger) as \"") |
152 | + aFirstIndex + "\""; |
83ae3591 |
153 | myMessageDriver->Send (aMessageString, Message_Fail); |
7fd59977 |
154 | return Standard_False; |
155 | } |
156 | |
157 | // Read the LastIndex; |
158 | XmlObjMgt_DOMString aLastIndex = anElement.getAttribute(::LastIntegerIndex()); |
159 | if(aLastIndex == NULL) { |
160 | aFirstInd = 0; |
161 | aLastInd = 0; |
162 | } else if (!aLastIndex.GetInteger(aLastInd)) { |
163 | TCollection_ExtendedString aMessageString = |
164 | TCollection_ExtendedString("Cannot retrieve the last index for NamedData" |
165 | " attribute (DataMapOfStringInteger) as \"") |
166 | + aLastIndex + "\""; |
83ae3591 |
167 | myMessageDriver->Send (aMessageString, Message_Fail); |
7fd59977 |
168 | return Standard_False; |
169 | } |
170 | try { |
171 | Handle(TDataStd_NamedData) T = Handle(TDataStd_NamedData)::DownCast(theTarget); |
172 | LDOM_Node aCurNode; |
173 | |
174 | if((aFirstInd | aLastInd) && aLastInd >= aFirstInd) { |
175 | if ( !anElement.hasChildNodes() ) |
83ae3591 |
176 | { |
177 | TCollection_ExtendedString aMessageString = |
178 | TCollection_ExtendedString("Cannot retrieve DataMapOfStringInteger"); |
179 | myMessageDriver->Send (aMessageString, Message_Fail); |
180 | return Standard_False; |
181 | } |
7fd59977 |
182 | aCurNode = anElement.getFirstChild(); |
183 | LDOM_Element* aCurElement = (LDOM_Element*)&aCurNode; |
184 | TCollection_ExtendedString aValueStr, aKey; |
185 | TColStd_DataMapOfStringInteger aMap; |
186 | for (ind = aFirstInd; ind < aLastInd; ind++) { |
83ae3591 |
187 | XmlObjMgt::GetExtendedString( *aCurElement, aKey ); |
188 | aValueStr = SplitItemFromEnd(aKey); |
189 | if(aValueStr.Length() == 0) { |
190 | TCollection_ExtendedString aMessageString = |
191 | TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey; |
192 | myMessageDriver->Send (aMessageString, Message_Fail); |
193 | return Standard_False; |
194 | } |
195 | TCollection_AsciiString aVal(aValueStr,'?'); |
196 | Standard_Integer aValue = aVal.IntegerValue(); |
197 | aMap.Bind(aKey, aValue); |
198 | aCurNode = aCurElement->getNextSibling(); |
199 | aCurElement = (LDOM_Element*)&aCurNode; |
7fd59977 |
200 | } |
201 | XmlObjMgt::GetExtendedString( *aCurElement, aKey ); |
202 | aValueStr = SplitItemFromEnd(aKey); |
203 | if(aValueStr.Length() == 0) { |
83ae3591 |
204 | TCollection_ExtendedString aMessageString = |
205 | TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey; |
206 | myMessageDriver->Send (aMessageString, Message_Fail); |
207 | return Standard_False; |
7fd59977 |
208 | } |
209 | TCollection_AsciiString aVal(aValueStr,'?'); |
210 | Standard_Integer aValue = aVal.IntegerValue(); |
211 | aMap.Bind(aKey, aValue); |
212 | T->ChangeIntegers(aMap); |
213 | } |
214 | |
83ae3591 |
215 | //DataMapOfStringReal |
7fd59977 |
216 | aFirstIndex = anElement.getAttribute(::FirstRealIndex()); |
217 | if (aFirstIndex == NULL) |
218 | aFirstInd = 1; |
219 | else if (!aFirstIndex.GetInteger(aFirstInd)) |
83ae3591 |
220 | { |
221 | TCollection_ExtendedString aMessageString = |
222 | TCollection_ExtendedString("Cannot retrieve the first index for NamedData " |
223 | "attribute (DataMapOfStringReal) as \"") |
224 | + aFirstIndex + "\""; |
225 | myMessageDriver->Send (aMessageString, Message_Fail); |
226 | return Standard_False; |
227 | } |
7fd59977 |
228 | |
83ae3591 |
229 | // Read the LastIndex; |
7fd59977 |
230 | aLastIndex = anElement.getAttribute(::LastRealIndex()); |
231 | if(aLastIndex == NULL) { |
232 | aFirstInd = 0; |
233 | aLastInd = 0; |
234 | } else if (!aLastIndex.GetInteger(aLastInd)) { |
235 | TCollection_ExtendedString aMessageString = |
83ae3591 |
236 | TCollection_ExtendedString("Cannot retrieve the last index for NamedData" |
237 | " attribute (DataMapOfStringReal) as \"") |
238 | + aLastIndex + "\""; |
239 | myMessageDriver->Send (aMessageString, Message_Fail); |
7fd59977 |
240 | return Standard_False; |
241 | } |
242 | |
243 | if((aFirstInd | aLastInd) && aLastInd >= aFirstInd) { |
244 | if ( !anElement.hasChildNodes()) |
83ae3591 |
245 | { |
246 | TCollection_ExtendedString aMessageString = |
247 | TCollection_ExtendedString("Cannot retrieve DataMapOfStringReal"); |
248 | myMessageDriver->Send (aMessageString, Message_Fail); |
249 | return Standard_False; |
250 | } |
251 | |
56fabb31 |
252 | LDOM_Element* aCurElement; |
7fd59977 |
253 | if (aCurNode.isNull()) |
83ae3591 |
254 | aCurNode = anElement.getFirstChild(); |
56fabb31 |
255 | else |
256 | aCurNode = ((LDOM_Element*)&aCurNode)->getNextSibling(); |
83ae3591 |
257 | |
7fd59977 |
258 | aCurElement = (LDOM_Element*)&aCurNode; |
259 | TCollection_ExtendedString aValueStr, aKey; |
260 | TDataStd_DataMapOfStringReal aMap; |
261 | for (ind = aFirstInd; ind < aLastInd; ind++) { |
83ae3591 |
262 | XmlObjMgt::GetExtendedString( *aCurElement, aKey ); |
263 | aValueStr = SplitItemFromEnd(aKey); |
264 | if(aValueStr.Length() == 0) { |
265 | TCollection_ExtendedString aMessageString = |
266 | TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey; |
267 | myMessageDriver->Send (aMessageString, Message_Fail); |
268 | return Standard_False; |
269 | } |
270 | TCollection_AsciiString aVal(aValueStr,'?'); |
271 | Standard_Real aValue = aVal.RealValue(); |
272 | aMap.Bind(aKey, aValue); |
273 | aCurNode = aCurElement->getNextSibling(); |
274 | aCurElement = (LDOM_Element*)&aCurNode; |
7fd59977 |
275 | } |
276 | XmlObjMgt::GetExtendedString( *aCurElement, aKey ); |
277 | aValueStr = SplitItemFromEnd(aKey); |
278 | if(aValueStr.Length() == 0) { |
83ae3591 |
279 | TCollection_ExtendedString aMessageString = |
280 | TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey; |
281 | myMessageDriver->Send (aMessageString, Message_Fail); |
282 | return Standard_False; |
7fd59977 |
283 | } |
284 | TCollection_AsciiString aVal(aValueStr,'?'); |
285 | Standard_Real aValue = aVal.RealValue(); |
286 | aMap.Bind(aKey, aValue); |
287 | T->ChangeReals(aMap); |
288 | } |
289 | |
290 | //DataMapOfStringString |
291 | aFirstIndex = anElement.getAttribute(::FirstStringIndex()); |
292 | if (aFirstIndex == NULL) |
293 | aFirstInd = 1; |
294 | else if (!aFirstIndex.GetInteger(aFirstInd)) |
83ae3591 |
295 | { |
296 | TCollection_ExtendedString aMessageString = |
297 | TCollection_ExtendedString("Cannot retrieve the first index for NamedData" |
298 | " attribute (DataMapOfStringString) as \"") |
299 | + aFirstIndex + "\""; |
300 | myMessageDriver->Send (aMessageString, Message_Fail); |
301 | return Standard_False; |
302 | } |
7fd59977 |
303 | aLastIndex = anElement.getAttribute(::LastStringIndex()); |
304 | if(aLastIndex == NULL) { |
305 | aFirstInd = 0; |
306 | aLastInd = 0; |
307 | } else if (!aLastIndex.GetInteger(aLastInd)) { |
308 | TCollection_ExtendedString aMessageString = |
83ae3591 |
309 | TCollection_ExtendedString("Cannot retrieve the last index for NamedData" |
310 | " attribute (DataMapOfStringString) as \"") |
311 | + aLastIndex + "\""; |
312 | myMessageDriver->Send (aMessageString, Message_Fail); |
7fd59977 |
313 | return Standard_False; |
314 | } |
83ae3591 |
315 | |
7fd59977 |
316 | if((aFirstInd | aLastInd) && aLastInd >= aFirstInd) { |
317 | if ( !anElement.hasChildNodes()) |
83ae3591 |
318 | { |
319 | TCollection_ExtendedString aMessageString = |
320 | TCollection_ExtendedString("Cannot retrieve DataMapOfStringString"); |
321 | myMessageDriver->Send (aMessageString, Message_Fail); |
322 | return Standard_False; |
323 | } |
7fd59977 |
324 | LDOM_Element* aCurElement; |
325 | if (aCurNode.isNull()) |
83ae3591 |
326 | aCurNode = anElement.getFirstChild(); |
7fd59977 |
327 | else |
83ae3591 |
328 | aCurNode = ((LDOM_Element*)&aCurNode)->getNextSibling(); |
329 | |
7fd59977 |
330 | aCurElement = (LDOM_Element*)&aCurNode; |
331 | TCollection_ExtendedString aValue, aKey; |
332 | TDataStd_DataMapOfStringString aMap; |
333 | for (ind = aFirstInd; ind < aLastInd; ind++) { |
83ae3591 |
334 | XmlObjMgt::GetExtendedString( *aCurElement, aKey ); |
335 | aValue = SplitItemFromStart(aKey); // ==>from start |
336 | if(aValue.Length() == 0) { |
337 | TCollection_ExtendedString aMessageString = |
338 | TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey; |
339 | myMessageDriver->Send (aMessageString, Message_Fail); |
340 | return Standard_False; |
341 | } |
342 | aMap.Bind(aKey, aValue); |
343 | aCurNode = aCurElement->getNextSibling(); |
344 | aCurElement = (LDOM_Element*)&aCurNode; |
7fd59977 |
345 | } |
346 | XmlObjMgt::GetExtendedString( *aCurElement, aKey ); |
347 | aValue = SplitItemFromStart(aKey); |
348 | if(aValue.Length() == 0) { |
83ae3591 |
349 | TCollection_ExtendedString aMessageString = |
350 | TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey; |
351 | myMessageDriver->Send (aMessageString, Message_Fail); |
352 | return Standard_False; |
7fd59977 |
353 | } |
83ae3591 |
354 | |
7fd59977 |
355 | aMap.Bind(aKey, aValue); |
356 | T->ChangeStrings(aMap); |
357 | } |
358 | |
359 | //DataMapOfStringByte |
360 | aFirstIndex = anElement.getAttribute(::FirstByteIndex()); |
361 | if (aFirstIndex == NULL) |
362 | aFirstInd = 1; |
363 | else if (!aFirstIndex.GetInteger(aFirstInd)) |
83ae3591 |
364 | { |
365 | TCollection_ExtendedString aMessageString = |
366 | TCollection_ExtendedString("Cannot retrieve the first index for NamedData " |
367 | "attribute (DataMapOfStringByte) as \"") |
368 | + aFirstIndex + "\""; |
369 | myMessageDriver->Send (aMessageString, Message_Fail); |
370 | return Standard_False; |
371 | } |
7fd59977 |
372 | |
83ae3591 |
373 | // Read the LastIndex; |
7fd59977 |
374 | aLastIndex = anElement.getAttribute(::LastByteIndex()); |
375 | if(aLastIndex == NULL) { |
376 | aFirstInd = 0; |
377 | aLastInd = 0; |
378 | } else if (!aLastIndex.GetInteger(aLastInd)) { |
379 | TCollection_ExtendedString aMessageString = |
83ae3591 |
380 | TCollection_ExtendedString("Cannot retrieve the last index for NamedData" |
381 | " attribute (DataMapOfStringByte) as \"") |
382 | + aLastIndex + "\""; |
383 | myMessageDriver->Send (aMessageString, Message_Fail); |
7fd59977 |
384 | return Standard_False; |
385 | } |
83ae3591 |
386 | |
7fd59977 |
387 | if((aFirstInd | aLastInd) && aLastInd >= aFirstInd) { |
388 | if ( !anElement.hasChildNodes()) |
83ae3591 |
389 | { |
390 | TCollection_ExtendedString aMessageString = |
391 | TCollection_ExtendedString("Cannot retrieve DataMapOfStringByte"); |
392 | myMessageDriver->Send (aMessageString, Message_Fail); |
393 | return Standard_False; |
394 | } |
395 | |
7fd59977 |
396 | LDOM_Element* aCurElement; |
397 | if (aCurNode.isNull()) |
83ae3591 |
398 | aCurNode = anElement.getFirstChild(); |
7fd59977 |
399 | else |
83ae3591 |
400 | aCurNode = ((LDOM_Element*)&aCurNode)->getNextSibling(); |
401 | |
7fd59977 |
402 | aCurElement = (LDOM_Element*)&aCurNode; |
403 | TCollection_ExtendedString aValueStr, aKey; |
404 | TDataStd_DataMapOfStringByte aMap; |
405 | for (ind = aFirstInd; ind < aLastInd; ind++) { |
83ae3591 |
406 | XmlObjMgt::GetExtendedString( *aCurElement, aKey ); |
407 | aValueStr = SplitItemFromEnd(aKey); |
408 | if(aValueStr.Length() == 0) { |
409 | TCollection_ExtendedString aMessageString = |
410 | TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey; |
411 | myMessageDriver->Send (aMessageString, Message_Fail); |
412 | return Standard_False; |
413 | } |
414 | |
415 | TCollection_AsciiString aVal(aValueStr,'?'); |
416 | Standard_Byte aValue = (Standard_Byte)aVal.IntegerValue(); |
417 | |
418 | aMap.Bind(aKey, aValue); |
419 | aCurNode = aCurElement->getNextSibling(); |
420 | aCurElement = (LDOM_Element*)&aCurNode; |
7fd59977 |
421 | } |
422 | XmlObjMgt::GetExtendedString( *aCurElement, aKey ); |
423 | aValueStr = SplitItemFromEnd(aKey); |
424 | if(aValueStr.Length() == 0) { |
83ae3591 |
425 | TCollection_ExtendedString aMessageString = |
426 | TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey; |
427 | myMessageDriver->Send (aMessageString, Message_Fail); |
428 | return Standard_False; |
7fd59977 |
429 | } |
83ae3591 |
430 | |
7fd59977 |
431 | TCollection_AsciiString aVal(aValueStr,'?'); |
432 | Standard_Byte aValue = (Standard_Byte)aVal.IntegerValue(); |
433 | aMap.Bind(aKey, aValue); |
434 | T->ChangeBytes(aMap); |
435 | } |
436 | |
437 | //DataMapOfStringHArray1OfInteger |
438 | aFirstIndex = anElement.getAttribute(::FirstIntArrIndex()); |
439 | if (aFirstIndex == NULL) |
440 | aFirstInd = 1; |
441 | else if (!aFirstIndex.GetInteger(aFirstInd)) |
83ae3591 |
442 | { |
443 | TCollection_ExtendedString aMessageString = |
444 | TCollection_ExtendedString("Cannot retrieve the first index for NamedData " |
445 | "attribute (DataMapOfStringHArray1OfInteger) as \"") |
446 | + aFirstIndex + "\""; |
447 | myMessageDriver->Send (aMessageString, Message_Fail); |
448 | return Standard_False; |
449 | } |
7fd59977 |
450 | |
451 | // Read the LastIndex; |
452 | aLastIndex = anElement.getAttribute(::LastIntArrIndex()); |
453 | if(aLastIndex == NULL) { |
454 | aFirstInd = 0; |
455 | aLastInd = 0; |
456 | } else if (!aLastIndex.GetInteger(aLastInd)) { |
457 | TCollection_ExtendedString aMessageString = |
83ae3591 |
458 | TCollection_ExtendedString("Cannot retrieve the last index for NamedData" |
459 | " attribute (DataMapOfStringHArray1OfInteger) as \"") |
460 | + aLastIndex + "\""; |
461 | myMessageDriver->Send (aMessageString, Message_Fail); |
7fd59977 |
462 | return Standard_False; |
463 | } |
83ae3591 |
464 | |
7fd59977 |
465 | if((aFirstInd | aLastInd) && aLastInd >= aFirstInd) { |
466 | if ( !anElement.hasChildNodes()) |
83ae3591 |
467 | { |
468 | TCollection_ExtendedString aMessageString = |
469 | TCollection_ExtendedString("Cannot retrieve DataMapOfStringHArray1OfInteger"); |
470 | myMessageDriver->Send (aMessageString, Message_Fail); |
471 | return Standard_False; |
472 | } |
7fd59977 |
473 | LDOM_Element* aCurElement; |
474 | if (aCurNode.isNull()) |
83ae3591 |
475 | aCurNode = anElement.getFirstChild(); |
7fd59977 |
476 | else |
83ae3591 |
477 | aCurNode =((LDOM_Element*)&aCurNode)->getNextSibling(); |
478 | |
7fd59977 |
479 | aCurElement = (LDOM_Element*)&aCurNode; |
480 | TCollection_ExtendedString aKey, aValueStr; |
481 | TDataStd_DataMapOfStringHArray1OfInteger aMap; |
83ae3591 |
482 | |
7fd59977 |
483 | for (ind = aFirstInd; ind < aLastInd; ind++) { |
83ae3591 |
484 | XmlObjMgt::GetExtendedString( *aCurElement, aKey );// Len - at the end |
485 | aValueStr = SplitItemFromEnd(aKey); |
486 | if(aValueStr.Length() == 0) { |
487 | TCollection_ExtendedString aMessageString = |
488 | TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey; |
489 | myMessageDriver->Send (aMessageString, Message_Fail); |
490 | return Standard_False; |
491 | } |
492 | TCollection_AsciiString aVal(aValueStr,'?'); |
493 | Standard_Integer aLen = aVal.IntegerValue(); |
494 | |
495 | TCollection_AsciiString aValueString = aCurElement->getAttribute(::Value()); |
496 | Handle(TColStd_HArray1OfInteger) aValue = BuildIntArray(aValueString, aLen); |
497 | if(aValue.IsNull()) { |
498 | TCollection_ExtendedString aMessageString = |
499 | TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey; |
500 | myMessageDriver->Send (aMessageString, Message_Fail); |
501 | return Standard_False; |
502 | } |
503 | |
504 | aMap.Bind(aKey, aValue); |
505 | aCurNode = aCurElement->getNextSibling(); |
506 | aCurElement = (LDOM_Element*)&aCurNode; |
7fd59977 |
507 | } |
83ae3591 |
508 | |
7fd59977 |
509 | XmlObjMgt::GetExtendedString( *aCurElement, aKey ); |
510 | aValueStr = SplitItemFromEnd(aKey); |
511 | if(aValueStr.Length() == 0) { |
83ae3591 |
512 | TCollection_ExtendedString aMessageString = |
513 | TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey; |
514 | myMessageDriver->Send (aMessageString, Message_Fail); |
515 | return Standard_False; |
7fd59977 |
516 | } |
517 | TCollection_AsciiString aVal(aValueStr,'?'); |
518 | Standard_Integer aLen = aVal.IntegerValue(); |
7fd59977 |
519 | TCollection_AsciiString aValueString = aCurElement->getAttribute(::Value()); |
520 | Handle(TColStd_HArray1OfInteger) aValue = BuildIntArray(aValueString, aLen); |
521 | if(aValue.IsNull()) { |
83ae3591 |
522 | TCollection_ExtendedString aMessageString = |
523 | TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey; |
524 | myMessageDriver->Send (aMessageString, Message_Fail); |
525 | return Standard_False; |
7fd59977 |
526 | } |
527 | aMap.Bind(aKey, aValue); |
528 | T->ChangeArraysOfIntegers(aMap); |
529 | } |
530 | |
531 | //DataMapOfStringHArray1OfReal |
532 | aFirstIndex = anElement.getAttribute(::FirstRealArrIndex()); |
533 | if (aFirstIndex == NULL) |
534 | aFirstInd = 1; |
535 | else if (!aFirstIndex.GetInteger(aFirstInd)) |
83ae3591 |
536 | { |
537 | TCollection_ExtendedString aMessageString = |
538 | TCollection_ExtendedString("Cannot retrieve the first index for NamedData " |
539 | "attribute (DataMapOfStringHArray1OfReal) as \"") |
540 | + aFirstIndex + "\""; |
541 | myMessageDriver->Send (aMessageString, Message_Fail); |
542 | return Standard_False; |
543 | } |
544 | |
545 | // Read the LastIndex; |
7fd59977 |
546 | aLastIndex = anElement.getAttribute(::LastRealArrIndex()); |
547 | if(aLastIndex == NULL) { |
548 | aFirstInd = 0; |
549 | aLastInd = 0; |
550 | } else if (!aLastIndex.GetInteger(aLastInd)) { |
551 | TCollection_ExtendedString aMessageString = |
83ae3591 |
552 | TCollection_ExtendedString("Cannot retrieve the last index for NamedData" |
553 | " attribute (DataMapOfStringHArray1OfReal) as \"") |
554 | + aLastIndex + "\""; |
555 | myMessageDriver->Send (aMessageString, Message_Fail); |
7fd59977 |
556 | return Standard_False; |
557 | } |
83ae3591 |
558 | |
7fd59977 |
559 | if((aFirstInd | aLastInd) && aLastInd >= aFirstInd) { |
560 | if ( !anElement.hasChildNodes()) |
83ae3591 |
561 | { |
562 | TCollection_ExtendedString aMessageString = |
563 | TCollection_ExtendedString("Cannot retrieve DataMapOfStringHArray1OfReal"); |
564 | myMessageDriver->Send (aMessageString, Message_Fail); |
565 | return Standard_False; |
566 | } |
567 | |
7fd59977 |
568 | LDOM_Element* aCurElement; |
569 | if (aCurNode.isNull()) |
83ae3591 |
570 | aCurNode = anElement.getFirstChild(); |
7fd59977 |
571 | else |
83ae3591 |
572 | aCurNode =((LDOM_Element*)&aCurNode)->getNextSibling(); |
573 | |
7fd59977 |
574 | aCurElement = (LDOM_Element*)&aCurNode; |
575 | TCollection_ExtendedString aKey, aValueStr; |
576 | TDataStd_DataMapOfStringHArray1OfReal aMap; |
83ae3591 |
577 | |
7fd59977 |
578 | for (ind = aFirstInd; ind < aLastInd; ind++) { |
83ae3591 |
579 | XmlObjMgt::GetExtendedString( *aCurElement, aKey );// Len - at the end |
580 | aValueStr = SplitItemFromEnd(aKey); |
581 | if(aValueStr.Length() == 0) { |
582 | TCollection_ExtendedString aMessageString = |
583 | TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey; |
584 | myMessageDriver->Send (aMessageString, Message_Fail); |
585 | return Standard_False; |
586 | } |
587 | TCollection_AsciiString aVal(aValueStr,'?'); |
588 | Standard_Integer aLen = aVal.IntegerValue(); |
589 | |
590 | TCollection_AsciiString aValueString = aCurElement->getAttribute(::Value()); |
591 | Handle(TColStd_HArray1OfReal) aValue = BuildRealArray(aValueString, aLen); |
592 | if(aValue.IsNull()) { |
593 | TCollection_ExtendedString aMessageString = |
594 | TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey; |
595 | myMessageDriver->Send (aMessageString, Message_Fail); |
596 | return Standard_False; |
597 | } |
598 | |
599 | aMap.Bind(aKey, aValue); |
600 | aCurNode = aCurElement->getNextSibling(); |
601 | aCurElement = (LDOM_Element*)&aCurNode; |
7fd59977 |
602 | } |
83ae3591 |
603 | |
7fd59977 |
604 | XmlObjMgt::GetExtendedString( *aCurElement, aKey ); |
605 | aValueStr = SplitItemFromEnd(aKey); |
606 | if(aValueStr.Length() == 0) { |
83ae3591 |
607 | TCollection_ExtendedString aMessageString = |
608 | TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey; |
609 | myMessageDriver->Send (aMessageString, Message_Fail); |
610 | return Standard_False; |
7fd59977 |
611 | } |
612 | TCollection_AsciiString aVal(aValueStr,'?'); |
613 | Standard_Integer aLen = aVal.IntegerValue(); |
83ae3591 |
614 | |
7fd59977 |
615 | TCollection_AsciiString aValueString = aCurElement->getAttribute(::Value()); |
616 | Handle(TColStd_HArray1OfReal) aValue = BuildRealArray(aValueString, aLen); |
617 | if(aValue.IsNull()) { |
83ae3591 |
618 | TCollection_ExtendedString aMessageString = |
619 | TCollection_ExtendedString("Cannot retrieve a value from item = ") + aKey; |
620 | myMessageDriver->Send (aMessageString, Message_Fail); |
621 | return Standard_False; |
7fd59977 |
622 | } |
83ae3591 |
623 | |
7fd59977 |
624 | aMap.Bind(aKey, aValue); |
83ae3591 |
625 | T->ChangeArraysOfReals(aMap); |
7fd59977 |
626 | } |
627 | } catch (EXCEPTION) { |
628 | TCollection_ExtendedString aMessageString = |
629 | TCollection_ExtendedString("Unknown exception during data retrieve in NamedDatDriver "); |
83ae3591 |
630 | myMessageDriver->Send (aMessageString, Message_Fail); |
631 | return Standard_False;} |
632 | |
633 | return Standard_True; |
7fd59977 |
634 | } |
635 | |
636 | //======================================================================= |
637 | //function : Paste |
638 | //purpose : transient -> persistent (store) |
639 | //======================================================================= |
640 | void XmlMDataStd_NamedDataDriver::Paste(const Handle(TDF_Attribute)& theSource, |
83ae3591 |
641 | XmlObjMgt_Persistent& theTarget, |
642 | XmlObjMgt_SRelocationTable& ) const |
7fd59977 |
643 | { |
644 | Handle(TDataStd_NamedData) S = Handle(TDataStd_NamedData)::DownCast(theSource); |
645 | if(S.IsNull()) { |
83ae3591 |
646 | myMessageDriver->Send ("NamedDataDriver:: The source attribute is Null.", Message_Warning); |
7fd59977 |
647 | return;} |
648 | |
649 | Standard_Integer i=0, up; |
650 | XmlObjMgt_Element& anElement = theTarget; |
e8862cf4 |
651 | XmlObjMgt_Document aDoc (anElement.getOwnerDocument()); |
7fd59977 |
652 | if(S->HasIntegers() && !S->GetIntegersContainer().IsEmpty()) { |
653 | // store a set of elements with string in each of them |
654 | up = S->GetIntegersContainer().Extent(); |
655 | theTarget.Element().setAttribute(::LastIntegerIndex(), up); |
656 | |
657 | TColStd_DataMapIteratorOfDataMapOfStringInteger itr(S->GetIntegersContainer()); |
658 | for (i=1; itr.More(); itr.Next(),i++) { |
659 | const TCollection_ExtendedString aValueStr = |
83ae3591 |
660 | itr.Key() + ' ' + TCollection_ExtendedString(itr.Value());// key - value; |
7fd59977 |
661 | XmlObjMgt_Element aCurTarget = aDoc.createElement( ::ExtString() ); |
662 | XmlObjMgt::SetExtendedString( aCurTarget, aValueStr ); |
663 | anElement.appendChild( aCurTarget ); |
664 | } |
665 | } |
666 | |
667 | if(S->HasReals() && !S->GetRealsContainer().IsEmpty()) { |
668 | up = S->GetRealsContainer().Extent(); |
669 | theTarget.Element().setAttribute(::LastRealIndex(), up); |
670 | TDataStd_DataMapIteratorOfDataMapOfStringReal itr(S->GetRealsContainer()); |
671 | for (i=1; itr.More(); itr.Next(),i++) { |
83ae3591 |
672 | const TCollection_ExtendedString aValueStr = |
673 | itr.Key() + ' ' + TCollection_ExtendedString(itr.Value());// key - value; |
674 | XmlObjMgt_Element aCurTarget = aDoc.createElement( ::ExtString() ); |
675 | XmlObjMgt::SetExtendedString( aCurTarget, aValueStr ); |
676 | anElement.appendChild( aCurTarget ); |
7fd59977 |
677 | } |
678 | } |
679 | |
680 | if(S->HasStrings() && !S->GetStringsContainer().IsEmpty()) { |
681 | up = S->GetStringsContainer().Extent(); |
682 | theTarget.Element().setAttribute(::LastStringIndex(), up); |
683 | TDataStd_DataMapIteratorOfDataMapOfStringString itr(S->GetStringsContainer()); |
684 | for (i=1; itr.More(); itr.Next(),i++) { |
685 | const TCollection_ExtendedString aValueStr = |
83ae3591 |
686 | itr.Key() + ' ' + TCollection_ExtendedString(itr.Value());// key(without blanks) - value; |
7fd59977 |
687 | XmlObjMgt_Element aCurTarget = aDoc.createElement( ::ExtString() ); |
688 | XmlObjMgt::SetExtendedString( aCurTarget, aValueStr ); |
689 | anElement.appendChild( aCurTarget ); |
690 | } |
691 | } |
692 | |
693 | if(S->HasBytes() && !S->GetBytesContainer().IsEmpty()) { |
694 | up = S->GetBytesContainer().Extent(); |
695 | theTarget.Element().setAttribute(::LastByteIndex(), up); |
696 | TDataStd_DataMapIteratorOfDataMapOfStringByte itr(S->GetBytesContainer()); |
697 | for (i=1; itr.More(); itr.Next(),i++) { |
698 | const TCollection_ExtendedString aValueStr = |
83ae3591 |
699 | itr.Key() + ' ' + TCollection_ExtendedString(itr.Value());// key - value; |
7fd59977 |
700 | XmlObjMgt_Element aCurTarget = aDoc.createElement( ::ExtString() ); |
701 | XmlObjMgt::SetExtendedString( aCurTarget, aValueStr ); |
702 | anElement.appendChild( aCurTarget ); |
703 | } |
704 | } |
705 | |
706 | if(S->HasArraysOfIntegers() && !S->GetArraysOfIntegersContainer().IsEmpty()) { |
707 | up = S->GetArraysOfIntegersContainer().Extent(); |
708 | theTarget.Element().setAttribute(::LastIntArrIndex(), up); |
709 | TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfInteger itr(S->GetArraysOfIntegersContainer()); |
710 | for (i=1; itr.More(); itr.Next(),i++) { |
711 | const TColStd_Array1OfInteger& anArr1 = itr.Value()->Array1(); |
712 | const Standard_Integer aLen = anArr1.Upper() - anArr1.Lower() +1; |
713 | |
714 | const TCollection_ExtendedString aValueStr = |
83ae3591 |
715 | itr.Key() + ' ' + TCollection_ExtendedString(aLen);// key - Num_of_Arr_elements; |
7fd59977 |
716 | XmlObjMgt_Element aCurTarget = aDoc.createElement( ::ExtString() ); |
717 | XmlObjMgt::SetExtendedString( aCurTarget, aValueStr); //key |
718 | anElement.appendChild( aCurTarget ); |
719 | |
720 | //Value = Array |
721 | TCollection_AsciiString aValueStr2; |
722 | Standard_Integer j = anArr1.Lower(); |
83ae3591 |
723 | for(;;) { |
724 | aValueStr2 += TCollection_AsciiString(anArr1.Value(j)); |
725 | if (j >= anArr1.Upper()) break; |
726 | aValueStr2 += ' '; |
727 | j++; |
728 | } |
7fd59977 |
729 | |
730 | aCurTarget.setAttribute(::Value(), aValueStr2.ToCString()); |
731 | } |
732 | } |
733 | |
734 | if(S->HasArraysOfReals() && !S->GetArraysOfRealsContainer().IsEmpty()) { |
735 | up = S->GetArraysOfRealsContainer().Extent(); |
736 | theTarget.Element().setAttribute(::LastRealArrIndex(), up); |
737 | TDataStd_DataMapIteratorOfDataMapOfStringHArray1OfReal itr(S->GetArraysOfRealsContainer()); |
738 | for (i=1; itr.More(); itr.Next(),i++) { |
739 | const TColStd_Array1OfReal& anArr1 = itr.Value()->Array1(); |
740 | const Standard_Integer aLen = anArr1.Upper() - anArr1.Lower() +1; |
741 | |
742 | //key |
743 | const TCollection_ExtendedString aValueStr = |
83ae3591 |
744 | itr.Key() + ' ' + TCollection_ExtendedString(aLen);// key - Num_of_Arr_elements; |
7fd59977 |
745 | XmlObjMgt_Element aCurTarget = aDoc.createElement( ::ExtString() ); |
746 | XmlObjMgt::SetExtendedString( aCurTarget, aValueStr); //key |
747 | anElement.appendChild( aCurTarget ); |
748 | |
749 | //Value = Array |
750 | TCollection_AsciiString aValueStr2; |
751 | Standard_Integer j = anArr1.Lower(); |
302f96fb |
752 | for(;;) { |
83ae3591 |
753 | char aValueChar[32]; |
754 | Sprintf(aValueChar, "%.15g", anArr1.Value(j)); |
755 | TCollection_AsciiString aValueStr3(aValueChar); |
756 | aValueStr2 += aValueStr3; |
757 | if (j >= anArr1.Upper()) break; |
758 | aValueStr2 += ' '; |
759 | j++; |
7fd59977 |
760 | } |
761 | aCurTarget.setAttribute(::Value(), aValueStr2.ToCString()); |
762 | |
763 | } |
764 | } |
765 | } |