]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAPI/GeomAPI_Face.cpp
Salome HOME
Merge branch 'master' into cgt/devCEA
[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   // Double check needed bacause BOPTools_AlgoTools::CheckSameGeom not very smart.
72   Standard_Boolean aRes = BOPTools_AlgoTools::CheckSameGeom(aMyFace, aInFace, aContext)
73     && BOPTools_AlgoTools::CheckSameGeom(aInFace, aMyFace, aContext);
74
75   return aRes == Standard_True;
76 }
77
78 bool GeomAPI_Face::isCylindrical() const
79 {
80   const TopoDS_Shape& aShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
81   Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aShape));
82   Handle(Geom_RectangularTrimmedSurface) aTrimmed =
83     Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf);
84   if (!aTrimmed.IsNull())
85     aSurf = aTrimmed->BasisSurface();
86   return aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) == Standard_True;
87 }
88
89 std::shared_ptr<GeomAPI_Pln> GeomAPI_Face::getPlane() const
90 {
91   std::shared_ptr<GeomAPI_Pln> aResult;
92   TopoDS_Shape aShape = this->impl<TopoDS_Shape>();
93   if (aShape.IsNull())
94     return aResult;  // null shape
95   if (aShape.ShapeType() != TopAbs_FACE)
96     return aResult;  // not face
97   TopoDS_Face aFace = TopoDS::Face(aShape);
98   if (aFace.IsNull())
99     return aResult;  // not face
100   Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
101   if (aSurf.IsNull())
102     return aResult;  // no surface
103   GeomLib_IsPlanarSurface isPlanar(aSurf);
104   if(!isPlanar.IsPlanar()) {
105     return aResult;
106   }
107   gp_Pln aPln = isPlanar.Plan();
108   double aA, aB, aC, aD;
109   aPln.Coefficients(aA, aB, aC, aD);
110   if (aFace.Orientation() == TopAbs_REVERSED) {
111     aA = -aA;
112     aB = -aB;
113     aC = -aC;
114     aD = -aD;
115   }
116   aResult = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
117   return aResult;
118 }