]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_PaveFiller.cpp
Salome HOME
76df6cbb93dc0510e0c8fec5f3840d37afce968b
[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, 
19                                                const bool theIsMakeCompSolids)
20 {
21   build(theListOfShape, theIsMakeCompSolids);
22 }
23
24
25 //=================================================================================================
26 void GeomAlgoAPI_PaveFiller::build(const ListOfShape& theListOfShape,
27                                    const bool theIsMakeCompSolids)
28 {
29   BOPAlgo_PaveFiller aPaveFiller;
30   BOPCol_ListOfShape aListOfShape;
31   for(ListOfShape::const_iterator 
32     anIt = theListOfShape.cbegin(); anIt != theListOfShape.cend(); anIt++) {
33     const TopoDS_Shape& aShape = (*anIt)->impl<TopoDS_Shape>();
34     if(aShape.ShapeType() == TopAbs_COMPOUND) {
35       for(TopoDS_Iterator anIter(aShape); anIter.More(); anIter.Next()) {
36         aListOfShape.Append(anIter.Value());
37       }
38     } else {
39       aListOfShape.Append(aShape);
40     }
41   }
42   aPaveFiller.SetArguments(aListOfShape);
43   aPaveFiller.Perform();
44   Standard_Integer iErr = aPaveFiller.ErrorStatus();
45   if(iErr) {
46     return;
47   }
48
49   BOPAlgo_Builder* aBuilder = new BOPAlgo_Builder();
50   this->setImpl(aBuilder);
51   this->setBuilderType(OCCT_BOPAlgo_Builder);
52   aBuilder->SetArguments(aListOfShape);
53   aBuilder->PerformWithFiller(aPaveFiller);
54   iErr = aBuilder->ErrorStatus();
55   if(iErr) {
56     return;
57   }
58
59   TopoDS_Shape aResult = aBuilder->Shape();
60   if(aResult.ShapeType() == TopAbs_COMPOUND) {
61     aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
62   }
63   if(theIsMakeCompSolids && aResult.ShapeType() == TopAbs_COMPOUND) {
64     std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
65     aGeomShape->setImpl(new TopoDS_Shape(aResult));
66     ListOfShape aCompSolids, aFreeSolids;
67     aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape,
68                                                        GeomAPI_Shape::COMPSOLID,
69                                                        aCompSolids,
70                                                        aFreeSolids);
71     aResult = aGeomShape->impl<TopoDS_Shape>();
72   }
73
74   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
75   aShape->setImpl(new TopoDS_Shape(aResult));
76   this->setShape(aShape);
77   this->setDone(true);
78 }