1 // Copyright (C) 2017-2019 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"
22 #include <BRep_Tool.hxx>
23 #include <BRepFilletAPI_MakeChamfer.hxx>
24 #include <BRepTools.hxx>
26 #include <TopExp_Explorer.hxx>
28 #include <TopoDS_Face.hxx>
30 //=================================================================================================
31 GeomAlgoAPI_Chamfer::GeomAlgoAPI_Chamfer(const GeomShapePtr& theBaseSolid,
32 const ListOfShape& theChamferShapes,
33 const std::map<GeomShapePtr, GeomShapePtr> aMapEdgeFace,
34 const bool performDistances,
38 build(theBaseSolid, theChamferShapes, aMapEdgeFace, performDistances, aVal1, aVal2);
41 //=================================================================================================
42 void GeomAlgoAPI_Chamfer::build(const GeomShapePtr& theBaseSolid,
43 const ListOfShape& theChamferShapes,
44 const std::map<GeomShapePtr, GeomShapePtr> aMapEdgeFace,
45 const bool performDistances,
49 TopoDS_Shape aShapeBase = theBaseSolid->impl<TopoDS_Shape>();
50 TopTools_IndexedDataMapOfShapeListOfShape M;
51 TopExp::MapShapesAndAncestors(aShapeBase, TopAbs_EDGE, TopAbs_FACE, M);
53 // create chamfer builder
54 BRepFilletAPI_MakeChamfer* aChamferBuilder =
55 new BRepFilletAPI_MakeChamfer(aShapeBase);
56 setImpl(aChamferBuilder);
57 setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
59 for (ListOfShape::const_iterator anIt = theChamferShapes.begin();
60 anIt != theChamferShapes.end(); ++anIt) {
61 if ((*anIt)->isEdge()) {
62 TopoDS_Edge E = (*anIt)->impl<TopoDS_Edge>();
63 if (aMapEdgeFace.find(*anIt) != aMapEdgeFace.end()) {
64 //TopoDS_Face F = (aMapEdgeFace[*anIt])->impl<TopoDS_Face>();
65 TopoDS_Face F = (aMapEdgeFace.at(*anIt))->impl<TopoDS_Face>();
66 if (!BRepTools::IsReallyClosed(E,F) && !BRep_Tool::Degenerated(E) &&
67 M.FindFromKey(E).Extent() == 2) {
68 if (performDistances) {
69 aChamferBuilder->Add(aVal1, aVal2, E, F);
71 aChamferBuilder->AddDA(aVal1, aVal2 * M_PI / 180., E, F);
75 const TopTools_ListOfShape& aFacesList = M.FindFromKey(E);
76 TopoDS_Face F = TopoDS::Face(aFacesList.First());
77 if (performDistances) {
78 aChamferBuilder->Add(aVal1, aVal2, E, F);
80 aChamferBuilder->AddDA(aVal1, aVal2 * M_PI / 180., E, F);
86 // build and get result
87 aChamferBuilder->Build();
88 if (!aChamferBuilder->IsDone())
90 const TopoDS_Shape& aResult = aChamferBuilder->Shape();
92 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
93 aShape->setImpl(new TopoDS_Shape(aResult));