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
41 anObjectsIt = theObjects.begin(); anObjectsIt != theObjects.end(); anObjectsIt++) {
42 const TopoDS_Shape& aShape = (*anObjectsIt)->impl<TopoDS_Shape>();
43 if(!aShape.IsNull()) {
44 anObjects.Append(aShape);
47 anOperation->SetArguments(anObjects);
50 TopTools_ListOfShape aTools;
51 for (ListOfShape::const_iterator
52 aToolsIt = theTools.begin(); aToolsIt != theTools.end(); aToolsIt++) {
53 const TopoDS_Shape& aShape = (*aToolsIt)->impl<TopoDS_Shape>();
54 if(!aShape.IsNull()) {
55 aTools.Append(aShape);
58 anOperation->SetTools(aTools);
60 // Building and getting result.
62 if(!anOperation->IsDone()) {
65 TopoDS_Shape aResult = anOperation->Shape();
67 if(aResult.ShapeType() == TopAbs_COMPOUND) {
68 aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
71 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
72 aShape->setImpl(new TopoDS_Shape(aResult));
73 this->setShape(aShape);