1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAPI_Edge.cpp
4 // Created: 24 Jul 2014
5 // Author: Artem ZHIDKOV
7 #include<GeomAPI_Edge.h>
8 #include<GeomAPI_Pnt.h>
9 #include<GeomAPI_Circ.h>
10 #include<GeomAPI_Dir.h>
12 #include <TopoDS_Shape.hxx>
13 #include <TopoDS_Edge.hxx>
15 #include <BRep_Tool.hxx>
16 #include <Geom_Curve.hxx>
17 #include <Geom_Line.hxx>
18 #include <Geom_Circle.hxx>
19 #include <GeomAdaptor_Curve.hxx>
22 GeomAPI_Edge::GeomAPI_Edge()
27 GeomAPI_Edge::GeomAPI_Edge(const std::shared_ptr<GeomAPI_Shape>& theShape)
29 if (!theShape->isNull() && theShape->isEdge()) {
30 setImpl(new TopoDS_Shape(theShape->impl<TopoDS_Shape>()));
34 bool GeomAPI_Edge::isLine() const
36 const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
38 Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
39 if (aCurve->IsKind(STANDARD_TYPE(Geom_Line)))
44 bool GeomAPI_Edge::isCircle() const
46 const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
48 Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
49 if (aCurve->IsKind(STANDARD_TYPE(Geom_Circle)) && aCurve->IsClosed())
54 bool GeomAPI_Edge::isArc() const
56 const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
58 Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
59 if (aCurve->IsKind(STANDARD_TYPE(Geom_Circle)) && !aCurve->IsClosed())
64 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Edge::firstPoint()
66 const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
68 Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
70 aCurve->D0(aFirst, aPoint);
71 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
74 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Edge::lastPoint()
76 const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
78 Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
80 aCurve->D0(aLast, aPoint);
81 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
84 std::shared_ptr<GeomAPI_Circ> GeomAPI_Edge::circle()
86 const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
88 Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
90 Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast(aCurve);
92 gp_Pnt aLoc = aCirc->Location();
93 std::shared_ptr<GeomAPI_Pnt> aCenter(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
94 gp_Dir anAxis = aCirc->Axis().Direction();
95 std::shared_ptr<GeomAPI_Dir> aDir(new GeomAPI_Dir(anAxis.X(), anAxis.Y(), anAxis.Z()));
96 return std::shared_ptr<GeomAPI_Circ>(new GeomAPI_Circ(aCenter, aDir, aCirc->Radius()));
99 return std::shared_ptr<GeomAPI_Circ>(); // not circle
103 bool GeomAPI_Edge::isEqual(const std::shared_ptr<GeomAPI_Shape> theEdge) const
105 const TopoDS_Shape& aMyShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
106 const TopoDS_Shape& aInShape = theEdge->impl<TopoDS_Shape>();
108 if (aMyShape.ShapeType() != aInShape.ShapeType())
111 double aMyStart, aMyEnd;
112 Handle(Geom_Curve) aMyCurve = BRep_Tool::Curve(TopoDS::Edge(aMyShape), aMyStart, aMyEnd);
113 double aInStart, aInEnd;
114 Handle(Geom_Curve) aInCurve = BRep_Tool::Curve(TopoDS::Edge(aInShape), aInStart, aInEnd);
116 // Check that curves a the same type
117 GeomAdaptor_Curve aMyAdaptor(aMyCurve);
118 GeomAdaptor_Curve aInAdaptor(aInCurve);
119 if (aMyAdaptor.GetType() != aInAdaptor.GetType())
122 // Check that end point parameters are the same
123 if ((aMyStart != aInStart) || (aMyEnd != aInEnd))
126 // Check that end points are equal
127 gp_Pnt aMyPnt1 = aMyAdaptor.Value(aMyStart);
128 gp_Pnt aMyPnt2 = aMyAdaptor.Value(aMyEnd);
129 gp_Pnt aInPnt1 = aInAdaptor.Value(aInStart);
130 gp_Pnt aInPnt2 = aInAdaptor.Value(aInEnd);
132 if ((!aMyPnt1.IsEqual(aInPnt1, Precision::Confusion())) ||
133 (!aMyPnt2.IsEqual(aInPnt2, Precision::Confusion())))