From 68bff67ff7bbc9988222b82fd81048cbd9415ba0 Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 26 May 2014 11:49:20 +0400 Subject: [PATCH] Issue #71: abort all actions inside of the sketch on sketch abort --- src/Model/Model_Document.cpp | 42 +++++++++++++++++++++++++----------- src/Model/Model_Document.h | 3 +++ 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 2c29b6535..87ad7e0b1 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -184,6 +184,8 @@ void Model_Document::startOperation() myNestedNum = 0; myDoc->InitDeltaCompaction(); } + myIsEmptyTr[myTransactionsAfterSave] = false; + myTransactionsAfterSave++; myDoc->NewCommand(); } else { // start of simple command myDoc->NewCommand(); @@ -194,6 +196,17 @@ void Model_Document::startOperation() subDocument(*aSubIter)->startOperation(); } +void Model_Document::compactNested() { + while(myNestedNum != -1) { + myTransactionsAfterSave--; + myIsEmptyTr.erase(myTransactionsAfterSave); + myNestedNum--; + } + myIsEmptyTr[myTransactionsAfterSave] = false; + myTransactionsAfterSave++; + myDoc->PerformDeltaCompaction(); +} + void Model_Document::finishOperation() { // just to be sure that everybody knows that changes were performed @@ -205,15 +218,8 @@ void Model_Document::finishOperation() myNestedNum++; if (!myDoc->HasOpenCommand()) { if (myNestedNum != -1) { - myNestedNum -= 2; // one is just incremented before, one is left (and not empty!) - while(myNestedNum != -1) { - myIsEmptyTr.erase(myTransactionsAfterSave); - myTransactionsAfterSave--; - myNestedNum--; - } - myIsEmptyTr[myTransactionsAfterSave] = false; - myTransactionsAfterSave++; - myDoc->PerformDeltaCompaction(); + myNestedNum--; + compactNested(); } } else { // returns false if delta is empty and no transaction was made @@ -229,13 +235,23 @@ void Model_Document::finishOperation() void Model_Document::abortOperation() { - if (myNestedNum == 0) - myNestedNum = -1; - myDoc->AbortCommand(); + if (myNestedNum > 0 && !myDoc->HasOpenCommand()) { // abort all what was done in nested + // first compact all nested + compactNested(); + // for nested it is undo and clear redos + myDoc->Undo(); + myDoc->ClearRedos(); + myTransactionsAfterSave--; + myIsEmptyTr.erase(myTransactionsAfterSave); + } else { + if (myNestedNum == 0) // abort only high-level + myNestedNum = -1; + myDoc->AbortCommand(); + } synchronizeFeatures(true); // abort for all subs set::iterator aSubIter = mySubs.begin(); - for(; aSubIter != mySubs.end(); aSubIter++) + for(; aSubIter != mySubs.end(); aSubIter++) subDocument(*aSubIter)->abortOperation(); } diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index 097a3ba24..41f7d51f6 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -110,6 +110,9 @@ protected: Handle_TDocStd_Document document() {return myDoc;} + //! performas compactification of all nested operations into one + void compactNested(); + friend class Model_Application; friend class Model_PluginManager; -- 2.39.2