1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_Partition.cpp
4 // Created: 21 Aug 2015
5 // Author: Sergey POKHODENKO
7 #include "GeomAlgoAPI_Partition.h"
9 #include <GeomAlgoAPI_DFLoader.h>
10 #include <GeomAlgoAPI_ShapeTools.h>
12 #include <GEOMAlgo_Splitter.hxx>
14 #include <TopExp_Explorer.hxx>
15 #include <TopoDS_Builder.hxx>
17 //=================================================================================================
18 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Partition::make(const ListOfShape& theObjects,
19 const ListOfShape& theTools)
21 GeomAlgoAPI_Partition aPartitionAlgo(theObjects, theTools);
22 if(aPartitionAlgo.isDone() && !aPartitionAlgo.shape()->isNull() && aPartitionAlgo.isValid()) {
23 return aPartitionAlgo.shape();
25 return std::shared_ptr<GeomAPI_Shape>();
28 //=================================================================================================
29 GeomAlgoAPI_Partition::GeomAlgoAPI_Partition(const ListOfShape& theObjects,
30 const ListOfShape& theTools)
32 build(theObjects, theTools);
36 //=================================================================================================
37 void GeomAlgoAPI_Partition::build(const ListOfShape& theObjects,
38 const ListOfShape& theTools)
40 if (theObjects.empty()) {
44 // Creating partition operation.
45 GEOMAlgo_Splitter* anOperation = new GEOMAlgo_Splitter;
46 this->setImpl(anOperation);
47 this->setBuilderType(OCCT_BOPAlgo_Builder);
50 for (ListOfShape::const_iterator
51 anObjectsIt = theObjects.begin(); anObjectsIt != theObjects.end(); anObjectsIt++) {
52 const TopoDS_Shape& aShape = (*anObjectsIt)->impl<TopoDS_Shape>();
53 anOperation->AddArgument(aShape);
57 for (ListOfShape::const_iterator
58 aToolsIt = theTools.begin(); aToolsIt != theTools.end(); aToolsIt++) {
59 const TopoDS_Shape& aShape = (*aToolsIt)->impl<TopoDS_Shape>();
60 anOperation->AddTool(aShape);
63 // Building and getting result.
64 anOperation->Perform();
65 if(anOperation->ErrorStatus() != 0) {
68 TopoDS_Shape aResult = anOperation->Shape();
70 if(aResult.ShapeType() == TopAbs_COMPOUND) {
71 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
72 aGeomShape->setImpl(new TopoDS_Shape(aResult));
73 aResult = GeomAlgoAPI_ShapeTools::groupSharedTopology(aGeomShape)->impl<TopoDS_Shape>();
77 if(aResult.IsNull()) {
80 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
81 aShape->setImpl(new TopoDS_Shape(aResult));
82 this->setShape(aShape);