From d8b4cd8e33bf0afa94010a947b663a040106027c Mon Sep 17 00:00:00 2001 From: mpv Date: Wed, 3 Sep 2014 11:47:52 +0400 Subject: [PATCH] Make open/save undo, redo and abort don't cause recomputation of the whole model --- src/ConstructionPlugin/ConstructionPlugin_Point.h | 3 +++ src/Model/Model_Document.cpp | 3 +++ src/Model/Model_Document.h | 8 +++++++- src/Model/Model_Update.cpp | 6 +++++- src/ModelAPI/ModelAPI_Feature.h | 4 ++++ src/SketchPlugin/SketchPlugin_Feature.h | 5 ++++- 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.h b/src/ConstructionPlugin/ConstructionPlugin_Point.h index 63a134226..4e62d79ae 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.h @@ -45,6 +45,9 @@ class ConstructionPlugin_Point : public ModelAPI_Feature /// Request for initialization of data model of the feature: adding all attributes CONSTRUCTIONPLUGIN_EXPORT virtual void initAttributes(); + /// Construction result is allways recomuted on the fly + CONSTRUCTIONPLUGIN_EXPORT virtual bool isPersistentResult() {return false;} + /// Use plugin manager for features creation ConstructionPlugin_Point(); }; diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index e667f2e61..dfcb4b659 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -51,6 +51,7 @@ Model_Document::Model_Document(const std::string theID) myDoc->SetUndoLimit(UNDO_LIMIT); myTransactionsAfterSave = 0; myNestedNum = -1; + myExecuteFeatures = true; //myDoc->SetNestedTransactionMode(); // to have something in the document and avoid empty doc open/save problem // in transaction for nesting correct working @@ -719,6 +720,7 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated) // after all updates, sends a message that groups of features were created or updated boost::static_pointer_cast(Model_PluginManager::get())->setCheckTransactions( false); + myExecuteFeatures = false; Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED)); if (theMarkUpdated) Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); @@ -726,6 +728,7 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated) Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); boost::static_pointer_cast(Model_PluginManager::get())->setCheckTransactions( true); + myExecuteFeatures = true; } void Model_Document::storeResult(boost::shared_ptr theFeatureData, diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index 240082532..e7b92a945 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -115,7 +115,11 @@ class Model_Document : public ModelAPI_Document //! Returns a feature by result (owner of result) MODEL_EXPORT virtual boost::shared_ptr - feature(const boost::shared_ptr& theResult); + feature(const boost::shared_ptr& theResult); + + ///! Returns true if parametric updater need to execute feature on recomputartion + ///! On abort, undo or redo it is not necessary: results in document are updated automatically + bool executeFeatures() {return myExecuteFeatures;} protected: @@ -167,6 +171,8 @@ class Model_Document : public ModelAPI_Document std::set mySubs; /// transaction indexes (related to myTransactionsAfterSave) which were empty in this doc std::map myIsEmptyTr; + /// If it is true, features are not executed on update (on abort, undo, redo) + bool myExecuteFeatures; }; #endif diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index 7a4050335..a57471405 100644 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -3,6 +3,7 @@ // Author: Mikhail PONIKAROV #include +#include #include #include #include @@ -91,7 +92,10 @@ bool Model_Update::updateFeature(FeaturePtr theFeature) } // execute feature if it must be updated if (aMustbeUpdated) { - theFeature->execute(); + + if (boost::dynamic_pointer_cast(theFeature->document())->executeFeatures() || + !theFeature->isPersistentResult()) + theFeature->execute(); // redisplay all results static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY); const std::list >& aResults = theFeature->results(); diff --git a/src/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index 5b35b7e50..910807423 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -58,6 +58,10 @@ class ModelAPI_Feature : public ModelAPI_Object MODELAPI_EXPORT void setResult(const boost::shared_ptr& theResult, const int theIndex); + /// Returns true if result is persistent (stored in document) and on undo-redo, save-open + /// it is not needed to recompute it. + virtual bool isPersistentResult() {return true;} + /// Returns true if this feature must not be created: this is just an action /// that is not stored in the features history and data model (like "delete part"). virtual bool isAction() diff --git a/src/SketchPlugin/SketchPlugin_Feature.h b/src/SketchPlugin/SketchPlugin_Feature.h index 9deef3f09..d51301880 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.h +++ b/src/SketchPlugin/SketchPlugin_Feature.h @@ -49,7 +49,10 @@ class SketchPlugin_Feature : public ModelAPI_Feature /// \param thePoint the point virtual double distanceToPoint(const boost::shared_ptr& thePoint) = 0; - protected: + /// Construction result is allways recomuted on the fly + SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;} + +protected: /// Sets the higher-level feature for the sub-feature (sketch for line) void setSketch(SketchPlugin_Sketch* theSketch) { -- 2.39.2