X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_Boolean.cpp;h=0a3305bcde991df10043552c0915703f31ceaa26;hb=fe702b25ca5829b28290fe15dc8784c670dd995f;hp=0f68186e4b67cc01235f573e72d640783e09693b;hpb=ba737434252ae41c4bee1b792a0f0bb098ffae87;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp index 0f68186e4..0a3305bcd 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp @@ -1,24 +1,156 @@ +// 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 +//================================================================================================= +std::shared_ptr GeomAlgoAPI_Boolean::makeCut(const ListOfShape& theObjects, + const ListOfShape& theTools) +{ + GeomAlgoAPI_Boolean aBoolAlgo(theObjects, theTools, BOOL_CUT); + if(aBoolAlgo.isDone() && !aBoolAlgo.shape()->isNull() && aBoolAlgo.isValid()) { + return aBoolAlgo.shape(); + } + return std::shared_ptr(); +} -boost::shared_ptr GeomAlgoAPI_Boolean::makeCut( - boost::shared_ptr theShape, - boost::shared_ptr theTool) +//================================================================================================= +std::shared_ptr GeomAlgoAPI_Boolean::makeFuse(const ListOfShape& theObjects, + const ListOfShape& theTools) { - const TopoDS_Shape& aShape = theShape->impl(); - const TopoDS_Shape& aTool = theTool->impl(); + GeomAlgoAPI_Boolean aBoolAlgo(theObjects, theTools, BOOL_FUSE); + if(aBoolAlgo.isDone() && !aBoolAlgo.shape()->isNull() && aBoolAlgo.isValid()) { + return aBoolAlgo.shape(); + } + return std::shared_ptr(); +} + +//================================================================================================= +std::shared_ptr GeomAlgoAPI_Boolean::makeCommon(const ListOfShape& theObjects, + const ListOfShape& theTools) +{ + GeomAlgoAPI_Boolean aBoolAlgo(theObjects, theTools, BOOL_COMMON); + if(aBoolAlgo.isDone() && !aBoolAlgo.shape()->isNull() && aBoolAlgo.isValid()) { + return aBoolAlgo.shape(); + } + return std::shared_ptr(); +} + +//================================================================================================= +GeomAlgoAPI_Boolean::GeomAlgoAPI_Boolean(const ListOfShape& theObjects, + const ListOfShape& theTools, + const OperationType theOperationType) +: myDone(false), + myShape(new GeomAPI_Shape()), + myMap(new GeomAPI_DataMapOfShapeShape()), + myMkShape(new GeomAlgoAPI_MakeShape()) +{ + build(theObjects, theTools, theOperationType); +} + + +//================================================================================================= +void GeomAlgoAPI_Boolean::build(const ListOfShape& theObjects, + const ListOfShape& theTools, + const OperationType theOperationType) +{ + 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()); + } - BRepAlgoAPI_Cut aCut(aShape, aTool); - if (aCut.IsDone()) { - boost::shared_ptr aResult(new GeomAPI_Shape()); - aResult->setImpl(new TopoDS_Shape(aCut.Shape())); - return aResult; + // Creating boolean operation. + BRepAlgoAPI_BooleanOperation* anOperation; + switch (theOperationType) { + case BOOL_CUT: { + anOperation = new BRepAlgoAPI_Cut(); + break; + } + case BOOL_FUSE: { + anOperation = new BRepAlgoAPI_Fuse(); + break; + } + case BOOL_COMMON: { + anOperation = new BRepAlgoAPI_Common(); + break; + } + default: { + return; + } } - return boost::shared_ptr(); + myMkShape->setImpl(anOperation); + anOperation->SetArguments(anObjects); + anOperation->SetTools(aTools); + + // Building and getting result. + anOperation->Build(); + myDone = anOperation->IsDone() == Standard_True; + if(!myDone) { + return; + } + TopoDS_Shape aResult = anOperation->Shape(); + + // fill data map to keep correct orientation of sub-shapes + for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) { + std::shared_ptr aCurrentShape(new GeomAPI_Shape()); + aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current())); + myMap->bind(aCurrentShape, aCurrentShape); + } + myShape->setImpl(new TopoDS_Shape(aResult)); + +} + +//================================================================================================= +const bool GeomAlgoAPI_Boolean::isDone() const +{ + return myDone; +} + +//================================================================================================= +const bool GeomAlgoAPI_Boolean::isValid() const +{ + BRepCheck_Analyzer aChecker(myShape->impl()); + return (aChecker.IsValid() == Standard_True); +} + +//================================================================================================= +const std::shared_ptr& GeomAlgoAPI_Boolean::shape() const +{ + return myShape; +} + +//================================================================================================= +std::shared_ptr GeomAlgoAPI_Boolean::mapOfShapes() const +{ + return myMap; +} + +//================================================================================================= +std::shared_ptr GeomAlgoAPI_Boolean::makeShape() const +{ + return myMkShape; }