Salome HOME
Degrees of freedom for a sketch (issue #796)
[modules/shaper.git] / src / GeomAPI / GeomAPI_Curve.cpp
index 77bf7d9a2660842d0fee494d689961fbe6b57106..f96fd7b7850d7d4492dbbbf4419a85064ce66621 100644 (file)
@@ -1,8 +1,11 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        GeomAPI_Curve.cpp
 // Created:     04 Sep 2014
 // Author:      Mikhail PONIKAROV
 
 #include<GeomAPI_Curve.h>
+#include<GeomAPI_Pnt.h>
 
 #include <TopoDS_Shape.hxx>
 #include <Geom_Curve.hxx>
 #include <BRep_Tool.hxx>
 #include <TopoDS_Edge.hxx>
 #include <TopoDS.hxx>
+#include <GeomAdaptor_Curve.hxx>
 
-#define MY_CURVE (*(static_cast<Handle_Geom_Curve*>(myImpl)))
+#define MY_CURVE (*(implPtr<Handle_Geom_Curve>()))
 
 GeomAPI_Curve::GeomAPI_Curve()
-    : GeomAPI_Interface(new Handle_Geom_Curve())
+    : GeomAPI_Interface(new Handle_Geom_Curve()), myStart(0), myEnd(1)
 {
 }
 
-GeomAPI_Curve::GeomAPI_Curve(const boost::shared_ptr<GeomAPI_Shape>& theShape)
+GeomAPI_Curve::GeomAPI_Curve(const std::shared_ptr<GeomAPI_Shape>& theShape)
   : GeomAPI_Interface(new Handle_Geom_Curve()) // initially it is null
 {
   const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
   TopoDS_Edge anEdge = TopoDS::Edge(aShape);
   if (!anEdge.IsNull()) {
-    Standard_Real aStart, anEnd;
-    Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aStart, anEnd);
+    Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, myStart, myEnd);
     if (!aCurve.IsNull()) {
-      setImpl(&aCurve);
+      setImpl(new Handle(Geom_Curve)(aCurve));
     }
   }
 }
@@ -47,3 +50,10 @@ bool GeomAPI_Curve::isCircle() const
 {
   return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Circle);
 }
+
+std::shared_ptr<GeomAPI_Pnt> GeomAPI_Curve::getPoint(double theParam)
+{
+  GeomAdaptor_Curve aAdaptor(MY_CURVE, myStart, myEnd);
+  gp_Pnt aPnt = aAdaptor.Value(theParam);
+  return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z()));
+}