1 // Copyright (C) 2017-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_Chamfer.h"
21 #include "GeomAlgoAPI_DFLoader.h"
23 #include <BRep_Tool.hxx>
24 #include <BRepFilletAPI_MakeChamfer.hxx>
25 #include <BRepTools.hxx>
27 #include <TopExp_Explorer.hxx>
29 #include <TopoDS_Face.hxx>
31 //=================================================================================================
32 GeomAlgoAPI_Chamfer::GeomAlgoAPI_Chamfer(const GeomShapePtr& theBaseSolid,
33 const ListOfShape& theChamferShapes,
34 const std::map<GeomShapePtr, GeomShapePtr> theMapEdgeFace,
35 const bool performDistances,
39 build(theBaseSolid, theChamferShapes, theMapEdgeFace, performDistances, theVal1, theVal2);
42 //=================================================================================================
43 void GeomAlgoAPI_Chamfer::build(const GeomShapePtr& theBaseSolid,
44 const ListOfShape& theChamferShapes,
45 const std::map<GeomShapePtr, GeomShapePtr> theMapEdgeFace,
46 const bool performDistances,
50 TopoDS_Shape aShapeBase = theBaseSolid->impl<TopoDS_Shape>();
51 TopTools_IndexedDataMapOfShapeListOfShape M;
52 TopExp::MapShapesAndAncestors(aShapeBase, TopAbs_EDGE, TopAbs_FACE, M);
54 // create chamfer builder
55 BRepFilletAPI_MakeChamfer* aChamferBuilder =
56 new BRepFilletAPI_MakeChamfer(aShapeBase);
57 setImpl(aChamferBuilder);
58 setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
60 for (ListOfShape::const_iterator anIt = theChamferShapes.begin();
61 anIt != theChamferShapes.end(); ++anIt) {
62 if ((*anIt)->isEdge()) {
63 TopoDS_Edge E = (*anIt)->impl<TopoDS_Edge>();
64 if (theMapEdgeFace.find(*anIt) != theMapEdgeFace.end()) {
65 //TopoDS_Face F = (theMapEdgeFace[*anIt])->impl<TopoDS_Face>();
66 TopoDS_Face F = (theMapEdgeFace.at(*anIt))->impl<TopoDS_Face>();
67 if (!BRepTools::IsReallyClosed(E,F) && !BRep_Tool::Degenerated(E) &&
68 M.FindFromKey(E).Extent() == 2) {
69 if (performDistances) {
70 aChamferBuilder->Add(theVal1, theVal2, E, F);
72 aChamferBuilder->AddDA(theVal1, theVal2 * M_PI / 180., E, F);
76 const TopTools_ListOfShape& aFacesList = M.FindFromKey(E);
77 TopoDS_Face F = TopoDS::Face(aFacesList.First());
78 if (performDistances) {
79 aChamferBuilder->Add(theVal1, theVal2, E, F);
81 aChamferBuilder->AddDA(theVal1, theVal2 * M_PI / 180., E, F);
87 // build and get result
88 aChamferBuilder->Build();
89 if (!aChamferBuilder->IsDone())
91 TopoDS_Shape aResult = GeomAlgoAPI_DFLoader::refineResult(aChamferBuilder->Shape());
93 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
94 aShape->setImpl(new TopoDS_Shape(aResult));