Salome HOME
Issue #1860: fix end lines with spaces
[modules/shaper.git] / src / GeomAPI / GeomAPI_Face.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAPI_Face.cpp
4 // Created:     2 Dec 2014
5 // Author:      Artem ZHIDKOV
6
7 #include "GeomAPI_Face.h"
8
9 #include "GeomAPI_Dir.h"
10 #include "GeomAPI_Pln.h"
11 #include "GeomAPI_Pnt.h"
12
13 #include <BOPTools_AlgoTools.hxx>
14 #include <BRep_Tool.hxx>
15 #include <BRepAdaptor_Surface.hxx>
16 #include <Geom_Surface.hxx>
17 #include <Geom_CylindricalSurface.hxx>
18 #include <Geom_RectangularTrimmedSurface.hxx>
19 #include <GeomLib_IsPlanarSurface.hxx>
20 #include <IntTools_Context.hxx>
21 #include <TopoDS.hxx>
22 #include <TopoDS_Face.hxx>
23
24 GeomAPI_Face::GeomAPI_Face()
25   : GeomAPI_Shape()
26 {
27 }
28
29 GeomAPI_Face::GeomAPI_Face(const std::shared_ptr<GeomAPI_Shape>& theShape)
30 {
31   if (!theShape->isNull() && theShape->isFace()) {
32     setImpl(new TopoDS_Shape(theShape->impl<TopoDS_Shape>()));
33   }
34 }
35
36 bool GeomAPI_Face::isEqual(std::shared_ptr<GeomAPI_Shape> theFace) const
37 {
38   if (!theFace.get())
39     return false;
40
41   if (!theFace->isFace())
42     return false;
43
44   const TopoDS_Shape& aMyShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
45   const TopoDS_Shape& aInShape = theFace->impl<TopoDS_Shape>();
46
47   TopoDS_Face aMyFace = TopoDS::Face(aMyShape);
48   TopoDS_Face aInFace = TopoDS::Face(aInShape);
49
50   Handle(Geom_Surface) aMySurf = BRep_Tool::Surface(aMyFace);
51   Handle(Geom_Surface) aInSurf = BRep_Tool::Surface(aInFace);
52
53   // Check that surfaces a the same type
54   if (aMySurf->DynamicType() != aInSurf->DynamicType())
55     return false;
56
57   // Get parameters of surfaces
58   double aMyUMin, aMyUMax, aMyVMin, aMyVMax;
59   aMySurf->Bounds(aMyUMin, aMyUMax, aMyVMin, aMyVMax);
60   double aInUMin, aInUMax, aInVMin, aInVMax;
61   aInSurf->Bounds(aInUMin, aInUMax, aInVMin, aInVMax);
62
63   // Check that parameters are the same
64   if (fabs(aMyUMin - aInUMin) > Precision::PConfusion() ||
65       fabs(aMyUMax - aInUMax) > Precision::PConfusion() ||
66       fabs(aMyVMin - aInVMin) > Precision::PConfusion() ||
67       fabs(aMyVMax - aInVMax) > Precision::PConfusion())
68     return false;
69
70   Handle(IntTools_Context) aContext = new IntTools_Context();
71   Standard_Boolean aRes = BOPTools_AlgoTools::CheckSameGeom(aMyFace, aInFace, aContext);
72
73   return aRes == Standard_True;
74 }
75
76 bool GeomAPI_Face::isCylindrical() const
77 {
78   const TopoDS_Shape& aShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
79   Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aShape));
80   Handle(Geom_RectangularTrimmedSurface) aTrimmed =
81     Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf);
82   if (!aTrimmed.IsNull())
83     aSurf = aTrimmed->BasisSurface();
84   return aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) == Standard_True;
85 }
86
87 std::shared_ptr<GeomAPI_Pln> GeomAPI_Face::getPlane() const
88 {
89   std::shared_ptr<GeomAPI_Pln> aResult;
90   TopoDS_Shape aShape = this->impl<TopoDS_Shape>();
91   if (aShape.IsNull())
92     return aResult;  // null shape
93   if (aShape.ShapeType() != TopAbs_FACE)
94     return aResult;  // not face
95   TopoDS_Face aFace = TopoDS::Face(aShape);
96   if (aFace.IsNull())
97     return aResult;  // not face
98   Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
99   if (aSurf.IsNull())
100     return aResult;  // no surface
101   GeomLib_IsPlanarSurface isPlanar(aSurf);
102   if(!isPlanar.IsPlanar()) {
103     return aResult;
104   }
105   gp_Pln aPln = isPlanar.Plan();
106   double aA, aB, aC, aD;
107   aPln.Coefficients(aA, aB, aC, aD);
108   if (aFace.Orientation() == TopAbs_REVERSED) {
109     aA = -aA;
110     aB = -aB;
111     aC = -aC;
112     aD = -aD;
113   }
114   aResult = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
115   return aResult;
116 }