X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2FFeaturesPlugin%2FFeaturesPlugin_Boolean.cpp;h=d10b03f1c365ed906aefd7150e61682d5bea1328;hb=2714903267d23cd0c81166c506fb3edd1e069d40;hp=cc12d94841a91c2b5cfc832a41cdac81147cf01e;hpb=2532fb2df83ee1ddd9ff3e8b381d3788eaa15b69;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp index cc12d9484..d10b03f1c 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp @@ -14,7 +14,8 @@ // 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 +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com // #include "FeaturesPlugin_Boolean.h" @@ -31,10 +32,12 @@ #include #include +#include #include #include #include #include +#include #include #include @@ -86,7 +89,7 @@ void FeaturesPlugin_Boolean::execute() return; OperationType aType = (FeaturesPlugin_Boolean::OperationType)aTypeAttr->value(); - ListOfShape anObjects, aTools, anEdgesAndFaces; + ListOfShape anObjects, aTools, anEdgesAndFaces, aPlanes; std::map, ListOfShape> aCompSolidsObjects; // Getting objects. @@ -100,7 +103,8 @@ void FeaturesPlugin_Boolean::execute() } ResultPtr aContext = anObjectAttr->context(); ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext); - if(aResCompSolidPtr.get()) { + if(aResCompSolidPtr.get() + && aResCompSolidPtr->shape()->shapeType() == GeomAPI_Shape::COMPSOLID) { std::shared_ptr aContextShape = aResCompSolidPtr->shape(); std::map, ListOfShape>::iterator anIt = aCompSolidsObjects.begin(); @@ -114,10 +118,14 @@ void FeaturesPlugin_Boolean::execute() aCompSolidsObjects[aContextShape].push_back(anObject); } } else { - if(anObject->shapeType() == GeomAPI_Shape::EDGE || - anObject->shapeType() == GeomAPI_Shape::FACE) { + if(aType != BOOL_FILL + && (anObject->shapeType() == GeomAPI_Shape::EDGE + || anObject->shapeType() == GeomAPI_Shape::FACE)) + { anEdgesAndFaces.push_back(anObject); - } else { + } + else + { anObjects.push_back(anObject); } } @@ -127,12 +135,16 @@ void FeaturesPlugin_Boolean::execute() AttributeSelectionListPtr aToolsSelList = selectionList(FeaturesPlugin_Boolean::TOOL_LIST_ID()); for(int aToolsIndex = 0; aToolsIndex < aToolsSelList->size(); aToolsIndex++) { AttributeSelectionPtr aToolAttr = aToolsSelList->value(aToolsIndex); - std::shared_ptr aTool = aToolAttr->value(); + GeomShapePtr aTool = aToolAttr->value(); if(!aTool.get()) { - return; + // It could be a construction plane. + ResultPtr aContext = aToolAttr->context(); + aPlanes.push_back(aToolAttr->context()->shape()); } - if(aTool->shapeType() == GeomAPI_Shape::EDGE || - aTool->shapeType() == GeomAPI_Shape::FACE) { + else if(aType != BOOL_FILL + && (aTool->shapeType() == GeomAPI_Shape::EDGE + || aTool->shapeType() == GeomAPI_Shape::FACE)) + { anEdgesAndFaces.push_back(aTool); } else { aTools.push_back(aTool); @@ -145,7 +157,8 @@ void FeaturesPlugin_Boolean::execute() case BOOL_CUT: case BOOL_COMMON: case BOOL_FILL: { - if((anObjects.empty() && aCompSolidsObjects.empty()) || aTools.empty()) { + if((anObjects.empty() && aCompSolidsObjects.empty()) + || (aTools.empty() && aPlanes.empty())) { std::string aFeatureError = "Error: Not enough objects for boolean operation."; setError(aFeatureError); return; @@ -157,25 +170,46 @@ void FeaturesPlugin_Boolean::execute() std::shared_ptr anObject = *anObjectsIt; ListOfShape aListWithObject; aListWithObject.push_back(anObject); - GeomAlgoAPI_MakeShape aBoolAlgo; + GeomAlgoAPI_MakeShapeList aMakeShapeList; + std::shared_ptr aBoolAlgo; GeomShapePtr aResShape; switch(aType) { case BOOL_CUT: { - aBoolAlgo = - GeomAlgoAPI_Boolean(aListWithObject, aTools, GeomAlgoAPI_Boolean::BOOL_CUT); - aResShape = aBoolAlgo.shape(); + aBoolAlgo.reset(new GeomAlgoAPI_Boolean(aListWithObject, + aTools, + GeomAlgoAPI_Boolean::BOOL_CUT)); + aResShape = aBoolAlgo->shape(); break; } case BOOL_COMMON: { - aBoolAlgo = - GeomAlgoAPI_Boolean(aListWithObject, aTools, GeomAlgoAPI_Boolean::BOOL_COMMON); - aResShape = aBoolAlgo.shape(); + aBoolAlgo.reset(new GeomAlgoAPI_Boolean(aListWithObject, + aTools, + GeomAlgoAPI_Boolean::BOOL_COMMON)); + aResShape = aBoolAlgo->shape(); break; } case BOOL_FILL: { - aBoolAlgo = GeomAlgoAPI_Partition(aListWithObject, aTools); - aResShape = aBoolAlgo.shape(); + std::list > aBoundingPoints = + GeomAlgoAPI_ShapeTools::getBoundingBox(aListWithObject, 1.0); + + // Resize planes. + ListOfShape aToolsWithPlanes = aTools; + for(ListOfShape::const_iterator anIt = aPlanes.cbegin(); + anIt != aPlanes.cend(); + ++anIt) + { + GeomShapePtr aPlane = *anIt; + GeomShapePtr aTool = GeomAlgoAPI_ShapeTools::fitPlaneToBox(aPlane, aBoundingPoints); + std::shared_ptr aMkShCustom( + new GeomAlgoAPI_MakeShapeCustom); + aMkShCustom->addModified(aPlane, aTool); + aMakeShapeList.appendAlgo(aMkShCustom); + aToolsWithPlanes.push_back(aTool); + } + + aBoolAlgo.reset(new GeomAlgoAPI_Partition(aListWithObject, aToolsWithPlanes)); + aResShape = aBoolAlgo->shape(); if(aResShape->shapeType() == GeomAPI_Shape::COMPOUND) { int aSubResultsNb = 0; GeomAPI_ShapeIterator anIt(aResShape); @@ -194,7 +228,7 @@ void FeaturesPlugin_Boolean::execute() } // Checking that the algorithm worked properly. - if(!aBoolAlgo.isDone()) { + if(!aBoolAlgo->isDone()) { static const std::string aFeatureError = "Error: Boolean algorithm failed."; setError(aFeatureError); return; @@ -204,17 +238,27 @@ void FeaturesPlugin_Boolean::execute() setError(aShapeError); return; } - if(!aBoolAlgo.isValid()) { + if(!aBoolAlgo->isValid()) { std::string aFeatureError = "Error: Resulting shape is not valid."; setError(aFeatureError); return; } - if(GeomAlgoAPI_ShapeTools::volume(aResShape) > 1.e-27) { + aMakeShapeList.appendAlgo(aBoolAlgo); + + if(GeomAlgoAPI_ShapeTools::volume(aResShape) > 1.e-27 + || (aType != BOOL_CUT && aType != BOOL_COMMON)) + { std::shared_ptr aResultBody = document()->createBody(data(), aResultIndex); - loadNamingDS(aResultBody, anObject, aTools, aResShape, - aBoolAlgo, *aBoolAlgo.mapOfSubShapes().get()); + + ListOfShape aUsedTools = aTools; + if (aType == BOOL_FILL) { + aUsedTools.insert(aUsedTools.end(), aPlanes.begin(), aPlanes.end()); + } + + loadNamingDS(aResultBody, anObject, aUsedTools, aResShape, + aMakeShapeList, *(aBoolAlgo->mapOfSubShapes()), aType == BOOL_FILL); setResult(aResultBody, aResultIndex); aResultIndex++; } @@ -243,6 +287,7 @@ void FeaturesPlugin_Boolean::execute() } } + GeomAlgoAPI_MakeShapeList aMakeShapeList; std::shared_ptr aBoolAlgo; switch(aType) { @@ -259,7 +304,25 @@ void FeaturesPlugin_Boolean::execute() break; } case BOOL_FILL: { - aBoolAlgo.reset(new GeomAlgoAPI_Partition(aUsedInOperationSolids, aTools)); + std::list > aBoundingPoints = + GeomAlgoAPI_ShapeTools::getBoundingBox(aUsedInOperationSolids, 1.0); + + // Resize planes. + ListOfShape aToolsWithPlanes = aTools; + for(ListOfShape::const_iterator anIt = aPlanes.cbegin(); + anIt != aPlanes.cend(); + ++anIt) + { + GeomShapePtr aPlane = *anIt; + GeomShapePtr aTool = GeomAlgoAPI_ShapeTools::fitPlaneToBox(aPlane, aBoundingPoints); + std::shared_ptr aMkShCustom( + new GeomAlgoAPI_MakeShapeCustom); + aMkShCustom->addModified(aPlane, aTool); + aMakeShapeList.appendAlgo(aMkShCustom); + aToolsWithPlanes.push_back(aTool); + } + + aBoolAlgo.reset(new GeomAlgoAPI_Partition(aUsedInOperationSolids, aToolsWithPlanes)); break; } } @@ -281,7 +344,6 @@ void FeaturesPlugin_Boolean::execute() return; } - GeomAlgoAPI_MakeShapeList aMakeShapeList; aMakeShapeList.appendAlgo(aBoolAlgo); GeomAPI_DataMapOfShapeShape aMapOfShapes; aMapOfShapes.merge(aBoolAlgo->mapOfSubShapes()); @@ -304,10 +366,24 @@ void FeaturesPlugin_Boolean::execute() aResultShape = aFillerAlgo->shape(); } - if(GeomAlgoAPI_ShapeTools::volume(aResultShape) > 1.e-27) { + if(GeomAlgoAPI_ShapeTools::volume(aResultShape) > 1.e-27 + || (aType != BOOL_CUT && aType != BOOL_COMMON)) + { std::shared_ptr aResultBody = document()->createBody(data(), aResultIndex); - loadNamingDS(aResultBody, aCompSolid, aTools, aResultShape, aMakeShapeList, aMapOfShapes); + + ListOfShape aUsedTools = aTools; + if (aType == BOOL_FILL) { + aUsedTools.insert(aUsedTools.end(), aPlanes.begin(), aPlanes.end()); + } + + loadNamingDS(aResultBody, + aCompSolid, + aUsedTools, + aResultShape, + aMakeShapeList, + aMapOfShapes, + aType == BOOL_FILL); setResult(aResultBody, aResultIndex); aResultIndex++; } @@ -624,11 +700,12 @@ void FeaturesPlugin_Boolean::loadNamingDS(std::shared_ptr t const ListOfShape& theTools, const std::shared_ptr theResultShape, GeomAlgoAPI_MakeShape& theMakeShape, - GeomAPI_DataMapOfShapeShape& theMapOfShapes) + GeomAPI_DataMapOfShapeShape& theMapOfShapes, + const bool theIsStoreAsGenerated) { //load result if(theBaseShape->isEqual(theResultShape)) { - theResultBody->store(theResultShape); + theResultBody->store(theResultShape, false); } else { const int aModifyTag = 1; const int aDeletedTag = 2; @@ -643,7 +720,7 @@ void FeaturesPlugin_Boolean::loadNamingDS(std::shared_ptr t const std::string aModFName = "Modified_Face"; theResultBody->loadAndOrientModifiedShapes(&theMakeShape, theBaseShape, GeomAPI_Shape::FACE, - aModifyTag, aModName, theMapOfShapes); + aModifyTag, aModName, theMapOfShapes, false, theIsStoreAsGenerated, true); theResultBody->loadDeletedShapes(&theMakeShape, theBaseShape, GeomAPI_Shape::FACE, aDeletedTag); @@ -664,7 +741,7 @@ void FeaturesPlugin_Boolean::loadNamingDS(std::shared_ptr t } theResultBody->loadAndOrientModifiedShapes(&theMakeShape, *anIter, aName == aModEName ? GeomAPI_Shape::EDGE : GeomAPI_Shape::FACE, - aTag, aName, theMapOfShapes); + aTag, aName, theMapOfShapes, false, theIsStoreAsGenerated, true); theResultBody->loadDeletedShapes(&theMakeShape, *anIter, GeomAPI_Shape::FACE, aDeletedTag); } }