From: mpv Date: Wed, 16 Dec 2015 09:33:00 +0000 (+0300) Subject: Fix for activation of deleted and undo-deleted documents. X-Git-Tag: V_2.1.0~173 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f74f5e57b4c647e061575929334db69c0f4fc8e2;p=modules%2Fshaper.git Fix for activation of deleted and undo-deleted documents. --- diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index b083c265c..b34d47f14 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -562,6 +562,13 @@ void Model_Objects::setUniqueName(FeaturePtr theFeature) isSameName = (*aRIter)->data()->name() == aName; } } + // for new Parts create names that are not in the Postponed list + if (!isSameName && (theFeature->getKind() == "Part" || theFeature->getKind() == "Duplicate")) { + std::shared_ptr aSession = + std::dynamic_pointer_cast(Model_Session::get()); + isSameName = aSession->isLoadByDemand(aName) || aSession->hasDocument(aName); + } + if (isSameName) { aNumObjects++; std::stringstream aNameStream; diff --git a/src/Model/Model_ResultPart.cpp b/src/Model/Model_ResultPart.cpp index b38c0bb09..431576afb 100644 --- a/src/Model/Model_ResultPart.cpp +++ b/src/Model/Model_ResultPart.cpp @@ -62,8 +62,15 @@ void Model_ResultPart::activate() std::shared_ptr aDocRef = data()->document(DOC_REF()); + // activation may cause changes in current features in document, so it must be in transaction + bool isNewTransaction = false; + SessionPtr aMgr = ModelAPI_Session::get(); if (!aDocRef->value().get()) { // create (or open) a document if it is not yet created myIsInLoad = true; + if (!aMgr->isOperation()) { + aMgr->startOperation("Activation"); + isNewTransaction = true; + } std::shared_ptr aDoc = document()->subDocument(data()->name()); myIsInLoad = false; if (aDoc) { @@ -72,16 +79,10 @@ void Model_ResultPart::activate() } } if (aDocRef->value().get()) { - SessionPtr aMgr = ModelAPI_Session::get(); - bool isNewTransaction = !aMgr->isOperation(); - // activation may cause changes in current features in document, so it must be in transaction - if (isNewTransaction) { - aMgr->startOperation("Activation"); - } ModelAPI_Session::get()->setActiveDocument(aDocRef->value()); - if (isNewTransaction) { - aMgr->finishOperation(); - } + } + if (isNewTransaction) { + aMgr->finishOperation(); } } diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index 172b7d3ff..6b3194d5a 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -61,8 +61,11 @@ void Model_Session::startOperation(const std::string& theId, const bool theAttac (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); + // MPV: this code is dangerous now because it may close the document that is activated right now + // but not in the list of the opened documents yet (create, delete, undo, activate Part) + // later this must be updated by correct usage of uniques IDs of documents, not names of results + //std::list > aUsedDocs = allOpenedDocuments(); + //Model_Application::getApplication()->removeUselessDocuments(aUsedDocs); } void Model_Session::finishOperation() @@ -208,6 +211,11 @@ bool Model_Session::hasModuleDocument() return Model_Application::getApplication()->hasDocument("root"); } +bool Model_Session::hasDocument(std::string theDocID) +{ + return Model_Application::getApplication()->hasDocument(theDocID); +} + std::shared_ptr Model_Session::activeDocument() { if (!myCurrentDoc || !Model_Application::getApplication()->hasDocument(myCurrentDoc->id())) diff --git a/src/Model/Model_Session.h b/src/Model/Model_Session.h index 1e200f40e..04eadff1c 100644 --- a/src/Model/Model_Session.h +++ b/src/Model/Model_Session.h @@ -81,6 +81,8 @@ class Model_Session : public ModelAPI_Session, public Events_Listener /// Returns the document by ID, loads if not loaded yet. Returns null if no such document. MODEL_EXPORT virtual std::shared_ptr document(std::string theDocID); + /// Return true if document with such ID has been already created + MODEL_EXPORT virtual bool hasDocument(std::string theDocID); /// Return true if root document has been already created MODEL_EXPORT virtual bool hasModuleDocument();