Salome HOME
An attempt of porting to current OCCT.
[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;
44   BOPCol_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 #ifdef USE_OCCT_720
59   if (aPaveFiller.HasErrors())
60     return;
61 #else
62   Standard_Integer iErr = aPaveFiller.ErrorStatus();
63   if(iErr) {
64     return;
65   }
66 #endif
67
68   BOPAlgo_Builder* aBuilder = new BOPAlgo_Builder();
69   this->setImpl(aBuilder);
70   this->setBuilderType(OCCT_BOPAlgo_Builder);
71   aBuilder->SetArguments(aListOfShape);
72   aBuilder->PerformWithFiller(aPaveFiller);
73 #ifdef USE_OCCT_720
74   if (aBuilder->HasErrors())
75     return;
76 #else
77   iErr = aBuilder->ErrorStatus();
78   if(iErr) {
79     return;
80   }
81 #endif
82
83   TopoDS_Shape aResult = aBuilder->Shape();
84   if(aResult.ShapeType() == TopAbs_COMPOUND) {
85     aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
86   }
87   if(theIsMakeCompSolids && aResult.ShapeType() == TopAbs_COMPOUND) {
88     std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
89     aGeomShape->setImpl(new TopoDS_Shape(aResult));
90     ListOfShape aCompSolids, aFreeSolids;
91     aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape,
92                                                        GeomAPI_Shape::COMPSOLID,
93                                                        aCompSolids,
94                                                        aFreeSolids);
95     aResult = aGeomShape->impl<TopoDS_Shape>();
96   }
97
98   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
99   aShape->setImpl(new TopoDS_Shape(aResult));
100   this->setShape(aShape);
101   this->setDone(true);
102 }