Salome HOME
Make extrusions features correctly eat as a base a whole sketch feature selection.
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_RemoveSubShapes.cpp
index 2f54129831f54599ecfee4f72b51c36924e03050..75b1d9c09dceec344b4969a45518951d7d32f82e 100644 (file)
@@ -23,7 +23,6 @@
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_ResultBody.h>
-#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
@@ -72,14 +71,14 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID)
   }
 
   ResultPtr aContext = aShapeAttrSelection->context();
-  ResultCompSolidPtr aResultCompSolid =
-    std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aContext);
-  if(!aResultCompSolid.get()) {
+  ResultBodyPtr aResultBody =
+    std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContext);
+  if (!aResultBody.get()) {
     aSubShapesToKeepAttrList->clear();
     aSubShapesToRemoveAttrList->clear();
     return;
   }
-  const int aNumOfSubs = aResultCompSolid->numberOfSubs();
+  const int aNumOfSubs = aResultBody->numberOfSubs();
 
   GeomShapePtr aBaseShape = aShapeAttrSelection->value();
   if(!aBaseShape.get()) {
@@ -101,8 +100,8 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID)
       if(aNumOfSubs == 0) {
         aSubShapesToKeepAttrList->append(aContext, aSubShape);
       } else {
-        for(int anIndex = 0; anIndex < aResultCompSolid->numberOfSubs(); ++anIndex) {
-          ResultBodyPtr aSubResult = aResultCompSolid->subResult(anIndex);
+        for (int anIndex = 0; anIndex < aResultBody->numberOfSubs(); ++anIndex) {
+          ResultBodyPtr aSubResult = aResultBody->subResult(anIndex);
           if(aSubResult->shape()->isEqual(aSubShape)) {
             aSubShapesToKeepAttrList->append(aSubResult, aSubShape);
             break;
@@ -135,8 +134,8 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID)
         if(aNumOfSubs == 0) {
           aSubShapesToRemoveAttrList->append(aContext, aSubShape);
         } else {
-          for(int anIndex = 0; anIndex < aResultCompSolid->numberOfSubs(); ++anIndex) {
-            ResultBodyPtr aSubResult = aResultCompSolid->subResult(anIndex);
+          for (int anIndex = 0; anIndex < aResultBody->numberOfSubs(); ++anIndex) {
+            ResultBodyPtr aSubResult = aResultBody->subResult(anIndex);
             if(aSubResult->shape()->isEqual(aSubShape)) {
               aSubShapesToRemoveAttrList->append(aSubResult, aSubShape);
               break;
@@ -170,8 +169,8 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID)
         if(aNumOfSubs == 0) {
           aSubShapesToKeepAttrList->append(aContext, aSubShape);
         } else {
-          for(int anIndex = 0; anIndex < aResultCompSolid->numberOfSubs(); ++anIndex) {
-            ResultBodyPtr aSubResult = aResultCompSolid->subResult(anIndex);
+          for (int anIndex = 0; anIndex < aResultBody->numberOfSubs(); ++anIndex) {
+            ResultBodyPtr aSubResult = aResultBody->subResult(anIndex);
             if(aSubResult->shape()->isEqual(aSubShape)) {
               aSubShapesToKeepAttrList->append(aSubResult, aSubShape);
               break;
@@ -216,9 +215,11 @@ void FeaturesPlugin_RemoveSubShapes::execute()
     AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(0);
     aResultShape = anAttrSelectionInList->value();
   }
+  // deleted and copied must be jointed to one list which keeps all the history
+  GeomAlgoAPI_MakeShapeList aMakeShapeList;
 
   // find all removed shapes
-  GeomAlgoAPI_MakeShapeCustom aDeletedSubs;
+  std::shared_ptr<GeomAlgoAPI_MakeShapeCustom> aDeletedSubs(new GeomAlgoAPI_MakeShapeCustom);
   std::set<GeomAPI_Shape::ShapeType> aTypes; // types that where removed
   aTypes.insert(GeomAPI_Shape::FACE);
   for(GeomAPI_ShapeIterator anIt(aBaseShape); anIt.more(); anIt.next()) {
@@ -233,32 +234,32 @@ void FeaturesPlugin_RemoveSubShapes::execute()
       }
     }
     if (anIndex == aSubsNb) { // not found in left
-      aDeletedSubs.addDeleted(anIt.current());
+      aDeletedSubs->addDeleted(anIt.current());
       aTypes.insert(anIt.current()->shapeType());
       if (anIt.current()->shapeType() != GeomAPI_Shape::FACE) {
         GeomAPI_ShapeExplorer aFaces(anIt.current(), GeomAPI_Shape::FACE);
         for(; aFaces.more(); aFaces.next())
-          aDeletedSubs.addDeleted(aFaces.current());
+          aDeletedSubs->addDeleted(aFaces.current());
       }
     }
   }
+  aMakeShapeList.appendAlgo(aDeletedSubs);
 
-
-  GeomAlgoAPI_Copy aCopy(aResultShape);
-  aResultShape = aCopy.shape();
+  std::shared_ptr<GeomAlgoAPI_Copy> aCopy(new GeomAlgoAPI_Copy(aResultShape));
+  aResultShape = aCopy->shape();
+  aMakeShapeList.appendAlgo(aCopy);
 
   // Store result.
   ResultBodyPtr aResultBody = document()->createBody(data());
   aResultBody->storeModified(aBaseShape, aResultShape, 1);
   std::set<GeomAPI_Shape::ShapeType>::iterator aTypeIter = aTypes.begin();
   for(; aTypeIter != aTypes.end(); aTypeIter++)
-    aResultBody->loadDeletedShapes(&aDeletedSubs, aBaseShape, *aTypeIter, 1);
-  aResultBody->loadAndOrientModifiedShapes(&aCopy,
-                                           aBaseShape,
-                                           GeomAPI_Shape::FACE,
-                                           2,
-                                           "Modified_Face",
-                                           *aCopy.mapOfSubShapes().get(),
-                                           true, false, true);
+    aResultBody->loadDeletedShapes(&aMakeShapeList, aBaseShape, *aTypeIter, 1);
+  aResultBody->loadAndOrientModifiedShapes(&aMakeShapeList, aBaseShape, GeomAPI_Shape::FACE,
+         2, "Modified_Face", *aMakeShapeList.mapOfSubShapes().get(), true, false, true);
+  aResultBody->loadAndOrientModifiedShapes(&aMakeShapeList, aBaseShape, GeomAPI_Shape::EDGE,
+         3, "Modified_Edge", *aMakeShapeList.mapOfSubShapes().get(), false, false, true);
+  aResultBody->loadAndOrientModifiedShapes(&aMakeShapeList, aBaseShape, GeomAPI_Shape::VERTEX,
+         4, "Modified_Vertex", *aMakeShapeList.mapOfSubShapes().get());
   setResult(aResultBody);
 }