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>
13 #include <BRep_Tool.hxx>
14 #include <Geom_Curve.hxx>
15 #include <Geom_Line.hxx>
16 #include <Geom_Circle.hxx>
17 #include <GeomAdaptor_Curve.hxx>
20 GeomAPI_Edge::GeomAPI_Edge()
25 GeomAPI_Edge::GeomAPI_Edge(const std::shared_ptr<GeomAPI_Shape>& theShape)
27 if (!theShape->isNull() && theShape->isEdge()) {
28 setImpl(new TopoDS_Shape(theShape->impl<TopoDS_Shape>()));
32 bool GeomAPI_Edge::isLine() const
34 const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
36 Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
37 if (aCurve->IsKind(STANDARD_TYPE(Geom_Line)))
42 bool GeomAPI_Edge::isCircle() const
44 const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
46 Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
47 if (aCurve->IsKind(STANDARD_TYPE(Geom_Circle)) && aCurve->IsClosed())
52 bool GeomAPI_Edge::isArc() const
54 const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
56 Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
57 if (aCurve->IsKind(STANDARD_TYPE(Geom_Circle)) && !aCurve->IsClosed())
62 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Edge::firstPoint()
64 const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
66 Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
68 aCurve->D0(aFirst, aPoint);
69 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
72 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Edge::lastPoint()
74 const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
76 Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
78 aCurve->D0(aLast, aPoint);
79 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
82 std::shared_ptr<GeomAPI_Circ> GeomAPI_Edge::circle()
84 const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
86 Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
88 Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast(aCurve);
90 gp_Pnt aLoc = aCirc->Location();
91 std::shared_ptr<GeomAPI_Pnt> aCenter(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
92 gp_Dir anAxis = aCirc->Axis().Direction();
93 std::shared_ptr<GeomAPI_Dir> aDir(new GeomAPI_Dir(anAxis.X(), anAxis.Y(), anAxis.Z()));
94 return std::shared_ptr<GeomAPI_Circ>(new GeomAPI_Circ(aCenter, aDir, aCirc->Radius()));
97 return std::shared_ptr<GeomAPI_Circ>(); // not circle
101 bool GeomAPI_Edge::isEqual(std::shared_ptr<GeomAPI_Shape> theEdge)
103 const TopoDS_Shape& aMyShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
104 const TopoDS_Shape& aInShape = theEdge->impl<TopoDS_Shape>();
106 double aMyStart, aMyEnd;
107 Handle(Geom_Curve) aMyCurve = BRep_Tool::Curve(TopoDS::Edge(aMyShape), aMyStart, aMyEnd);
108 double aInStart, aInEnd;
109 Handle(Geom_Curve) aInCurve = BRep_Tool::Curve(TopoDS::Edge(aInShape), aInStart, aInEnd);
111 // Check that curves a the same type
112 GeomAdaptor_Curve aMyAdaptor(aMyCurve);
113 GeomAdaptor_Curve aInAdaptor(aInCurve);
114 if (aMyAdaptor.GetType() != aInAdaptor.GetType())
117 // Check that end point parameters are the same
118 if ((aMyStart != aInStart) || (aMyEnd != aInEnd))
121 // Check that end points are equal
122 gp_Pnt aMyPnt1 = aMyAdaptor.Value(aMyStart);
123 gp_Pnt aMyPnt2 = aMyAdaptor.Value(aMyEnd);
124 gp_Pnt aInPnt1 = aInAdaptor.Value(aInStart);
125 gp_Pnt aInPnt2 = aInAdaptor.Value(aInEnd);
127 if ((!aMyPnt1.IsEqual(aInPnt1, Precision::Confusion())) ||
128 (!aMyPnt2.IsEqual(aInPnt2, Precision::Confusion())))