]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
A correction to remove non-active part.
authornds <natalia.donis@opencascade.com>
Thu, 28 May 2015 08:53:38 +0000 (11:53 +0300)
committernds <natalia.donis@opencascade.com>
Thu, 28 May 2015 08:54:09 +0000 (11:54 +0300)
Scenario: Create Part_1, create Part_2, delete Part_2, delete Part_1. Result is crash.

src/Model/Model_Objects.cpp
src/PartSet/PartSet_Module.cpp
src/PartSetPlugin/PartSetPlugin_Remove.cpp

index 6bab4002bb9c3049dc51a0e44afffadb4413fe85..6196ca95390c5353b62ccd0602aaabd1767aeab0 100644 (file)
@@ -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);
   }
 }
 
index 563bd786c90403d2532382d3908b3091f512820a..90fded22d857738709120457e8eef8ccb84573f8 100644 (file)
@@ -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<ModelAPI_Feature>(aObj);
       if (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID())) {
-        std::shared_ptr<ModelAPI_Document> 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<ModelAPI_ResultPart> aPart =
+                       std::dynamic_pointer_cast<ModelAPI_ResultPart>(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;
 }
index 0c47368fc1eeb4ea8c56f0a99c44e78b33c3eb1a..56881ca51238c578361d7126271ac2b3127684bb 100644 (file)
@@ -17,14 +17,11 @@ void PartSetPlugin_Remove::execute()
 {
   std::shared_ptr<ModelAPI_Session> aPManager = ModelAPI_Session::get();
   std::shared_ptr<ModelAPI_Document> aRoot = aPManager->moduleDocument();
-  std::shared_ptr<ModelAPI_Document> aCurrent;
   std::shared_ptr<PartSetPlugin_Part> a;
   for (int a = aRoot->size(ModelAPI_ResultPart::group()) - 1; a >= 0; a--) {
     ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(
         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