From abc04a43de67947a851486f8173e2a86bdd4c376 Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 9 Jul 2015 13:09:37 +0300 Subject: [PATCH] Update of transactions management after the nested operation finished in extrusion cut --- .../FeaturesPlugin_CompositeBoolean.cpp | 10 ++++++---- src/Model/Model_Session.cpp | 12 +++++++++++- src/Model/Model_Session.h | 6 +++++- src/ModelAPI/ModelAPI_Session.h | 5 ++++- src/PartSet/PartSet_WidgetSketchCreator.cpp | 18 ++++++++++++------ 5 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp index c11ed54d5..4783e23b1 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp @@ -82,10 +82,12 @@ void FeaturesPlugin_CompositeBoolean::removeFeature(std::shared_ptr(data()->reference(SKETCH_OBJECT_ID())->value()); - if (aSketch.get() && aSketch->data()->isValid()) { - document()->removeFeature(aSketch); + if (data().get() && data()->isValid()) { // on abort of sketch of this composite it may be invalid + FeaturePtr aSketch = + std::dynamic_pointer_cast(data()->reference(SKETCH_OBJECT_ID())->value()); + if (aSketch.get() && aSketch->data()->isValid()) { + document()->removeFeature(aSketch); + } } ModelAPI_CompositeFeature::erase(); } diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index daae187f0..c0d83dd64 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -52,8 +52,9 @@ void Model_Session::closeAll() Model_Application::getApplication()->deleteAllDocuments(); } -void Model_Session::startOperation(const std::string& theId) +void Model_Session::startOperation(const std::string& theId, const bool theAttachedToNested) { + myOperationAttachedToNext = theAttachedToNested; ROOT_DOC->startOperation(); ROOT_DOC->operationId(theId); static std::shared_ptr aStartedMsg @@ -68,6 +69,10 @@ void Model_Session::finishOperation() { setCheckTransactions(false); ROOT_DOC->finishOperation(); + if (myOperationAttachedToNext) { // twice, with nested + ROOT_DOC->finishOperation(); + myOperationAttachedToNext = false; + } setCheckTransactions(true); } @@ -75,6 +80,10 @@ void Model_Session::abortOperation() { setCheckTransactions(false); ROOT_DOC->abortOperation(); + if (myOperationAttachedToNext) { // twice, with nested + ROOT_DOC->abortOperation(); + myOperationAttachedToNext = false; + } setCheckTransactions(true); // here the update mechanism may work after abort, so, supress the warnings about // modifications outside of the transactions @@ -314,6 +323,7 @@ Model_Session::Model_Session() { myPluginsInfoLoaded = false; myCheckTransactions = true; + myOperationAttachedToNext = false; ModelAPI_Session::setSession(std::shared_ptr(this)); // register the configuration reading listener Events_Loop* aLoop = Events_Loop::loop(); diff --git a/src/Model/Model_Session.h b/src/Model/Model_Session.h index 62d69e5be..df9a63a57 100644 --- a/src/Model/Model_Session.h +++ b/src/Model/Model_Session.h @@ -31,6 +31,7 @@ class Model_Session : public ModelAPI_Session, public Events_Listener std::string myCurrentPluginName; ///< name of the plugin that must be loaded currently std::shared_ptr myCurrentDoc; ///< current working document bool myCheckTransactions; ///< if true, generates error if document is updated outside of transaction + bool myOperationAttachedToNext; ///< the current operation must be commited twice, with nested public: //! Loads the OCAF document from the file. @@ -48,7 +49,10 @@ class Model_Session : public ModelAPI_Session, public Events_Listener MODEL_EXPORT virtual void closeAll(); //! Starts a new operation (opens a tansaction) - MODEL_EXPORT virtual void startOperation(const std::string& theId = ""); + //! \param theAttachedToNested if it is true, it means that this transaction is attached to the nested + //! where it is located and will be commited on the next commit with the nested + MODEL_EXPORT virtual void startOperation( + const std::string& theId = "", const bool theAttachedToNested = false); //! Finishes the previously started operation (closes the transaction) MODEL_EXPORT virtual void finishOperation(); //! Aborts the operation diff --git a/src/ModelAPI/ModelAPI_Session.h b/src/ModelAPI/ModelAPI_Session.h index 33aa5a67d..fe78aebf3 100644 --- a/src/ModelAPI/ModelAPI_Session.h +++ b/src/ModelAPI/ModelAPI_Session.h @@ -46,7 +46,10 @@ class MODELAPI_EXPORT ModelAPI_Session //! Starts a new operation (opens a tansaction) //! \param theId of operation for history (optional) - virtual void startOperation(const std::string& theId = "") = 0; + //! \param theAttachedToNested if it is true, it means that this transaction is attached to the nested + //! where it is located and will be commited on the next commit with the nested + virtual void startOperation( + const std::string& theId = "", const bool theAttachedToNested = false) = 0; //! Finishes the previously started operation (closes the transaction) virtual void finishOperation() = 0; //! Aborts the operation diff --git a/src/PartSet/PartSet_WidgetSketchCreator.cpp b/src/PartSet/PartSet_WidgetSketchCreator.cpp index a5d9cddb1..7f08fe33e 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.cpp +++ b/src/PartSet/PartSet_WidgetSketchCreator.cpp @@ -140,10 +140,12 @@ bool PartSet_WidgetSketchCreator::focusTo() connect(myModule, SIGNAL(operationResumed(ModuleBase_Operation*)), SLOT(onResumed(ModuleBase_Operation*))); SessionPtr aMgr = ModelAPI_Session::get(); + // Open transaction that is general for the previous nested one: it will be closed on nested commit bool aIsOp = aMgr->isOperation(); - // Open transaction if it was closed before - if (!aIsOp) - aMgr->startOperation(); + if (!aIsOp) { + const static std::string aNestedOpID("Parameters modification"); + aMgr->startOperation(aNestedOpID, true); + } restoreValue(); return false; @@ -158,10 +160,14 @@ void PartSet_WidgetSketchCreator::onResumed(ModuleBase_Operation* theOp) if (aSketchFeature->numberOfSubs() == 0) { // Abort operation SessionPtr aMgr = ModelAPI_Session::get(); - bool aIsOp = aMgr->isOperation(); // Close transaction - if (aIsOp) - aMgr->abortOperation(); + /* + bool aIsOp = aMgr->isOperation(); + if (aIsOp) { + const static std::string aNestedOpID("Parameters cancelation"); + aMgr->startOperation(aNestedOpID, true); + } + */ theOp->abort(); } else { // Hide sketcher result -- 2.39.2