From: mpv Date: Tue, 11 Nov 2014 12:34:06 +0000 (+0300) Subject: Correctly close the document on opening the new one X-Git-Tag: V_0.5~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=34b118cd5567416cde2d00a2b7d62832d62f7a51;p=modules%2Fshaper.git Correctly close the document on opening the new one --- diff --git a/src/Model/Model_Application.cpp b/src/Model/Model_Application.cpp index 23ecf05ae..d53dc665c 100644 --- a/src/Model/Model_Application.cpp +++ b/src/Model/Model_Application.cpp @@ -40,7 +40,17 @@ const boost::shared_ptr& Model_Application::getDocument(string t void Model_Application::deleteDocument(string theDocID) { - myDocs.erase(theDocID); + if (myDocs.find(theDocID) != myDocs.end()) { + myDocs[theDocID]->close(true); + myDocs.erase(theDocID); + } + myLoadedByDemand.clear(); +} + +void Model_Application::deleteAllDocuments() +{ + myDocs.clear(); + myLoadedByDemand.clear(); } //======================================================================= diff --git a/src/Model/Model_Application.h b/src/Model/Model_Application.h index ae68024ee..d9eb4bb20 100644 --- a/src/Model/Model_Application.h +++ b/src/Model/Model_Application.h @@ -36,6 +36,8 @@ class Model_Application : public TDocStd_Application MODEL_EXPORT bool hasDocument(std::string theDocID); //! Deletes the document from the application MODEL_EXPORT void deleteDocument(std::string theDocID); + //! Deletes all documents existing in the application + MODEL_EXPORT void deleteAllDocuments(); //! Set path for the loaded by demand documents void setLoadPath(std::string thePath); diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index a224cc99f..06ec246f3 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -202,7 +202,7 @@ bool Model_Document::save(const char* theFileName, std::list& theRe return isDone; } -void Model_Document::close() +void Model_Document::close(const bool theForever) { boost::shared_ptr aPM = Model_Session::get(); if (this != aPM->moduleDocument().get() && this == aPM->activeDocument().get()) { @@ -211,14 +211,36 @@ void Model_Document::close() // close all subs std::set::iterator aSubIter = mySubs.begin(); for (; aSubIter != mySubs.end(); aSubIter++) - subDoc(*aSubIter)->close(); + subDoc(*aSubIter)->close(theForever); mySubs.clear(); - // close this only if it is module document, otherwise it can be undoed - if (this == aPM->moduleDocument().get()) { + + // close for thid document needs no transaction in this document + boost::static_pointer_cast(Model_Session::get())->setCheckTransactions(false); + + // delete all features of this document + boost::shared_ptr aThis = + Model_Application::getApplication()->getDocument(myID); + Events_Loop* aLoop = Events_Loop::loop(); + NCollection_DataMap::Iterator aFeaturesIter(myObjs); + for(; aFeaturesIter.More(); aFeaturesIter.Next()) { + FeaturePtr aFeature = aFeaturesIter.Value(); + static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + ModelAPI_EventCreator::get()->sendDeleted(aThis, ModelAPI_Feature::group()); + ModelAPI_EventCreator::get()->sendUpdated(aFeature, EVENT_DISP); + aFeature->eraseResults(); + aFeature->erase(); + } + myObjs.Clear(); + aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED)); + aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + + // close all only if it is really asked, otherwise it can be undoed/redoed + if (theForever) { if (myDoc->CanClose() == CDM_CCS_OK) myDoc->Close(); - Model_Application::getApplication()->deleteDocument(myID); } + + boost::static_pointer_cast(Model_Session::get())->setCheckTransactions(true); } void Model_Document::startOperation() @@ -629,6 +651,8 @@ int Model_Document::size(const std::string& theGroupID, const bool theHidden) for (; aLabIter.More(); aLabIter.Next()) { TDF_Label aFLabel = aLabIter.Value()->Label(); FeaturePtr aFeature = feature(aFLabel); + if (!aFeature) // may be on close + continue; const std::list >& aResults = aFeature->results(); std::list >::const_iterator aRIter = aResults.begin(); for (; aRIter != aResults.cend(); aRIter++) { diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index d8743f099..05d7d76eb 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -49,7 +49,8 @@ class Model_Document : public ModelAPI_Document MODEL_EXPORT virtual bool save(const char* theFileName, std::list& theResults); //! Removes document data - MODEL_EXPORT virtual void close(); + //! \param theForever if it is false, document is just hiden (to keep possibility make it back on Undo/Redo) + MODEL_EXPORT virtual void close(const bool theForever = false); //! Starts a new operation (opens a tansaction) MODEL_EXPORT virtual void startOperation(); diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index 23e7a2621..2c9a5abad 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -39,6 +39,12 @@ bool Model_Session::save(const char* theFileName, std::list& theRes return ROOT_DOC->save(theFileName, theResults); } +void Model_Session::closeAll() +{ + ROOT_DOC->close(true); + Model_Application::getApplication()->deleteAllDocuments(); +} + void Model_Session::startOperation() { ROOT_DOC->startOperation(); diff --git a/src/Model/Model_Session.h b/src/Model/Model_Session.h index fd4f9c0b5..5186a2497 100644 --- a/src/Model/Model_Session.h +++ b/src/Model/Model_Session.h @@ -43,6 +43,9 @@ class Model_Session : public ModelAPI_Session, public Events_Listener //! \returns true if file was stored successfully MODEL_EXPORT virtual bool save(const char* theFileName, std::list& theResults); + //! Closes all documents + MODEL_EXPORT virtual void closeAll(); + //! Starts a new operation (opens a tansaction) MODEL_EXPORT virtual void startOperation(); //! Finishes the previously started operation (closes the transaction) diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index 703ab0f88..0b67c44f1 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -35,7 +35,8 @@ public: virtual const std::string& kind() const = 0; //! Removes document data - virtual void close() = 0; + //! \param theForever if it is false, document is just hiden (to keep possibility make it back on Undo/Redo) + virtual void close(const bool theForever = false) = 0; //! Adds to the document the new feature of the given feature id //! \param creates feature and puts it in the document (if it is not action) diff --git a/src/ModelAPI/ModelAPI_Session.h b/src/ModelAPI/ModelAPI_Session.h index c97105421..95199bbab 100644 --- a/src/ModelAPI/ModelAPI_Session.h +++ b/src/ModelAPI/ModelAPI_Session.h @@ -40,6 +40,9 @@ class MODELAPI_EXPORT ModelAPI_Session //! \returns true if file was stored successfully virtual bool save(const char* theFileName, std::list& theResults) = 0; + //! Closes all documents + virtual void closeAll() = 0; + //! Starts a new operation (opens a tansaction) virtual void startOperation() = 0; //! Finishes the previously started operation (closes the transaction) diff --git a/src/XGUI/XGUI_PartDataModel.cpp b/src/XGUI/XGUI_PartDataModel.cpp index 42d22cce9..75b573034 100644 --- a/src/XGUI/XGUI_PartDataModel.cpp +++ b/src/XGUI/XGUI_PartDataModel.cpp @@ -448,7 +448,9 @@ DocumentPtr XGUI_PartDataModel::partDocument() const DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId); ResultPartPtr aPart = boost::dynamic_pointer_cast(aObject); - return aPart->partDoc(); + if (aPart) + return aPart->partDoc(); + return DocumentPtr(); // null if not found } ObjectPtr XGUI_PartDataModel::object(const QModelIndex& theIndex) const diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index ad21e62aa..12e6bb7b3 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -726,7 +726,7 @@ void XGUI_Workshop::onOpen() } else if (anAnswer == QMessageBox::Cancel) { return; } - aSession->moduleDocument()->close(); + aSession->closeAll(); myCurrentDir = ""; } @@ -1327,6 +1327,6 @@ void XGUI_Workshop::closeDocument() objectBrowser()->clearContent(); SessionPtr aMgr = ModelAPI_Session::get(); - aMgr->moduleDocument()->close(); + aMgr->closeAll(); objectBrowser()->clearContent(); }