1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "GeomAlgoAPI_Partition.h"
22 #include <GeomAlgoAPI_DFLoader.h>
23 #include <GeomAlgoAPI_ShapeTools.h>
25 #include <GEOMAlgo_Splitter.hxx>
27 #include <TopExp_Explorer.hxx>
28 #include <TopoDS_Builder.hxx>
30 //=================================================================================================
31 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Partition::make(const ListOfShape& theObjects,
32 const ListOfShape& theTools)
34 GeomAlgoAPI_Partition aPartitionAlgo(theObjects, theTools);
35 if(aPartitionAlgo.isDone() && !aPartitionAlgo.shape()->isNull() && aPartitionAlgo.isValid()) {
36 return aPartitionAlgo.shape();
38 return std::shared_ptr<GeomAPI_Shape>();
41 //=================================================================================================
42 GeomAlgoAPI_Partition::GeomAlgoAPI_Partition(const ListOfShape& theObjects,
43 const ListOfShape& theTools)
45 build(theObjects, theTools);
49 //=================================================================================================
50 void GeomAlgoAPI_Partition::build(const ListOfShape& theObjects,
51 const ListOfShape& theTools)
53 if (theObjects.empty()) {
57 // Creating partition operation.
58 GEOMAlgo_Splitter* anOperation = new GEOMAlgo_Splitter;
59 this->setImpl(anOperation);
60 this->setBuilderType(OCCT_BOPAlgo_Builder);
63 for (ListOfShape::const_iterator
64 anObjectsIt = theObjects.begin(); anObjectsIt != theObjects.end(); anObjectsIt++) {
65 const TopoDS_Shape& aShape = (*anObjectsIt)->impl<TopoDS_Shape>();
66 anOperation->AddArgument(aShape);
70 for (ListOfShape::const_iterator
71 aToolsIt = theTools.begin(); aToolsIt != theTools.end(); aToolsIt++) {
72 const TopoDS_Shape& aShape = (*aToolsIt)->impl<TopoDS_Shape>();
73 anOperation->AddTool(aShape);
76 // Building and getting result.
77 anOperation->Perform();
78 if(anOperation->ErrorStatus() != 0) {
81 TopoDS_Shape aResult = anOperation->Shape();
83 if(aResult.ShapeType() == TopAbs_COMPOUND) {
84 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
85 aGeomShape->setImpl(new TopoDS_Shape(aResult));
86 aResult = GeomAlgoAPI_ShapeTools::groupSharedTopology(aGeomShape)->impl<TopoDS_Shape>();
90 if(aResult.IsNull()) {
93 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
94 aShape->setImpl(new TopoDS_Shape(aResult));
95 this->setShape(aShape);