From 7b4be16ca6e44bd9fc8aaca8cda03646801adcd4 Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 6 Jul 2017 12:06:31 +0300 Subject: [PATCH] Fix for the problem: Open document with Sketch and Part (Extrusion is inside) select Sketch+Part, Delete create new Part Bug: it is not activated activate this new part bug: this new part contains the Extrusion of the previous part, moreover it uses sketch not presented in the object browser --- src/GeomValidators/GeomValidators_Positive.cpp | 1 - src/Model/Model_Application.cpp | 5 +++-- src/Model/Model_Application.h | 2 +- src/Model/Model_ResultPart.cpp | 2 +- src/Model/Model_Session.cpp | 4 ++-- src/Model/Model_Session.h | 2 +- src/ModelAPI/ModelAPI_Session.h | 2 +- src/PartSetPlugin/PartSetPlugin_Part.cpp | 4 +++- 8 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/GeomValidators/GeomValidators_Positive.cpp b/src/GeomValidators/GeomValidators_Positive.cpp index 446470df2..139239be9 100644 --- a/src/GeomValidators/GeomValidators_Positive.cpp +++ b/src/GeomValidators/GeomValidators_Positive.cpp @@ -48,7 +48,6 @@ bool GeomValidators_Positive::isValid(const AttributePtr& theAttribute, double aMinValue = 1.e-5; if(theArguments.size() == 1) { std::list::const_iterator anIt = theArguments.begin(); - char *aErr; double aValue = Config_PropManager::stringToDouble((*anIt).c_str()); if(aValue != 0) { // very probably ok diff --git a/src/Model/Model_Application.cpp b/src/Model/Model_Application.cpp index ed730d1c8..a5688b66e 100644 --- a/src/Model/Model_Application.cpp +++ b/src/Model/Model_Application.cpp @@ -136,9 +136,10 @@ void Model_Application::setLoadByDemand(std::string theID, const int theDocID) } //======================================================================= -bool Model_Application::isLoadByDemand(std::string theID) +bool Model_Application::isLoadByDemand(std::string theID, const int theDocIndex) { - return myLoadedByDemand.find(theID) != myLoadedByDemand.end(); + return myLoadedByDemand.find(theID) != myLoadedByDemand.end() && + myLoadedByDemand[theID] == theDocIndex; } //======================================================================= diff --git a/src/Model/Model_Application.h b/src/Model/Model_Application.h index 8f5526c0d..6ec3c8df9 100644 --- a/src/Model/Model_Application.h +++ b/src/Model/Model_Application.h @@ -76,7 +76,7 @@ public: //! Defines that specified document must be loaded by demand void setLoadByDemand(std::string theID, const int theDocID); //! Returns true if specified document must be loaded by demand - bool isLoadByDemand(std::string theID); + bool isLoadByDemand(std::string theID, const int theDocIndex); //! Closes and removes the documents that are not loaded by demand and //! not in the given list void removeUselessDocuments(std::list > theUsedDocs); diff --git a/src/Model/Model_ResultPart.cpp b/src/Model/Model_ResultPart.cpp index c0c20223f..863a681c0 100644 --- a/src/Model/Model_ResultPart.cpp +++ b/src/Model/Model_ResultPart.cpp @@ -92,7 +92,7 @@ void Model_ResultPart::activate() } if (!aDocRef->value().get()) { // create (or open) a document if it is not yet created Handle(Model_Application) anApp = Model_Application::getApplication(); - if (anApp->isLoadByDemand(data()->name())) { + if (anApp->isLoadByDemand(data()->name(), aDocRef->docId())) { anApp->loadDocument(data()->name(), aDocRef->docId()); // if it is just ne part, load may fail } else { anApp->createDocument(aDocRef->docId()); diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index 072382a6f..10bd28f20 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -332,9 +332,9 @@ std::list > Model_Session::allOpenedDocuments return aResult; } -bool Model_Session::isLoadByDemand(const std::string theDocID) +bool Model_Session::isLoadByDemand(const std::string theDocID, const int theDocIndex) { - return Model_Application::getApplication()->isLoadByDemand(theDocID); + return Model_Application::getApplication()->isLoadByDemand(theDocID, theDocIndex); } std::shared_ptr Model_Session::copy( diff --git a/src/Model/Model_Session.h b/src/Model/Model_Session.h index e98077451..89b9d548c 100644 --- a/src/Model/Model_Session.h +++ b/src/Model/Model_Session.h @@ -113,7 +113,7 @@ class Model_Session : public ModelAPI_Session, public Events_Listener MODEL_EXPORT virtual std::list > allOpenedDocuments(); /// Returns true if document is not loaded yet - MODEL_EXPORT virtual bool isLoadByDemand(const std::string theDocID); + MODEL_EXPORT virtual bool isLoadByDemand(const std::string theDocID, const int theDocIndex); /// Registers the plugin that creates features. /// It is obligatory for each plugin to call this function on loading to be found by diff --git a/src/ModelAPI/ModelAPI_Session.h b/src/ModelAPI/ModelAPI_Session.h index 21fe583db..7b2d7dd1b 100644 --- a/src/ModelAPI/ModelAPI_Session.h +++ b/src/ModelAPI/ModelAPI_Session.h @@ -112,7 +112,7 @@ class MODELAPI_EXPORT ModelAPI_Session virtual std::list > allOpenedDocuments() = 0; /// Returns true if document is not loaded yet - virtual bool isLoadByDemand(const std::string theDocID) = 0; + virtual bool isLoadByDemand(const std::string theDocID, const int theDocIndex) = 0; /// Copies the document to the new one with the given id virtual std::shared_ptr copy( diff --git a/src/PartSetPlugin/PartSetPlugin_Part.cpp b/src/PartSetPlugin/PartSetPlugin_Part.cpp index 8ec96b449..4eee01130 100644 --- a/src/PartSetPlugin/PartSetPlugin_Part.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Part.cpp @@ -42,7 +42,9 @@ void PartSetPlugin_Part::execute() setResult(aResult); // do not activate part by simple execution if it is not loaded yet: it must be explicitly // activated for this - if (!ModelAPI_Session::get()->isLoadByDemand(aResult->data()->name())) { + std::shared_ptr aDocRef = + aResult->data()->document(ModelAPI_ResultPart::DOC_REF()); + if (!ModelAPI_Session::get()->isLoadByDemand(aResult->data()->name(), aDocRef->docId())) { // On undo/redo creation of the part result the Object Browser must get creation event // earlier that activation of this part event (otherwise the crash is produced) // So, send a creation event earlier, without any grouping -- 2.30.2