1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_Intersection.cpp
4 // Created: 16 Feb 2016
5 // Author: Dmitry Bobylev
7 #include "GeomAlgoAPI_Intersection.h"
9 #include <GeomAlgoAPI_DFLoader.h>
10 #include <GeomAlgoAPI_ShapeTools.h>
12 #include <BRepAlgoAPI_Section.hxx>
13 #include <TopExp_Explorer.hxx>
14 #include <TopoDS_Builder.hxx>
16 //=================================================================================================
17 GeomAlgoAPI_Intersection::GeomAlgoAPI_Intersection(const ListOfShape& theObjects,
18 const ListOfShape& theTools)
20 build(theObjects, theTools);
23 //=================================================================================================
24 void GeomAlgoAPI_Intersection::build(const ListOfShape& theObjects,
25 const ListOfShape& theTools)
27 if (theObjects.empty() || theTools.empty()) {
31 // Creating partition operation.
32 BRepAlgoAPI_Section* anOperation = new BRepAlgoAPI_Section;
33 this->setImpl(anOperation);
34 this->setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
36 TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
39 TopTools_ListOfShape anObjects;
40 for (ListOfShape::const_iterator anObjectsIt = theObjects.begin(); anObjectsIt != theObjects.end(); anObjectsIt++) {
41 const TopoDS_Shape& aShape = (*anObjectsIt)->impl<TopoDS_Shape>();
42 if(!aShape.IsNull()) {
43 anObjects.Append(aShape);
46 anOperation->SetArguments(anObjects);
49 TopTools_ListOfShape aTools;
50 for (ListOfShape::const_iterator aToolsIt = theTools.begin(); aToolsIt != theTools.end(); aToolsIt++) {
51 const TopoDS_Shape& aShape = (*aToolsIt)->impl<TopoDS_Shape>();
52 if(!aShape.IsNull()) {
53 aTools.Append(aShape);
56 anOperation->SetTools(aTools);
58 // Building and getting result.
60 if(!anOperation->IsDone()) {
63 TopoDS_Shape aResult = anOperation->Shape();
65 if(aResult.ShapeType() == TopAbs_COMPOUND) {
66 aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
69 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
70 aShape->setImpl(new TopoDS_Shape(aResult));
71 this->setShape(aShape);