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>
11 #include <GEOMAlgo_Splitter.hxx>
13 #include <BRepCheck_Analyzer.hxx>
14 #include <TopExp_Explorer.hxx>
15 #include <TopTools_ListOfShape.hxx>
17 //=================================================================================================
18 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Partition::make(const ListOfShape& theObjects,
19 const ListOfShape& theTools)
21 GeomAlgoAPI_Partition aBoolAlgo(theObjects, theTools);
22 if(aBoolAlgo.isDone() && !aBoolAlgo.shape()->isNull() && aBoolAlgo.isValid()) {
23 return aBoolAlgo.shape();
25 return std::shared_ptr<GeomAPI_Shape>();
28 //=================================================================================================
29 GeomAlgoAPI_Partition::GeomAlgoAPI_Partition(const ListOfShape& theObjects,
30 const ListOfShape& theTools)
33 build(theObjects, theTools);
37 //=================================================================================================
38 void GeomAlgoAPI_Partition::build(const ListOfShape& theObjects,
39 const ListOfShape& theTools)
41 if (theObjects.empty() || theTools.empty()) {
45 // Creating partition operation.
46 GEOMAlgo_Splitter* anOperation = new GEOMAlgo_Splitter;
47 myMkShape.reset(new GeomAlgoAPI_MakeShape(anOperation, GeomAlgoAPI_MakeShape::BOPAlgoBuilder));
50 for (ListOfShape::const_iterator anObjectsIt = theObjects.begin(); anObjectsIt != theObjects.end(); anObjectsIt++) {
51 const TopoDS_Shape& aShape = (*anObjectsIt)->impl<TopoDS_Shape>();
52 anOperation->AddArgument(aShape);
56 for (ListOfShape::const_iterator aToolsIt = theTools.begin(); aToolsIt != theTools.end(); aToolsIt++) {
57 const TopoDS_Shape& aShape = (*aToolsIt)->impl<TopoDS_Shape>();
58 anOperation->AddTool(aShape);
61 // Building and getting result.
62 anOperation->Perform();
63 TopoDS_Shape aResult = anOperation->Shape();
64 myDone = !aResult.IsNull();
69 if(aResult.ShapeType() == TopAbs_COMPOUND) {
70 aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
73 // fill data map to keep correct orientation of sub-shapes
74 myMap.reset(new GeomAPI_DataMapOfShapeShape());
75 for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
76 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
77 aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current()));
78 myMap->bind(aCurrentShape, aCurrentShape);
80 myShape.reset(new GeomAPI_Shape());
81 myShape->setImpl(new TopoDS_Shape(aResult));
84 //=================================================================================================
85 const bool GeomAlgoAPI_Partition::isDone() const
90 //=================================================================================================
91 const bool GeomAlgoAPI_Partition::isValid() const
93 BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
94 return (aChecker.IsValid() == Standard_True);
97 //=================================================================================================
98 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Partition::shape() const
103 //=================================================================================================
104 std::shared_ptr<GeomAPI_DataMapOfShapeShape> GeomAlgoAPI_Partition::mapOfShapes() const
109 //=================================================================================================
110 std::shared_ptr<GeomAlgoAPI_MakeShape> GeomAlgoAPI_Partition::makeShape() const