1 // Copyright (C) 2014-2022 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "GeomAlgoAPI_GlueFaces.h"
22 #include <GeomAPI_ShapeIterator.h>
23 #include <GEOMAlgo_Gluer2.hxx>
24 #include <BRep_Builder.hxx>
25 #include <BRepBuilderAPI_MakeShape.hxx>
26 #include <TopExp_Explorer.hxx>
27 #include <TopoDS_Iterator.hxx>
28 #include <TopoDS_Shape.hxx>
30 //==================================================================================================
31 GeomAlgoAPI_GlueFaces::GeomAlgoAPI_GlueFaces(const ListOfShape& theShapes, const double theTolerance/*=1.e-7*/, const bool theKeepNonSolids/*=true*/)
33 build(theShapes, theTolerance, theKeepNonSolids);
36 //==================================================================================================
37 void GeomAlgoAPI_GlueFaces::build(const ListOfShape& theShapes, const double theTolerance, const bool theKeepNonSolids)
39 if (theShapes.empty())
44 // Create a compound of all shapes in the list
45 TopoDS_Shape aBaseShape;
46 if (theShapes.size() == 1)
48 aBaseShape = theShapes.front()->impl<TopoDS_Shape>();
52 TopoDS_Compound aCompound;
53 BRep_Builder aBuilder;
54 aBuilder.MakeCompound(aCompound);
55 ListOfShape::const_iterator anIt = theShapes.cbegin();
56 for (; anIt != theShapes.cend(); ++anIt)
58 const TopoDS_Shape& aShape = (*anIt)->impl<TopoDS_Shape>();
59 if (aShape.IsNull()) break;
60 aBuilder.Add(aCompound, aShape);
62 if (anIt == theShapes.cend())
64 aBaseShape = aCompound;
71 if (aBaseShape.IsNull())
73 myError = "Shape for gluing is null";
77 GEOMAlgo_Gluer2 aGlueAlgo;
80 aGlueAlgo.SetArgument(aBaseShape);
81 aGlueAlgo.SetTolerance(theTolerance);
82 Standard_Boolean aIsKeepNonSolids = theKeepNonSolids;
83 aGlueAlgo.SetKeepNonSolids(aIsKeepNonSolids);
85 // Detect interfered shapes
87 Standard_Integer iWrnDetect = aGlueAlgo.WarningStatus();
90 myError = "Glue Error Sticked Shapes";
94 Standard_Integer iErr = aGlueAlgo.ErrorStatus();
100 myError = "GEOMAlgo_GlueDetector failed";
104 myError = "PerformImagesToWork failed";
108 // description of all errors see in GEOMAlgo_Gluer2.cxx
109 myError = "Error in GEOMAlgo_Gluer2 with code ";
110 myError += std::to_string(iErr);
119 iErr = aGlueAlgo.ErrorStatus();
125 myError = "GEOMAlgo_GlueDetector failed";
129 myError = "PerformImagesToWork failed";
133 // description of all errors see in GEOMAlgo_Gluer2.cxx
134 myError = "Error in GEOMAlgo_Gluer2 with code ";
135 myError += std::to_string(iErr);
142 Standard_Integer iWrn = aGlueAlgo.WarningStatus();
148 myError = "No shapes to glue";
151 // description of all warnings see in GEOMAlgo_Gluer2.cxx
152 myError = "Warning in GEOMAlgo_Gluer2 with code ";
153 myError += std::to_string(iWrn);
159 TopoDS_Shape aResult = aGlueAlgo.Shape();
161 std::shared_ptr<GeomAPI_Shape> aResShape(new GeomAPI_Shape());
162 aResShape->setImpl(new TopoDS_Shape(aResult));
163 this->setShape(aResShape);