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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "GeomAlgoAPI_Partition.h"
23 #include <GeomAlgoAPI_DFLoader.h>
24 #include <GeomAlgoAPI_ShapeTools.h>
26 #include <GEOMAlgo_Splitter.hxx>
28 #include <TopExp_Explorer.hxx>
29 #include <TopoDS_Builder.hxx>
31 //=================================================================================================
32 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Partition::make(const ListOfShape& theObjects,
33 const ListOfShape& theTools)
35 GeomAlgoAPI_Partition aPartitionAlgo(theObjects, theTools);
36 if(aPartitionAlgo.isDone() && !aPartitionAlgo.shape()->isNull() && aPartitionAlgo.isValid()) {
37 return aPartitionAlgo.shape();
39 return std::shared_ptr<GeomAPI_Shape>();
42 //=================================================================================================
43 GeomAlgoAPI_Partition::GeomAlgoAPI_Partition(const ListOfShape& theObjects,
44 const ListOfShape& theTools)
46 build(theObjects, theTools);
50 //=================================================================================================
51 void GeomAlgoAPI_Partition::build(const ListOfShape& theObjects,
52 const ListOfShape& theTools)
54 if (theObjects.empty()) {
58 // Creating partition operation.
59 GEOMAlgo_Splitter* anOperation = new GEOMAlgo_Splitter;
60 this->setImpl(anOperation);
61 this->setBuilderType(OCCT_BOPAlgo_Builder);
64 for (ListOfShape::const_iterator
65 anObjectsIt = theObjects.begin(); anObjectsIt != theObjects.end(); anObjectsIt++) {
66 const TopoDS_Shape& aShape = (*anObjectsIt)->impl<TopoDS_Shape>();
67 anOperation->AddArgument(aShape);
71 for (ListOfShape::const_iterator
72 aToolsIt = theTools.begin(); aToolsIt != theTools.end(); aToolsIt++) {
73 const TopoDS_Shape& aShape = (*aToolsIt)->impl<TopoDS_Shape>();
74 anOperation->AddTool(aShape);
77 // Building and getting result.
78 anOperation->Perform();
79 if(anOperation->ErrorStatus() != 0) {
82 TopoDS_Shape aResult = anOperation->Shape();
84 if(aResult.ShapeType() == TopAbs_COMPOUND) {
85 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
86 aGeomShape->setImpl(new TopoDS_Shape(aResult));
87 aResult = GeomAlgoAPI_ShapeTools::groupSharedTopology(aGeomShape)->impl<TopoDS_Shape>();
91 if(aResult.IsNull()) {
94 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
95 aShape->setImpl(new TopoDS_Shape(aResult));
96 this->setShape(aShape);