Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1999-06-30 |
2 | // Created by: Denis PASCAL | |
3 | // Copyright (c) 1999-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. | |
7fd59977 | 16 | |
bc73b006 | 17 | #include <TDocStd_Application.hxx> |
7fd59977 | 18 | |
7fd59977 | 19 | #include <CDF_Directory.hxx> |
42cf5bc1 | 20 | #include <CDF_DirectoryIterator.hxx> |
42cf5bc1 | 21 | #include <CDF_Store.hxx> |
6fe96f84 | 22 | #include <PCDM_RetrievalDriver.hxx> |
4ff92abe | 23 | #include <PCDM_StorageDriver.hxx> |
d5c71e20 | 24 | #include <PCDM_ReaderFilter.hxx> |
4ff92abe | 25 | #include <Plugin.hxx> |
42cf5bc1 | 26 | #include <Plugin_Failure.hxx> |
27 | #include <Resource_Manager.hxx> | |
28 | #include <Standard_DomainError.hxx> | |
bc73b006 | 29 | #include <Standard_Dump.hxx> |
7fd59977 | 30 | #include <Standard_ErrorHandler.hxx> |
42cf5bc1 | 31 | #include <Standard_NoSuchObject.hxx> |
7fd59977 | 32 | #include <Standard_NotImplemented.hxx> |
42cf5bc1 | 33 | #include <TCollection_ExtendedString.hxx> |
42cf5bc1 | 34 | #include <TDocStd_Document.hxx> |
35 | #include <TDocStd_Owner.hxx> | |
7fd59977 | 36 | #include <TDocStd_PathParser.hxx> |
d9d03f10 | 37 | #include <OSD_Thread.hxx> |
7fd59977 | 38 | |
92efcf78 | 39 | IMPLEMENT_STANDARD_RTTIEXT(TDocStd_Application,CDF_Application) |
40 | ||
7fd59977 | 41 | // TDocStd_Owner attribute have pointer of closed TDocStd_Document |
7fd59977 | 42 | //======================================================================= |
43 | //function : TDocStd_Application | |
44 | //purpose : | |
45 | //======================================================================= | |
7fd59977 | 46 | TDocStd_Application::TDocStd_Application() |
83ae3591 | 47 | : myIsDriverLoaded (Standard_True) |
7fd59977 | 48 | { |
d9d03f10 | 49 | if(myMetaDataDriver.IsNull()) |
7fd59977 | 50 | myIsDriverLoaded = Standard_False; |
7fd59977 | 51 | } |
52 | ||
7fd59977 | 53 | //======================================================================= |
54 | //function : IsDriverLoaded | |
55 | //purpose : | |
56 | //======================================================================= | |
57 | Standard_Boolean TDocStd_Application::IsDriverLoaded() const | |
58 | { | |
59 | return myIsDriverLoaded; | |
60 | } | |
61 | ||
62 | //======================================================================= | |
63 | //function : Resources | |
64 | //purpose : | |
65 | //======================================================================= | |
66 | ||
67 | Handle(Resource_Manager) TDocStd_Application::Resources() { | |
68 | if (myResources.IsNull()) { | |
69 | myResources = new Resource_Manager(ResourcesName()); | |
70 | } | |
71 | return myResources; | |
72 | } | |
73 | ||
6fe96f84 | 74 | //======================================================================= |
75 | //function : ResourcesName | |
76 | //purpose : | |
77 | //======================================================================= | |
78 | ||
79 | Standard_CString TDocStd_Application::ResourcesName() | |
80 | { | |
81 | return ""; | |
82 | } | |
83 | ||
84 | //======================================================================= | |
85 | //function : DefineFormat | |
86 | //purpose : | |
87 | //======================================================================= | |
88 | void TDocStd_Application::DefineFormat (const TCollection_AsciiString& theFormat, | |
89 | const TCollection_AsciiString& theDescription, | |
90 | const TCollection_AsciiString& theExtension, | |
91 | const Handle(PCDM_RetrievalDriver)& theReader, | |
92 | const Handle(PCDM_StorageDriver)& theWriter) | |
93 | { | |
94 | // register resources for CDM mechanics to work | |
95 | Handle(Resource_Manager) aResources = Resources(); | |
96 | aResources->SetResource ((theFormat + ".Description" ).ToCString(), theDescription.ToCString()); | |
97 | aResources->SetResource ((theFormat + ".FileExtension").ToCString(), theExtension.ToCString()); | |
98 | aResources->SetResource ((theExtension + ".FileFormat").ToCString(), theFormat.ToCString()); | |
99 | ||
100 | // set format ID in the drivers to allow them putting it in | |
101 | // the OCAF documents opened by these drivers | |
102 | if (!theReader.IsNull()) | |
103 | theReader->SetFormat(theFormat); | |
104 | if (!theWriter.IsNull()) | |
105 | theWriter->SetFormat(theFormat); | |
106 | ||
107 | // register drivers | |
2613378e | 108 | myReaders.Add(theFormat, theReader); |
109 | myWriters.Add(theFormat, theWriter); | |
110 | } | |
111 | ||
112 | //======================================================================= | |
113 | //function : ReadingFormats | |
114 | //purpose : | |
115 | //======================================================================= | |
116 | ||
117 | void TDocStd_Application::ReadingFormats(TColStd_SequenceOfAsciiString &theFormats) | |
118 | { | |
119 | theFormats.Clear(); | |
120 | ||
121 | NCollection_IndexedDataMap<TCollection_ExtendedString, Handle(PCDM_RetrievalDriver)>::Iterator | |
122 | anIter(myReaders); | |
123 | for (; anIter.More(); anIter.Next()) { | |
124 | Handle(PCDM_RetrievalDriver) aDriver = anIter.Value(); | |
125 | if (aDriver.IsNull() == Standard_False) { | |
126 | theFormats.Append(anIter.Key()); | |
127 | } | |
128 | } | |
129 | } | |
130 | ||
131 | //======================================================================= | |
132 | //function : WritingFormats | |
133 | //purpose : | |
134 | //======================================================================= | |
135 | ||
136 | void TDocStd_Application::WritingFormats(TColStd_SequenceOfAsciiString &theFormats) | |
137 | { | |
138 | theFormats.Clear(); | |
139 | ||
140 | NCollection_IndexedDataMap<TCollection_ExtendedString, Handle(PCDM_StorageDriver)>::Iterator | |
141 | anIter(myWriters); | |
142 | for (; anIter.More(); anIter.Next()) { | |
143 | Handle(PCDM_StorageDriver) aDriver = anIter.Value(); | |
144 | if (aDriver.IsNull() == Standard_False) { | |
145 | theFormats.Append(anIter.Key()); | |
146 | } | |
147 | } | |
6fe96f84 | 148 | } |
7fd59977 | 149 | |
150 | //======================================================================= | |
151 | //function : NbDocuments | |
152 | //purpose : | |
153 | //======================================================================= | |
154 | ||
155 | Standard_Integer TDocStd_Application::NbDocuments() const | |
156 | { | |
8a39adb7 | 157 | return myDirectory->Length(); |
7fd59977 | 158 | } |
159 | ||
160 | //======================================================================= | |
161 | //function : GetDocument | |
162 | //purpose : | |
163 | //======================================================================= | |
164 | ||
d5c71e20 | 165 | void TDocStd_Application::GetDocument(const Standard_Integer index,Handle(TDocStd_Document)& theDoc) const |
7fd59977 | 166 | { |
d9d03f10 | 167 | CDF_DirectoryIterator it (myDirectory); |
7fd59977 | 168 | Standard_Integer current = 0; |
169 | for (;it.MoreDocument();it.NextDocument()) { | |
170 | current++; | |
171 | if (index == current) { | |
172 | Handle(TDocStd_Document) D = | |
173 | Handle(TDocStd_Document)::DownCast(it.Document()); | |
d5c71e20 | 174 | theDoc = D; |
7fd59977 | 175 | return; |
176 | } | |
177 | } | |
178 | } | |
179 | ||
180 | //======================================================================= | |
181 | //function : NewDocument | |
182 | //purpose : | |
183 | //======================================================================= | |
184 | ||
d5c71e20 | 185 | void TDocStd_Application::NewDocument(const TCollection_ExtendedString& format, Handle(CDM_Document)& theDoc) |
7fd59977 | 186 | { |
187 | Handle(TDocStd_Document) D = new TDocStd_Document(format); | |
188 | InitDocument (D); | |
189 | CDF_Application::Open(D); // add the document in the session | |
d5c71e20 | 190 | theDoc = D; |
7fd59977 | 191 | } |
192 | ||
5fd0b800 | 193 | //======================================================================= |
194 | //function : NewDocument | |
195 | //purpose : A non-virtual method taking a TDocStd_Documment object as an input. | |
196 | // : Internally it calls a virtual method NewDocument() with CDM_Document object. | |
197 | //======================================================================= | |
198 | ||
d5c71e20 | 199 | void TDocStd_Application::NewDocument (const TCollection_ExtendedString& format, Handle(TDocStd_Document)& theDoc) |
5fd0b800 | 200 | { |
201 | Handle(CDM_Document) aCDMDoc; | |
202 | NewDocument (format, aCDMDoc); | |
d5c71e20 | 203 | theDoc = Handle(TDocStd_Document)::DownCast (aCDMDoc); |
5fd0b800 | 204 | } |
205 | ||
7fd59977 | 206 | //======================================================================= |
207 | //function : InitDocument | |
208 | //purpose : do nothing | |
209 | //======================================================================= | |
210 | ||
5fd0b800 | 211 | void TDocStd_Application::InitDocument(const Handle(CDM_Document)& /*aDoc*/) const |
7fd59977 | 212 | { |
213 | } | |
214 | ||
7fd59977 | 215 | //======================================================================= |
216 | //function : Close | |
217 | //purpose : | |
218 | //======================================================================= | |
219 | ||
d5c71e20 | 220 | void TDocStd_Application::Close(const Handle(TDocStd_Document)& theDoc) |
7fd59977 | 221 | { |
d5c71e20 | 222 | if (theDoc.IsNull()) |
b6c0b841 RL |
223 | { |
224 | return; | |
225 | } | |
226 | ||
7fd59977 | 227 | Handle(TDocStd_Owner) Owner; |
d5c71e20 | 228 | if (theDoc->Main().Root().FindAttribute(TDocStd_Owner::GetID(),Owner)) { |
7fd59977 | 229 | Handle(TDocStd_Document) emptyDoc; |
230 | Owner->SetDocument(emptyDoc); | |
231 | } | |
d5c71e20 | 232 | theDoc->BeforeClose(); |
233 | CDF_Application::Close(theDoc); | |
7fd59977 | 234 | } |
7fd59977 | 235 | |
236 | //======================================================================= | |
237 | //function : IsInSession | |
238 | //purpose : | |
239 | //======================================================================= | |
240 | ||
241 | Standard_Integer TDocStd_Application::IsInSession (const TCollection_ExtendedString& path) const | |
242 | { | |
bcb0fd43 V |
243 | TCollection_ExtendedString unifiedPath(path); |
244 | unifiedPath.ChangeAll('/', '|'); | |
245 | unifiedPath.ChangeAll('\\', '|'); | |
246 | ||
247 | Standard_Integer nbdoc = NbDocuments(); | |
248 | Handle(TDocStd_Document) D; | |
249 | for (Standard_Integer i = 1; i <= nbdoc; i++) | |
250 | { | |
251 | GetDocument(i,D); | |
252 | if (D->IsSaved()) | |
253 | { | |
254 | TCollection_ExtendedString unifiedDocPath(D->GetPath()); | |
255 | unifiedDocPath.ChangeAll('/', '|'); | |
256 | unifiedDocPath.ChangeAll('\\', '|'); | |
257 | ||
258 | if (unifiedPath == unifiedDocPath) | |
259 | return i; | |
260 | } | |
7fd59977 | 261 | } |
bcb0fd43 | 262 | return 0; |
7fd59977 | 263 | } |
264 | ||
265 | //======================================================================= | |
266 | //function : Open | |
267 | //purpose : | |
268 | //======================================================================= | |
269 | ||
7e785937 | 270 | PCDM_ReaderStatus TDocStd_Application::Open (const TCollection_ExtendedString& path, |
d5c71e20 | 271 | Handle(TDocStd_Document)& theDoc, |
272 | const Handle(PCDM_ReaderFilter)& theFilter, | |
7e785937 | 273 | const Message_ProgressRange& theRange) |
6d8f9f4a | 274 | { |
15e8b082 | 275 | PCDM_ReaderStatus status = PCDM_RS_DriverFailure; |
7fd59977 | 276 | TDocStd_PathParser tool (path); |
277 | TCollection_ExtendedString directory = tool.Trek(); | |
278 | TCollection_ExtendedString file = tool.Name(); | |
6d8f9f4a | 279 | file += "."; |
280 | file += tool.Extension(); | |
d5c71e20 | 281 | status = CanRetrieve(directory, file, !theFilter.IsNull() && theFilter->IsAppendMode()); |
6d8f9f4a | 282 | |
283 | if (status != PCDM_RS_OK) | |
284 | { | |
285 | return status; | |
286 | } | |
287 | ||
288 | try | |
289 | { | |
7fd59977 | 290 | OCC_CATCH_SIGNALS |
291 | Handle(TDocStd_Document) D = | |
d5c71e20 | 292 | Handle(TDocStd_Document)::DownCast(Retrieve(directory, file, Standard_True, theFilter, theRange)); |
293 | if (theFilter.IsNull() || !theFilter->IsAppendMode()) | |
294 | CDF_Application::Open(D); | |
295 | theDoc = D; | |
7fd59977 | 296 | } |
6d8f9f4a | 297 | catch (Standard_Failure const& anException) |
298 | { | |
299 | // status = GetRetrieveStatus(); | |
300 | if (!MessageDriver().IsNull()) | |
301 | { | |
302 | // Standard_SStream aMsg; | |
303 | // aMsg << Standard_Failure::Caught() << std::endl; | |
304 | // std::cout << "TDocStd_Application::Open(): " << aMsg.rdbuf()->str() << std::endl; | |
9775fa61 | 305 | TCollection_ExtendedString aString (anException.GetMessageString()); |
83ae3591 | 306 | MessageDriver()->Send(aString.ToExtString(), Message_Fail); |
7fd59977 | 307 | } |
308 | } | |
309 | status = GetRetrieveStatus(); | |
0797d9d3 | 310 | #ifdef OCCT_DEBUG |
6d8f9f4a | 311 | std::cout << "TDocStd_Application::Open(): The status = " << status << std::endl; |
7fd59977 | 312 | #endif |
313 | return status; | |
314 | } | |
315 | ||
4ff92abe | 316 | //======================================================================= |
317 | //function : Open | |
318 | //purpose : | |
319 | //======================================================================= | |
7e785937 | 320 | PCDM_ReaderStatus TDocStd_Application::Open (Standard_IStream& theIStream, |
321 | Handle(TDocStd_Document)& theDoc, | |
d5c71e20 | 322 | const Handle(PCDM_ReaderFilter)& theFilter, |
7e785937 | 323 | const Message_ProgressRange& theRange) |
4ff92abe | 324 | { |
325 | try | |
326 | { | |
327 | OCC_CATCH_SIGNALS | |
d5c71e20 | 328 | Handle(CDM_Document) aCDMDoc = theDoc; |
329 | Read(theIStream, aCDMDoc, theFilter, theRange); | |
330 | // Read calls NewDocument of TDocStd_Application, so, it should the TDocStd_Document in the result anyway | |
331 | theDoc = Handle(TDocStd_Document)::DownCast(aCDMDoc); | |
4ff92abe | 332 | |
d5c71e20 | 333 | if (!theDoc.IsNull() && (theFilter.IsNull() || !theFilter->IsAppendMode())) |
4ff92abe | 334 | { |
d5c71e20 | 335 | CDF_Application::Open(theDoc); |
4ff92abe | 336 | } |
337 | } | |
6d8f9f4a | 338 | |
9775fa61 | 339 | catch (Standard_Failure const& anException) |
4ff92abe | 340 | { |
9775fa61 | 341 | if (!MessageDriver().IsNull()) |
4ff92abe | 342 | { |
9775fa61 | 343 | TCollection_ExtendedString aFailureMessage (anException.GetMessageString()); |
83ae3591 | 344 | MessageDriver()->Send (aFailureMessage.ToExtString(), Message_Fail); |
4ff92abe | 345 | } |
346 | } | |
4ff92abe | 347 | return GetRetrieveStatus(); |
348 | } | |
349 | ||
7fd59977 | 350 | //======================================================================= |
351 | //function : SaveAs | |
352 | //purpose : | |
353 | //======================================================================= | |
354 | ||
d5c71e20 | 355 | PCDM_StoreStatus TDocStd_Application::SaveAs (const Handle(TDocStd_Document)& theDoc, |
7e785937 | 356 | const TCollection_ExtendedString& path, |
357 | const Message_ProgressRange& theRange) | |
6d8f9f4a | 358 | { |
7fd59977 | 359 | TDocStd_PathParser tool (path); |
360 | TCollection_ExtendedString directory = tool.Trek(); | |
361 | TCollection_ExtendedString file = tool.Name(); | |
362 | file+="."; | |
363 | file+=tool.Extension(); | |
d5c71e20 | 364 | theDoc->Open(this); |
365 | CDF_Store storer (theDoc); | |
7fd59977 | 366 | if (!storer.SetFolder(directory)) |
367 | { | |
368 | TCollection_ExtendedString aMsg ("TDocStd_Application::SaveAs() - folder "); | |
369 | aMsg += directory; | |
370 | aMsg += " does not exist"; | |
371 | if(!MessageDriver().IsNull()) | |
83ae3591 | 372 | MessageDriver()->Send(aMsg.ToExtString(), Message_Fail); |
7fd59977 | 373 | return storer.StoreStatus(); //CDF_SS_Failure; |
374 | } | |
7fd59977 | 375 | storer.SetName (file); |
376 | try { | |
377 | OCC_CATCH_SIGNALS | |
7e785937 | 378 | storer.Realize (theRange); |
7fd59977 | 379 | } |
9775fa61 | 380 | catch (Standard_Failure const& anException) { |
381 | if (!MessageDriver().IsNull()) { | |
382 | TCollection_ExtendedString aString (anException.GetMessageString()); | |
83ae3591 | 383 | MessageDriver()->Send(aString.ToExtString(), Message_Fail); |
7fd59977 | 384 | } |
385 | } | |
15e8b082 | 386 | if(storer.StoreStatus() == PCDM_SS_OK) |
d5c71e20 | 387 | theDoc->SetSaved(); |
0797d9d3 | 388 | #ifdef OCCT_DEBUG |
04232180 | 389 | std::cout<<"TDocStd_Application::SaveAs(): The status = "<<storer.StoreStatus()<<std::endl; |
7fd59977 | 390 | #endif |
391 | return storer.StoreStatus(); | |
7fd59977 | 392 | } |
393 | ||
4ff92abe | 394 | //======================================================================= |
395 | //function : SaveAs | |
396 | //purpose : | |
397 | //======================================================================= | |
6d8f9f4a | 398 | PCDM_StoreStatus TDocStd_Application::SaveAs(const Handle(TDocStd_Document)& theDoc, |
399 | Standard_OStream& theOStream, | |
7e785937 | 400 | const Message_ProgressRange& theRange) |
4ff92abe | 401 | { |
6fe96f84 | 402 | try |
4ff92abe | 403 | { |
6fe96f84 | 404 | Handle(PCDM_StorageDriver) aDocStorageDriver = WriterFromFormat(theDoc->StorageFormat()); |
4ff92abe | 405 | |
6fe96f84 | 406 | if (aDocStorageDriver.IsNull()) |
407 | { | |
408 | return PCDM_SS_DriverFailure; | |
409 | } | |
4ff92abe | 410 | |
6fe96f84 | 411 | aDocStorageDriver->SetFormat(theDoc->StorageFormat()); |
7e785937 | 412 | aDocStorageDriver->Write(theDoc, theOStream, theRange); |
4ff92abe | 413 | |
6fe96f84 | 414 | if (aDocStorageDriver->GetStoreStatus() == PCDM_SS_OK) |
4ff92abe | 415 | { |
6fe96f84 | 416 | theDoc->SetSaved(); |
4ff92abe | 417 | } |
6fe96f84 | 418 | |
419 | return aDocStorageDriver->GetStoreStatus(); | |
4ff92abe | 420 | } |
9775fa61 | 421 | catch (Standard_Failure const& anException) |
4ff92abe | 422 | { |
9775fa61 | 423 | if (!MessageDriver().IsNull()) |
6fe96f84 | 424 | { |
9775fa61 | 425 | TCollection_ExtendedString aString(anException.GetMessageString()); |
83ae3591 | 426 | MessageDriver()->Send(aString.ToExtString(), Message_Fail); |
6fe96f84 | 427 | } |
4ff92abe | 428 | } |
6fe96f84 | 429 | return PCDM_SS_Failure; |
4ff92abe | 430 | } |
431 | ||
7fd59977 | 432 | //======================================================================= |
433 | //function : Save | |
434 | //purpose : | |
435 | //======================================================================= | |
436 | ||
6d8f9f4a | 437 | PCDM_StoreStatus TDocStd_Application::Save (const Handle(TDocStd_Document)& D, |
7e785937 | 438 | const Message_ProgressRange& theRange) |
6d8f9f4a | 439 | { |
15e8b082 | 440 | PCDM_StoreStatus status = PCDM_SS_OK; |
7fd59977 | 441 | if (D->IsSaved()) { |
442 | CDF_Store storer (D); | |
443 | try{ | |
444 | OCC_CATCH_SIGNALS | |
7e785937 | 445 | storer.Realize (theRange); |
7fd59977 | 446 | } |
9775fa61 | 447 | catch (Standard_Failure const& anException) { |
448 | if (!MessageDriver().IsNull()) { | |
449 | TCollection_ExtendedString aString (anException.GetMessageString()); | |
83ae3591 | 450 | MessageDriver()->Send(aString.ToExtString(), Message_Fail); |
7fd59977 | 451 | } |
452 | } | |
15e8b082 | 453 | if(storer.StoreStatus() == PCDM_SS_OK) |
7fd59977 | 454 | D->SetSaved(); |
7fd59977 | 455 | status = storer.StoreStatus(); |
7fd59977 | 456 | } else { |
7fd59977 | 457 | if(!MessageDriver().IsNull()) { |
15e8b082 | 458 | TCollection_ExtendedString aMsg("Document has not been saved yet"); |
83ae3591 | 459 | MessageDriver()->Send(aMsg.ToExtString(), Message_Fail); |
7fd59977 | 460 | } |
15e8b082 | 461 | status = PCDM_SS_Failure; |
7fd59977 | 462 | } |
0797d9d3 | 463 | #ifdef OCCT_DEBUG |
04232180 | 464 | std::cout<<"TDocStd_Application::Save(): The status = "<<status<<std::endl; |
7fd59977 | 465 | #endif |
466 | return status; | |
7fd59977 | 467 | } |
468 | ||
7fd59977 | 469 | //======================================================================= |
470 | //function : SaveAs | |
471 | //purpose : | |
472 | //======================================================================= | |
473 | ||
15e8b082 | 474 | PCDM_StoreStatus TDocStd_Application::SaveAs(const Handle(TDocStd_Document)& D, |
83ae3591 | 475 | const TCollection_ExtendedString& path, |
6d8f9f4a | 476 | TCollection_ExtendedString& theStatusMessage, |
7e785937 | 477 | const Message_ProgressRange& theRange) |
7fd59977 | 478 | { |
479 | TDocStd_PathParser tool (path); | |
15e8b082 | 480 | PCDM_StoreStatus aStatus = PCDM_SS_Failure; |
7fd59977 | 481 | TCollection_ExtendedString directory = tool.Trek(); |
482 | TCollection_ExtendedString file = tool.Name(); | |
483 | file+="."; | |
484 | file+=tool.Extension(); | |
485 | D->Open(this); | |
486 | CDF_Store storer (D); | |
487 | if (storer.SetFolder(directory)) { | |
488 | storer.SetName (file); | |
489 | try { | |
490 | OCC_CATCH_SIGNALS | |
7e785937 | 491 | storer.Realize (theRange); |
7fd59977 | 492 | } |
9775fa61 | 493 | catch (Standard_Failure const& anException) { |
494 | if (!MessageDriver().IsNull()) { | |
495 | TCollection_ExtendedString aString (anException.GetMessageString()); | |
83ae3591 | 496 | MessageDriver()->Send(aString.ToExtString(), Message_Fail); |
7fd59977 | 497 | } |
498 | } | |
15e8b082 | 499 | if(storer.StoreStatus() == PCDM_SS_OK) |
7fd59977 | 500 | D->SetSaved(); |
501 | theStatusMessage = storer.AssociatedStatusText(); | |
502 | aStatus = storer.StoreStatus(); | |
503 | } else { | |
504 | theStatusMessage = | |
505 | TCollection_ExtendedString("TDocStd_Application::SaveAs" | |
506 | ": No such directory ") + directory; | |
15e8b082 | 507 | aStatus = PCDM_SS_Failure; |
7fd59977 | 508 | } |
509 | return aStatus; | |
510 | } | |
511 | ||
4ff92abe | 512 | //======================================================================= |
513 | //function : SaveAs | |
514 | //purpose : | |
515 | //======================================================================= | |
516 | ||
517 | PCDM_StoreStatus TDocStd_Application::SaveAs (const Handle(TDocStd_Document)& theDoc, | |
518 | Standard_OStream& theOStream, | |
6d8f9f4a | 519 | TCollection_ExtendedString& theStatusMessage, |
7e785937 | 520 | const Message_ProgressRange& theRange) |
4ff92abe | 521 | { |
6fe96f84 | 522 | try |
4ff92abe | 523 | { |
6fe96f84 | 524 | Handle(PCDM_StorageDriver) aDocStorageDriver = WriterFromFormat (theDoc->StorageFormat()); |
525 | if (aDocStorageDriver.IsNull()) | |
4ff92abe | 526 | { |
6fe96f84 | 527 | theStatusMessage = TCollection_ExtendedString("TDocStd_Application::SaveAs: no storage driver"); |
528 | return PCDM_SS_DriverFailure; | |
529 | } | |
4ff92abe | 530 | |
6fe96f84 | 531 | aDocStorageDriver->SetFormat(theDoc->StorageFormat()); |
7e785937 | 532 | aDocStorageDriver->Write(theDoc, theOStream, theRange); |
4ff92abe | 533 | |
6fe96f84 | 534 | if (aDocStorageDriver->GetStoreStatus() == PCDM_SS_OK) |
4ff92abe | 535 | { |
6fe96f84 | 536 | theDoc->SetSaved(); |
4ff92abe | 537 | } |
6fe96f84 | 538 | |
539 | return aDocStorageDriver->GetStoreStatus(); | |
4ff92abe | 540 | } |
9775fa61 | 541 | catch (Standard_Failure const& anException) |
4ff92abe | 542 | { |
9775fa61 | 543 | if (!MessageDriver().IsNull()) |
6fe96f84 | 544 | { |
9775fa61 | 545 | TCollection_ExtendedString aString(anException.GetMessageString()); |
83ae3591 | 546 | MessageDriver()->Send(aString.ToExtString(), Message_Fail); |
6fe96f84 | 547 | } |
4ff92abe | 548 | } |
6fe96f84 | 549 | return PCDM_SS_Failure; |
4ff92abe | 550 | } |
551 | ||
7fd59977 | 552 | //======================================================================= |
553 | //function : Save | |
554 | //purpose : | |
555 | //======================================================================= | |
556 | ||
15e8b082 | 557 | PCDM_StoreStatus TDocStd_Application::Save (const Handle(TDocStd_Document)& D, |
7e785937 | 558 | TCollection_ExtendedString& theStatusMessage, |
559 | const Message_ProgressRange& theRange) | |
7fd59977 | 560 | { |
15e8b082 | 561 | PCDM_StoreStatus status = PCDM_SS_OK; |
7fd59977 | 562 | if (D->IsSaved()) { |
563 | CDF_Store storer (D); | |
564 | try { | |
565 | OCC_CATCH_SIGNALS | |
7e785937 | 566 | storer.Realize (theRange); |
7fd59977 | 567 | } |
9775fa61 | 568 | catch (Standard_Failure const& anException) { |
569 | if (!MessageDriver().IsNull()) { | |
570 | TCollection_ExtendedString aString (anException.GetMessageString()); | |
83ae3591 | 571 | MessageDriver()->Send(aString.ToExtString(), Message_Fail); |
7fd59977 | 572 | } |
573 | } | |
15e8b082 | 574 | if(storer.StoreStatus() == PCDM_SS_OK) |
7fd59977 | 575 | D->SetSaved(); |
576 | status = storer.StoreStatus(); | |
577 | theStatusMessage = storer.AssociatedStatusText(); | |
578 | } else { | |
15e8b082 M |
579 | theStatusMessage = "TDocStd_Application::the document has not been saved yet"; |
580 | status = PCDM_SS_Failure; | |
7fd59977 | 581 | } |
582 | return status; | |
583 | } | |
584 | ||
585 | ||
586 | //======================================================================= | |
587 | //function : OnOpenTransaction | |
588 | //purpose : | |
589 | //======================================================================= | |
590 | ||
591 | void TDocStd_Application::OnOpenTransaction (const Handle(TDocStd_Document)&) | |
592 | { | |
593 | // nothing to do on this level | |
594 | } | |
595 | ||
596 | //======================================================================= | |
597 | //function : OnAbortTransaction | |
598 | //purpose : | |
599 | //======================================================================= | |
600 | ||
601 | void TDocStd_Application::OnAbortTransaction (const Handle(TDocStd_Document)&) | |
602 | { | |
603 | // nothing to do on this level | |
604 | } | |
605 | ||
606 | //======================================================================= | |
607 | //function : OnCommitTransaction | |
608 | //purpose : | |
609 | //======================================================================= | |
610 | ||
611 | void TDocStd_Application::OnCommitTransaction (const Handle(TDocStd_Document)&) | |
612 | { | |
613 | // nothing to do on this level | |
614 | } | |
bc73b006 | 615 | |
616 | //======================================================================= | |
617 | //function : DumpJson | |
618 | //purpose : | |
619 | //======================================================================= | |
620 | void TDocStd_Application::DumpJson (Standard_OStream& theOStream, Standard_Integer) const | |
621 | { | |
622 | OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) | |
623 | ||
624 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsDriverLoaded) | |
625 | } |