From 398bc2217f2f51514ae3ec1ab2ed68e0e5fd4144 Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 8 Dec 2014 11:43:25 +0300 Subject: [PATCH] Fixed the problem with the transactions management after save --- src/Model/Model_Document.cpp | 42 ++++++++++++++++++++---------------- src/Model/Model_Document.h | 6 ++++-- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 62b157e04..304df74cb 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -51,7 +51,8 @@ Model_Document::Model_Document(const std::string theID, const std::string theKin myDoc(new TDocStd_Document("BinOcaf")) // binary OCAF format { myDoc->SetUndoLimit(UNDO_LIMIT); - myTransactionsAfterSave = 0; + myTransactionsCounter = 0; + myTransactionSave = 0; myNestedNum = -1; myExecuteFeatures = true; // to have something in the document and avoid empty doc open/save problem @@ -191,7 +192,7 @@ bool Model_Document::save(const char* theFileName, std::list& theRe break; } } - myTransactionsAfterSave = 0; + myTransactionSave = myTransactionsCounter; if (isDone) { // save also sub-documents if any theResults.push_back(TCollection_AsciiString(aPath).ToCString()); std::set::iterator aSubIter = mySubs.begin(); @@ -250,8 +251,8 @@ void Model_Document::startOperation() myNestedNum = 0; myDoc->InitDeltaCompaction(); } - myIsEmptyTr[myTransactionsAfterSave] = !myDoc->CommitCommand(); - myTransactionsAfterSave++; + myIsEmptyTr[myTransactionsCounter] = !myDoc->CommitCommand(); + myTransactionsCounter++; myDoc->OpenCommand(); } else { // start the simple command myDoc->NewCommand(); @@ -266,15 +267,15 @@ bool Model_Document::compactNested() { bool allWasEmpty = true; while (myNestedNum != -1) { - myTransactionsAfterSave--; - if (!myIsEmptyTr[myTransactionsAfterSave]) { + myTransactionsCounter--; + if (!myIsEmptyTr[myTransactionsCounter]) { allWasEmpty = false; } - myIsEmptyTr.erase(myTransactionsAfterSave); + myIsEmptyTr.erase(myTransactionsCounter); myNestedNum--; } - myIsEmptyTr[myTransactionsAfterSave] = allWasEmpty; - myTransactionsAfterSave++; + myIsEmptyTr[myTransactionsCounter] = allWasEmpty; + myTransactionsCounter++; if (allWasEmpty) { // Issue 151: if everything is empty, it is a problem for OCCT to work with it, // just commit the empty that returns nothing @@ -329,8 +330,8 @@ void Model_Document::finishOperation() } } else { // returns false if delta is empty and no transaction was made - myIsEmptyTr[myTransactionsAfterSave] = !myDoc->CommitCommand(); // && (myNestedNum == -1); - myTransactionsAfterSave++; + myIsEmptyTr[myTransactionsCounter] = !myDoc->CommitCommand(); // && (myNestedNum == -1); + myTransactionsCounter++; } } @@ -342,8 +343,8 @@ void Model_Document::abortOperation() myDoc->Undo(); // undo only compacted, if not: do not undo the empty transaction } myDoc->ClearRedos(); - myTransactionsAfterSave--; - myIsEmptyTr.erase(myTransactionsAfterSave); + myTransactionsCounter--; + myIsEmptyTr.erase(myTransactionsCounter); } else { if (myNestedNum == 0) // abort only high-level myNestedNum = -1; @@ -365,13 +366,13 @@ bool Model_Document::isOperation() bool Model_Document::isModified() { // is modified if at least one operation was commited and not undoed - return myTransactionsAfterSave > 0 || isOperation(); + return myTransactionsCounter != myTransactionSave || isOperation(); } bool Model_Document::canUndo() { if (myDoc->GetAvailableUndos() > 0 && myNestedNum != 0 - && myTransactionsAfterSave != 0 /* for omitting the first useless transaction */) + && myTransactionsCounter != 0 /* for omitting the first useless transaction */) return true; // check other subs contains operation that can be undoed std::set::iterator aSubIter = mySubs.begin(); @@ -383,10 +384,10 @@ bool Model_Document::canUndo() void Model_Document::undo() { - myTransactionsAfterSave--; + myTransactionsCounter--; if (myNestedNum > 0) myNestedNum--; - if (!myIsEmptyTr[myTransactionsAfterSave]) + if (!myIsEmptyTr[myTransactionsCounter]) myDoc->Undo(); synchronizeFeatures(true, true); // undo for all subs @@ -411,9 +412,9 @@ void Model_Document::redo() { if (myNestedNum != -1) myNestedNum++; - if (!myIsEmptyTr[myTransactionsAfterSave]) + if (!myIsEmptyTr[myTransactionsCounter]) myDoc->Redo(); - myTransactionsAfterSave++; + myTransactionsCounter++; synchronizeFeatures(true, true); // redo for all subs std::set::iterator aSubIter = mySubs.begin(); @@ -1014,6 +1015,9 @@ void Model_Document::updateResults(FeaturePtr theFeature) } aResIter++; } + // it may be on undo + if (!theFeature->data() || !theFeature->data()->isValid()) + return; // check that results are presented on all labels int aResSize = theFeature->results().size(); TDF_ChildIterator aLabIter(resultLabel(theFeature->data(), 0).Father()); diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index 519c57a19..c753ebff0 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -188,8 +188,10 @@ class Model_Document : public ModelAPI_Document std::string myID; ///< identifier of the document in the application std::string myKind; ///< kind of the document in the application Handle_TDocStd_Document myDoc; ///< OCAF document - /// number of transactions after the last "save" call, used for "IsModified" method - int myTransactionsAfterSave; + /// counter of transactions + int myTransactionsCounter; + /// counter value of transaction on the last "save" call, used for "IsModified" method + int myTransactionSave; /// number of nested transactions performed (or -1 if not nested) int myNestedNum; /// All features managed by this document (not only in history of OB) -- 2.39.2