X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_Boolean.cpp;h=709031f3b14626ceb742a05169eb89ae20f22367;hb=86c435d69e7b27d36c037ed028d79d8f32f021ac;hp=9d3a05873507cc28a76d59a47d59f0ace60616cc;hpb=f1cd93fd02a54259f72e3191d037323a496b2bef;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp index 9d3a05873..709031f3b 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp @@ -6,165 +6,123 @@ #include "GeomAlgoAPI_Boolean.h" -#include +#include + +#include #include +#include #include #include #include -#include +#include -std::shared_ptr GeomAlgoAPI_Boolean::makeCut( - std::shared_ptr theShape, - std::shared_ptr theTool) +//================================================================================================= +GeomAlgoAPI_Boolean::GeomAlgoAPI_Boolean(const ListOfShape& theObjects, + const ListOfShape& theTools, + const OperationType theOperationType) +: myDone(false) { - const TopoDS_Shape& aShape = theShape->impl(); - const TopoDS_Shape& aTool = theTool->impl(); - - BRepAlgoAPI_Cut aCut(aShape, aTool); - if (aCut.IsDone()) { - std::shared_ptr aResult(new GeomAPI_Shape()); - aResult->setImpl(new TopoDS_Shape(aCut.Shape())); - return aResult; - } - return std::shared_ptr(); + build(theObjects, theTools, theOperationType); } -std::shared_ptr GeomAlgoAPI_Boolean::makeFuse( - std::shared_ptr theShape, - std::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()) { - std::shared_ptr aResult(new GeomAPI_Shape()); - aResult->setImpl(new TopoDS_Shape(aFuse.Shape())); - return aResult; + if(theObjects.empty() || theTools.empty()) { + return; } - return std::shared_ptr(); -} + // Getting objects. + TopTools_ListOfShape anObjects; + for(ListOfShape::const_iterator anObjectsIt = theObjects.begin(); anObjectsIt != theObjects.end(); anObjectsIt++) + { + anObjects.Append((*anObjectsIt)->impl()); + } -std::shared_ptr GeomAlgoAPI_Boolean::makeCommon( - std::shared_ptr theShape, - std::shared_ptr theTool) -{ - const TopoDS_Shape& aShape = theShape->impl(); - const TopoDS_Shape& aTool = theTool->impl(); - - BRepAlgoAPI_Common aCommon(aShape, aTool); - if (aCommon.IsDone()) { - std::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()); } - return std::shared_ptr(); -} -//============================================================================ -GeomAlgoAPI_Boolean::GeomAlgoAPI_Boolean(std::shared_ptr theObject, - std::shared_ptr theTool, - int theType) -: myOperation(theType), myDone(false), myShape(new GeomAPI_Shape()) -{ - build(theObject, theTool); -} + // 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; + } + } + myMkShape.reset(new GeomAlgoAPI_MakeShape(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(); + if(aResult.ShapeType() == TopAbs_COMPOUND) { + aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); + } -//============================================================================ -void GeomAlgoAPI_Boolean::build(std::shared_ptr theObject, - std::shared_ptr theTool) -{ - const TopoDS_Shape& anObject = theObject->impl(); - const TopoDS_Shape& aTool = theTool->impl(); - TopoDS_Shape aResult; - switch (myOperation) { - case BOOL_FUSE: - { - BRepAlgoAPI_Fuse* mkFuse = new BRepAlgoAPI_Fuse(anObject, aTool); - if (mkFuse && mkFuse->IsDone()) { - setImpl(mkFuse); - myDone = mkFuse->IsDone() == Standard_True; - myMkShape = new GeomAlgoAPI_MakeShape (mkFuse); - aResult = mkFuse->Shape();//GeomAlgoAPI_DFLoader::refineResult(aFuse->Shape()); - } - break; - } - case BOOL_CUT: - { - BRepAlgoAPI_Cut* mkCut = new BRepAlgoAPI_Cut(anObject, aTool); - if (mkCut && mkCut->IsDone()) { - setImpl(mkCut); - myDone = mkCut->IsDone() == Standard_True; - myMkShape = new GeomAlgoAPI_MakeShape (mkCut); - aResult = mkCut->Shape(); - } - break; - } - case BOOL_COMMON: - { - BRepAlgoAPI_Common* mkCom = new BRepAlgoAPI_Common(anObject, aTool); - if (mkCom && mkCom->IsDone()) { - setImpl(mkCom); - myDone = mkCom->IsDone() == Standard_True; - myMkShape = new GeomAlgoAPI_MakeShape (mkCom); - aResult = mkCom->Shape(); - } - break; - } + // fill data map to keep correct orientation of sub-shapes + myMap.reset(new GeomAPI_DataMapOfShapeShape()); + 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); } - if(myDone) { - if(aResult.ShapeType() == TopAbs_COMPOUND) - aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); - myShape->setImpl(new TopoDS_Shape(aResult)); - std::shared_ptr aGeomResult(new GeomAPI_Shape()); - aGeomResult->setImpl(new TopoDS_Shape(aResult)); - - // 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.reset(new GeomAPI_Shape()); + myShape->setImpl(new TopoDS_Shape(aResult)); +} -//============================================================================ +//================================================================================================= const bool GeomAlgoAPI_Boolean::isDone() const -{return myDone;} +{ + 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 +//================================================================================================= +const std::shared_ptr& GeomAlgoAPI_Boolean::shape() const { return myShape; } -//============================================================================ -void GeomAlgoAPI_Boolean::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const +//================================================================================================= +std::shared_ptr GeomAlgoAPI_Boolean::mapOfShapes() const { - theMap = myMap; + return myMap; } -//============================================================================ -GeomAlgoAPI_MakeShape * GeomAlgoAPI_Boolean::makeShape() const +//================================================================================================= +std::shared_ptr GeomAlgoAPI_Boolean::makeShape() const { return myMkShape; } - -//============================================================================ -GeomAlgoAPI_Boolean::~GeomAlgoAPI_Boolean() -{ - if (myImpl) { - myMap.clear(); - } -} \ No newline at end of file