X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FFeaturesPlugin%2FFeaturesPlugin_RemoveSubShapes.cpp;h=75b335b61eede0794c06f50e54bf1a3ce0949fcd;hb=a55586483e5dccc5466d6ec241e2147e210d839f;hp=75b1d9c09dceec344b4969a45518951d7d32f82e;hpb=1e2eaa713f139d2617c80eba9ede62d4e9976bb7;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp b/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp index 75b1d9c09..75b335b61 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -78,7 +79,7 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID) aSubShapesToRemoveAttrList->clear(); return; } - const int aNumOfSubs = aResultBody->numberOfSubs(); + const bool isHasSubs = ModelAPI_Tools::hasSubResults(aResultBody); GeomShapePtr aBaseShape = aShapeAttrSelection->value(); if(!aBaseShape.get()) { @@ -95,15 +96,20 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID) return; } - for(GeomAPI_ShapeIterator anIt(aBaseShape); anIt.more(); anIt.next()) { - GeomShapePtr aSubShape = anIt.current(); - if(aNumOfSubs == 0) { + std::list aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape); + for (ListOfShape::const_iterator anIt = aSubShapes.cbegin(); anIt != aSubShapes.cend(); ++anIt) + { + GeomShapePtr aSubShape = *anIt; + if(!isHasSubs) { aSubShapesToKeepAttrList->append(aContext, aSubShape); } else { - for (int anIndex = 0; anIndex < aResultBody->numberOfSubs(); ++anIndex) { - ResultBodyPtr aSubResult = aResultBody->subResult(anIndex); - if(aSubResult->shape()->isEqual(aSubShape)) { - aSubShapesToKeepAttrList->append(aSubResult, aSubShape); + std::list anAllSubs; + ModelAPI_Tools::allSubs(aResultBody, anAllSubs); + std::list::iterator aSubsIt = anAllSubs.begin(); + for(; aSubsIt != anAllSubs.end(); aSubsIt++) { + ResultBodyPtr aSub = std::dynamic_pointer_cast(*aSubsIt); + if (aSub && aSub->shape().get() && aSub->shape()->isSubShape(aSubShape)) { + aSubShapesToKeepAttrList->append(aSub, aSubShape); break; } } @@ -120,24 +126,30 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID) int anIndex; const int aSubsToKeepNb = aSubShapesToKeepAttrList->size(); - for(GeomAPI_ShapeIterator anIt(aBaseShape); anIt.more(); anIt.next()) { - GeomShapePtr aSubShape = anIt.current(); + std::list aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape); + for (ListOfShape::const_iterator anIt = aSubShapes.cbegin(); anIt != aSubShapes.cend(); ++anIt) + { + GeomShapePtr aSubShape = *anIt; for(anIndex = 0; anIndex < aSubsToKeepNb; ++anIndex) { AttributeSelectionPtr anAttrSelectionInList = aSubShapesToKeepAttrList->value(anIndex); GeomShapePtr aSubShapeToKeep = anAttrSelectionInList->value(); - if (aSubShapeToKeep.get() && aSubShapeToKeep->isEqual(aSubShape)) { + if (aSubShapeToKeep.get() && + (aSubShapeToKeep->isEqual(aSubShape) || aSubShapeToKeep->isSubShape(aSubShape))) { break; } } if (anIndex == aSubsToKeepNb) { - if(aNumOfSubs == 0) { + if(!isHasSubs) { aSubShapesToRemoveAttrList->append(aContext, aSubShape); } else { - for (int anIndex = 0; anIndex < aResultBody->numberOfSubs(); ++anIndex) { - ResultBodyPtr aSubResult = aResultBody->subResult(anIndex); - if(aSubResult->shape()->isEqual(aSubShape)) { - aSubShapesToRemoveAttrList->append(aSubResult, aSubShape); + std::list anAllSubs; + ModelAPI_Tools::allSubs(aResultBody, anAllSubs); + std::list::iterator aSubsIt = anAllSubs.begin(); + for(; aSubsIt != anAllSubs.end(); aSubsIt++) { + ResultBodyPtr aSub = std::dynamic_pointer_cast(*aSubsIt); + if (aSub && aSub->shape().get() && aSub->shape()->isSubShape(aSubShape)) { + aSubShapesToRemoveAttrList->append(aSub, aSubShape); break; } } @@ -155,24 +167,30 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID) int anIndex; const int aSubsToRemoveNb = aSubShapesToRemoveAttrList->size(); - for(GeomAPI_ShapeIterator anIt(aBaseShape); anIt.more(); anIt.next()) { - GeomShapePtr aSubShape = anIt.current(); + std::list aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape); + for (ListOfShape::const_iterator anIt = aSubShapes.cbegin(); anIt != aSubShapes.cend(); ++anIt) + { + GeomShapePtr aSubShape = *anIt; for(anIndex = 0; anIndex < aSubsToRemoveNb; ++anIndex) { AttributeSelectionPtr anAttrSelectionInList = aSubShapesToRemoveAttrList->value(anIndex); GeomShapePtr aSubShapeToRemove = anAttrSelectionInList->value(); - if (aSubShapeToRemove.get() && aSubShapeToRemove->isEqual(aSubShape)) { + if (aSubShapeToRemove.get() && + (aSubShapeToRemove->isEqual(aSubShape) || aSubShapeToRemove->isSubShape(aSubShape))) { break; } } if (anIndex == aSubsToRemoveNb) { - if(aNumOfSubs == 0) { + if(!isHasSubs) { aSubShapesToKeepAttrList->append(aContext, aSubShape); } else { - for (int anIndex = 0; anIndex < aResultBody->numberOfSubs(); ++anIndex) { - ResultBodyPtr aSubResult = aResultBody->subResult(anIndex); - if(aSubResult->shape()->isEqual(aSubShape)) { - aSubShapesToKeepAttrList->append(aSubResult, aSubShape); + std::list anAllSubs; + ModelAPI_Tools::allSubs(aResultBody, anAllSubs); + std::list::iterator aSubsIt = anAllSubs.begin(); + for(; aSubsIt != anAllSubs.end(); aSubsIt++) { + ResultBodyPtr aSub = std::dynamic_pointer_cast(*aSubsIt); + if (aSub && aSub->shape().get() && aSub->shape()->isSubShape(aSubShape)) { + aSubShapesToKeepAttrList->append(aSub, aSubShape); break; } } @@ -222,22 +240,26 @@ void FeaturesPlugin_RemoveSubShapes::execute() std::shared_ptr aDeletedSubs(new GeomAlgoAPI_MakeShapeCustom); std::set aTypes; // types that where removed aTypes.insert(GeomAPI_Shape::FACE); - for(GeomAPI_ShapeIterator anIt(aBaseShape); anIt.more(); anIt.next()) { - if (!anIt.current().get() || anIt.current()->isNull()) + + std::list aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape); + for (ListOfShape::const_iterator anIt = aSubShapes.cbegin(); anIt != aSubShapes.cend(); ++anIt) { + GeomShapePtr aSubShape = *anIt; + if (!aSubShape.get() || aSubShape->isNull()) continue; + int anIndex; for(anIndex = 0; anIndex < aSubsNb; ++anIndex) { AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex); GeomShapePtr aLeftShape = anAttrSelectionInList->value(); - if (anIt.current()->isEqual(aLeftShape)) { + if (aSubShape->isEqual(aLeftShape)) { break; // found in a left-list } } if (anIndex == aSubsNb) { // not found in left - aDeletedSubs->addDeleted(anIt.current()); - aTypes.insert(anIt.current()->shapeType()); - if (anIt.current()->shapeType() != GeomAPI_Shape::FACE) { - GeomAPI_ShapeExplorer aFaces(anIt.current(), GeomAPI_Shape::FACE); + aDeletedSubs->addDeleted(aSubShape); + aTypes.insert(aSubShape->shapeType()); + if (aSubShape->shapeType() != GeomAPI_Shape::FACE) { + GeomAPI_ShapeExplorer aFaces(aSubShape, GeomAPI_Shape::FACE); for(; aFaces.more(); aFaces.next()) aDeletedSubs->addDeleted(aFaces.current()); } @@ -249,6 +271,18 @@ void FeaturesPlugin_RemoveSubShapes::execute() aResultShape = aCopy->shape(); aMakeShapeList.appendAlgo(aCopy); + if (aResultShape->shapeType() == GeomAPI_Shape::COMPOUND) { + aResultShape = GeomAlgoAPI_ShapeTools::groupSharedTopology(aResultShape); + if (aResultShape->shapeType() == GeomAPI_Shape::COMPOUND) { + // if the result has only one sub-shape, discard the compound + GeomAPI_ShapeIterator aSubIt(aResultShape); + GeomShapePtr aSub = aSubIt.current(); + aSubIt.next(); + if (!aSubIt.more()) + aResultShape = aSub; + } + } + // Store result. ResultBodyPtr aResultBody = document()->createBody(data()); aResultBody->storeModified(aBaseShape, aResultShape, 1); @@ -256,10 +290,10 @@ void FeaturesPlugin_RemoveSubShapes::execute() for(; aTypeIter != aTypes.end(); aTypeIter++) aResultBody->loadDeletedShapes(&aMakeShapeList, aBaseShape, *aTypeIter, 1); aResultBody->loadAndOrientModifiedShapes(&aMakeShapeList, aBaseShape, GeomAPI_Shape::FACE, - 2, "Modified_Face", *aMakeShapeList.mapOfSubShapes().get(), true, false, true); + 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); + 3, "Modified_Edge", *aMakeShapeList.mapOfSubShapes().get(), false, false, true); aResultBody->loadAndOrientModifiedShapes(&aMakeShapeList, aBaseShape, GeomAPI_Shape::VERTEX, - 4, "Modified_Vertex", *aMakeShapeList.mapOfSubShapes().get()); + 4, "Modified_Vertex", *aMakeShapeList.mapOfSubShapes().get()); setResult(aResultBody); }