From 9f8379064ab359da1eda4c3a258a8e67ee2c7f7a Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 6 Apr 2017 10:53:12 +0300 Subject: [PATCH] Fixes for issue #1956 and issue #2104 : correctly remove features on part remove. --- src/Model/Model_Objects.cpp | 23 +++++++++++++++++++++- src/Model/Model_ResultPart.cpp | 2 +- src/ModelAPI/ModelAPI_Feature.cpp | 3 ++- src/PartSetPlugin/PartSetPlugin_Part.cpp | 3 ++- src/PartSetPlugin/PartSetPlugin_Remove.cpp | 5 +++-- src/XGUI/XGUI_DataModel.cpp | 6 +----- 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index b0964875d..949f99b92 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -271,7 +271,28 @@ void Model_Objects::removeFeature(FeaturePtr theFeature) void Model_Objects::eraseAllFeatures() { - ModelAPI_EventCreator::get()->sendDeleted(myDoc, ModelAPI_Feature::group()); + static Events_ID kDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY); + static const ModelAPI_EventCreator* kCreator = ModelAPI_EventCreator::get(); + // make all features invalid (like deleted) + NCollection_DataMap::Iterator aFIter(myFeatures); + for(; aFIter.More(); aFIter.Next()) { + FeaturePtr aFeature = aFIter.Value(); + std::list aResList; + ModelAPI_Tools::allResults(aFeature, aResList); + std::list::iterator aRIter = aResList.begin(); + for(; aRIter != aResList.end(); aRIter++) { + ResultPtr aRes = *aRIter; + if (aRes && aRes->data()->isValid()) { + kCreator->sendDeleted(myDoc, aRes->groupName()); + kCreator->sendUpdated(aRes, kDispEvent); + aRes->setData(aRes->data()->invalidPtr()); + + } + } + kCreator->sendUpdated(aFeature, kDispEvent); + aFeature->setData(aFeature->data()->invalidPtr()); + } + kCreator->sendDeleted(myDoc, ModelAPI_Feature::group()); myFeatures.Clear(); // just remove features without modification of DS updateHistory(ModelAPI_Feature::group()); } diff --git a/src/Model/Model_ResultPart.cpp b/src/Model/Model_ResultPart.cpp index d06786869..2beb5f562 100644 --- a/src/Model/Model_ResultPart.cpp +++ b/src/Model/Model_ResultPart.cpp @@ -177,7 +177,7 @@ std::shared_ptr Model_ResultPart::shape() for(int a = aDoc->size(aBodyGroup) - 1; a >= 0; a--) { ResultPtr aBody = std::dynamic_pointer_cast(aDoc->object(aBodyGroup, a)); // "object" method filters out disabled and concealed anyway, so don't check - if (aBody.get() && aBody->shape().get()) { + if (aBody.get() && aBody->data()->isValid() && aBody->shape().get()) { TopoDS_Shape aShape = *(aBody->shape()->implPtr()); if (!aShape.IsNull()) { aBuilder.Add(aResultComp, aShape); diff --git a/src/ModelAPI/ModelAPI_Feature.cpp b/src/ModelAPI/ModelAPI_Feature.cpp index f83cf00a8..783a33009 100644 --- a/src/ModelAPI/ModelAPI_Feature.cpp +++ b/src/ModelAPI/ModelAPI_Feature.cpp @@ -167,7 +167,8 @@ void ModelAPI_Feature::erase() ModelAPI_Feature::~ModelAPI_Feature() { - erase(); + if (data() && data()->isValid()) + erase(); } FeaturePtr ModelAPI_Feature::feature(ObjectPtr theObject) diff --git a/src/PartSetPlugin/PartSetPlugin_Part.cpp b/src/PartSetPlugin/PartSetPlugin_Part.cpp index df8b64510..97100e89b 100644 --- a/src/PartSetPlugin/PartSetPlugin_Part.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Part.cpp @@ -112,7 +112,8 @@ void PartSetPlugin_Part::erase() { ResultPartPtr aResult = std::dynamic_pointer_cast(firstResult()); if (aResult.get()) { DocumentPtr aDoc = aResult->partDoc(); - aDoc->eraseAllFeatures(); + if (aDoc.get()) + aDoc->eraseAllFeatures(); } ModelAPI_Feature::erase(); } diff --git a/src/PartSetPlugin/PartSetPlugin_Remove.cpp b/src/PartSetPlugin/PartSetPlugin_Remove.cpp index bf5434709..7bc6f3a1c 100644 --- a/src/PartSetPlugin/PartSetPlugin_Remove.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Remove.cpp @@ -27,8 +27,9 @@ void PartSetPlugin_Remove::execute() if (aPart.get()) { FeaturePtr aFeature = aRoot->feature(aPart); if (aFeature) { - // do remove - aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value()->close(); + // do remove, but don't do real close (features are erased without persistence changes + // document remove may be undoed) + // aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value()->close(); std::set > aRefFeatures; aRoot->refsToFeature(aFeature, aRefFeatures); if (aRefFeatures.empty()) { diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index 88fb28eeb..2eef35a76 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -644,11 +644,7 @@ QModelIndex XGUI_DataModel::index(int theRow, int theColumn, const QModelIndex & } else { // this is an object under sub document root std::string aType = myXMLReader->subType(); - int aCount = theRow - aNbSubFolders; - // To check number of objects before using - if (aSubDoc->size(aType) <= aCount) - return QModelIndex(); - ObjectPtr aObj = aSubDoc->object(aType, aCount); + ObjectPtr aObj = aSubDoc->object(aType, theRow - aNbSubFolders); aIndex = objectIndex(aObj); } } else { -- 2.30.2