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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "GeomAlgoAPI_Intersection.h"
22 #include <GeomAlgoAPI_DFLoader.h>
23 #include <GeomAlgoAPI_ShapeTools.h>
25 #include <BRepAlgoAPI_Section.hxx>
26 #include <TopExp_Explorer.hxx>
27 #include <TopoDS_Builder.hxx>
29 //=================================================================================================
30 GeomAlgoAPI_Intersection::GeomAlgoAPI_Intersection(const ListOfShape& theObjects,
31 const ListOfShape& theTools)
33 build(theObjects, theTools);
36 //=================================================================================================
37 void GeomAlgoAPI_Intersection::build(const ListOfShape& theObjects,
38 const ListOfShape& theTools)
40 if (theObjects.empty() || theTools.empty()) {
44 // Creating partition operation.
45 BRepAlgoAPI_Section* anOperation = new BRepAlgoAPI_Section;
46 this->setImpl(anOperation);
47 this->setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
49 TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
52 TopTools_ListOfShape anObjects;
53 for (ListOfShape::const_iterator
54 anObjectsIt = theObjects.begin(); anObjectsIt != theObjects.end(); anObjectsIt++) {
55 const TopoDS_Shape& aShape = (*anObjectsIt)->impl<TopoDS_Shape>();
56 if(!aShape.IsNull()) {
57 anObjects.Append(aShape);
60 anOperation->SetArguments(anObjects);
63 TopTools_ListOfShape aTools;
64 for (ListOfShape::const_iterator
65 aToolsIt = theTools.begin(); aToolsIt != theTools.end(); aToolsIt++) {
66 const TopoDS_Shape& aShape = (*aToolsIt)->impl<TopoDS_Shape>();
67 if(!aShape.IsNull()) {
68 aTools.Append(aShape);
71 anOperation->SetTools(aTools);
73 // Building and getting result.
75 if(!anOperation->IsDone()) {
78 TopoDS_Shape aResult = anOperation->Shape();
80 if(aResult.ShapeType() == TopAbs_COMPOUND) {
81 aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
84 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
85 aShape->setImpl(new TopoDS_Shape(aResult));
86 this->setShape(aShape);