1 // Copyright (C) 2020 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_Defeaturing.h>
21 #include <GeomAlgoAPI_DFLoader.h>
23 #include <BRepAlgoAPI_Defeaturing.hxx>
25 GeomAlgoAPI_Defeaturing::GeomAlgoAPI_Defeaturing(const GeomShapePtr& theBaseSolid,
26 const ListOfShape& theFacesToRemove)
28 build(theBaseSolid, theFacesToRemove);
31 void GeomAlgoAPI_Defeaturing::build(const GeomShapePtr& theBaseSolid,
32 const ListOfShape& theFacesToRemove)
34 if (!theBaseSolid || theFacesToRemove.empty())
37 BRepAlgoAPI_Defeaturing* aDefeaturing = new BRepAlgoAPI_Defeaturing;
38 aDefeaturing->SetShape(theBaseSolid->impl<TopoDS_Shape>());
39 aDefeaturing->SetRunParallel(Standard_True);
41 // collect faces to remove
42 TopTools_ListOfShape aFaces;
43 for (ListOfShape::const_iterator anIt = theFacesToRemove.begin();
44 anIt != theFacesToRemove.end(); ++anIt)
45 aDefeaturing->AddFaceToRemove((*anIt)->impl<TopoDS_Shape>());
47 setImpl(aDefeaturing);
48 setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
50 // build and get result
51 aDefeaturing->Build();
52 if (!aDefeaturing->IsDone() || aDefeaturing->HasErrors() || aDefeaturing->HasWarnings()) {
53 std::ostringstream errors;
54 aDefeaturing->DumpErrors(errors);
55 aDefeaturing->DumpWarnings(errors);
56 myError = errors.str();
57 // the error string may end by '\n', remove it for correct translation
58 size_t aNbToRemove = 0;
59 for (std::string::reverse_iterator it = myError.rbegin();
60 it != myError.rend() && *it == '\n'; ++it)
63 myError = myError.substr(0, myError.size() - aNbToRemove);
67 TopoDS_Shape aResult = GeomAlgoAPI_DFLoader::refineResult(aDefeaturing->Shape());
69 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
70 aShape->setImpl(new TopoDS_Shape(aResult));