mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-09 18:50:54 +03:00
0032125: Application Framework, OCAF - need to have adequate message if document cannot be saved due to unrecognized format
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.
This commit is contained in:
parent
9443cf8ec4
commit
632deee0b0
@ -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
|
|
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
#include <CDF_Application.hxx>
|
#include <CDF_Application.hxx>
|
||||||
#include <CDF_MetaDataDriver.hxx>
|
#include <CDF_MetaDataDriver.hxx>
|
||||||
#include <CDF_MetaDataDriverError.hxx>
|
|
||||||
#include <CDF_StoreList.hxx>
|
#include <CDF_StoreList.hxx>
|
||||||
#include <CDM_Document.hxx>
|
#include <CDM_Document.hxx>
|
||||||
#include <CDM_MetaData.hxx>
|
#include <CDM_MetaData.hxx>
|
||||||
@ -25,8 +24,6 @@
|
|||||||
#include <PCDM.hxx>
|
#include <PCDM.hxx>
|
||||||
#include <PCDM_Document.hxx>
|
#include <PCDM_Document.hxx>
|
||||||
#include <PCDM_StorageDriver.hxx>
|
#include <PCDM_StorageDriver.hxx>
|
||||||
#include <Standard_ErrorHandler.hxx>
|
|
||||||
#include <Standard_NoSuchObject.hxx>
|
|
||||||
#include <TCollection_ExtendedString.hxx>
|
#include <TCollection_ExtendedString.hxx>
|
||||||
|
|
||||||
IMPLEMENT_STANDARD_RTTIEXT(CDF_StoreList,Standard_Transient)
|
IMPLEMENT_STANDARD_RTTIEXT(CDF_StoreList,Standard_Transient)
|
||||||
@ -77,62 +74,65 @@ PCDM_StoreStatus CDF_StoreList::Store (Handle(CDM_MetaData)& aMetaData,
|
|||||||
TCollection_ExtendedString& aStatusAssociatedText,
|
TCollection_ExtendedString& aStatusAssociatedText,
|
||||||
const Message_ProgressRange& theRange)
|
const Message_ProgressRange& theRange)
|
||||||
{
|
{
|
||||||
Handle(CDF_MetaDataDriver) theMetaDataDriver = Handle(CDF_Application)::DownCast((myMainDocument->Application()))->MetaDataDriver();
|
|
||||||
|
|
||||||
PCDM_StoreStatus status = PCDM_SS_OK;
|
PCDM_StoreStatus status = PCDM_SS_OK;
|
||||||
|
Handle(CDF_MetaDataDriver) theMetaDataDriver = Handle(CDF_Application)::DownCast ((myMainDocument->Application()))->MetaDataDriver();
|
||||||
|
for (; !myStack.IsEmpty(); myStack.RemoveFirst())
|
||||||
{
|
{
|
||||||
try {
|
Handle(CDM_Document) theDocument = myStack.First();
|
||||||
OCC_CATCH_SIGNALS
|
if (theDocument == myMainDocument || theDocument->IsModified())
|
||||||
for (; !myStack.IsEmpty(); myStack.RemoveFirst()) {
|
{
|
||||||
|
try
|
||||||
Handle(CDM_Document) theDocument = myStack.First();
|
{
|
||||||
if( theDocument == myMainDocument || theDocument->IsModified()) {
|
OCC_CATCH_SIGNALS
|
||||||
|
Handle(CDF_Application) anApp = Handle(CDF_Application)::DownCast (theDocument->Application());
|
||||||
Handle(CDF_Application) anApp = Handle(CDF_Application)::DownCast (theDocument->Application());
|
if (anApp.IsNull())
|
||||||
if (anApp.IsNull())
|
{
|
||||||
{
|
aStatusAssociatedText = "driver failed; reason: ";
|
||||||
throw Standard_Failure("Document has no application, cannot save!");
|
aStatusAssociatedText += "document has no application, cannot save!";
|
||||||
}
|
status = PCDM_SS_Failure;
|
||||||
Handle(PCDM_StorageDriver) aDocumentStorageDriver =
|
}
|
||||||
anApp->WriterFromFormat(theDocument->StorageFormat());
|
else
|
||||||
|
{
|
||||||
|
Handle(PCDM_StorageDriver) aDocumentStorageDriver = anApp->WriterFromFormat(theDocument->StorageFormat());
|
||||||
if (aDocumentStorageDriver.IsNull())
|
if (aDocumentStorageDriver.IsNull())
|
||||||
{
|
{
|
||||||
Standard_SStream aMsg;
|
aStatusAssociatedText = "driver not found; reason: no storage driver does exist for this format: ";
|
||||||
aMsg <<"No storage driver does exist for this format: " << theDocument->StorageFormat() << (char)0;
|
aStatusAssociatedText += theDocument->StorageFormat();
|
||||||
throw Standard_Failure(aMsg.str().c_str());
|
status = PCDM_SS_UnrecognizedFormat;
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
|
|
||||||
// Reset the store-status.
|
if (!theMetaDataDriver->FindFolder(theDocument->RequestedFolder()))
|
||||||
// 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);
|
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);
|
||||||
|
|
||||||
if(!theMetaDataDriver->FindFolder(theDocument->RequestedFolder())) {
|
CDM_ReferenceIterator it (theDocument);
|
||||||
Standard_SStream aMsg; aMsg << "could not find the active dbunit";
|
for (; it.More(); it.Next())
|
||||||
aMsg << TCollection_ExtendedString(theDocument->RequestedFolder())<< (char)0;
|
theMetaDataDriver->CreateReference (aMetaData, it.Document()->MetaData(), it.ReferenceIdentifier(), it.DocumentVersion());
|
||||||
throw Standard_NoSuchObject(aMsg.str().c_str());
|
}
|
||||||
}
|
|
||||||
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 (Standard_Failure const& anException)
|
||||||
|
{
|
||||||
catch (CDF_MetaDataDriverError const& anException) {
|
CAUGHT (anException, aStatusAssociatedText, TCollection_ExtendedString ("driver failed; reason: "));
|
||||||
CAUGHT(anException, aStatusAssociatedText, TCollection_ExtendedString("metadatadriver failed; reason:"));
|
status = PCDM_SS_DriverFailure;
|
||||||
status = PCDM_SS_DriverFailure;
|
}
|
||||||
}
|
|
||||||
catch (Standard_Failure const& anException) {
|
|
||||||
CAUGHT(anException, aStatusAssociatedText, TCollection_ExtendedString("driver failed; reason:"));
|
|
||||||
status = PCDM_SS_Failure;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ CDF_FWOSDriver.cxx
|
|||||||
CDF_FWOSDriver.hxx
|
CDF_FWOSDriver.hxx
|
||||||
CDF_MetaDataDriver.cxx
|
CDF_MetaDataDriver.cxx
|
||||||
CDF_MetaDataDriver.hxx
|
CDF_MetaDataDriver.hxx
|
||||||
CDF_MetaDataDriverError.hxx
|
|
||||||
CDF_MetaDataDriverFactory.cxx
|
CDF_MetaDataDriverFactory.cxx
|
||||||
CDF_MetaDataDriverFactory.hxx
|
CDF_MetaDataDriverFactory.hxx
|
||||||
CDF_Store.cxx
|
CDF_Store.cxx
|
||||||
|
@ -17,17 +17,20 @@
|
|||||||
#ifndef _PCDM_StoreStatus_HeaderFile
|
#ifndef _PCDM_StoreStatus_HeaderFile
|
||||||
#define _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
|
enum PCDM_StoreStatus
|
||||||
{
|
{
|
||||||
PCDM_SS_OK,
|
PCDM_SS_OK, //!< Document is saved successfully
|
||||||
PCDM_SS_DriverFailure,
|
PCDM_SS_DriverFailure, //!< Storage driver is not found
|
||||||
PCDM_SS_WriteFailure,
|
PCDM_SS_WriteFailure, //!< Attempt to write a file on disk failed
|
||||||
PCDM_SS_Failure,
|
PCDM_SS_Failure, //!< A general error occurred (unexpected)
|
||||||
PCDM_SS_Doc_IsNull,
|
PCDM_SS_Doc_IsNull, //!< Attempt to save a null document
|
||||||
PCDM_SS_No_Obj,
|
PCDM_SS_No_Obj, //!< Document has no objects to be saved
|
||||||
PCDM_SS_Info_Section_Error,
|
PCDM_SS_Info_Section_Error, //!< Error occured on writing of an information-section
|
||||||
PCDM_SS_UserBreak
|
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
|
#endif // _PCDM_StoreStatus_HeaderFile
|
||||||
|
@ -383,8 +383,10 @@ PCDM_StoreStatus TDocStd_Application::SaveAs (const Handle(TDocStd_Document)& th
|
|||||||
MessageDriver()->Send(aString.ToExtString(), Message_Fail);
|
MessageDriver()->Send(aString.ToExtString(), Message_Fail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(storer.StoreStatus() == PCDM_SS_OK)
|
if (storer.StoreStatus() == PCDM_SS_OK)
|
||||||
theDoc->SetSaved();
|
theDoc->SetSaved();
|
||||||
|
else if (!MessageDriver().IsNull())
|
||||||
|
MessageDriver()->Send (storer.AssociatedStatusText(), Message_Fail);
|
||||||
#ifdef OCCT_DEBUG
|
#ifdef OCCT_DEBUG
|
||||||
std::cout<<"TDocStd_Application::SaveAs(): The status = "<<storer.StoreStatus()<<std::endl;
|
std::cout<<"TDocStd_Application::SaveAs(): The status = "<<storer.StoreStatus()<<std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
@ -194,6 +194,9 @@ static Standard_Integer saveDoc (Draw_Interpretor& di, Standard_Integer argc, co
|
|||||||
case PCDM_SS_UserBreak:
|
case PCDM_SS_UserBreak:
|
||||||
di << "Storage error: user break\n";
|
di << "Storage error: user break\n";
|
||||||
break;
|
break;
|
||||||
|
case PCDM_SS_UnrecognizedFormat:
|
||||||
|
di << "Storage error: unrecognized document storage format " << D->StorageFormat() << "\n";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user