From: mpv Date: Fri, 11 Apr 2014 07:21:43 +0000 (+0400) Subject: Added the hasRootDocument method for GUI NewDocument checking X-Git-Tag: V_0.1~20 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=053481dcc854e8f47d2674bf2cf04b424f773cde;p=modules%2Fshaper.git Added the hasRootDocument method for GUI NewDocument checking --- diff --git a/src/Model/Model_Application.cxx b/src/Model/Model_Application.cxx index a8c8966b3..40704967e 100644 --- a/src/Model/Model_Application.cxx +++ b/src/Model/Model_Application.cxx @@ -12,18 +12,12 @@ using namespace std; static Handle_Model_Application TheApplication = new Model_Application; -//======================================================================= -//function : getApplication -//purpose : //======================================================================= Handle(Model_Application) Model_Application::getApplication() { return TheApplication; } -//======================================================================= -//function : getDocument -//purpose : //======================================================================= const std::shared_ptr& Model_Application::getDocument(string theDocID) { @@ -41,8 +35,11 @@ void Model_Application::deleteDocument(string theDocID) } //======================================================================= -//function : OCAFApp_Application -//purpose : +bool Model_Application::hasDocument(std::string theDocID) +{ + return myDocs.find(theDocID) != myDocs.end(); +} + //======================================================================= Model_Application::Model_Application() { @@ -51,18 +48,12 @@ Model_Application::Model_Application() TheKeepHandle = this; } -//======================================================================= -//function : Formats -//purpose : //======================================================================= void Model_Application::Formats(TColStd_SequenceOfExtendedString& theFormats) { theFormats.Append(TCollection_ExtendedString("BinOcaf")); // standard binary schema } -//======================================================================= -//function : ResourcesName -//purpose : //======================================================================= Standard_CString Model_Application::ResourcesName() { diff --git a/src/Model/Model_Application.h b/src/Model/Model_Application.h index c4f578f04..386543479 100644 --- a/src/Model/Model_Application.h +++ b/src/Model/Model_Application.h @@ -31,6 +31,8 @@ public: MODEL_EXPORT static Handle_Model_Application getApplication(); //! Returns the main document (on first call creates it) by the string identifier MODEL_EXPORT const std::shared_ptr& getDocument(std::string theDocID); + //! Returns true if document has been created + MODEL_EXPORT bool hasDocument(std::string theDocID); //! Deletes the document from the application MODEL_EXPORT void deleteDocument(std::string theDocID); diff --git a/src/Model/Model_PluginManager.cxx b/src/Model/Model_PluginManager.cxx index ea0b826a6..724f30e26 100644 --- a/src/Model/Model_PluginManager.cxx +++ b/src/Model/Model_PluginManager.cxx @@ -43,6 +43,11 @@ std::shared_ptr Model_PluginManager::rootDocument() Model_Application::getApplication()->getDocument("root")); } +bool Model_PluginManager::hasRootDocument() +{ + return Model_Application::getApplication()->hasDocument("root"); +} + shared_ptr Model_PluginManager::currentDocument() { if (!myCurrentDoc) diff --git a/src/Model/Model_PluginManager.h b/src/Model/Model_PluginManager.h index 6da805cfa..8fc49bdf2 100644 --- a/src/Model/Model_PluginManager.h +++ b/src/Model/Model_PluginManager.h @@ -30,6 +30,9 @@ public: /// Returns the root document of the application (that may contains sub-documents) MODEL_EXPORT virtual std::shared_ptr rootDocument(); + /// Return true if root document has been already created + MODEL_EXPORT virtual bool hasRootDocument(); + /// Returns the current document that used for current work in the application MODEL_EXPORT virtual std::shared_ptr currentDocument(); diff --git a/src/ModelAPI/ModelAPI_PluginManager.h b/src/ModelAPI/ModelAPI_PluginManager.h index 8aab3f6f4..90e1ca81d 100644 --- a/src/ModelAPI/ModelAPI_PluginManager.h +++ b/src/ModelAPI/ModelAPI_PluginManager.h @@ -34,6 +34,9 @@ public: /// Returns the root document of the application (that may contains sub-documents) virtual std::shared_ptr rootDocument() = 0; + /// Return true if root document has been already created + virtual bool hasRootDocument() = 0; + /// Returns the current document that used for current work in the application virtual std::shared_ptr currentDocument() = 0; diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 9def6b185..2c0e7d9d7 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -289,7 +289,8 @@ void ModuleBase_Operation::startOperation() { std::shared_ptr aDoc = ModelAPI_PluginManager::get()->rootDocument(); myFeature = aDoc->addFeature(myOperationId.toStdString()); - myFeature->execute(); + if (myFeature) // TODO: generate an error if feature was not created + myFeature->execute(); //emit callSlot(); //commit(); } @@ -319,7 +320,7 @@ void ModuleBase_Operation::abortOperation() */ void ModuleBase_Operation::commitOperation() { - myFeature->execute(); + if (myFeature) myFeature->execute(); } /*!