X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_Boolean.cpp;h=21458a9ce2ab14459e803371484d2342e0b391c5;hb=f0cec241aae9ca16d86e166f45cb5c4987d2c792;hp=0f68186e4b67cc01235f573e72d640783e09693b;hpb=b801d5f85aa3dc5786510acf87c8003f1d59eadd;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp index 0f68186e4..21458a9ce 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp @@ -1,24 +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 + +//================================================================================================= +GeomAlgoAPI_Boolean::GeomAlgoAPI_Boolean(const ListOfShape& theObjects, + const ListOfShape& theTools, + const OperationType theOperationType) +{ + build(theObjects, theTools, theOperationType); +} -boost::shared_ptr GeomAlgoAPI_Boolean::makeCut( - 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_Cut aCut(aShape, aTool); - if (aCut.IsDone()) { - boost::shared_ptr aResult(new GeomAPI_Shape()); - aResult->setImpl(new TopoDS_Shape(aCut.Shape())); - return aResult; + if(theObjects.empty() || theTools.empty()) { + return; + } + + // Getting objects. + TopTools_ListOfShape anObjects; + for(ListOfShape::const_iterator anObjectsIt = theObjects.begin(); anObjectsIt != theObjects.end(); anObjectsIt++) + { + anObjects.Append((*anObjectsIt)->impl()); + } + + // Getting tools. + TopTools_ListOfShape aTools; + for(ListOfShape::const_iterator aToolsIt = theTools.begin(); aToolsIt != theTools.end(); aToolsIt++) + { + aTools.Append((*aToolsIt)->impl()); } - return boost::shared_ptr(); + + // 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; + } + } + 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); }