Salome HOME
b3a0187f1b419b4a6890cd193dd3c42f572c738f
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Utils.cpp
1 // Copyright (C) 2014-2023  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "GeomAlgoAPI_Utils.h"
21
22 #include <BRepCheck_Analyzer.hxx>
23 #include <ShapeFix_Shape.hxx>
24 #include <ShapeFix_ShapeTolerance.hxx>
25 #include <TopAbs.hxx>
26
27
28 //==================================================================================================
29 bool GeomAlgoAPI_Utils::FixShapeTolerance(TopoDS_Shape& theShape,
30                                           TopAbs_ShapeEnum theType,
31                                           const double theTolerance,
32                                           const bool theCheckGeometry)
33 {
34   ShapeFix_ShapeTolerance aSft;
35   aSft.LimitTolerance(theShape, theTolerance, theTolerance, theType);
36   Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(theShape);
37   aSfs->Perform();
38   theShape = aSfs->Shape();
39   return CheckShape(theShape, theCheckGeometry);
40 }
41
42 //==================================================================================================
43 bool GeomAlgoAPI_Utils::FixShapeTolerance(TopoDS_Shape& theShape,
44                                           const double theTolerance,
45                                           const bool theCheckGeometry)
46 {
47   return FixShapeTolerance(theShape, TopAbs_SHAPE, theTolerance, theCheckGeometry);
48 }
49
50 //==================================================================================================
51 bool GeomAlgoAPI_Utils::FixShapeTolerance(TopoDS_Shape& theShape,
52                                           const bool theCheckGeometry)
53 {
54   return FixShapeTolerance(theShape, Precision::Confusion(), theCheckGeometry);
55 }
56
57 //==================================================================================================
58 bool GeomAlgoAPI_Utils::CheckShape(TopoDS_Shape& theShape,
59                                    const bool theCheckGeometry)
60 {
61   BRepCheck_Analyzer analyzer(theShape, theCheckGeometry);
62   return analyzer.IsValid();
63 }