Salome HOME
updated copyright message
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_PaveFiller.cpp
1 // Copyright (C) 2014-2023  CEA, EDF
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 //=================================================================================================
32 GeomAlgoAPI_PaveFiller::GeomAlgoAPI_PaveFiller(const ListOfShape& theListOfShape,
33                                                const bool theIsMakeCompSolids,
34                                                const double theFuzzy)
35 {
36   build(theListOfShape, theIsMakeCompSolids, theFuzzy);
37 }
38
39
40 //=================================================================================================
41 void GeomAlgoAPI_PaveFiller::build(const ListOfShape& theListOfShape,
42                                    const bool theIsMakeCompSolids,
43                                    const double theFuzzy)
44 {
45   BOPAlgo_PaveFiller* aPaveFiller = new BOPAlgo_PaveFiller;
46   TopTools_ListOfShape aListOfShape;
47   for(ListOfShape::const_iterator
48     anIt = theListOfShape.cbegin(); anIt != theListOfShape.cend(); anIt++) {
49     const TopoDS_Shape& aShape = (*anIt)->impl<TopoDS_Shape>();
50     if(aShape.ShapeType() == TopAbs_COMPOUND) {
51       for(TopoDS_Iterator anIter(aShape); anIter.More(); anIter.Next()) {
52         aListOfShape.Append(anIter.Value());
53       }
54     } else {
55       aListOfShape.Append(aShape);
56     }
57   }
58   aPaveFiller->SetArguments(aListOfShape);
59   if (theFuzzy > 0) aPaveFiller->SetFuzzyValue(theFuzzy);
60   aPaveFiller->Perform();
61   if (aPaveFiller->HasErrors())
62     return;
63
64   BOPAlgo_Builder* aBuilder = new BOPAlgo_Builder();
65   this->setImpl(aBuilder);
66   this->setBuilderType(OCCT_BOPAlgo_Builder);
67   aBuilder->SetArguments(aListOfShape);
68   if (theFuzzy > 0) aBuilder->SetFuzzyValue(theFuzzy);
69   aBuilder->PerformWithFiller(*aPaveFiller);
70   if (aBuilder->HasErrors())
71     return;
72
73   TopoDS_Shape aResult = aBuilder->Shape();
74   if(aResult.ShapeType() == TopAbs_COMPOUND) {
75     aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
76   }
77   if(theIsMakeCompSolids && aResult.ShapeType() == TopAbs_COMPOUND) {
78     std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
79     aGeomShape->setImpl(new TopoDS_Shape(aResult));
80     ListOfShape aResults;
81     aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape,
82                                                        GeomAPI_Shape::COMPSOLID,
83                                                        aResults);
84     aResult = aGeomShape->impl<TopoDS_Shape>();
85   }
86
87   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
88   aShape->setImpl(new TopoDS_Shape(aResult));
89   this->setShape(aShape);
90   this->setDone(true);
91 }