From ebc5236aba00c21e854d6705d1cbbc6599e1bf36 Mon Sep 17 00:00:00 2001 From: dbv Date: Mon, 5 Dec 2016 18:43:20 +0300 Subject: [PATCH] Issue #1916: Fatal error when create sketch on body Remove subshapes Fixed --- .../FeaturesPlugin_RemoveSubShapes.cpp | 41 ++++++++++++++----- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp b/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp index 222880d87..7279cf446 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp @@ -15,6 +15,7 @@ #include +#include #include #include @@ -93,22 +94,40 @@ void FeaturesPlugin_RemoveSubShapes::execute() return; } - // Copy base shape. + // Get base shape. GeomShapePtr aBaseShape = aShapeAttrSelection->value(); - if(!aBaseShape.get()) { - return; - } - GeomShapePtr aResultShape = aBaseShape->emptyCopied(); - // Copy sub-shapes from list to new shape. - for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) { - AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex); - GeomShapePtr aShapeToAdd = anAttrSelectionInList->value(); - GeomAlgoAPI_ShapeBuilder::add(aResultShape, aShapeToAdd); + GeomShapePtr aResultShape; + int aSubsNb = aSubShapesAttrList->size(); + if(aSubsNb > 1) { + if(!aBaseShape.get()) { + return; + } + GeomShapePtr aResultShape = aBaseShape->emptyCopied(); + + // Copy sub-shapes from list to new shape. + for(int anIndex = 0; anIndex < aSubsNb; ++anIndex) { + AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex); + GeomShapePtr aShapeToAdd = anAttrSelectionInList->value(); + GeomAlgoAPI_ShapeBuilder::add(aResultShape, aShapeToAdd); + } + } else if(aSubsNb == 1) { + AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(0); + aResultShape = anAttrSelectionInList->value(); } + GeomAlgoAPI_Copy aCopy(aResultShape); + aResultShape = aCopy.shape(); + // Store result. ResultBodyPtr aResultBody = document()->createBody(data()); - aResultBody->storeModified(aBaseShape, aResultShape); + aResultBody->storeModified(aBaseShape, aResultShape, 1); + aResultBody->loadAndOrientModifiedShapes(&aCopy, + aBaseShape, + GeomAPI_Shape::FACE, + 10000, + "Modified_Face", + *aCopy.mapOfSubShapes().get(), + true); setResult(aResultBody); } -- 2.39.2