From 2760e152b279ea889b7839e263071c6875d5f073 Mon Sep 17 00:00:00 2001 From: mpv Date: Wed, 17 Sep 2014 10:38:18 +0400 Subject: [PATCH] Fixed crash with abort of sketch in the Part document --- src/Model/Model_Document.cpp | 14 ++++++++------ src/Model/Model_Document.h | 5 +++-- src/ModelAPI/ModelAPI_Feature.cpp | 16 ++++++++++------ 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index cb5d28394..9057ab82f 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -224,9 +224,9 @@ void Model_Document::startOperation() myNestedNum = 0; myDoc->InitDeltaCompaction(); } - myIsEmptyTr[myTransactionsAfterSave] = false; + myIsEmptyTr[myTransactionsAfterSave] = !myDoc->CommitCommand(); myTransactionsAfterSave++; - myDoc->NewCommand(); + myDoc->OpenCommand(); } else { // start the simple command myDoc->NewCommand(); } @@ -236,7 +236,7 @@ void Model_Document::startOperation() subDoc(*aSubIter)->startOperation(); } -void Model_Document::compactNested() +bool Model_Document::compactNested() { bool allWasEmpty = true; while (myNestedNum != -1) { @@ -250,6 +250,7 @@ void Model_Document::compactNested() myIsEmptyTr[myTransactionsAfterSave] = allWasEmpty; myTransactionsAfterSave++; myDoc->PerformDeltaCompaction(); + return !allWasEmpty; } void Model_Document::finishOperation() @@ -291,9 +292,10 @@ void Model_Document::abortOperation() { 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(); + if (compactNested()) { + // for nested it is undo and clear redos + myDoc->Undo(); + } myDoc->ClearRedos(); myTransactionsAfterSave--; myIsEmptyTr.erase(myTransactionsAfterSave); diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index 598c3b633..f9bbd0809 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -145,8 +145,9 @@ class Model_Document : public ModelAPI_Document return myDoc; } - //! performas compactification of all nested operations into one - void compactNested(); + //! performs compactification of all nested operations into one + //! \returns true if resulting transaction is not empty and can be undoed + bool compactNested(); //! Initializes the data fields of the feature void initData(ObjectPtr theObj, TDF_Label theLab, const int theTag); diff --git a/src/ModelAPI/ModelAPI_Feature.cpp b/src/ModelAPI/ModelAPI_Feature.cpp index a34d71bc5..aec952e79 100644 --- a/src/ModelAPI/ModelAPI_Feature.cpp +++ b/src/ModelAPI/ModelAPI_Feature.cpp @@ -77,13 +77,17 @@ void ModelAPI_Feature::removeResult(const boost::shared_ptr& th void ModelAPI_Feature::eraseResults() { - std::list >::iterator aResIter = myResults.begin(); - for(; aResIter != myResults.end(); aResIter++) { - (*aResIter)->data()->erase(); - static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED); - ModelAPI_EventCreator::get()->sendDeleted(document(), (*aResIter)->groupName()); + if (!myResults.empty()) { + static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED); + std::list >::iterator aResIter = myResults.begin(); + for(; aResIter != myResults.end(); aResIter++) { + (*aResIter)->data()->erase(); + ModelAPI_EventCreator::get()->sendDeleted(document(), (*aResIter)->groupName()); + } + myResults.clear(); + // flush it to avoid left presentations after input of invalid arguments (radius=0) + Events_Loop::loop()->flush(anEvent); } - myResults.clear(); } boost::shared_ptr ModelAPI_Feature::documentToAdd() -- 2.39.2