X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_RemoveSubShapes.cpp;h=73f353af524d1ffc9120b4d5683121e5fb542127;hb=fc72d43b677baa05ae7fd317346fd8b723b799ed;hp=d2bd7e5dea977411440b3e49077b9165b450b8cb;hpb=9b61e5ee5eafe9d6948d9a78667efa2abec132c3;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp b/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp index d2bd7e5de..73f353af5 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2023 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,10 +12,9 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "FeaturesPlugin_RemoveSubShapes.h" @@ -87,65 +86,71 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID) } myChangedInCode = true; + if (theID == BASE_SHAPE_ID() || theID == SUBSHAPES_TO_KEEP_ID() || + theID == SUBSHAPES_TO_REMOVE_ID()) { + std::list anAllSubs; + ModelAPI_Tools::allSubs(aResultBody, anAllSubs); - if(theID == BASE_SHAPE_ID()) { - aSubShapesToKeepAttrList->clear(); - aSubShapesToRemoveAttrList->clear(); + if(theID == BASE_SHAPE_ID()) { + aSubShapesToKeepAttrList->clear(); + aSubShapesToRemoveAttrList->clear(); - if (!aBaseShape.get()) { - return; - } + if (!aBaseShape.get()) { + return; + } - 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 { - 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; + std::list aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape); + ListOfShape::const_iterator anIt = aSubShapes.cbegin(); + for (; anIt != aSubShapes.cend(); ++anIt) + { + GeomShapePtr aSubShape = *anIt; + if(!isHasSubs) { + aSubShapesToKeepAttrList->append(aContext, aSubShape); + } else { + 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; + } } } } } - } - else if (theID == SUBSHAPES_TO_KEEP_ID()) - { - aSubShapesToRemoveAttrList->clear(); + else if (theID == SUBSHAPES_TO_KEEP_ID()) + { + aSubShapesToRemoveAttrList->clear(); - if (!aBaseShape.get()) { - return; - } + if (!aBaseShape.get()) { + return; + } - int anIndex; - const int aSubsToKeepNb = aSubShapesToKeepAttrList->size(); - std::list aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape); - for (ListOfShape::const_iterator anIt = aSubShapes.cbegin(); anIt != aSubShapes.cend(); ++anIt) - { - GeomShapePtr aSubShape = *anIt; + int anIndex; + // optimization: collect selection attribute values into a map + const int aSubsToKeepNb = aSubShapesToKeepAttrList->size(); + GeomAPI_DataMapOfShapeShape aSubShapesToKeep; for(anIndex = 0; anIndex < aSubsToKeepNb; ++anIndex) { AttributeSelectionPtr anAttrSelectionInList = aSubShapesToKeepAttrList->value(anIndex); GeomShapePtr aSubShapeToKeep = anAttrSelectionInList->value(); - if (aSubShapeToKeep.get() && aSubShapeToKeep->isEqual(aSubShape)) { - break; - } + if (aSubShapeToKeep.get()) + aSubShapesToKeep.bind(aSubShapeToKeep, aSubShapeToKeep); } - if (anIndex == aSubsToKeepNb) { + std::list aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape); + ListOfShape::const_iterator anIt = aSubShapes.cbegin(); + for (; anIt != aSubShapes.cend(); ++anIt) + { + GeomShapePtr aSubShape = *anIt; + if (aSubShapesToKeep.isBound(aSubShape)) + continue; + if(!isHasSubs) { aSubShapesToRemoveAttrList->append(aContext, aSubShape); - } else { - std::list anAllSubs; - ModelAPI_Tools::allSubs(aResultBody, anAllSubs); + } + else { std::list::iterator aSubsIt = anAllSubs.begin(); - for(; aSubsIt != anAllSubs.end(); aSubsIt++) { + 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); @@ -155,37 +160,39 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID) } } } - } - else if (theID == SUBSHAPES_TO_REMOVE_ID()) - { - aSubShapesToKeepAttrList->clear(); + else if (theID == SUBSHAPES_TO_REMOVE_ID()) + { + aSubShapesToKeepAttrList->clear(); - if (!aBaseShape.get()) { - return; - } + if (!aBaseShape.get()) { + return; + } - int anIndex; - const int aSubsToRemoveNb = aSubShapesToRemoveAttrList->size(); - std::list aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape); - for (ListOfShape::const_iterator anIt = aSubShapes.cbegin(); anIt != aSubShapes.cend(); ++anIt) - { - GeomShapePtr aSubShape = *anIt; + int anIndex; + const int aSubsToRemoveNb = aSubShapesToRemoveAttrList->size(); + GeomAPI_DataMapOfShapeShape aSubShapesToRemove; for(anIndex = 0; anIndex < aSubsToRemoveNb; ++anIndex) { AttributeSelectionPtr anAttrSelectionInList = aSubShapesToRemoveAttrList->value(anIndex); GeomShapePtr aSubShapeToRemove = anAttrSelectionInList->value(); - if (aSubShapeToRemove.get() && aSubShapeToRemove->isEqual(aSubShape)) { - break; - } + if (aSubShapeToRemove.get()) + aSubShapesToRemove.bind(aSubShapeToRemove, aSubShapeToRemove); } - if (anIndex == aSubsToRemoveNb) { - if(!isHasSubs) { + + std::list aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape); + ListOfShape::const_iterator anIt = aSubShapes.cbegin(); + for (; anIt != aSubShapes.cend(); ++anIt) + { + GeomShapePtr aSubShape = *anIt; + if (aSubShapesToRemove.isBound(aSubShape)) + continue; + + if (!isHasSubs) { aSubShapesToKeepAttrList->append(aContext, aSubShape); - } else { - std::list anAllSubs; - ModelAPI_Tools::allSubs(aResultBody, anAllSubs); + } + else { std::list::iterator aSubsIt = anAllSubs.begin(); - for(; aSubsIt != anAllSubs.end(); aSubsIt++) { + 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); @@ -283,7 +290,9 @@ void FeaturesPlugin_RemoveSubShapes::execute() // Store result. ResultBodyPtr aResultBody = document()->createBody(data()); - aResultBody->storeModified(aBaseShape, aResultShape); + std::list anOldShapes; + anOldShapes.push_back(aBaseShape); + aResultBody->storeModified(anOldShapes, aResultShape, aMakeShapeList); for (std::set::iterator aTypeIter = aTypes.begin(); aTypeIter != aTypes.end(); ++aTypeIter)