Salome HOME
Fix regression in unit tests
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_PaveFiller.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_PaveFiller.cpp
4 // Created:     27 August 2015
5 // Author:      Dmitry Bobylev
6
7 #include "GeomAlgoAPI_PaveFiller.h"
8
9 #include <GeomAlgoAPI_DFLoader.h>
10 #include <GeomAlgoAPI_ShapeTools.h>
11
12 #include <BOPAlgo_Builder.hxx>
13 #include <BOPAlgo_PaveFiller.hxx>
14 #include <TopoDS_Builder.hxx>
15
16 //=================================================================================================
17 GeomAlgoAPI_PaveFiller::GeomAlgoAPI_PaveFiller(const ListOfShape& theListOfShape, const bool theIsMakeCompSolids)
18 {
19   build(theListOfShape, theIsMakeCompSolids);
20 }
21
22
23 //=================================================================================================
24 void GeomAlgoAPI_PaveFiller::build(const ListOfShape& theListOfShape, const bool theIsMakeCompSolids)
25 {
26   BOPAlgo_PaveFiller aPaveFiller;
27   BOPCol_ListOfShape aListOfShape;
28   for(ListOfShape::const_iterator anIt = theListOfShape.cbegin(); anIt != theListOfShape.cend(); anIt++) {
29     aListOfShape.Append((*anIt)->impl<TopoDS_Shape>());
30   }
31   aPaveFiller.SetArguments(aListOfShape);
32   aPaveFiller.Perform();
33   Standard_Integer iErr = aPaveFiller.ErrorStatus();
34   if(iErr) {
35     return;
36   }
37
38   BOPAlgo_Builder* aBuilder = new BOPAlgo_Builder();
39   this->setImpl(aBuilder);
40   this->setBuilderType(OCCT_BOPAlgo_Builder);
41   aBuilder->SetArguments(aListOfShape);
42   aBuilder->PerformWithFiller(aPaveFiller);
43   iErr = aBuilder->ErrorStatus();
44   if(iErr) {
45     return;
46   }
47
48   TopoDS_Shape aResult = aBuilder->Shape();
49   if(aResult.ShapeType() == TopAbs_COMPOUND) {
50     aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
51   }
52   if(theIsMakeCompSolids && aResult.ShapeType() == TopAbs_COMPOUND) {
53     std::shared_ptr<GeomAPI_Shape> aCompound(new GeomAPI_Shape);
54     aCompound->setImpl(new TopoDS_Shape(aResult));
55     ListOfShape aCompSolids, aFreeSolids;
56     GeomAlgoAPI_ShapeTools::combineShapes(aCompound, GeomAPI_Shape::COMPSOLID, aCompSolids, aFreeSolids);
57     if(aCompSolids.size() == 1 && aFreeSolids.size() == 0) {
58       aResult = aCompSolids.front()->impl<TopoDS_Shape>();
59     } else if (aCompSolids.size() > 1 || (aCompSolids.size() >= 1 && aFreeSolids.size() >= 1)) {
60       TopoDS_Compound aResultComp;
61       TopoDS_Builder aBuilder;
62       aBuilder.MakeCompound(aResultComp);
63       for(ListOfShape::const_iterator anIter = aCompSolids.cbegin(); anIter != aCompSolids.cend(); anIter++) {
64         aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
65       }
66       for(ListOfShape::const_iterator anIter = aFreeSolids.cbegin(); anIter != aFreeSolids.cend(); anIter++) {
67         aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
68       }
69       aResult = aResultComp;
70     }
71   }
72
73   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
74   aShape->setImpl(new TopoDS_Shape(aResult));
75   this->setShape(aShape);
76   this->setDone(true);
77 }