1 // File: GeomAPI_Edge.cpp
2 // Created: 24 Jul 2014
3 // Author: Artem ZHIDKOV
5 #include<GeomAPI_Edge.h>
6 #include<GeomAPI_Pnt.h>
7 #include<GeomAPI_Circ.h>
8 #include<GeomAPI_Dir.h>
10 #include <TopoDS_Shape.hxx>
11 #include <TopoDS_Edge.hxx>
12 #include <BRep_Tool.hxx>
13 #include <Geom_Curve.hxx>
14 #include <Geom_Line.hxx>
15 #include <Geom_Circle.hxx>
18 GeomAPI_Edge::GeomAPI_Edge()
23 GeomAPI_Edge::GeomAPI_Edge(const boost::shared_ptr<GeomAPI_Shape>& theShape)
25 if (!theShape->isNull() && theShape->isEdge()) {
26 setImpl(new TopoDS_Shape(theShape->impl<TopoDS_Shape>()));
30 bool GeomAPI_Edge::isLine() const
32 const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
34 Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
35 if (aCurve->IsKind(STANDARD_TYPE(Geom_Line)))
40 bool GeomAPI_Edge::isCircle() const
42 const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
44 Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
45 if (aCurve->IsKind(STANDARD_TYPE(Geom_Circle)) && aCurve->IsClosed())
50 bool GeomAPI_Edge::isArc() const
52 const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
54 Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
55 if (aCurve->IsKind(STANDARD_TYPE(Geom_Circle)) && !aCurve->IsClosed())
60 boost::shared_ptr<GeomAPI_Pnt> GeomAPI_Edge::firstPoint()
62 const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
64 Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
66 aCurve->D0(aFirst, aPoint);
67 return boost::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
70 boost::shared_ptr<GeomAPI_Pnt> GeomAPI_Edge::lastPoint()
72 const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
74 Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
76 aCurve->D0(aLast, aPoint);
77 return boost::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
80 boost::shared_ptr<GeomAPI_Circ> GeomAPI_Edge::circle()
82 const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
84 Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
86 Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast(aCurve);
88 gp_Pnt aLoc = aCirc->Location();
89 boost::shared_ptr<GeomAPI_Pnt> aCenter(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
90 gp_Dir anAxis = aCirc->Axis().Direction();
91 boost::shared_ptr<GeomAPI_Dir> aDir(new GeomAPI_Dir(anAxis.X(), anAxis.Y(), anAxis.Z()));
92 return boost::shared_ptr<GeomAPI_Circ>(new GeomAPI_Circ(aCenter, aDir, aCirc->Radius()));
95 return boost::shared_ptr<GeomAPI_Circ>(); // not circle