]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_PaveFiller.cpp
Salome HOME
Fixed validators for Boolean and Intersection
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_PaveFiller.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_PaveFiller.cpp
4 // Created:     27 August 2015
5 // Author:      Dmitry Bobylev
6
7 #include "GeomAlgoAPI_PaveFiller.h"
8
9 #include <GeomAlgoAPI_DFLoader.h>
10 #include <GeomAlgoAPI_ShapeTools.h>
11
12 #include <BOPAlgo_Builder.hxx>
13 #include <BOPAlgo_PaveFiller.hxx>
14 #include <TopoDS_Builder.hxx>
15 #include <TopoDS_Iterator.hxx>
16
17 //=================================================================================================
18 GeomAlgoAPI_PaveFiller::GeomAlgoAPI_PaveFiller(const ListOfShape& theListOfShape, const bool theIsMakeCompSolids)
19 {
20   build(theListOfShape, theIsMakeCompSolids);
21 }
22
23
24 //=================================================================================================
25 void GeomAlgoAPI_PaveFiller::build(const ListOfShape& theListOfShape, const bool theIsMakeCompSolids)
26 {
27   BOPAlgo_PaveFiller aPaveFiller;
28   BOPCol_ListOfShape aListOfShape;
29   for(ListOfShape::const_iterator anIt = theListOfShape.cbegin(); anIt != theListOfShape.cend(); anIt++) {
30     const TopoDS_Shape& aShape = (*anIt)->impl<TopoDS_Shape>();
31     if(aShape.ShapeType() == TopAbs_COMPOUND) {
32       for(TopoDS_Iterator anIter(aShape); anIter.More(); anIter.Next()) {
33         aListOfShape.Append(anIter.Value());
34       }
35     } else {
36       aListOfShape.Append(aShape);
37     }
38   }
39   aPaveFiller.SetArguments(aListOfShape);
40   aPaveFiller.Perform();
41   Standard_Integer iErr = aPaveFiller.ErrorStatus();
42   if(iErr) {
43     return;
44   }
45
46   BOPAlgo_Builder* aBuilder = new BOPAlgo_Builder();
47   this->setImpl(aBuilder);
48   this->setBuilderType(OCCT_BOPAlgo_Builder);
49   aBuilder->SetArguments(aListOfShape);
50   aBuilder->PerformWithFiller(aPaveFiller);
51   iErr = aBuilder->ErrorStatus();
52   if(iErr) {
53     return;
54   }
55
56   TopoDS_Shape aResult = aBuilder->Shape();
57   if(aResult.ShapeType() == TopAbs_COMPOUND) {
58     aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
59   }
60   if(theIsMakeCompSolids && aResult.ShapeType() == TopAbs_COMPOUND) {
61     std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
62     aGeomShape->setImpl(new TopoDS_Shape(aResult));
63     ListOfShape aCompSolids, aFreeSolids;
64     aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape,
65                                                        GeomAPI_Shape::COMPSOLID,
66                                                        aCompSolids,
67                                                        aFreeSolids);
68     aResult = aGeomShape->impl<TopoDS_Shape>();
69   }
70
71   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
72   aShape->setImpl(new TopoDS_Shape(aResult));
73   this->setShape(aShape);
74   this->setDone(true);
75 }