Salome HOME
5561cb09c34710245fe05ea404bb53ec945b8895
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_PaveFiller.cpp
1 // Copyright (C) 2014-2020  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "GeomAlgoAPI_PaveFiller.h"
21
22 #include <GeomAlgoAPI_DFLoader.h>
23 #include <GeomAlgoAPI_ShapeTools.h>
24
25 #include <BOPAlgo_Builder.hxx>
26 #include <BOPAlgo_PaveFiller.hxx>
27 #include <TopoDS_Builder.hxx>
28 #include <TopoDS_Iterator.hxx>
29
30 //=================================================================================================
31 GeomAlgoAPI_PaveFiller::GeomAlgoAPI_PaveFiller(const ListOfShape& theListOfShape,
32                                                const bool theIsMakeCompSolids)
33 {
34   build(theListOfShape, theIsMakeCompSolids);
35 }
36
37
38 //=================================================================================================
39 void GeomAlgoAPI_PaveFiller::build(const ListOfShape& theListOfShape,
40                                    const bool theIsMakeCompSolids)
41 {
42   BOPAlgo_PaveFiller* aPaveFiller = new BOPAlgo_PaveFiller;
43   TopTools_ListOfShape aListOfShape;
44   for(ListOfShape::const_iterator
45     anIt = theListOfShape.cbegin(); anIt != theListOfShape.cend(); anIt++) {
46     const TopoDS_Shape& aShape = (*anIt)->impl<TopoDS_Shape>();
47     if(aShape.ShapeType() == TopAbs_COMPOUND) {
48       for(TopoDS_Iterator anIter(aShape); anIter.More(); anIter.Next()) {
49         aListOfShape.Append(anIter.Value());
50       }
51     } else {
52       aListOfShape.Append(aShape);
53     }
54   }
55   aPaveFiller->SetArguments(aListOfShape);
56   aPaveFiller->Perform();
57   if (aPaveFiller->HasErrors())
58     return;
59
60   BOPAlgo_Builder* aBuilder = new BOPAlgo_Builder();
61   this->setImpl(aBuilder);
62   this->setBuilderType(OCCT_BOPAlgo_Builder);
63   aBuilder->SetArguments(aListOfShape);
64   aBuilder->PerformWithFiller(*aPaveFiller);
65   if (aBuilder->HasErrors())
66     return;
67
68   TopoDS_Shape aResult = aBuilder->Shape();
69   if(aResult.ShapeType() == TopAbs_COMPOUND) {
70     aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
71   }
72   if(theIsMakeCompSolids && aResult.ShapeType() == TopAbs_COMPOUND) {
73     std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
74     aGeomShape->setImpl(new TopoDS_Shape(aResult));
75     ListOfShape aResults;
76     aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape,
77                                                        GeomAPI_Shape::COMPSOLID,
78                                                        aResults);
79     aResult = aGeomShape->impl<TopoDS_Shape>();
80   }
81
82   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
83   aShape->setImpl(new TopoDS_Shape(aResult));
84   this->setShape(aShape);
85   this->setDone(true);
86 }