X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_CompositeBoolean.cpp;h=cfe002fb0b1ff080ad3d279ac92825f87d85b8e5;hb=a13f87935d2a6f52f942790b6abc874f1016c9fc;hp=de5a25f859071ac85ae8afbad5a5dee41da75238;hpb=fe3678a85238df2b57ea18b341003ebef176e287;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp index de5a25f85..cfe002fb0 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp @@ -1,21 +1,34 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: FeaturesPlugin_CompositeBoolean.cpp -// Created: 11 June 2015 -// Author: Dmitry Bobylev +// Copyright (C) 2014-2019 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// 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 +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include "FeaturesPlugin_CompositeBoolean.h" #include -#include #include #include +#include #include #include #include -#include +#include #include @@ -56,32 +69,51 @@ void FeaturesPlugin_CompositeBoolean::executeCompositeBoolean() // Store result. int aResultIndex = 0; + std::vector aResultBaseAlgoList; + ListOfShape aResultShapesList; ListOfShape::const_iterator aBoolObjIt = aBooleanObjects.cbegin(); ListOfMakeShape::const_iterator aBoolMSIt = aBooleanMakeShapes.cbegin(); for(; aBoolObjIt != aBooleanObjects.cend() && aBoolMSIt != aBooleanMakeShapes.cend(); ++aBoolObjIt, ++aBoolMSIt) { - int aTag = 1; - ResultBodyPtr aResultBody = myFeature->document()->createBody(myFeature->data(), aResultIndex); - aResultBody->storeModified(*aBoolObjIt, (*aBoolMSIt)->shape(), aTag); - - aTag += 5000; - // Store generation history. - ListOfShape::const_iterator aGenBaseIt = aGenBaseShapes.cbegin(); - ListOfMakeShape::const_iterator aGenMSIt = aGenMakeShapes.cbegin(); - for(; aGenBaseIt != aGenBaseShapes.cend() && aGenMSIt != aGenMakeShapes.cend(); - ++aGenBaseIt, ++aGenMSIt) { - storeGenerationHistory(aResultBody, *aGenBaseIt, *aGenMSIt, aTag); + if((*aBoolObjIt)->isEqual((*aBoolMSIt)->shape())) { + aResultBody->store((*aBoolMSIt)->shape(), false); } + else + { + aResultBody->storeModified(*aBoolObjIt, (*aBoolMSIt)->shape()); + + // Store generation history. + ListOfShape::const_iterator aGenBaseIt = aGenBaseShapes.cbegin(); + ListOfMakeShape::const_iterator aGenMSIt = aGenMakeShapes.cbegin(); + for(; aGenBaseIt != aGenBaseShapes.cend() && aGenMSIt != aGenMakeShapes.cend(); + ++aGenBaseIt, ++aGenMSIt) { + std::shared_ptr aMSList(new GeomAlgoAPI_MakeShapeList()); + aMSList->appendAlgo(*aGenMSIt); + aMSList->appendAlgo(*aBoolMSIt); + storeGenerationHistory(aResultBody, *aGenBaseIt, aMSList); + } + + storeModificationHistory(aResultBody, *aBoolObjIt, aTools, *aBoolMSIt); - int aModTag = aTag; - storeModificationHistory(aResultBody, *aBoolObjIt, aTools, *aBoolMSIt, aModTag); + ResultBaseAlgo aRBA; + aRBA.resultBody = aResultBody; + aRBA.baseShape = *aBoolObjIt; + aRBA.makeShape = *aBoolMSIt; + aResultBaseAlgoList.push_back(aRBA); + aResultShapesList.push_back((*aBoolMSIt)->shape()); + } myFeature->setResult(aResultBody, aResultIndex++); } + // Store deleted shapes after all results has been proceeded. This is to avoid issue when in one + // result shape has been deleted, but in another it was modified or stayed. + GeomShapePtr aResultShapesCompound = GeomAlgoAPI_CompoundBuilder::compound(aResultShapesList); + storeDeletedShapes(aResultBaseAlgoList, aTools, aResultShapesCompound); + myFeature->removeResults(aResultIndex); } @@ -102,7 +134,7 @@ bool FeaturesPlugin_CompositeBoolean::makeBoolean(const ListOfShape& theTools, return false; } ResultPtr aContext = anObjectAttr->context(); - ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext); + ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext); if(aResCompSolidPtr.get()) { GeomShapePtr aContextShape = aResCompSolidPtr->shape(); std::map::iterator anIt = aCompSolidsObjects.begin(); @@ -141,7 +173,7 @@ bool FeaturesPlugin_CompositeBoolean::makeBoolean(const ListOfShape& theTools, aListWithObject.push_back(anObject); std::shared_ptr aBoolAlgo(new GeomAlgoAPI_Boolean(aListWithObject, theTools, - GeomAlgoAPI_Boolean::BOOL_CUT)); + GeomAlgoAPI_Tools::BOOL_CUT)); // Checking that the algorithm worked properly. if(!aBoolAlgo->isDone() || aBoolAlgo->shape()->isNull() || !aBoolAlgo->isValid()) { @@ -163,9 +195,11 @@ bool FeaturesPlugin_CompositeBoolean::makeBoolean(const ListOfShape& theTools, // Collecting solids from compsolids which will not be modified in boolean operation. ListOfShape aShapesToAdd; - for(GeomAPI_ShapeExplorer - anExp(aCompSolid, GeomAPI_Shape::SOLID); anExp.more(); anExp.next()) { - GeomShapePtr aSolidInCompSolid = anExp.current(); + for (GeomAPI_ShapeIterator aCompSolidIt(aCompSolid); + aCompSolidIt.more(); + aCompSolidIt.next()) + { + GeomShapePtr aSolidInCompSolid = aCompSolidIt.current(); ListOfShape::const_iterator aUsedShapesIt = aUsedShapes.cbegin(); for(; aUsedShapesIt != aUsedShapes.cend(); ++aUsedShapesIt) { if(aSolidInCompSolid->isEqual(*aUsedShapesIt)) { @@ -179,7 +213,7 @@ bool FeaturesPlugin_CompositeBoolean::makeBoolean(const ListOfShape& theTools, std::shared_ptr aBoolAlgo(new GeomAlgoAPI_Boolean(aUsedShapes, theTools, - GeomAlgoAPI_Boolean::BOOL_CUT)); + GeomAlgoAPI_Tools::BOOL_CUT)); // Checking that the algorithm worked properly. if(!aBoolAlgo->isDone() || aBoolAlgo->shape()->isNull() || !aBoolAlgo->isValid()) { @@ -191,17 +225,20 @@ bool FeaturesPlugin_CompositeBoolean::makeBoolean(const ListOfShape& theTools, aMakeShapeList->appendAlgo(aBoolAlgo); // Add result to not used solids from compsolid. - aShapesToAdd.push_back(aBoolAlgo->shape()); - std::shared_ptr aFillerAlgo( - new GeomAlgoAPI_PaveFiller(aShapesToAdd, true)); - if(!aFillerAlgo->isDone() || aFillerAlgo->shape()->isNull() || !aFillerAlgo->isValid()) { - myFeature->setError("Error: PaveFiller algorithm failed."); - return false; + GeomShapePtr aBoolRes = aBoolAlgo->shape(); + if (!aShapesToAdd.empty()) { + aShapesToAdd.push_back(aBoolRes); + std::shared_ptr aFillerAlgo( + new GeomAlgoAPI_PaveFiller(aShapesToAdd, true)); + if(!aFillerAlgo->isDone() || aFillerAlgo->shape()->isNull() || !aFillerAlgo->isValid()) { + myFeature->setError("Error: PaveFiller algorithm failed."); + return false; + } + aBoolRes = aFillerAlgo->shape(); + aMakeShapeList->appendAlgo(aFillerAlgo); } - aMakeShapeList->appendAlgo(aFillerAlgo); - - if(GeomAlgoAPI_ShapeTools::volume(aFillerAlgo->shape()) > 1.e-27) { + if(GeomAlgoAPI_ShapeTools::volume(aBoolRes) > 1.e-27) { theObjects.push_back(aCompSolid); theMakeShapes.push_back(aMakeShapeList); } @@ -246,9 +283,11 @@ bool FeaturesPlugin_CompositeBoolean::makeBoolean(const ListOfShape& theTools, aSolidsToFuse.insert(aSolidsToFuse.end(), aUsedShapes.begin(), aUsedShapes.end()); // Collect solids from compsolid which will not be modified in boolean operation. - for(GeomAPI_ShapeExplorer - anExp(aCompSolid, GeomAPI_Shape::SOLID); anExp.more(); anExp.next()) { - GeomShapePtr aSolidInCompSolid = anExp.current(); + for (GeomAPI_ShapeIterator aCompSolidIt(aCompSolid); + aCompSolidIt.more(); + aCompSolidIt.next()) + { + GeomShapePtr aSolidInCompSolid = aCompSolidIt.current(); ListOfShape::iterator anIt = aUsedShapes.begin(); for(; anIt != aUsedShapes.end(); anIt++) { if(aSolidInCompSolid->isEqual(*anIt)) { @@ -271,7 +310,7 @@ bool FeaturesPlugin_CompositeBoolean::makeBoolean(const ListOfShape& theTools, if(!anEdgesAndFaces.empty() && !aCutTools.empty()) { std::shared_ptr aCutAlgo(new GeomAlgoAPI_Boolean(anEdgesAndFaces, aCutTools, - GeomAlgoAPI_Boolean::BOOL_CUT)); + GeomAlgoAPI_Tools::BOOL_CUT)); if(aCutAlgo->isDone() && !aCutAlgo->shape()->isNull() && aCutAlgo->isValid()) { anEdgesAndFaces.clear(); anEdgesAndFaces.push_back(aCutAlgo->shape()); @@ -283,7 +322,7 @@ bool FeaturesPlugin_CompositeBoolean::makeBoolean(const ListOfShape& theTools, if(!aShapesToAdd.empty()) { std::shared_ptr aCutAlgo(new GeomAlgoAPI_Boolean(aSolidsToFuse, aShapesToAdd, - GeomAlgoAPI_Boolean::BOOL_CUT)); + GeomAlgoAPI_Tools::BOOL_CUT)); if(aCutAlgo->isDone() && GeomAlgoAPI_ShapeTools::volume(aCutAlgo->shape()) > 1.e-27) { aSolidsToFuse.clear(); aSolidsToFuse.push_back(aCutAlgo->shape()); @@ -303,7 +342,7 @@ bool FeaturesPlugin_CompositeBoolean::makeBoolean(const ListOfShape& theTools, std::shared_ptr aFuseAlgo(new GeomAlgoAPI_Boolean(anObjects, aTools, - GeomAlgoAPI_Boolean::BOOL_FUSE)); + GeomAlgoAPI_Tools::BOOL_FUSE)); // Checking that the algorithm worked properly. if(!aFuseAlgo->isDone() || aFuseAlgo->shape()->isNull() || !aFuseAlgo->isValid()) { @@ -344,38 +383,41 @@ bool FeaturesPlugin_CompositeBoolean::makeBoolean(const ListOfShape& theTools, void FeaturesPlugin_CompositeBoolean::storeModificationHistory(ResultBodyPtr theResultBody, const GeomShapePtr theObject, const ListOfShape& theTools, - const std::shared_ptr theMakeShape, - int& theTag) + const std::shared_ptr theMakeShape) { - int aModTag = theTag; - int anEdgesAndFacesTag = ++aModTag; - int aDelTag = ++anEdgesAndFacesTag; - theTag = aDelTag; - - const std::string aModName = "Modfied"; - ListOfShape aTools = theTools; aTools.push_back(theObject); - std::shared_ptr aMap = theMakeShape->mapOfSubShapes(); - - int aTag; - std::string aName; for(ListOfShape::const_iterator anIt = aTools.begin(); anIt != aTools.end(); anIt++) { - if((*anIt)->shapeType() == GeomAPI_Shape::EDGE) { - aTag = anEdgesAndFacesTag; - aName = aModName + "_Edge"; - } - else if((*anIt)->shapeType() == GeomAPI_Shape::FACE) { - aTag = anEdgesAndFacesTag; - aName = aModName + "_Face"; - } else { - aTag = aModTag; - aName = aModName; + theResultBody->loadModifiedShapes(theMakeShape, *anIt, + (*anIt)->shapeType() == GeomAPI_Shape::EDGE ? + GeomAPI_Shape::EDGE : + GeomAPI_Shape::FACE); + } +} + +//================================================================================================== +void FeaturesPlugin_CompositeBoolean::storeDeletedShapes( + std::vector& theResultBaseAlgoList, + const ListOfShape& theTools, + const GeomShapePtr theResultShapesCompound) +{ + for (std::vector::iterator anIt = theResultBaseAlgoList.begin(); + anIt != theResultBaseAlgoList.end(); + ++anIt) + { + ResultBaseAlgo& aRCA = *anIt; + aRCA.resultBody->loadDeletedShapes(aRCA.makeShape, + aRCA.baseShape, + GeomAPI_Shape::FACE, + theResultShapesCompound); + + for (ListOfShape::const_iterator anIter = theTools.begin(); anIter != theTools.end(); anIter++) + { + aRCA.resultBody->loadDeletedShapes(aRCA.makeShape, + *anIter, + GeomAPI_Shape::FACE, + theResultShapesCompound); } - theResultBody->loadAndOrientModifiedShapes(theMakeShape.get(), *anIt, - (*anIt)->shapeType() == GeomAPI_Shape::EDGE ? - GeomAPI_Shape::EDGE : GeomAPI_Shape::FACE, aTag, aName, *aMap.get()); - theResultBody->loadDeletedShapes(theMakeShape.get(), *anIt, GeomAPI_Shape::FACE, aDelTag); } }