X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_Chamfer.cpp;fp=src%2FGeomAlgoAPI%2FGeomAlgoAPI_Chamfer.cpp;h=d0bd0693604d49c02dd1443b8deb92290932963c;hb=5bb9c8772caf3c566f14036a7f8b5c99c9b81f32;hp=0000000000000000000000000000000000000000;hpb=20afea6c885668f6901e7ae42ee19c7b8fb40ac4;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Chamfer.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Chamfer.cpp new file mode 100644 index 000000000..d0bd06936 --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Chamfer.cpp @@ -0,0 +1,95 @@ +// Copyright (C) 2017-2019 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "GeomAlgoAPI_Chamfer.h" + +#include +#include +#include +#include +#include +#include +#include + +//================================================================================================= +GeomAlgoAPI_Chamfer::GeomAlgoAPI_Chamfer(const GeomShapePtr& theBaseSolid, + const ListOfShape& theChamferShapes, + const std::map aMapEdgeFace, + const bool performDistances, + const double aVal1, + const double aVal2) +{ + build(theBaseSolid, theChamferShapes, aMapEdgeFace, performDistances, aVal1, aVal2); +} + +//================================================================================================= +void GeomAlgoAPI_Chamfer::build(const GeomShapePtr& theBaseSolid, + const ListOfShape& theChamferShapes, + const std::map aMapEdgeFace, + const bool performDistances, + const double aVal1, + const double aVal2) +{ + TopoDS_Shape aShapeBase = theBaseSolid->impl(); + TopTools_IndexedDataMapOfShapeListOfShape M; + TopExp::MapShapesAndAncestors(aShapeBase, TopAbs_EDGE, TopAbs_FACE, M); + + // create chamfer builder + BRepFilletAPI_MakeChamfer* aChamferBuilder = + new BRepFilletAPI_MakeChamfer(aShapeBase); + setImpl(aChamferBuilder); + setBuilderType(OCCT_BRepBuilderAPI_MakeShape); + + for (ListOfShape::const_iterator anIt = theChamferShapes.begin(); + anIt != theChamferShapes.end(); ++anIt) { + if ((*anIt)->isEdge()) { + TopoDS_Edge E = (*anIt)->impl(); + if (aMapEdgeFace.find(*anIt) != aMapEdgeFace.end()) { + TopoDS_Face F = (aMapEdgeFace[*anIt])->impl(); + if (!BRepTools::IsReallyClosed(E,F) && !BRep_Tool::Degenerated(E) && + M.FindFromKey(E).Extent() == 2) { + if (performDistances) { + aChamferBuilder->Add(aVal1, aVal2, E, F); + } else { + aChamferBuilder->AddDA(aVal1, aVal2 * M_PI / 180., E, F); + } + } + } else { + const TopTools_ListOfShape& aFacesList = M.FindFromKey(E); + TopoDS_Face F = TopoDS::Face(aFacesList.First()); + if (performDistances) { + aChamferBuilder->Add(aVal1, aVal2, E, F); + } else { + aChamferBuilder->AddDA(aVal1, aVal2 * M_PI / 180., E, F); + } + } + } + } + + // build and get result + aChamferBuilder->Build(); + if (!aChamferBuilder->IsDone()) + return; + const TopoDS_Shape& aResult = aChamferBuilder->Shape(); + + std::shared_ptr aShape(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(aResult)); + setShape(aShape); + setDone(true); +}