]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_PaveFiller.cpp
Salome HOME
Merge branch 'master' into cgt/devCEA
[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   Standard_Integer iErr = aPaveFiller.ErrorStatus();
59   if(iErr) {
60     return;
61   }
62
63   BOPAlgo_Builder* aBuilder = new BOPAlgo_Builder();
64   this->setImpl(aBuilder);
65   this->setBuilderType(OCCT_BOPAlgo_Builder);
66   aBuilder->SetArguments(aListOfShape);
67   aBuilder->PerformWithFiller(aPaveFiller);
68   iErr = aBuilder->ErrorStatus();
69   if(iErr) {
70     return;
71   }
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 aCompSolids, aFreeSolids;
81     aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape,
82                                                        GeomAPI_Shape::COMPSOLID,
83                                                        aCompSolids,
84                                                        aFreeSolids);
85     aResult = aGeomShape->impl<TopoDS_Shape>();
86   }
87
88   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
89   aShape->setImpl(new TopoDS_Shape(aResult));
90   this->setShape(aShape);
91   this->setDone(true);
92 }