]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_PaveFiller.cpp
Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[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 email : webmaster.salome@opencascade.com<mailto: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;
43   BOPCol_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   Standard_Integer iErr = aPaveFiller.ErrorStatus();
58   if(iErr) {
59     return;
60   }
61
62   BOPAlgo_Builder* aBuilder = new BOPAlgo_Builder();
63   this->setImpl(aBuilder);
64   this->setBuilderType(OCCT_BOPAlgo_Builder);
65   aBuilder->SetArguments(aListOfShape);
66   aBuilder->PerformWithFiller(aPaveFiller);
67   iErr = aBuilder->ErrorStatus();
68   if(iErr) {
69     return;
70   }
71
72   TopoDS_Shape aResult = aBuilder->Shape();
73   if(aResult.ShapeType() == TopAbs_COMPOUND) {
74     aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
75   }
76   if(theIsMakeCompSolids && aResult.ShapeType() == TopAbs_COMPOUND) {
77     std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
78     aGeomShape->setImpl(new TopoDS_Shape(aResult));
79     ListOfShape aCompSolids, aFreeSolids;
80     aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape,
81                                                        GeomAPI_Shape::COMPSOLID,
82                                                        aCompSolids,
83                                                        aFreeSolids);
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 }