Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1997-08-08 |
2 | // Created by: Jean-Louis Frenkel | |
3 | // Copyright (c) 1997-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
d5f74e42 | 8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
12 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
b311480e | 16 | |
7fd59977 | 17 | // Modified by rmi, Wed Jan 14 08:17:35 1998 |
18 | ||
42cf5bc1 | 19 | #include <CDF_Application.hxx> |
7fd59977 | 20 | #include <CDF_Directory.hxx> |
21 | #include <CDF_MetaDataDriver.hxx> | |
42cf5bc1 | 22 | #include <CDF_Session.hxx> |
23 | #include <CDF_Timer.hxx> | |
24 | #include <CDM_CanCloseStatus.hxx> | |
25 | #include <CDM_Document.hxx> | |
26 | #include <CDM_MetaData.hxx> | |
27 | #include <PCDM_Reader.hxx> | |
15e8b082 | 28 | #include <PCDM_ReaderStatus.hxx> |
7fd59977 | 29 | #include <PCDM_ReadWriter.hxx> |
30 | #include <PCDM_RetrievalDriver.hxx> | |
31 | #include <PCDM_StorageDriver.hxx> | |
7fd59977 | 32 | #include <Plugin.hxx> |
42cf5bc1 | 33 | #include <Standard_ErrorHandler.hxx> |
34 | #include <Standard_GUID.hxx> | |
35 | #include <Standard_NoSuchObject.hxx> | |
36 | #include <Standard_ProgramError.hxx> | |
37 | #include <Standard_Type.hxx> | |
38 | #include <TCollection_ExtendedString.hxx> | |
7fd59977 | 39 | #include <UTL.hxx> |
40 | ||
92efcf78 | 41 | IMPLEMENT_STANDARD_RTTIEXT(CDF_Application,CDM_Application) |
42 | ||
7fd59977 | 43 | #define theMetaDataDriver CDF_Session::CurrentSession()->MetaDataDriver() |
44 | ||
45 | ||
46 | //======================================================================= | |
47 | //function : | |
48 | //purpose : | |
49 | //======================================================================= | |
15e8b082 | 50 | CDF_Application::CDF_Application():myRetrievableStatus(PCDM_RS_OK) {} |
7fd59977 | 51 | |
52 | //======================================================================= | |
53 | //function : Load | |
54 | //purpose : | |
55 | //======================================================================= | |
56 | Handle(CDF_Application) CDF_Application::Load(const Standard_GUID& aGUID) { | |
57 | return Handle(CDF_Application)::DownCast(Plugin::Load(aGUID)); | |
58 | } | |
59 | ||
60 | //======================================================================= | |
61 | //function : Open | |
62 | //purpose : | |
63 | //======================================================================= | |
64 | void CDF_Application::Open(const Handle(CDM_Document)& aDocument) { | |
65 | CDF_Session::CurrentSession()->Directory()->Add(aDocument); | |
66 | aDocument->Open(this); | |
67 | Activate(aDocument,CDF_TOA_New); | |
68 | } | |
69 | ||
70 | //======================================================================= | |
71 | //function : CanClose | |
72 | //purpose : | |
73 | //======================================================================= | |
74 | CDM_CanCloseStatus CDF_Application::CanClose(const Handle(CDM_Document)& aDocument) { | |
75 | return aDocument->CanClose(); | |
76 | } | |
77 | ||
78 | //======================================================================= | |
79 | //function : Close | |
80 | //purpose : | |
81 | //======================================================================= | |
82 | void CDF_Application::Close(const Handle(CDM_Document)& aDocument) { | |
83 | CDF_Session::CurrentSession()->Directory()->Remove(aDocument); | |
84 | aDocument->Close(); | |
85 | } | |
86 | ||
87 | //======================================================================= | |
88 | //function : Retrieve | |
89 | //purpose : | |
90 | //======================================================================= | |
91 | Handle(CDM_Document) CDF_Application::Retrieve(const TCollection_ExtendedString& aFolder, | |
92 | const TCollection_ExtendedString& aName, | |
93 | const Standard_Boolean UseStorageConfiguration) { | |
94 | TCollection_ExtendedString nullVersion; | |
95 | return Retrieve(aFolder,aName,nullVersion,UseStorageConfiguration); | |
96 | } | |
97 | ||
98 | //======================================================================= | |
99 | //function : Retrieve | |
100 | //purpose : | |
101 | //======================================================================= | |
102 | Handle(CDM_Document) CDF_Application::Retrieve(const TCollection_ExtendedString& aFolder, | |
103 | const TCollection_ExtendedString& aName, | |
104 | const TCollection_ExtendedString& aVersion, | |
105 | const Standard_Boolean UseStorageConfiguration) { | |
0797d9d3 | 106 | #ifdef OCCT_DEBUG |
7fd59977 | 107 | CDF_Timer theTimer; |
108 | #endif | |
109 | ||
110 | Handle(CDM_MetaData) theMetaData; | |
111 | ||
112 | if(aVersion.Length() == 0) | |
113 | theMetaData=theMetaDataDriver->MetaData(aFolder,aName); | |
114 | else | |
115 | theMetaData=theMetaDataDriver->MetaData(aFolder,aName,aVersion); | |
116 | ||
0797d9d3 | 117 | #ifdef OCCT_DEBUG |
7fd59977 | 118 | theTimer.ShowAndRestart("Getting MetaData: "); |
119 | #endif | |
120 | ||
121 | CDF_TypeOfActivation theTypeOfActivation=TypeOfActivation(theMetaData); | |
122 | Handle(CDM_Document) theDocument=Retrieve(theMetaData,UseStorageConfiguration,Standard_False); | |
123 | ||
0797d9d3 | 124 | #ifdef OCCT_DEBUG |
7fd59977 | 125 | theTimer.ShowAndRestart("Creating Transient: "); |
126 | #endif | |
127 | ||
128 | CDF_Session::CurrentSession()->Directory()->Add(theDocument); | |
129 | Activate(theDocument,theTypeOfActivation); | |
130 | ||
0797d9d3 | 131 | #ifdef OCCT_DEBUG |
7fd59977 | 132 | theTimer.ShowAndStop("Activate: "); |
133 | #endif | |
134 | ||
135 | theDocument->Open(this); | |
136 | return theDocument; | |
137 | ||
138 | ||
139 | } | |
140 | ||
141 | //======================================================================= | |
142 | //function : CanRetrieve | |
143 | //purpose : | |
144 | //======================================================================= | |
15e8b082 | 145 | PCDM_ReaderStatus CDF_Application::CanRetrieve(const TCollection_ExtendedString& aFolder, const TCollection_ExtendedString& aName) { |
7fd59977 | 146 | TCollection_ExtendedString aVersion; |
147 | return CanRetrieve(aFolder,aName,aVersion); | |
148 | } | |
149 | ||
150 | //======================================================================= | |
151 | //function : CanRetrieve | |
152 | //purpose : | |
153 | //======================================================================= | |
15e8b082 | 154 | PCDM_ReaderStatus CDF_Application::CanRetrieve(const TCollection_ExtendedString& aFolder, const TCollection_ExtendedString& aName, const TCollection_ExtendedString& aVersion) { |
7fd59977 | 155 | |
0797d9d3 | 156 | #ifdef OCCT_DEBUG |
7fd59977 | 157 | CDF_Timer theTimer; |
158 | #endif | |
159 | ||
160 | if (!theMetaDataDriver->Find(aFolder,aName,aVersion)) | |
15e8b082 | 161 | return PCDM_RS_UnknownDocument; |
7fd59977 | 162 | else if (!theMetaDataDriver->HasReadPermission(aFolder,aName,aVersion)) |
15e8b082 | 163 | return PCDM_RS_PermissionDenied; |
7fd59977 | 164 | else { |
0797d9d3 | 165 | #ifdef OCCT_DEBUG |
7fd59977 | 166 | theTimer.ShowAndRestart("theMetaDataDriver->Find: "); |
167 | #endif | |
168 | ||
169 | Handle(CDM_MetaData) theMetaData = theMetaDataDriver->MetaData(aFolder,aName,aVersion); | |
170 | ||
0797d9d3 | 171 | #ifdef OCCT_DEBUG |
7fd59977 | 172 | theTimer.ShowAndStop("Getting MetaData: "); |
173 | #endif | |
174 | ||
175 | if(theMetaData->IsRetrieved()) { | |
176 | return theMetaData->Document()->IsModified() | |
15e8b082 | 177 | ? PCDM_RS_AlreadyRetrievedAndModified : PCDM_RS_AlreadyRetrieved; |
7fd59977 | 178 | } |
179 | else { | |
180 | TCollection_ExtendedString theFileName=theMetaData->FileName(); | |
181 | TCollection_ExtendedString theFormat=PCDM_ReadWriter::FileFormat(theFileName); | |
182 | if(theFormat.Length()==0) { | |
183 | TCollection_ExtendedString ResourceName=UTL::Extension(theFileName); | |
184 | ResourceName+=".FileFormat"; | |
185 | if(UTL::Find(Resources(),ResourceName)) { | |
186 | theFormat=UTL::Value(Resources(),ResourceName); | |
187 | } | |
188 | else | |
15e8b082 | 189 | return PCDM_RS_UnrecognizedFileFormat; |
7fd59977 | 190 | } |
15e8b082 | 191 | if(!FindReaderFromFormat(theFormat)) return PCDM_RS_NoDriver; |
7fd59977 | 192 | } |
193 | } | |
15e8b082 | 194 | return PCDM_RS_OK; |
7fd59977 | 195 | |
196 | } | |
197 | ||
198 | ||
199 | ||
200 | //======================================================================= | |
201 | //function : Activate | |
202 | //purpose : | |
203 | //======================================================================= | |
204 | //void CDF_Application::Activate(const Handle(CDM_Document)& aDocument,const CDF_TypeOfActivation aTypeOfActivation) { | |
205 | void CDF_Application::Activate(const Handle(CDM_Document)& ,const CDF_TypeOfActivation ) { | |
206 | } | |
207 | ||
208 | //======================================================================= | |
209 | //function : DefaultFolder | |
210 | //purpose : | |
211 | //======================================================================= | |
212 | Standard_ExtString CDF_Application::DefaultFolder(){ | |
213 | if(myDefaultFolder.Length() == 0) { | |
214 | myDefaultFolder=CDF_Session::CurrentSession()->MetaDataDriver()->DefaultFolder(); | |
215 | } | |
216 | return myDefaultFolder.ToExtString(); | |
217 | } | |
218 | ||
219 | //======================================================================= | |
220 | //function : SetDefaultFolder | |
221 | //purpose : | |
222 | //======================================================================= | |
223 | Standard_Boolean CDF_Application::SetDefaultFolder(const Standard_ExtString aFolder) { | |
224 | Standard_Boolean found = CDF_Session::CurrentSession()->MetaDataDriver()->FindFolder(aFolder); | |
225 | if(found) myDefaultFolder=aFolder; | |
226 | return found; | |
227 | } | |
228 | ||
229 | //======================================================================= | |
230 | //function : DefaultExtension | |
231 | //purpose : | |
232 | //======================================================================= | |
233 | Standard_ExtString CDF_Application::DefaultExtension() { | |
234 | static TCollection_ExtendedString theDefaultExtension; | |
235 | theDefaultExtension="*"; | |
236 | TColStd_SequenceOfExtendedString theFormats; | |
237 | Formats(theFormats); | |
238 | ||
239 | for (Standard_Integer i=1; i<= theFormats.Length(); i++) { | |
240 | TCollection_ExtendedString theResource(theFormats(i)); | |
241 | theResource+=".FileExtension"; | |
242 | if(UTL::Find(Resources(),theResource)) { | |
243 | theDefaultExtension=UTL::Value(Resources(),theResource); | |
244 | return theDefaultExtension.ToExtString(); | |
245 | } | |
246 | } | |
247 | return theDefaultExtension.ToExtString(); | |
248 | } | |
249 | ||
250 | //======================================================================= | |
251 | //function : Retrieve | |
252 | //purpose : | |
253 | //======================================================================= | |
254 | Handle(CDM_Document) CDF_Application::Retrieve(const Handle(CDM_MetaData)& aMetaData,const Standard_Boolean UseStorageConfiguration) { | |
255 | return Retrieve(aMetaData,UseStorageConfiguration,Standard_True); | |
256 | } | |
257 | ||
7fd59977 | 258 | //======================================================================= |
259 | //function : Retrieve | |
260 | //purpose : | |
261 | //======================================================================= | |
262 | Handle(CDM_Document) CDF_Application::Retrieve(const Handle(CDM_MetaData)& aMetaData,const Standard_Boolean UseStorageConfiguration, const Standard_Boolean IsComponent) { | |
263 | ||
264 | Handle(CDM_Document) theDocumentToReturn; | |
15e8b082 | 265 | myRetrievableStatus = PCDM_RS_DriverFailure; |
7fd59977 | 266 | if(IsComponent) { |
267 | Standard_SStream aMsg; | |
268 | switch (CanRetrieve(aMetaData)) { | |
15e8b082 | 269 | case PCDM_RS_UnknownDocument: |
7fd59977 | 270 | aMsg << "could not find the referenced document: " << aMetaData->Path() << "; not found." <<(char)0 << endl; |
15e8b082 | 271 | myRetrievableStatus = PCDM_RS_UnknownDocument; |
7fd59977 | 272 | Standard_Failure::Raise(aMsg); |
273 | break; | |
15e8b082 | 274 | case PCDM_RS_PermissionDenied: |
7fd59977 | 275 | aMsg << "Could not find the referenced document: " << aMetaData->Path() << "; permission denied. " <<(char)0 << endl; |
15e8b082 | 276 | myRetrievableStatus = PCDM_RS_PermissionDenied; |
7fd59977 | 277 | Standard_Failure::Raise(aMsg); |
278 | break; | |
279 | default: | |
280 | break; | |
281 | } | |
282 | ||
283 | } | |
284 | Standard_Boolean AlreadyRetrieved=aMetaData->IsRetrieved(); | |
15e8b082 | 285 | if(AlreadyRetrieved) myRetrievableStatus = PCDM_RS_AlreadyRetrieved; |
7fd59977 | 286 | Standard_Boolean Modified=AlreadyRetrieved && aMetaData->Document()->IsModified(); |
15e8b082 | 287 | if(Modified) myRetrievableStatus = PCDM_RS_AlreadyRetrievedAndModified; |
7fd59977 | 288 | if(!AlreadyRetrieved || Modified) { |
289 | ||
290 | Handle(PCDM_Reader) theReader=Reader(aMetaData->FileName()); | |
291 | ||
292 | ||
293 | Handle(CDM_Document) theDocument; | |
294 | ||
295 | if(Modified) { | |
296 | theDocument=aMetaData->Document(); | |
297 | theDocument->RemoveAllReferences(); | |
298 | } | |
299 | else | |
300 | theDocument=theReader->CreateDocument(); | |
301 | ||
302 | SetReferenceCounter(theDocument,PCDM_RetrievalDriver::ReferenceCounter(aMetaData->FileName(), MessageDriver())); | |
303 | ||
304 | SetDocumentVersion(theDocument,aMetaData); | |
305 | theMetaDataDriver->ReferenceIterator()->LoadReferences(theDocument,aMetaData,this,UseStorageConfiguration); | |
306 | ||
307 | try { | |
308 | OCC_CATCH_SIGNALS | |
309 | theReader->Read(aMetaData->FileName(),theDocument,this); | |
310 | } | |
311 | catch (Standard_Failure) { | |
15e8b082 M |
312 | myRetrievableStatus = theReader->GetStatus(); |
313 | if(myRetrievableStatus > PCDM_RS_AlreadyRetrieved){ | |
7fd59977 | 314 | Standard_SStream aMsg; |
315 | aMsg << Standard_Failure::Caught() << endl; | |
316 | Standard_Failure::Raise(aMsg); | |
317 | } | |
318 | } | |
15e8b082 | 319 | myRetrievableStatus = theReader->GetStatus(); |
7fd59977 | 320 | theDocument->SetMetaData(aMetaData); |
321 | ||
322 | theDocumentToReturn=theDocument; | |
323 | } | |
324 | else | |
325 | theDocumentToReturn=aMetaData->Document(); | |
326 | ||
327 | return theDocumentToReturn; | |
328 | } | |
329 | ||
330 | //======================================================================= | |
331 | //function : DocumentVersion | |
332 | //purpose : | |
333 | //======================================================================= | |
334 | Standard_Integer CDF_Application::DocumentVersion(const Handle(CDM_MetaData)& theMetaData) { | |
335 | // const Handle(CDM_MessageDriver)& aMsgDriver = MessageDriver(); | |
336 | return PCDM_RetrievalDriver::DocumentVersion(theMetaData->FileName(), MessageDriver()); | |
337 | } | |
338 | ||
339 | //======================================================================= | |
340 | //function : TypeOfActivation | |
341 | //purpose : | |
342 | //======================================================================= | |
343 | CDF_TypeOfActivation CDF_Application::TypeOfActivation(const Handle(CDM_MetaData)& aMetaData) { | |
344 | ||
345 | if(aMetaData->IsRetrieved()) { | |
346 | Handle(CDM_Document) theDocument=aMetaData->Document(); | |
347 | if(theDocument->IsOpened()) { | |
348 | if(theDocument->IsModified()) | |
349 | return CDF_TOA_Modified; | |
350 | else | |
351 | return CDF_TOA_Unchanged; | |
352 | } | |
353 | ||
354 | else | |
355 | return CDF_TOA_New; | |
356 | } | |
357 | return CDF_TOA_New; | |
358 | } | |
359 | ||
360 | ||
361 | //======================================================================= | |
362 | //function : FindReader | |
363 | //purpose : | |
364 | //======================================================================= | |
365 | Standard_Boolean CDF_Application::FindReader(const TCollection_ExtendedString& aFileName) { | |
366 | Standard_GUID voidGUID; | |
367 | TCollection_ExtendedString voidResourceName; | |
368 | return FindReader(aFileName,voidGUID,voidResourceName); | |
369 | } | |
370 | ||
371 | //======================================================================= | |
372 | //function : Reader | |
373 | //purpose : code dp | |
374 | //======================================================================= | |
375 | Handle(PCDM_Reader) CDF_Application::Reader (const TCollection_ExtendedString& aFileName) { | |
376 | TCollection_ExtendedString theFormat; | |
377 | if (!Format(aFileName,theFormat)) { | |
378 | Standard_SStream aMsg; | |
379 | aMsg << "Could not found the format" <<(char)0; | |
380 | Standard_NoSuchObject::Raise(aMsg); | |
381 | ||
382 | } | |
383 | return ReaderFromFormat (theFormat); | |
384 | } | |
385 | ||
4ff92abe | 386 | //======================================================================= |
387 | //function : Read | |
388 | //purpose : | |
389 | //======================================================================= | |
390 | Handle(CDM_Document) CDF_Application::Read (Standard_IStream& theIStream) | |
391 | { | |
392 | Handle(CDM_Document) aDoc; | |
393 | Handle(Storage_Data) dData; | |
394 | ||
395 | TCollection_ExtendedString aFormat; | |
396 | ||
397 | try | |
398 | { | |
399 | OCC_CATCH_SIGNALS | |
400 | ||
401 | aFormat = PCDM_ReadWriter::FileFormat (theIStream, dData); | |
402 | } | |
403 | catch (Standard_Failure) | |
404 | { | |
405 | myRetrievableStatus = PCDM_RS_FormatFailure; | |
406 | ||
407 | Standard_SStream aMsg; | |
408 | aMsg << Standard_Failure::Caught() << endl; | |
409 | Standard_Failure::Raise(aMsg); | |
410 | } | |
411 | ||
412 | if (aFormat.IsEmpty()) | |
413 | { | |
414 | myRetrievableStatus = PCDM_RS_FormatFailure; | |
415 | return aDoc; | |
416 | } | |
417 | ||
418 | // 1. use a format name to detect plugin corresponding to the format to continue reading | |
419 | Handle(PCDM_Reader) aReader = ReaderFromFormat (aFormat); | |
420 | ||
421 | // 2. create document with the detected reader | |
422 | aDoc = aReader->CreateDocument(); | |
423 | ||
424 | // 3. read the content of theIStream to aDoc | |
425 | try | |
426 | { | |
427 | OCC_CATCH_SIGNALS | |
428 | ||
429 | aReader->Read (theIStream, dData, aDoc, this); | |
430 | } | |
431 | catch (Standard_Failure) | |
432 | { | |
433 | myRetrievableStatus = aReader->GetStatus(); | |
434 | if (myRetrievableStatus > PCDM_RS_AlreadyRetrieved) | |
435 | { | |
436 | Standard_SStream aMsg; | |
437 | aMsg << Standard_Failure::Caught() << endl; | |
438 | Standard_Failure::Raise(aMsg); | |
439 | } | |
440 | } | |
441 | ||
442 | myRetrievableStatus = aReader->GetStatus(); | |
443 | ||
444 | return aDoc; | |
445 | } | |
446 | ||
7fd59977 | 447 | //======================================================================= |
448 | //function : FindReaderFromFormat | |
449 | //purpose : | |
450 | //======================================================================= | |
451 | Standard_Boolean CDF_Application::FindReaderFromFormat(const TCollection_ExtendedString& aFormat) { | |
452 | Standard_GUID voidGUID; | |
453 | TCollection_ExtendedString voidResourceName; | |
454 | return FindReaderFromFormat(aFormat,voidGUID,voidResourceName); | |
455 | } | |
456 | ||
457 | ||
458 | //======================================================================= | |
459 | //function : ReaderFromFormat | |
460 | //purpose : | |
461 | //======================================================================= | |
462 | Handle(PCDM_Reader) CDF_Application::ReaderFromFormat(const TCollection_ExtendedString& aFormat) { | |
463 | TCollection_ExtendedString UnfoundResourceName; | |
464 | Standard_GUID thePluginId; | |
465 | if(!FindReaderFromFormat(aFormat,thePluginId,UnfoundResourceName)) { | |
466 | Standard_SStream aMsg; | |
467 | aMsg << "Could not found the item:" << UnfoundResourceName <<(char)0; | |
15e8b082 | 468 | myRetrievableStatus = PCDM_RS_WrongResource; |
7fd59977 | 469 | Standard_NoSuchObject::Raise(aMsg); |
470 | } | |
471 | Handle(PCDM_Reader) R; | |
472 | try { | |
473 | OCC_CATCH_SIGNALS | |
474 | R = Handle(PCDM_Reader)::DownCast(Plugin::Load(thePluginId)); | |
475 | } | |
476 | catch (Standard_Failure) { | |
15e8b082 | 477 | myRetrievableStatus = PCDM_RS_WrongResource; |
7fd59977 | 478 | Standard_SStream aMsg; |
479 | aMsg << Standard_Failure::Caught() << endl; | |
480 | Standard_Failure::Raise(aMsg); | |
481 | } | |
482 | Handle(PCDM_RetrievalDriver) RD = Handle(PCDM_RetrievalDriver)::DownCast(R); | |
483 | if (!RD.IsNull()) { | |
484 | RD->SetFormat(aFormat); | |
485 | return RD; | |
486 | } else | |
15e8b082 | 487 | myRetrievableStatus = PCDM_RS_WrongResource; |
7fd59977 | 488 | return R; |
489 | } | |
490 | ||
491 | //======================================================================= | |
492 | //function : FindReader | |
493 | //purpose : | |
494 | //======================================================================= | |
495 | Standard_Boolean CDF_Application::FindReader(const TCollection_ExtendedString& aFileName, Standard_GUID& thePluginId, TCollection_ExtendedString& ResourceName) { | |
496 | ||
497 | TCollection_ExtendedString theFormat=PCDM_ReadWriter::FileFormat(aFileName); | |
498 | ||
0d969553 | 499 | // It is good if the format is in the file. Otherwise base on the extension. |
7fd59977 | 500 | |
501 | if(theFormat.Length()==0) { | |
502 | ResourceName=UTL::Extension(aFileName); | |
503 | ResourceName+=".FileFormat"; | |
504 | ||
505 | if(UTL::Find(Resources(),ResourceName)) { | |
506 | theFormat=UTL::Value(Resources(),ResourceName); | |
507 | } | |
508 | else | |
509 | return Standard_False; | |
510 | } | |
511 | return FindReaderFromFormat(theFormat,thePluginId,ResourceName); | |
512 | } | |
513 | ||
514 | //======================================================================= | |
515 | //function : Format | |
516 | //purpose : dp | |
517 | //======================================================================= | |
518 | Standard_Boolean CDF_Application::Format(const TCollection_ExtendedString& aFileName, | |
519 | TCollection_ExtendedString& theFormat) | |
520 | { | |
521 | ||
522 | theFormat = PCDM_ReadWriter::FileFormat(aFileName); | |
0d969553 | 523 | // It is good if the format is in the file. Otherwise base on the extension. |
7fd59977 | 524 | if(theFormat.Length()==0) { |
525 | TCollection_ExtendedString ResourceName; | |
526 | ResourceName=UTL::Extension(aFileName); | |
527 | ResourceName+=".FileFormat"; | |
528 | ||
529 | if(UTL::Find(Resources(),ResourceName)) { | |
530 | theFormat = UTL::Value(Resources(),ResourceName); | |
531 | } | |
532 | else return Standard_False; | |
533 | } | |
534 | return Standard_True; | |
535 | } | |
536 | ||
537 | //======================================================================= | |
538 | //function : FindReaderFromFormat | |
539 | //purpose : | |
540 | //======================================================================= | |
541 | Standard_Boolean CDF_Application::FindReaderFromFormat(const TCollection_ExtendedString& aFormat, Standard_GUID& thePluginId, TCollection_ExtendedString& ResourceName) { | |
542 | ||
543 | ResourceName=aFormat; | |
544 | ResourceName+=".RetrievalPlugin"; | |
545 | ||
546 | if(UTL::Find(Resources(),ResourceName)) { | |
bf4bf038 | 547 | // Get GUID as a string. |
548 | TCollection_ExtendedString strPluginId = UTL::Value(Resources(),ResourceName); | |
549 | ||
550 | // If the GUID (as a string) contains blanks, remove them. | |
551 | if (strPluginId.Search(' ') != -1) | |
552 | strPluginId.RemoveAll(' '); | |
553 | ||
554 | // Convert to GUID. | |
555 | thePluginId=UTL::GUID(strPluginId); | |
7fd59977 | 556 | return Standard_True; |
557 | } | |
558 | return Standard_False; | |
559 | } | |
560 | ||
561 | //======================================================================= | |
562 | //function : CanRetrieve | |
563 | //purpose : | |
564 | //======================================================================= | |
15e8b082 | 565 | PCDM_ReaderStatus CDF_Application::CanRetrieve(const Handle(CDM_MetaData)& aMetaData) { |
7fd59977 | 566 | if(aMetaData->HasVersion()) |
567 | return CanRetrieve(aMetaData->Folder(),aMetaData->Name(),aMetaData->Version()); | |
568 | else | |
569 | return CanRetrieve(aMetaData->Folder(),aMetaData->Name()); | |
570 | } |