]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_Intersection.cpp
Salome HOME
Fixed validators for Boolean and Intersection
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Intersection.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_Intersection.cpp
4 // Created:     16 Feb 2016
5 // Author:      Dmitry Bobylev
6
7 #include "GeomAlgoAPI_Intersection.h"
8
9 #include <GeomAlgoAPI_DFLoader.h>
10 #include <GeomAlgoAPI_ShapeTools.h>
11
12 #include <BRepAlgoAPI_Section.hxx>
13 #include <TopExp_Explorer.hxx>
14 #include <TopoDS_Builder.hxx>
15
16 //=================================================================================================
17 GeomAlgoAPI_Intersection::GeomAlgoAPI_Intersection(const ListOfShape& theObjects,
18                                                    const ListOfShape& theTools)
19 {
20   build(theObjects, theTools);
21 }
22
23 //=================================================================================================
24 void GeomAlgoAPI_Intersection::build(const ListOfShape& theObjects,
25                                      const ListOfShape& theTools)
26 {
27   if (theObjects.empty() || theTools.empty()) {
28     return;
29   }
30
31   // Creating partition operation.
32   BRepAlgoAPI_Section* anOperation = new BRepAlgoAPI_Section;
33   this->setImpl(anOperation);
34   this->setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
35
36   TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
37
38   // Getting objects.
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);
44     }
45   }
46   anOperation->SetArguments(anObjects);
47
48   // Getting tools.
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);
54     }
55   }
56   anOperation->SetTools(aTools);
57
58   // Building and getting result.
59   anOperation->Build();
60   if(!anOperation->IsDone()) {
61     return;
62   }
63   TopoDS_Shape aResult = anOperation->Shape();
64
65   if(aResult.ShapeType() == TopAbs_COMPOUND) {
66     aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
67   }
68
69   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
70   aShape->setImpl(new TopoDS_Shape(aResult));
71   this->setShape(aShape);
72   this->setDone(true);
73 }