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