X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_Boolean.cpp;h=c9d9524c41610898521dcb5c621638e44d23b201;hb=b06cf1477fb1ee46d7ae260c234cac5d0000abf2;hp=0f68186e4b67cc01235f573e72d640783e09693b;hpb=b801d5f85aa3dc5786510acf87c8003f1d59eadd;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp index 0f68186e4..c9d9524c4 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp @@ -1,24 +1,132 @@ -// 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 -boost::shared_ptr GeomAlgoAPI_Boolean::makeCut( - boost::shared_ptr theShape, - boost::shared_ptr theTool) +//================================================================================================= +GeomAlgoAPI_Boolean::GeomAlgoAPI_Boolean(const GeomShapePtr theObject, + const GeomShapePtr theTool, + 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; + ListOfShape aListWithObject, aListWithTool; + aListWithObject.push_back(theObject); + aListWithTool.push_back(theTool); + build(aListWithObject, aListWithTool, theOperationType); +} + +//================================================================================================= +GeomAlgoAPI_Boolean::GeomAlgoAPI_Boolean(const GeomShapePtr theObject, + const ListOfShape& theTools, + const OperationType theOperationType) +{ + ListOfShape aListWithObject; + aListWithObject.push_back(theObject); + build(aListWithObject, theTools, theOperationType); +} + +//================================================================================================= +GeomAlgoAPI_Boolean::GeomAlgoAPI_Boolean(const ListOfShape& theObjects, + const ListOfShape& theTools, + const OperationType theOperationType) +{ + build(theObjects, theTools, theOperationType); +} + + +//================================================================================================= +void GeomAlgoAPI_Boolean::build(const ListOfShape& theObjects, + const ListOfShape& theTools, + const OperationType theOperationType) +{ + 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()); + } + + // 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; + } + } + this->setImpl(aBuilder); + this->setBuilderType(OCCT_BOPAlgo_Builder); + aBuilder->SetArguments(anObjects); + aBuilder->SetTools(aTools); + + // Building and getting result. + aBuilder->Perform(); + if (aBuilder->HasErrors()) + 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); }