Salome HOME
Merge branch 'Pre_2.8.0_development'
[modules/shaper.git] / src / GeomAPI / GeomAPI_Edge.cpp
index c336050f9c08bdd5f35cf56cd3e08e8a090303da..9927c2ae9cc3bb899fcb53611073f05d3d67b436 100644 (file)
@@ -24,6 +24,8 @@
 #include<GeomAPI_Circ.h>
 #include<GeomAPI_Dir.h>
 #include<GeomAPI_Lin.h>
+#include<GeomAPI_Ax2.h>
+#include<GeomAPI_Ellipse.h>
 
 #include <BRepAdaptor_Curve.hxx>
 
 #include <Geom_Curve.hxx>
 #include <Geom_Line.hxx>
 #include <Geom_Circle.hxx>
+#include <Geom_Ellipse.hxx>
 #include <GeomAdaptor_Curve.hxx>
 #include <gp_Ax1.hxx>
 #include <gp_Pln.hxx>
+#include <gp_Elips.hxx>
 
 #include <GCPnts_AbscissaPoint.hxx>
 
@@ -96,6 +100,16 @@ bool GeomAPI_Edge::isArc() const
   return false;
 }
 
+bool GeomAPI_Edge::isEllipse() const
+{
+  const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
+  double aFirst, aLast;
+  Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
+  if (aCurve->IsKind(STANDARD_TYPE(Geom_Ellipse)))
+    return true;
+  return false;
+}
+
 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Edge::firstPoint()
 {
   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
@@ -116,14 +130,14 @@ std::shared_ptr<GeomAPI_Pnt> GeomAPI_Edge::lastPoint()
   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
 }
 
-std::shared_ptr<GeomAPI_Circ> GeomAPI_Edge::circle()
+std::shared_ptr<GeomAPI_Circ> GeomAPI_Edge::circle() const
 {
   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
   double aFirst, aLast;
   Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
-  if (aCurve) {
+  if (!aCurve.IsNull()) {
     Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast(aCurve);
-    if (aCirc) {
+    if (!aCirc.IsNull()) {
       gp_Pnt aLoc = aCirc->Location();
       std::shared_ptr<GeomAPI_Pnt> aCenter(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
       gp_Dir anAxis = aCirc->Axis().Direction();
@@ -134,7 +148,24 @@ std::shared_ptr<GeomAPI_Circ> GeomAPI_Edge::circle()
   return std::shared_ptr<GeomAPI_Circ>(); // not circle
 }
 
-std::shared_ptr<GeomAPI_Lin> GeomAPI_Edge::line()
+std::shared_ptr<GeomAPI_Ellipse> GeomAPI_Edge::ellipse() const
+{
+  const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
+  double aFirst, aLast;
+  Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
+  if (!aCurve.IsNull()) {
+    Handle(Geom_Ellipse) aElips = Handle(Geom_Ellipse)::DownCast(aCurve);
+    if (!aElips.IsNull()) {
+      gp_Elips aGpElips = aElips->Elips();
+      std::shared_ptr<GeomAPI_Ellipse> aEllipse(new GeomAPI_Ellipse());
+      aEllipse->setImpl(new gp_Elips(aGpElips));
+      return aEllipse;
+    }
+  }
+  return std::shared_ptr<GeomAPI_Ellipse>(); // not elipse
+}
+
+std::shared_ptr<GeomAPI_Lin> GeomAPI_Edge::line() const
 {
   const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
   double aFirst, aLast;