Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
[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
9 #include <TopoDS_Shape.hxx>
10 #include <Geom_Curve.hxx>
11 #include <Geom_Line.hxx>
12 #include <Geom_Circle.hxx>
13 #include <BRep_Tool.hxx>
14 #include <TopoDS_Edge.hxx>
15 #include <TopoDS.hxx>
16
17 #define MY_CURVE (*(static_cast<Handle_Geom_Curve*>(myImpl)))
18
19 GeomAPI_Curve::GeomAPI_Curve()
20     : GeomAPI_Interface(new Handle_Geom_Curve())
21 {
22 }
23
24 GeomAPI_Curve::GeomAPI_Curve(const std::shared_ptr<GeomAPI_Shape>& theShape)
25   : GeomAPI_Interface(new Handle_Geom_Curve()) // initially it is null
26 {
27   const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
28   TopoDS_Edge anEdge = TopoDS::Edge(aShape);
29   if (!anEdge.IsNull()) {
30     Standard_Real aStart, anEnd;
31     Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aStart, anEnd);
32     if (!aCurve.IsNull()) {
33       setImpl(new Handle(Geom_Curve)(aCurve));
34     }
35   }
36 }
37
38 bool GeomAPI_Curve::isNull() const
39 {
40   return MY_CURVE.IsNull() == Standard_True;
41 }
42
43 bool GeomAPI_Curve::isLine() const
44 {
45   return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Line);
46 }
47
48 bool GeomAPI_Curve::isCircle() const
49 {
50   return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Circle);
51 }