Salome HOME
Replace void* with shared_ptr<void> in GeomAPI_Interface
[modules/shaper.git] / src / GeomAPI / GeomAPI_Curve.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAPI_Curve.cpp
4 // Created:     04 Sep 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include<GeomAPI_Curve.h>
8 #include<GeomAPI_Pnt.h>
9
10 #include <TopoDS_Shape.hxx>
11 #include <Geom_Curve.hxx>
12 #include <Geom_Line.hxx>
13 #include <Geom_Circle.hxx>
14 #include <BRep_Tool.hxx>
15 #include <TopoDS_Edge.hxx>
16 #include <TopoDS.hxx>
17 #include <GeomAdaptor_Curve.hxx>
18
19 #define MY_CURVE (*(implPtr<Handle_Geom_Curve>()))
20
21 GeomAPI_Curve::GeomAPI_Curve()
22     : GeomAPI_Interface(new Handle_Geom_Curve()), myStart(0), myEnd(1)
23 {
24 }
25
26 GeomAPI_Curve::GeomAPI_Curve(const std::shared_ptr<GeomAPI_Shape>& theShape)
27   : GeomAPI_Interface(new Handle_Geom_Curve()) // initially it is null
28 {
29   const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
30   TopoDS_Edge anEdge = TopoDS::Edge(aShape);
31   if (!anEdge.IsNull()) {
32     Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, myStart, myEnd);
33     if (!aCurve.IsNull()) {
34       setImpl(new Handle(Geom_Curve)(aCurve));
35     }
36   }
37 }
38
39 bool GeomAPI_Curve::isNull() const
40 {
41   return MY_CURVE.IsNull() == Standard_True;
42 }
43
44 bool GeomAPI_Curve::isLine() const
45 {
46   return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Line);
47 }
48
49 bool GeomAPI_Curve::isCircle() const
50 {
51   return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Circle);
52 }
53
54 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Curve::getPoint(double theParam)
55 {
56   GeomAdaptor_Curve aAdaptor(MY_CURVE, myStart, myEnd);
57   gp_Pnt aPnt = aAdaptor.Value(theParam);
58   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z()));
59 }