From: nds Date: Thu, 28 May 2015 08:53:38 +0000 (+0300) Subject: A correction to remove non-active part. X-Git-Tag: V_1.2.0~36 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=30bf9b30a5f4ee8822bec7aa1c4523c31feaa2ec;p=modules%2Fshaper.git A correction to remove non-active part. Scenario: Create Part_1, create Part_2, delete Part_2, delete Part_1. Result is crash. --- diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index 6bab4002b..6196ca953 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -128,6 +128,7 @@ void Model_Objects::addFeature(FeaturePtr theFeature, const FeaturePtr theAfterT updateHistory(ModelAPI_Feature::group()); } else { // make feature has not-null data anyway theFeature->setData(Model_Data::invalidData()); + theFeature->setDoc(myDoc); } } diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 563bd786c..90fded22d 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -559,6 +559,7 @@ bool PartSet_Module::deleteObjects() aWorkshop->displayer()->updateViewer(); aMgr->finishOperation(); } else { + bool isPartRemoved = false; // Delete part with help of PartSet plugin // TODO: the deleted objects has to be processed by multiselection QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects(); @@ -566,15 +567,23 @@ bool PartSet_Module::deleteObjects() ObjectPtr aObj = aObjects.first(); FeaturePtr aFeature = std::dynamic_pointer_cast(aObj); if (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID())) { - std::shared_ptr aDoc = aMgr->activeDocument(); - aMgr->startOperation(PartSetPlugin_Remove::ID()); - FeaturePtr aFeature = aDoc->addFeature(PartSetPlugin_Remove::ID()); - aFeature->execute(); - aMgr->finishOperation(); - } else - return false; - } else - return false; + // Remove feature should be created in the document of the part results + ResultPtr aPartResult = aFeature->firstResult(); + if (aPartResult.get()) { + std::shared_ptr aPart = + std::dynamic_pointer_cast(aPartResult); + DocumentPtr aPartDoc = aPart->partDoc(); + if (aPartDoc.get()) { + aMgr->startOperation(PartSetPlugin_Remove::ID()); + FeaturePtr aFeature = aPartDoc->addFeature(PartSetPlugin_Remove::ID()); + aFeature->execute(); + aMgr->finishOperation(); + isPartRemoved = true; + } + } + } + } + return isPartRemoved; } return true; } diff --git a/src/PartSetPlugin/PartSetPlugin_Remove.cpp b/src/PartSetPlugin/PartSetPlugin_Remove.cpp index 0c47368fc..56881ca51 100644 --- a/src/PartSetPlugin/PartSetPlugin_Remove.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Remove.cpp @@ -17,14 +17,11 @@ void PartSetPlugin_Remove::execute() { std::shared_ptr aPManager = ModelAPI_Session::get(); std::shared_ptr aRoot = aPManager->moduleDocument(); - std::shared_ptr aCurrent; std::shared_ptr a; for (int a = aRoot->size(ModelAPI_ResultPart::group()) - 1; a >= 0; a--) { ResultPartPtr aPart = std::dynamic_pointer_cast( aRoot->object(ModelAPI_ResultPart::group(), a)); - if (aPart - && aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value() - == aPManager->activeDocument()) { + if (aPart && aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value() == document()) { FeaturePtr aFeature = aRoot->feature(aPart); if (aFeature) { // do remove