X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_Boolean.cpp;h=64dcb89497206d838606d3d604baafe6d84f9c79;hb=e675b9eb8df755fff9763560ddf36d5bfeb6fe35;hp=6d2e740be49e473810fe4203ccd0c2dff70b698e;hpb=2c97c8361728332e12fe152c3dfcefc3bd91fcf6;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp index 6d2e740be..64dcb8949 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp @@ -1,168 +1,112 @@ -// File: GeomAlgoAPI_Boolean.cpp -// Created: 02 Sept 2014 -// Author: Vitaly Smetannikov +// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// 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 +// #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) -{ - 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(); -} - +#include +#include -boost::shared_ptr GeomAlgoAPI_Boolean::makeFuse( - 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_Fuse aFuse(aShape, aTool); - if (aFuse.IsDone()) { - boost::shared_ptr aResult(new GeomAPI_Shape()); - aResult->setImpl(new TopoDS_Shape(aFuse.Shape())); - return aResult; - } - return boost::shared_ptr(); + build(theObjects, theTools, theOperationType); } -boost::shared_ptr GeomAlgoAPI_Boolean::makeCommon( - 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_Common aCommon(aShape, aTool); - if (aCommon.IsDone()) { - boost::shared_ptr aResult(new GeomAPI_Shape()); - aResult->setImpl(new TopoDS_Shape(aCommon.Shape())); - return aResult; + if(theObjects.empty() || theTools.empty()) { + return; } - return boost::shared_ptr(); -} -//============================================================================ -GeomAlgoAPI_Boolean::GeomAlgoAPI_Boolean(boost::shared_ptr theObject, - boost::shared_ptr theTool, - int theType) -: myOperation(theType), myDone(false), myShape(new GeomAPI_Shape()) -{ - build(theObject, theTool); -} - - -//============================================================================ -void GeomAlgoAPI_Boolean::build(boost::shared_ptr theObject, - boost::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; - } + // Getting objects. + TopTools_ListOfShape anObjects; + for(ListOfShape::const_iterator + anObjectsIt = theObjects.begin(); anObjectsIt != theObjects.end(); anObjectsIt++) + { + anObjects.Append((*anObjectsIt)->impl()); } - if(myDone) { - if(aResult.ShapeType() == TopAbs_COMPOUND) - aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); - myShape->setImpl(new TopoDS_Shape(aResult)); - boost::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()) { - boost::shared_ptr aCurrentShape(new GeomAPI_Shape()); - aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current())); - myMap.bind(aCurrentShape, aCurrentShape); - } - } -} - -//============================================================================ -const bool GeomAlgoAPI_Boolean::isDone() const -{return myDone;} - -//============================================================================ -const bool GeomAlgoAPI_Boolean::isValid() const -{ - BRepCheck_Analyzer aChecker(myShape->impl()); - return (aChecker.IsValid() == Standard_True); -} + // Getting tools. + TopTools_ListOfShape aTools; + for(ListOfShape::const_iterator + aToolsIt = theTools.begin(); aToolsIt != theTools.end(); aToolsIt++) + { + aTools.Append((*aToolsIt)->impl()); + } -//============================================================================ -const boost::shared_ptr& GeomAlgoAPI_Boolean::shape () const -{ - return myShape; -} + // 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(); -//============================================================================ -void GeomAlgoAPI_Boolean::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const -{ - theMap = myMap; -} + 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(); + } -//============================================================================ -GeomAlgoAPI_MakeShape * GeomAlgoAPI_Boolean::makeShape() const -{ - return myMkShape; + std::shared_ptr aShape(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(aResult)); + this->setShape(aShape); + this->setDone(true); } - -//============================================================================ -GeomAlgoAPI_Boolean::~GeomAlgoAPI_Boolean() -{ - if (myImpl) { - myMap.clear(); - } -} \ No newline at end of file