]> OCCT Git - occt.git/commitdiff
0032125: Application Framework, OCAF - need to have adequate message if document...
authorvro <vro@opencascade.com>
Wed, 1 Sep 2021 08:47:41 +0000 (11:47 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 3 Sep 2021 17:19:55 +0000 (20:19 +0300)
A list of storage statuses (PCDM_StoreStatus) is extended for PCDM_SS_UnrecognizedFormat. It is set if
- extension of a document file name is not defined (the extension doesn't correspond to any declared file formats) or
- a storage driver is not found for the document storage format.

Modified:
CDF_StoreList.cxx: the mechanism of raising and catching exceptions is replaced by direct setting the status and error message for each particular error.
PCDM_StoreStatus.hxx: a new enumeration value is added - PCDM_SS_UnrecognizedFormat. Also, a short explanation is added to each enumeration value.
DDocStd_ApplicationCommands.cxx: processing of a new enumeration value by the draw-command.
XDEDRAW.cxx: processed a new enumeration value PCDM_SS_UnrecognizedFormat by saveDoc draw-command.

Deleted:
CDF_MetaDataDriverError.hxx: It is not used anywhere and it seems it will not be used by someone.

src/CDF/CDF_MetaDataDriverError.hxx [deleted file]
src/CDF/CDF_StoreList.cxx
src/CDF/FILES
src/PCDM/PCDM_StoreStatus.hxx
src/TDocStd/TDocStd_Application.cxx
src/XDEDRAW/XDEDRAW.cxx

diff --git a/src/CDF/CDF_MetaDataDriverError.hxx b/src/CDF/CDF_MetaDataDriverError.hxx
deleted file mode 100644 (file)
index 4b9e173..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-// Created on: 1997-08-07
-// Created by: Jean-Louis Frenkel
-// Copyright (c) 1997-1999 Matra Datavision
-// Copyright (c) 1999-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#ifndef _CDF_MetaDataDriverError_HeaderFile
-#define _CDF_MetaDataDriverError_HeaderFile
-
-#include <Standard_Type.hxx>
-#include <Standard_DefineException.hxx>
-#include <Standard_SStream.hxx>
-#include <Standard_Failure.hxx>
-
-//! This exception is used in the deferred methods.
-//! Programmer implementing such methods may use this
-//! exception or any exception inheriting MetaDataDriverError.
-
-class CDF_MetaDataDriverError;
-DEFINE_STANDARD_HANDLE(CDF_MetaDataDriverError, Standard_Failure)
-
-#if !defined No_Exception && !defined No_CDF_MetaDataDriverError
-  #define CDF_MetaDataDriverError_Raise_if(CONDITION, MESSAGE) \
-  if (CONDITION) throw CDF_MetaDataDriverError(MESSAGE);
-#else
-  #define CDF_MetaDataDriverError_Raise_if(CONDITION, MESSAGE)
-#endif
-
-DEFINE_STANDARD_EXCEPTION(CDF_MetaDataDriverError, Standard_Failure)
-
-#endif // _CDF_MetaDataDriverError_HeaderFile
index 5ef2668fb63dd9cafb4c63e84c81952d249a1b00..e8b44c3a8666d45cc62ab1f8bded15ebd253f5e8 100644 (file)
@@ -17,7 +17,6 @@
 
 #include <CDF_Application.hxx>
 #include <CDF_MetaDataDriver.hxx>
-#include <CDF_MetaDataDriverError.hxx>
 #include <CDF_StoreList.hxx>
 #include <CDM_Document.hxx>
 #include <CDM_MetaData.hxx>
@@ -25,8 +24,6 @@
 #include <PCDM.hxx>
 #include <PCDM_Document.hxx>
 #include <PCDM_StorageDriver.hxx>
-#include <Standard_ErrorHandler.hxx>
-#include <Standard_NoSuchObject.hxx>
 #include <TCollection_ExtendedString.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(CDF_StoreList,Standard_Transient)
@@ -77,62 +74,65 @@ PCDM_StoreStatus CDF_StoreList::Store (Handle(CDM_MetaData)& aMetaData,
                                       TCollection_ExtendedString& aStatusAssociatedText, 
                                       const Message_ProgressRange& theRange)
 {
-  Handle(CDF_MetaDataDriver) theMetaDataDriver = Handle(CDF_Application)::DownCast((myMainDocument->Application()))->MetaDataDriver();
-
   PCDM_StoreStatus status = PCDM_SS_OK;
+  Handle(CDF_MetaDataDriver) theMetaDataDriver = Handle(CDF_Application)::DownCast ((myMainDocument->Application()))->MetaDataDriver();
+  for (; !myStack.IsEmpty(); myStack.RemoveFirst())
   {
-    try {
-      OCC_CATCH_SIGNALS
-      for (; !myStack.IsEmpty(); myStack.RemoveFirst()) {
-
-        Handle(CDM_Document) theDocument = myStack.First();
-        if( theDocument == myMainDocument || theDocument->IsModified()) {
-
-          Handle(CDF_Application) anApp = Handle(CDF_Application)::DownCast (theDocument->Application());
-          if (anApp.IsNull())
-          {
-            throw Standard_Failure("Document has no application, cannot save!");
-          }
-          Handle(PCDM_StorageDriver) aDocumentStorageDriver = 
-            anApp->WriterFromFormat(theDocument->StorageFormat());
+    Handle(CDM_Document) theDocument = myStack.First();
+    if (theDocument == myMainDocument || theDocument->IsModified())
+    {
+      try
+      {
+        OCC_CATCH_SIGNALS
+        Handle(CDF_Application) anApp = Handle(CDF_Application)::DownCast (theDocument->Application());
+        if (anApp.IsNull())
+        {
+          aStatusAssociatedText = "driver failed; reason: ";
+          aStatusAssociatedText += "document has no application, cannot save!";
+          status = PCDM_SS_Failure; 
+        }
+        else
+        {
+          Handle(PCDM_StorageDriver) aDocumentStorageDriver = anApp->WriterFromFormat(theDocument->StorageFormat());
           if (aDocumentStorageDriver.IsNull())
           {
-            Standard_SStream aMsg;
-            aMsg <<"No storage driver does exist for this format: " << theDocument->StorageFormat() << (char)0;
-            throw Standard_Failure(aMsg.str().c_str());
-          }
-
-          // Reset the store-status.
-          // It has sense in multi-threaded access to the storage driver - this way we reset the status for each call.
-          aDocumentStorageDriver->SetStoreStatus(PCDM_SS_OK);
-
-          if(!theMetaDataDriver->FindFolder(theDocument->RequestedFolder())) {
-            Standard_SStream aMsg; aMsg << "could not find the active dbunit";
-            aMsg << TCollection_ExtendedString(theDocument->RequestedFolder())<< (char)0;
-            throw Standard_NoSuchObject(aMsg.str().c_str());
+            aStatusAssociatedText = "driver not found; reason: no storage driver does exist for this format: ";
+            aStatusAssociatedText += theDocument->StorageFormat();
+            status = PCDM_SS_UnrecognizedFormat;
           }
-          TCollection_ExtendedString theName=theMetaDataDriver->BuildFileName(theDocument);
-
-          aDocumentStorageDriver->Write(theDocument, theName, theRange);
-          status = aDocumentStorageDriver->GetStoreStatus();
-          aMetaData = theMetaDataDriver->CreateMetaData(theDocument,theName);
-          theDocument->SetMetaData(aMetaData);
-
-          CDM_ReferenceIterator it(theDocument);
-          for(; it.More();it.Next()) {
-            theMetaDataDriver->CreateReference(aMetaData,it.Document()->MetaData(),it.ReferenceIdentifier(),it.DocumentVersion());
+          else
+          {
+            // Reset the store-status.
+            // It has sense in multi-threaded access to the storage driver - this way we reset the status for each call.
+            aDocumentStorageDriver->SetStoreStatus(PCDM_SS_OK);
+
+            if (!theMetaDataDriver->FindFolder(theDocument->RequestedFolder()))
+            {
+              aStatusAssociatedText = "driver not found; reason: ";
+              aStatusAssociatedText += "could not find the active dbunit ";
+              aStatusAssociatedText += theDocument->RequestedFolder();
+              status = PCDM_SS_UnrecognizedFormat;
+            }
+            else
+            {
+              TCollection_ExtendedString theName = theMetaDataDriver->BuildFileName (theDocument);
+              aDocumentStorageDriver->Write (theDocument, theName, theRange);
+              status = aDocumentStorageDriver->GetStoreStatus();
+              aMetaData = theMetaDataDriver->CreateMetaData (theDocument, theName);
+              theDocument->SetMetaData (aMetaData);
+
+              CDM_ReferenceIterator it (theDocument);
+              for (; it.More(); it.Next())
+                theMetaDataDriver->CreateReference (aMetaData, it.Document()->MetaData(), it.ReferenceIdentifier(), it.DocumentVersion());
+            }
           }
         }
       }
-    }
-
-    catch (CDF_MetaDataDriverError const& anException) {
-      CAUGHT(anException, aStatusAssociatedText, TCollection_ExtendedString("metadatadriver failed; reason:"));
-      status = PCDM_SS_DriverFailure;
-    }
-    catch (Standard_Failure const& anException) {
-      CAUGHT(anException, aStatusAssociatedText, TCollection_ExtendedString("driver failed; reason:"));
-      status = PCDM_SS_Failure; 
+      catch (Standard_Failure const& anException)
+      {
+        CAUGHT (anException, aStatusAssociatedText, TCollection_ExtendedString ("driver failed; reason: "));
+        status = PCDM_SS_DriverFailure;
+      }
     }
   }
 
index 1bdfb4dd5371bd8819d56a5ebaacedb8404601ba..fdf055df2c362b124c61b389e3d61de27f06e069 100755 (executable)
@@ -8,7 +8,6 @@ CDF_FWOSDriver.cxx
 CDF_FWOSDriver.hxx
 CDF_MetaDataDriver.cxx
 CDF_MetaDataDriver.hxx
-CDF_MetaDataDriverError.hxx
 CDF_MetaDataDriverFactory.cxx
 CDF_MetaDataDriverFactory.hxx
 CDF_Store.cxx
index cd0e56354c0a43ee91fc092318b02745621bbce7..ed6c50abedad04be678a0cac09b4dacbb43680a6 100644 (file)
 #ifndef _PCDM_StoreStatus_HeaderFile
 #define _PCDM_StoreStatus_HeaderFile
 
-
+//! Status of storage of a document on disk.
+//! If it is PCDM_SS_OK, the document is successfully saved on disk.
+//! Else - there is an error.
 enum PCDM_StoreStatus
 {
-PCDM_SS_OK,
-PCDM_SS_DriverFailure,
-PCDM_SS_WriteFailure,
-PCDM_SS_Failure,
-PCDM_SS_Doc_IsNull,
-PCDM_SS_No_Obj,
-PCDM_SS_Info_Section_Error,
-PCDM_SS_UserBreak
+PCDM_SS_OK,                 //!< Document is saved successfully
+PCDM_SS_DriverFailure,      //!< Storage driver is not found
+PCDM_SS_WriteFailure,       //!< Attempt to write a file on disk failed
+PCDM_SS_Failure,            //!< A general error occurred (unexpected)
+PCDM_SS_Doc_IsNull,         //!< Attempt to save a null document
+PCDM_SS_No_Obj,             //!< Document has no objects to be saved
+PCDM_SS_Info_Section_Error, //!< Error occured on writing of an information-section
+PCDM_SS_UserBreak,          //!< User interrupted the process of storage of the document on disk
+PCDM_SS_UnrecognizedFormat  //!< No storage driver exist for this document format
 };
 
 #endif // _PCDM_StoreStatus_HeaderFile
index 7c1d347f21630d4e4ccd012907c28eb09d036ee7..d172b0228fc5fae76002967f7258ad1f36d3e643 100644 (file)
@@ -383,8 +383,10 @@ PCDM_StoreStatus TDocStd_Application::SaveAs (const Handle(TDocStd_Document)& th
       MessageDriver()->Send(aString.ToExtString(), Message_Fail);
     }
   }
-  if(storer.StoreStatus() == PCDM_SS_OK)
+  if (storer.StoreStatus() == PCDM_SS_OK)
     theDoc->SetSaved();
+  else if (!MessageDriver().IsNull())
+    MessageDriver()->Send (storer.AssociatedStatusText(), Message_Fail);
 #ifdef OCCT_DEBUG
   std::cout<<"TDocStd_Application::SaveAs(): The status = "<<storer.StoreStatus()<<std::endl;
 #endif
index e3a278f00c961489858a48034f8a11cc4d3a09b3..a10b762eeef1765c9fe99ddd0050ad56ca2c6125 100644 (file)
@@ -194,6 +194,9 @@ static Standard_Integer saveDoc (Draw_Interpretor& di, Standard_Integer argc, co
     case PCDM_SS_UserBreak:
       di << "Storage error: user break\n";
       break;
+    case PCDM_SS_UnrecognizedFormat:
+      di << "Storage error: unrecognized document storage format " << D->StorageFormat() << "\n";
+      break;
   }
 
   return 0;