Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2001-07-09 |
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 | |
7fd59977 | 16 | |
42cf5bc1 | 17 | #include <CDM_Application.hxx> |
18 | #include <CDM_Document.hxx> | |
83ae3591 | 19 | #include <Message_Messenger.hxx> |
7e785937 | 20 | #include <Message_ProgressScope.hxx> |
42cf5bc1 | 21 | #include <CDM_MetaData.hxx> |
7fd59977 | 22 | #include <LDOM_DocumentType.hxx> |
42cf5bc1 | 23 | #include <LDOM_LDOMImplementation.hxx> |
7fd59977 | 24 | #include <LDOMParser.hxx> |
42cf5bc1 | 25 | #include <OSD_Path.hxx> |
4ff92abe | 26 | #include <OSD_OpenFile.hxx> |
42cf5bc1 | 27 | #include <PCDM_Document.hxx> |
4ff92abe | 28 | #include <PCDM_DOMHeaderParser.hxx> |
42cf5bc1 | 29 | #include <Standard_Type.hxx> |
30 | #include <TCollection_AsciiString.hxx> | |
31 | #include <TCollection_ExtendedString.hxx> | |
7fd59977 | 32 | #include <TDF_Data.hxx> |
7fd59977 | 33 | #include <TDocStd_Document.hxx> |
42cf5bc1 | 34 | #include <TDocStd_Owner.hxx> |
7fd59977 | 35 | #include <UTL.hxx> |
42cf5bc1 | 36 | #include <XmlLDrivers.hxx> |
37 | #include <XmlLDrivers_DocumentRetrievalDriver.hxx> | |
42cf5bc1 | 38 | #include <XmlMDF.hxx> |
39 | #include <XmlMDF_ADriver.hxx> | |
40 | #include <XmlMDF_ADriverTable.hxx> | |
41 | #include <XmlObjMgt.hxx> | |
42 | #include <XmlObjMgt_Document.hxx> | |
43 | #include <XmlObjMgt_RRelocationTable.hxx> | |
7fd59977 | 44 | |
92efcf78 | 45 | IMPLEMENT_STANDARD_RTTIEXT(XmlLDrivers_DocumentRetrievalDriver,PCDM_RetrievalDriver) |
46 | ||
57c28b61 | 47 | #ifdef _MSC_VER |
7fd59977 | 48 | # include <tchar.h> |
57c28b61 | 49 | #endif // _MSC_VER |
7fd59977 | 50 | |
51 | #include <locale.h> | |
52 | #include <Standard_Failure.hxx> | |
53 | #include <Standard_ErrorHandler.hxx> | |
54 | ||
55 | #define START_REF "START_REF" | |
56 | #define END_REF "END_REF" | |
4ff92abe | 57 | |
58 | #define MODIFICATION_COUNTER "MODIFICATION_COUNTER: " | |
59 | #define REFERENCE_COUNTER "REFERENCE_COUNTER: " | |
7fd59977 | 60 | |
7fd59977 | 61 | //#define TAKE_TIMES |
62 | static void take_time (const Standard_Integer, const char *, | |
83ae3591 | 63 | const Handle(Message_Messenger)&) |
7fd59977 | 64 | #ifdef TAKE_TIMES |
65 | ; | |
66 | #else | |
67 | {} | |
68 | #endif | |
69 | ||
70 | static Standard_Integer RemoveExtraSeparator(TCollection_AsciiString& aString) { | |
71 | ||
72 | Standard_Integer i, j, len ; | |
73 | ||
74 | len = aString.Length() ; | |
57c28b61 | 75 | #ifdef _WIN32 |
7fd59977 | 76 | // Case of network path, such as \\MACHINE\dir |
77 | for (i = j = 2 ; j <= len ; i++,j++) { | |
78 | #else | |
79 | for (i = j = 1 ; j <= len ; i++,j++) { | |
80 | #endif | |
81 | Standard_Character c = aString.Value(j) ; | |
82 | aString.SetValue(i,c) ; | |
83 | if (c == '/') | |
84 | while(j < len && aString.Value(j+1) == '/') j++ ; | |
85 | } | |
86 | len = i-1 ; | |
87 | if (aString.Value(len) == '/') len-- ; | |
88 | aString.Trunc(len) ; | |
89 | return len ; | |
90 | } | |
91 | static TCollection_AsciiString GetDirFromFile(const TCollection_ExtendedString& aFileName) { | |
92 | TCollection_AsciiString theCFile=UTL::CString(aFileName); | |
93 | TCollection_AsciiString theDirectory; | |
94 | Standard_Integer i=theCFile.SearchFromEnd("/"); | |
57c28b61 | 95 | #ifdef _WIN32 |
7fd59977 | 96 | // if(i==-1) i=theCFile.SearchFromEnd("\\"); |
97 | if(theCFile.SearchFromEnd("\\") > i) | |
98 | i=theCFile.SearchFromEnd("\\"); | |
99 | #endif | |
100 | if(i!=-1) theDirectory=theCFile.SubString(1,i); | |
101 | return theDirectory; | |
102 | } | |
103 | ||
104 | static TCollection_AsciiString AbsolutePath( | |
105 | const TCollection_AsciiString& aDirPath, | |
106 | const TCollection_AsciiString& aRelFilePath) | |
107 | { | |
108 | TCollection_AsciiString EmptyString = "" ; | |
57c28b61 | 109 | #ifdef _WIN32 |
7fd59977 | 110 | if (aRelFilePath.Search(":") == 2 || |
111 | (aRelFilePath.Search("\\") == 1 && aRelFilePath.Value(2) == '\\')) | |
112 | #else | |
113 | if(aRelFilePath.Search("/") == 1) | |
114 | #endif | |
115 | return aRelFilePath ; | |
116 | ||
117 | TCollection_AsciiString DirPath = aDirPath, RelFilePath = aRelFilePath ; | |
118 | Standard_Integer i,len ; | |
119 | ||
57c28b61 | 120 | #ifdef _WIN32 |
7fd59977 | 121 | if(DirPath.Search(":") != 2 && |
122 | (DirPath.Search("\\") != 1 || DirPath.Value(2) != '\\')) | |
123 | #else | |
124 | if (DirPath.Search("/") != 1 ) | |
125 | #endif | |
126 | return EmptyString ; | |
127 | ||
57c28b61 | 128 | #ifdef _WIN32 |
7fd59977 | 129 | DirPath.ChangeAll('\\','/') ; |
130 | RelFilePath.ChangeAll('\\','/') ; | |
131 | #endif | |
132 | ||
133 | RemoveExtraSeparator(DirPath) ; | |
134 | len = RemoveExtraSeparator(RelFilePath) ; | |
135 | ||
136 | while (RelFilePath.Search("../") == 1) { | |
137 | if (len == 3) | |
4fbddc7c | 138 | return EmptyString ; |
7fd59977 | 139 | RelFilePath = RelFilePath.SubString(4,len) ; |
140 | len -= 3 ; | |
141 | if (DirPath.IsEmpty()) | |
4fbddc7c | 142 | return EmptyString ; |
7fd59977 | 143 | i = DirPath.SearchFromEnd("/") ; |
144 | if (i < 0) | |
145 | return EmptyString ; | |
146 | DirPath.Trunc(i-1) ; | |
147 | } | |
148 | TCollection_AsciiString retx; | |
149 | retx= DirPath; | |
150 | retx+= "/"; | |
151 | retx+=RelFilePath ; | |
152 | return retx; | |
153 | } | |
154 | ||
155 | //======================================================================= | |
156 | //function : XmlLDrivers_DocumentRetrievalDriver | |
157 | //purpose : Constructor | |
158 | //======================================================================= | |
159 | XmlLDrivers_DocumentRetrievalDriver::XmlLDrivers_DocumentRetrievalDriver() | |
160 | { | |
161 | myReaderStatus = PCDM_RS_OK; | |
162 | } | |
163 | ||
7fd59977 | 164 | //======================================================================= |
165 | //function : Read | |
166 | //purpose : | |
167 | //======================================================================= | |
168 | void XmlLDrivers_DocumentRetrievalDriver::Read | |
6d8f9f4a | 169 | (const TCollection_ExtendedString& theFileName, |
170 | const Handle(CDM_Document)& theNewDocument, | |
171 | const Handle(CDM_Application)& theApplication, | |
d5c71e20 | 172 | const Handle(PCDM_ReaderFilter)& theFilter, |
7e785937 | 173 | const Message_ProgressRange& theRange) |
7fd59977 | 174 | { |
175 | myReaderStatus = PCDM_RS_DriverFailure; | |
176 | myFileName = theFileName; | |
4ff92abe | 177 | |
178 | std::ifstream aFileStream; | |
179 | OSD_OpenStream (aFileStream, myFileName, std::ios::in); | |
180 | ||
181 | if (aFileStream.is_open() && aFileStream.good()) | |
182 | { | |
d5c71e20 | 183 | Read (aFileStream, NULL, theNewDocument, theApplication, theFilter, theRange); |
4ff92abe | 184 | } |
185 | else | |
186 | { | |
187 | myReaderStatus = PCDM_RS_OpenError; | |
188 | ||
189 | TCollection_ExtendedString aMsg = TCollection_ExtendedString("Error: the file ") + | |
190 | theFileName + " cannot be opened for reading"; | |
191 | ||
83ae3591 | 192 | theApplication->MessageDriver()->Send (aMsg.ToExtString(), Message_Fail); |
9775fa61 | 193 | throw Standard_Failure("File cannot be opened for reading"); |
4ff92abe | 194 | } |
195 | } | |
196 | ||
197 | //======================================================================= | |
198 | //function : Read | |
199 | //purpose : | |
200 | //======================================================================= | |
201 | void XmlLDrivers_DocumentRetrievalDriver::Read (Standard_IStream& theIStream, | |
202 | const Handle(Storage_Data)& /*theStorageData*/, | |
203 | const Handle(CDM_Document)& theNewDocument, | |
6d8f9f4a | 204 | const Handle(CDM_Application)& theApplication, |
d5c71e20 | 205 | const Handle(PCDM_ReaderFilter)& /*theFilter*/, |
7e785937 | 206 | const Message_ProgressRange& theRange) |
4ff92abe | 207 | { |
83ae3591 | 208 | Handle(Message_Messenger) aMessageDriver = theApplication -> MessageDriver(); |
7fd59977 | 209 | ::take_time (~0, " +++++ Start RETRIEVE procedures ++++++", aMessageDriver); |
210 | ||
211 | // 1. Read DOM_Document from file | |
212 | LDOMParser aParser; | |
4ff92abe | 213 | |
5fce1605 | 214 | // if myFileName is not empty, "document" tag is required to be read |
215 | // from the received document | |
216 | Standard_Boolean aWithoutRoot = myFileName.IsEmpty(); | |
217 | ||
218 | if (aParser.parse(theIStream, Standard_False, aWithoutRoot)) | |
7fd59977 | 219 | { |
220 | TCollection_AsciiString aData; | |
04232180 | 221 | std::cout << aParser.GetError(aData) << ": " << aData << std::endl; |
7fd59977 | 222 | myReaderStatus = PCDM_RS_FormatFailure; |
223 | return; | |
224 | } | |
225 | const XmlObjMgt_Element anElement= aParser.getDocument().getDocumentElement(); | |
226 | ::take_time (0, " +++++ Fin parsing XML : ", aMessageDriver); | |
227 | ||
7e785937 | 228 | ReadFromDomDocument (anElement, theNewDocument, theApplication, theRange); |
7fd59977 | 229 | } |
230 | ||
231 | //======================================================================= | |
232 | //function : ReadFromDomDocument | |
233 | //purpose : management of the macro-structure of XML document data | |
234 | //remark : If the application needs to use myRelocTable to retrieve additional | |
235 | // data from LDOM, this method should be reimplemented | |
236 | //======================================================================= | |
237 | ||
238 | void XmlLDrivers_DocumentRetrievalDriver::ReadFromDomDocument | |
239 | (const XmlObjMgt_Element& theElement, | |
240 | const Handle(CDM_Document)& theNewDocument, | |
6d8f9f4a | 241 | const Handle(CDM_Application)& theApplication, |
7e785937 | 242 | const Message_ProgressRange& theRange) |
7fd59977 | 243 | { |
83ae3591 | 244 | const Handle(Message_Messenger) aMsgDriver = |
7fd59977 | 245 | theApplication -> MessageDriver(); |
246 | // 1. Read info // to be done | |
247 | TCollection_AsciiString anAbsoluteDirectory = GetDirFromFile(myFileName); | |
14eea829 | 248 | Standard_Integer aCurDocVersion = TDocStd_FormatVersion_VERSION_2; // minimum supported version |
7fd59977 | 249 | TCollection_ExtendedString anInfo; |
250 | const XmlObjMgt_Element anInfoElem = | |
251 | theElement.GetChildByTagName ("info"); | |
252 | if (anInfoElem != NULL) { | |
253 | XmlObjMgt_DOMString aDocVerStr = anInfoElem.getAttribute("DocVersion"); | |
14eea829 | 254 | if (aDocVerStr != NULL) |
255 | { | |
256 | Standard_Integer anIntegerVersion = 0; | |
257 | if (aDocVerStr.GetInteger (anIntegerVersion)) | |
258 | { | |
259 | aCurDocVersion = anIntegerVersion; | |
260 | } | |
261 | else | |
262 | { | |
263 | TCollection_ExtendedString aMsg = | |
264 | TCollection_ExtendedString ("Cannot retrieve the current Document version" | |
265 | " attribute as \"") + aDocVerStr + "\""; | |
266 | if (!aMsgDriver.IsNull()) | |
267 | { | |
268 | aMsgDriver->Send(aMsg.ToExtString(), Message_Fail); | |
269 | } | |
270 | } | |
4fbddc7c | 271 | } |
14eea829 | 272 | |
4551e1be | 273 | // oan: OCC22305 - check a document version and if it's greater than |
4fbddc7c | 274 | // current version of storage driver set an error status and return |
716cf4d9 | 275 | if( aCurDocVersion > TDocStd_Document::CurrentStorageFormatVersion() ) |
4fbddc7c O |
276 | { |
277 | TCollection_ExtendedString aMsg = | |
278 | TCollection_ExtendedString ("error: wrong file version: ") + | |
279 | aDocVerStr + " while current is " + | |
716cf4d9 | 280 | TDocStd_Document::CurrentStorageFormatVersion(); |
4fbddc7c O |
281 | myReaderStatus = PCDM_RS_NoVersion; |
282 | if(!aMsgDriver.IsNull()) | |
83ae3591 | 283 | aMsgDriver->Send(aMsg.ToExtString(), Message_Fail); |
4fbddc7c | 284 | return; |
7fd59977 | 285 | } |
4fbddc7c | 286 | |
7fd59977 | 287 | Standard_Boolean isRef = Standard_False; |
288 | for (LDOM_Node aNode = anInfoElem.getFirstChild(); | |
289 | aNode != NULL; aNode = aNode.getNextSibling()) { | |
290 | if (aNode.getNodeType() == LDOM_Node::ELEMENT_NODE) { | |
291 | if (XmlObjMgt::GetExtendedString ((LDOM_Element&)aNode, anInfo)) { | |
292 | ||
4fbddc7c O |
293 | // Read ref counter |
294 | if(anInfo.Search(REFERENCE_COUNTER) != -1) { | |
295 | try { | |
296 | OCC_CATCH_SIGNALS | |
297 | TCollection_AsciiString anInf(anInfo,'?'); | |
4ff92abe | 298 | Standard_Integer aRefCounter = anInf.Token(" ",2).IntegerValue(); |
299 | theNewDocument->SetReferenceCounter(aRefCounter); | |
4fbddc7c | 300 | } |
a738b534 | 301 | catch (Standard_Failure const&) { |
04232180 | 302 | // std::cout << "warning: could not read the reference counter in " << aFileName << std::endl; |
4fbddc7c O |
303 | TCollection_ExtendedString aMsg("Warning: "); |
304 | aMsg = aMsg.Cat("could not read the reference counter").Cat("\0"); | |
305 | if(!aMsgDriver.IsNull()) | |
83ae3591 | 306 | aMsgDriver->Send(aMsg.ToExtString(), Message_Warning); |
4fbddc7c O |
307 | } |
308 | } | |
4ff92abe | 309 | else if (anInfo.Search(MODIFICATION_COUNTER) != -1) { |
310 | try { | |
311 | OCC_CATCH_SIGNALS | |
312 | ||
313 | TCollection_AsciiString anInf(anInfo,'?'); | |
314 | Standard_Integer aModCounter = anInf.Token(" ",2).IntegerValue(); | |
315 | theNewDocument->SetModifications (aModCounter); | |
316 | } | |
a738b534 | 317 | catch (Standard_Failure const&) { |
4ff92abe | 318 | TCollection_ExtendedString aMsg("Warning: could not read the modification counter\0"); |
319 | if(!aMsgDriver.IsNull()) | |
83ae3591 | 320 | aMsgDriver->Send(aMsg.ToExtString(), Message_Warning); |
4ff92abe | 321 | } |
322 | } | |
4fbddc7c O |
323 | |
324 | if(anInfo == END_REF) | |
325 | isRef = Standard_False; | |
326 | if(isRef) { // Process References | |
327 | ||
328 | Standard_Integer pos=anInfo.Search(" "); | |
329 | if(pos != -1) { | |
330 | // Parce RefId, DocumentVersion and FileName | |
331 | Standard_Integer aRefId; | |
332 | TCollection_ExtendedString aFileName; | |
333 | Standard_Integer aDocumentVersion; | |
334 | ||
335 | ||
336 | TCollection_ExtendedString aRest=anInfo.Split(pos); | |
337 | aRefId = UTL::IntegerValue(anInfo); | |
338 | ||
339 | Standard_Integer pos2 = aRest.Search(" "); | |
340 | ||
341 | aFileName = aRest.Split(pos2); | |
342 | aDocumentVersion = UTL::IntegerValue(aRest); | |
343 | ||
344 | TCollection_AsciiString aPath = UTL::CString(aFileName); | |
345 | TCollection_AsciiString anAbsolutePath; | |
346 | if(!anAbsoluteDirectory.IsEmpty()) { | |
347 | anAbsolutePath = AbsolutePath(anAbsoluteDirectory,aPath); | |
348 | if(!anAbsolutePath.IsEmpty()) aPath=anAbsolutePath; | |
349 | } | |
350 | if(!aMsgDriver.IsNull()) { | |
04232180 | 351 | // std::cout << "reference found; ReferenceIdentifier: " << theReferenceIdentifier << "; File:" << thePath << ", version:" << theDocumentVersion; |
83ae3591 | 352 | TCollection_ExtendedString aMsg("Warning: "); |
353 | aMsg = aMsg.Cat("reference found; ReferenceIdentifier: ").Cat(aRefId).Cat("; File:").Cat(aPath).Cat(", version:").Cat(aDocumentVersion).Cat("\0"); | |
354 | aMsgDriver->Send(aMsg.ToExtString(), Message_Warning); | |
4fbddc7c O |
355 | } |
356 | // Add new ref! | |
357 | ///////////// | |
358 | TCollection_ExtendedString theFolder,theName; | |
359 | //TCollection_ExtendedString theFile=myReferences(myIterator).FileName(); | |
360 | TCollection_ExtendedString f(aPath); | |
57c28b61 | 361 | #ifndef _WIN32 |
4fbddc7c O |
362 | |
363 | Standard_Integer i= f.SearchFromEnd("/"); | |
364 | TCollection_ExtendedString n = f.Split(i); | |
365 | f.Trunc(f.Length()-1); | |
366 | theFolder = f; | |
367 | theName = n; | |
7fd59977 | 368 | #else |
4fbddc7c O |
369 | OSD_Path p = UTL::Path(f); |
370 | Standard_ExtCharacter chr; | |
371 | TCollection_ExtendedString dir, dirRet, name; | |
372 | ||
373 | dir = UTL::Disk(p); | |
374 | dir += UTL::Trek(p); | |
375 | ||
376 | for ( int i = 1; i <= dir.Length (); ++i ) { | |
377 | ||
378 | chr = dir.Value ( i ); | |
379 | ||
380 | switch ( chr ) { | |
7c65581d | 381 | |
382 | case '|': | |
383 | dirRet += "/"; | |
4fbddc7c | 384 | break; |
7c65581d | 385 | |
386 | case '^': | |
387 | ||
388 | dirRet += ".."; | |
4fbddc7c | 389 | break; |
7fd59977 | 390 | |
4fbddc7c O |
391 | default: |
392 | dirRet += chr; | |
393 | ||
394 | } | |
395 | } | |
396 | theFolder = dirRet; | |
397 | theName = UTL::Name(p); theName+= UTL::Extension(p); | |
57c28b61 | 398 | #endif // _WIN32 |
4fbddc7c | 399 | |
8a39adb7 | 400 | Handle(CDM_MetaData) aMetaData = |
401 | CDM_MetaData::LookUp(theApplication->MetaDataLookUpTable(), theFolder, theName, aPath, aPath, UTL::IsReadOnly(aFileName)); | |
7fd59977 | 402 | //////////// |
4fbddc7c O |
403 | theNewDocument->CreateReference(aMetaData,aRefId, |
404 | theApplication,aDocumentVersion,Standard_False); | |
7fd59977 | 405 | |
4fbddc7c O |
406 | |
407 | } | |
7fd59977 | 408 | |
4fbddc7c O |
409 | |
410 | } | |
411 | if(anInfo == START_REF) | |
412 | isRef = Standard_True; | |
7fd59977 | 413 | } |
414 | } | |
415 | } | |
416 | } | |
417 | ||
418 | // 2. Read comments | |
419 | TCollection_ExtendedString aComment; | |
420 | const XmlObjMgt_Element aCommentsElem = | |
421 | theElement.GetChildByTagName ("comments"); | |
422 | if (aCommentsElem != NULL) | |
423 | { | |
424 | for (LDOM_Node aNode = aCommentsElem.getFirstChild(); | |
425 | aNode != NULL; aNode = aNode.getNextSibling()) | |
426 | { | |
427 | if (aNode.getNodeType() == LDOM_Node::ELEMENT_NODE) | |
428 | { | |
429 | if (XmlObjMgt::GetExtendedString ((LDOM_Element&)aNode, aComment)) | |
430 | { | |
431 | theNewDocument->AddComment(aComment); | |
432 | } | |
433 | } | |
434 | } | |
435 | } | |
7e785937 | 436 | Message_ProgressScope aPS(theRange, "Reading document", 2); |
7fd59977 | 437 | // 2. Read Shapes section |
438 | if (myDrivers.IsNull()) myDrivers = AttributeDrivers (aMsgDriver); | |
7e785937 | 439 | const Handle(XmlMDF_ADriver) aNSDriver = ReadShapeSection(theElement, aMsgDriver, aPS.Next()); |
7fd59977 | 440 | if(!aNSDriver.IsNull()) |
441 | ::take_time (0, " +++++ Fin reading Shapes : ", aMsgDriver); | |
442 | ||
6d8f9f4a | 443 | if (!aPS.More()) |
444 | { | |
445 | myReaderStatus = PCDM_RS_UserBreak; | |
446 | return; | |
447 | } | |
6d8f9f4a | 448 | |
b34d86cb | 449 | // 2.1. Keep document format version in RT |
450 | Handle(Storage_HeaderData) aHeaderData = new Storage_HeaderData(); | |
451 | aHeaderData->SetStorageVersion(aCurDocVersion); | |
452 | myRelocTable.Clear(); | |
453 | myRelocTable.SetHeaderData(aHeaderData); | |
454 | ||
7fd59977 | 455 | // 5. Read document contents |
456 | try | |
457 | { | |
458 | OCC_CATCH_SIGNALS | |
0797d9d3 | 459 | #ifdef OCCT_DEBUG |
7fd59977 | 460 | TCollection_ExtendedString aMessage ("PasteDocument"); |
83ae3591 | 461 | aMsgDriver ->Send (aMessage.ToExtString(), Message_Trace); |
7fd59977 | 462 | #endif |
7e785937 | 463 | if (!MakeDocument(theElement, theNewDocument, aPS.Next())) |
7fd59977 | 464 | myReaderStatus = PCDM_RS_MakeFailure; |
465 | else | |
466 | myReaderStatus = PCDM_RS_OK; | |
467 | } | |
9775fa61 | 468 | catch (Standard_Failure const& anException) |
7fd59977 | 469 | { |
9775fa61 | 470 | TCollection_ExtendedString anErrorString (anException.GetMessageString()); |
83ae3591 | 471 | aMsgDriver ->Send (anErrorString.ToExtString(), Message_Fail); |
7fd59977 | 472 | } |
6d8f9f4a | 473 | if (!aPS.More()) |
474 | { | |
475 | myReaderStatus = PCDM_RS_UserBreak; | |
476 | return; | |
477 | } | |
7fd59977 | 478 | |
479 | // Wipe off the shapes written to the <shapes> section | |
480 | ShapeSetCleaning(aNSDriver); | |
481 | ||
482 | // Clean the relocation table. | |
483 | // If the application needs to use myRelocTable to retrieve additional | |
484 | // data from LDOM, this method should be reimplemented avoiding this step | |
485 | myRelocTable.Clear(); | |
486 | ::take_time (0, " +++++ Fin reading data OCAF : ", aMsgDriver); | |
487 | } | |
488 | ||
489 | //======================================================================= | |
490 | //function : MakeDocument | |
491 | //purpose : | |
492 | //======================================================================= | |
493 | Standard_Boolean XmlLDrivers_DocumentRetrievalDriver::MakeDocument | |
494 | (const XmlObjMgt_Element& theElement, | |
6d8f9f4a | 495 | const Handle(CDM_Document)& theTDoc, |
7e785937 | 496 | const Message_ProgressRange& theRange) |
7fd59977 | 497 | { |
498 | Standard_Boolean aResult = Standard_False; | |
499 | Handle(TDocStd_Document) TDOC = Handle(TDocStd_Document)::DownCast(theTDoc); | |
7fd59977 | 500 | if (!TDOC.IsNull()) |
501 | { | |
502 | Handle(TDF_Data) aTDF = new TDF_Data(); | |
7e785937 | 503 | aResult = XmlMDF::FromTo (theElement, aTDF, myRelocTable, myDrivers, theRange); |
7fd59977 | 504 | if (aResult) { |
505 | TDOC->SetData (aTDF); | |
506 | TDocStd_Owner::SetDocument (aTDF, TDOC); | |
507 | } | |
508 | } | |
509 | return aResult; | |
510 | } | |
511 | ||
512 | //======================================================================= | |
513 | //function : AttributeDrivers | |
514 | //purpose : | |
515 | //======================================================================= | |
516 | Handle(XmlMDF_ADriverTable) XmlLDrivers_DocumentRetrievalDriver::AttributeDrivers | |
83ae3591 | 517 | (const Handle(Message_Messenger)& theMessageDriver) |
7fd59977 | 518 | { |
519 | return XmlLDrivers::AttributeDrivers (theMessageDriver); | |
520 | } | |
521 | ||
522 | //======================================================================= | |
523 | //function : take_time | |
524 | //class : static | |
525 | //purpose : output astronomical time elapsed | |
526 | //======================================================================= | |
527 | #ifdef TAKE_TIMES | |
528 | #include <time.h> | |
529 | #include <sys/timeb.h> | |
530 | #include <sys/types.h> | |
531 | #include <stdio.h> | |
57c28b61 | 532 | #ifndef _WIN32 |
7fd59977 | 533 | extern "C" int ftime (struct timeb *tp); |
534 | #endif | |
535 | extern struct timeb tmbuf0; | |
536 | ||
537 | static void take_time (const Standard_Integer isReset, const char * aHeader, | |
83ae3591 | 538 | const Handle(Message_Messenger)& aMessageDriver) |
7fd59977 | 539 | { |
540 | struct timeb tmbuf; | |
541 | ftime (&tmbuf); | |
542 | TCollection_ExtendedString aMessage ((Standard_CString)aHeader); | |
543 | if (isReset) tmbuf0 = tmbuf; | |
544 | else { | |
545 | char take_tm_buf [64]; | |
91322f44 | 546 | Sprintf (take_tm_buf, "%9.2f s ++++", |
7fd59977 | 547 | double(tmbuf.time - tmbuf0.time) + |
548 | double(tmbuf.millitm - tmbuf0.millitm)/1000.); | |
549 | aMessage += take_tm_buf; | |
550 | } | |
551 | aMessageDriver -> Write (aMessage.ToExtString()); | |
552 | } | |
553 | #endif | |
554 | ||
7fd59977 | 555 | //======================================================================= |
556 | //function : ReadShapeSection | |
557 | //purpose : definition of ReadShapeSection | |
558 | //======================================================================= | |
559 | Handle(XmlMDF_ADriver) XmlLDrivers_DocumentRetrievalDriver::ReadShapeSection( | |
560 | const XmlObjMgt_Element& /*theElement*/, | |
6d8f9f4a | 561 | const Handle(Message_Messenger)& /*aMsgDriver*/, |
7e785937 | 562 | const Message_ProgressRange& /*theRange*/) |
7fd59977 | 563 | { |
564 | Handle(XmlMDF_ADriver) aDriver; | |
565 | //empty; to be redefined | |
566 | return aDriver; | |
567 | } | |
568 | ||
569 | //======================================================================= | |
570 | //function : ShapeSetCleaning | |
571 | //purpose : definition of ShapeSetCleaning | |
572 | //======================================================================= | |
573 | void XmlLDrivers_DocumentRetrievalDriver::ShapeSetCleaning( | |
4fbddc7c | 574 | const Handle(XmlMDF_ADriver)& /*theDriver*/) |
7fd59977 | 575 | {} |