From: mpv Date: Wed, 24 Dec 2014 09:29:11 +0000 (+0300) Subject: Fix for issue #319 : remove useless documents on start of the operation (undo/redo... X-Git-Tag: V_0.7.0_rc1~50^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2abc569e2ad23e1015317793f03bf30832f40851;p=modules%2Fshaper.git Fix for issue #319 : remove useless documents on start of the operation (undo/redo cleared on it) --- diff --git a/src/Model/Model_Application.cpp b/src/Model/Model_Application.cpp index 147bb4ac2..204cafe14 100644 --- a/src/Model/Model_Application.cpp +++ b/src/Model/Model_Application.cpp @@ -85,6 +85,26 @@ bool Model_Application::isLoadByDemand(std::string theID) return myLoadedByDemand.find(theID) != myLoadedByDemand.end(); } +//======================================================================= +void Model_Application::removeUselessDocuments( + std::list > theUsedDocs) +{ + std::map >::iterator aDoc = myDocs.begin(); + while(aDoc != myDocs.end()) { + bool aFound = false; + std::list >::iterator aUsed = theUsedDocs.begin(); + for(; !aFound && aUsed != theUsedDocs.end(); aUsed++) { + aFound = aDoc->second == *aUsed; + } + if (!aFound) { // remove the useless + aDoc->second->close(); + aDoc = myDocs.erase(aDoc); + } else { + aDoc++; + } + } +} + //======================================================================= Model_Application::Model_Application() { diff --git a/src/Model/Model_Application.h b/src/Model/Model_Application.h index aa25bcb4e..d1156b284 100644 --- a/src/Model/Model_Application.h +++ b/src/Model/Model_Application.h @@ -49,6 +49,9 @@ class Model_Application : public TDocStd_Application void setLoadByDemand(std::string theID); //! Returns true if specified document must be loaded by demand bool isLoadByDemand(std::string theID); + //! Closes and removes the documents that are not loaded by demand and + //! not in the given list + void removeUselessDocuments(std::list > theUsedDocs); public: // Redefined OCAF methods diff --git a/src/Model/Model_AttributeRefAttr.cpp b/src/Model/Model_AttributeRefAttr.cpp index 14e6eb4a1..b6ac11663 100644 --- a/src/Model/Model_AttributeRefAttr.cpp +++ b/src/Model/Model_AttributeRefAttr.cpp @@ -31,7 +31,7 @@ void Model_AttributeRefAttr::setAttr(std::shared_ptr theAttr std::shared_ptr Model_AttributeRefAttr::attr() { ObjectPtr anObj = object(); - if (anObj) { + if (anObj && anObj->data()) { std::shared_ptr aData = std::dynamic_pointer_cast(anObj->data()); return aData->attribute(TCollection_AsciiString(myID->Get()).ToCString()); } diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 60f163499..dfd03fefc 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -623,14 +623,16 @@ const std::set Model_Document::subDocuments(const bool theActivated for (; aLabIter.More(); aLabIter.Next()) { TDF_Label aFLabel = aLabIter.Value()->Label(); FeaturePtr aFeature = feature(aFLabel); - const std::list >& aResults = aFeature->results(); - std::list >::const_iterator aRIter = aResults.begin(); - for (; aRIter != aResults.cend(); aRIter++) { - if ((*aRIter)->groupName() != ModelAPI_ResultPart::group()) continue; - if ((*aRIter)->isInHistory()) { - ResultPartPtr aPart = std::dynamic_pointer_cast(*aRIter); - if (aPart && (!theActivatedOnly || aPart->isActivated())) - aResult.insert(aPart->data()->name()); + if (aFeature.get()) { // if document is closed the feature may be not in myObjs map + const std::list >& aResults = aFeature->results(); + std::list >::const_iterator aRIter = aResults.begin(); + for (; aRIter != aResults.cend(); aRIter++) { + if ((*aRIter)->groupName() != ModelAPI_ResultPart::group()) continue; + if ((*aRIter)->isInHistory()) { + ResultPartPtr aPart = std::dynamic_pointer_cast(*aRIter); + if (aPart && (!theActivatedOnly || aPart->isActivated())) + aResult.insert(aPart->data()->name()); + } } } } diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index 88d9f81d4..159b7a2f6 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -53,6 +53,9 @@ void Model_Session::startOperation() static std::shared_ptr aStartedMsg (new Events_Message(Events_Loop::eventByName("StartOperation"))); Events_Loop::loop()->send(aStartedMsg); + // remove all useless documents that has been closed: on start of operation undo/redo is cleared + std::list > aUsedDocs = allOpenedDocuments(); + Model_Application::getApplication()->removeUselessDocuments(aUsedDocs); } void Model_Session::finishOperation()