X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_Boolean.cpp;h=21458a9ce2ab14459e803371484d2342e0b391c5;hb=f0cec241aae9ca16d86e166f45cb5c4987d2c792;hp=d56a226aa8795aa529a5f865c79b6706cb2be649;hpb=ea948b36a6cc9163da5d2324b04572c9dddd5fd5;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp index d56a226aa..21458a9ce 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp @@ -1,60 +1,96 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: GeomAlgoAPI_Boolean.cpp // Created: 02 Sept 2014 // Author: Vitaly Smetannikov #include "GeomAlgoAPI_Boolean.h" -#include -#include -#include +#include +#include +#include +#include -boost::shared_ptr GeomAlgoAPI_Boolean::makeCut( - boost::shared_ptr theShape, - boost::shared_ptr theTool) +//================================================================================================= +GeomAlgoAPI_Boolean::GeomAlgoAPI_Boolean(const ListOfShape& theObjects, + const ListOfShape& theTools, + const OperationType theOperationType) { - const TopoDS_Shape& aShape = theShape->impl(); - const TopoDS_Shape& aTool = theTool->impl(); - - BRepAlgoAPI_Cut aCut(aShape, aTool); - if (aCut.IsDone()) { - boost::shared_ptr aResult(new GeomAPI_Shape()); - aResult->setImpl(new TopoDS_Shape(aCut.Shape())); - return aResult; - } - return boost::shared_ptr(); + build(theObjects, theTools, theOperationType); } -boost::shared_ptr GeomAlgoAPI_Boolean::makeFuse( - boost::shared_ptr theShape, - boost::shared_ptr theTool) +//================================================================================================= +void GeomAlgoAPI_Boolean::build(const ListOfShape& theObjects, + const ListOfShape& theTools, + const OperationType theOperationType) { - const TopoDS_Shape& aShape = theShape->impl(); - const TopoDS_Shape& aTool = theTool->impl(); - - BRepAlgoAPI_Fuse aFuse(aShape, aTool); - if (aFuse.IsDone()) { - boost::shared_ptr aResult(new GeomAPI_Shape()); - aResult->setImpl(new TopoDS_Shape(aFuse.Shape())); - return aResult; + if(theObjects.empty() || theTools.empty()) { + return; } - return boost::shared_ptr(); -} + // Getting objects. + TopTools_ListOfShape anObjects; + for(ListOfShape::const_iterator anObjectsIt = theObjects.begin(); anObjectsIt != theObjects.end(); anObjectsIt++) + { + anObjects.Append((*anObjectsIt)->impl()); + } -boost::shared_ptr GeomAlgoAPI_Boolean::makeCommon( - boost::shared_ptr theShape, - boost::shared_ptr theTool) -{ - const TopoDS_Shape& aShape = theShape->impl(); - const TopoDS_Shape& aTool = theTool->impl(); - - BRepAlgoAPI_Common aCommon(aShape, aTool); - if (aCommon.IsDone()) { - boost::shared_ptr aResult(new GeomAPI_Shape()); - aResult->setImpl(new TopoDS_Shape(aCommon.Shape())); - return aResult; + // Getting tools. + TopTools_ListOfShape aTools; + for(ListOfShape::const_iterator aToolsIt = theTools.begin(); aToolsIt != theTools.end(); aToolsIt++) + { + aTools.Append((*aToolsIt)->impl()); + } + + // Creating boolean operation. + BOPAlgo_BOP* aBuilder = new BOPAlgo_BOP(); + switch (theOperationType) { + case BOOL_CUT: { + aBuilder->SetOperation(BOPAlgo_CUT); + break; + } + case BOOL_FUSE: { + aBuilder->SetOperation(BOPAlgo_FUSE); + break; + } + case BOOL_COMMON: { + aBuilder->SetOperation(BOPAlgo_COMMON); + break; + } + default: { + return; + } } - return boost::shared_ptr(); -} \ No newline at end of file + this->setImpl(aBuilder); + this->setBuilderType(OCCT_BOPAlgo_Builder); + aBuilder->SetArguments(anObjects); + aBuilder->SetTools(aTools); + + // Building and getting result. + aBuilder->Perform(); + if(aBuilder->ErrorStatus() != 0) { + return; + } + TopoDS_Shape aResult = aBuilder->Shape(); + + if(aResult.ShapeType() == TopAbs_COMPOUND) { + aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); + } + if(aResult.ShapeType() == TopAbs_COMPOUND) { + std::shared_ptr aGeomShape(new GeomAPI_Shape); + aGeomShape->setImpl(new TopoDS_Shape(aResult)); + ListOfShape aCompSolids, aFreeSolids; + aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape, + GeomAPI_Shape::COMPSOLID, + aCompSolids, + aFreeSolids); + aResult = aGeomShape->impl(); + } + + std::shared_ptr aShape(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(aResult)); + this->setShape(aShape); + this->setDone(true); +}