Salome HOME
Issue 2556: Functionality of inspection “WhatIs”
[modules/shaper.git] / src / GeomAPI / GeomAPI_Face.cpp
index b025bca92ee2b6f3f081619f8bc071c09e1ca03b..89e39adfe2cdc3bce1b9740af4983182ac5c5bb6 100644 (file)
@@ -14,7 +14,8 @@
 // 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<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
 //
 
 #include "GeomAPI_Face.h"
 #include "GeomAPI_Dir.h"
 #include "GeomAPI_Pln.h"
 #include "GeomAPI_Pnt.h"
+#include "GeomAPI_Sphere.h"
+#include "GeomAPI_Cylinder.h"
+#include "GeomAPI_Cone.h"
+#include "GeomAPI_Torus.h"
 
 #include <BOPTools_AlgoTools.hxx>
 #include <BRep_Tool.hxx>
 #include <BRepAdaptor_Surface.hxx>
+#include <BRepTools.hxx>
 #include <Geom_Surface.hxx>
+#include <Geom_SphericalSurface.hxx>
+#include <Geom_ConicalSurface.hxx>
 #include <Geom_CylindricalSurface.hxx>
 #include <Geom_RectangularTrimmedSurface.hxx>
+#include <Geom_ToroidalSurface.hxx>
 #include <GeomLib_IsPlanarSurface.hxx>
 #include <IntTools_Context.hxx>
+#include <Standard_Type.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Face.hxx>
 
+#include <gp_Sphere.hxx>
+#include <gp_Cylinder.hxx>
+#include <gp_Cone.hxx>
+#include <gp_Torus.hxx>
+
+
 GeomAPI_Face::GeomAPI_Face()
   : GeomAPI_Shape()
 {
@@ -129,3 +145,89 @@ std::shared_ptr<GeomAPI_Pln> GeomAPI_Face::getPlane() const
   aResult = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
   return aResult;
 }
+
+std::shared_ptr<GeomAPI_Sphere> GeomAPI_Face::getSphere() const
+{
+  GeomSpherePtr aSphere;
+
+  const TopoDS_Face& aFace = TopoDS::Face(impl<TopoDS_Shape>());
+  Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
+  if (aSurf->IsKind(STANDARD_TYPE(Geom_SphericalSurface))) {
+    gp_Sphere aSph = Handle(Geom_SphericalSurface)::DownCast(aSurf)->Sphere();
+    const gp_Pnt& aCenter = aSph.Location();
+    double aRadius = aSph.Radius();
+
+    GeomPointPtr aCenterPnt(new GeomAPI_Pnt(aCenter.X(), aCenter.Y(), aCenter.Z()));
+    aSphere = GeomSpherePtr(new GeomAPI_Sphere(aCenterPnt, aRadius));
+  }
+  return aSphere;
+}
+
+std::shared_ptr<GeomAPI_Cylinder> GeomAPI_Face::getCylinder() const
+{
+  GeomCylinderPtr aCylinder;
+
+  const TopoDS_Face& aFace = TopoDS::Face(impl<TopoDS_Shape>());
+  Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
+  if (aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
+    gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(aSurf)->Cylinder();
+    gp_Pnt aLoc = aCyl.Location();
+    const gp_Dir& aDir = aCyl.Position().Direction();
+    double aRadius = aCyl.Radius();
+
+    double aUMin, aUMax, aVMin, aVMax;
+    BRepTools::UVBounds(aFace, aUMin, aUMax, aVMin, aVMax);
+    double aHeight = aVMax - aVMin;
+
+    aLoc.ChangeCoord() += aDir.XYZ() * aVMin;
+    GeomPointPtr aLocation(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
+    GeomDirPtr aDirection(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
+    aCylinder = GeomCylinderPtr(new GeomAPI_Cylinder(aLocation, aDirection, aRadius, aHeight));
+  }
+  return aCylinder;
+}
+
+std::shared_ptr<GeomAPI_Cone> GeomAPI_Face::getCone() const
+{
+  GeomConePtr aCone;
+
+  const TopoDS_Face& aFace = TopoDS::Face(impl<TopoDS_Shape>());
+  Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
+  if (aSurf->IsKind(STANDARD_TYPE(Geom_ConicalSurface))) {
+    gp_Cone aCon = Handle(Geom_ConicalSurface)::DownCast(aSurf)->Cone();
+    const gp_Pnt& aLoc = aCon.Location();
+    const gp_Dir& aDir = aCon.Position().Direction();
+    double aRadius1 = aCon.RefRadius();
+
+    double aUMin, aUMax, aVMin, aVMax;
+    BRepTools::UVBounds(aFace, aUMin, aUMax, aVMin, aVMax);
+
+    double aSemiAngle = Abs(aCon.SemiAngle());
+    double aRadius2 = aRadius1 - (aVMax - aVMin) * Sin(aSemiAngle);
+
+    GeomPointPtr aLocation(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
+    GeomDirPtr aDirection(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
+    aCone = GeomConePtr(new GeomAPI_Cone(aLocation, aDirection, aSemiAngle, aRadius1, aRadius2));
+  }
+  return aCone;
+}
+
+std::shared_ptr<GeomAPI_Torus> GeomAPI_Face::getTorus() const
+{
+  GeomTorusPtr aTorus;
+
+  const TopoDS_Face& aFace = TopoDS::Face(impl<TopoDS_Shape>());
+  Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
+  if (aSurf->IsKind(STANDARD_TYPE(Geom_ToroidalSurface))) {
+    gp_Torus aTor = Handle(Geom_ToroidalSurface)::DownCast(aSurf)->Torus();
+    const gp_Pnt& aLoc = aTor.Location();
+    const gp_Dir& aDir = aTor.Position().Direction();
+    double aMajorRadius = aTor.MajorRadius();
+    double aMinorRadius = aTor.MinorRadius();
+
+    GeomPointPtr aCenter(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
+    GeomDirPtr aDirection(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
+    aTorus = GeomTorusPtr(new GeomAPI_Torus(aCenter, aDirection, aMajorRadius, aMinorRadius));
+  }
+  return aTorus;
+}