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)))
51 // Check the difference of first and last parameters to be equal to the curve period
52 if (Abs(aLast - aFirst - aCurve->Period()) < Precision::PConfusion())
58 bool GeomAPI_Edge::isArc() const
60 const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
62 Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
63 if (aCurve->IsKind(STANDARD_TYPE(Geom_Circle)))
65 // Check the difference of first and last parameters is not equal the curve period
66 if (Abs(aLast - aFirst - aCurve->Period()) >= Precision::PConfusion())
72 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Edge::firstPoint()
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(aFirst, aPoint);
79 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
82 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Edge::lastPoint()
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 aCurve->D0(aLast, aPoint);
89 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
92 std::shared_ptr<GeomAPI_Circ> GeomAPI_Edge::circle()
94 const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
96 Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
98 Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast(aCurve);
100 gp_Pnt aLoc = aCirc->Location();
101 std::shared_ptr<GeomAPI_Pnt> aCenter(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
102 gp_Dir anAxis = aCirc->Axis().Direction();
103 std::shared_ptr<GeomAPI_Dir> aDir(new GeomAPI_Dir(anAxis.X(), anAxis.Y(), anAxis.Z()));
104 return std::shared_ptr<GeomAPI_Circ>(new GeomAPI_Circ(aCenter, aDir, aCirc->Radius()));
107 return std::shared_ptr<GeomAPI_Circ>(); // not circle
111 bool GeomAPI_Edge::isEqual(const std::shared_ptr<GeomAPI_Shape> theEdge) const
113 const TopoDS_Shape& aMyShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
114 const TopoDS_Shape& aInShape = theEdge->impl<TopoDS_Shape>();
116 if (aMyShape.ShapeType() != aInShape.ShapeType())
119 double aMyStart, aMyEnd;
120 Handle(Geom_Curve) aMyCurve = BRep_Tool::Curve(TopoDS::Edge(aMyShape), aMyStart, aMyEnd);
121 double aInStart, aInEnd;
122 Handle(Geom_Curve) aInCurve = BRep_Tool::Curve(TopoDS::Edge(aInShape), aInStart, aInEnd);
124 // Check that curves a the same type
125 GeomAdaptor_Curve aMyAdaptor(aMyCurve);
126 GeomAdaptor_Curve aInAdaptor(aInCurve);
127 if (aMyAdaptor.GetType() != aInAdaptor.GetType())
130 // Check that end point parameters are the same
131 if ((aMyStart != aInStart) || (aMyEnd != aInEnd))
134 // Check that end points are equal
135 gp_Pnt aMyPnt1 = aMyAdaptor.Value(aMyStart);
136 gp_Pnt aMyPnt2 = aMyAdaptor.Value(aMyEnd);
137 gp_Pnt aInPnt1 = aInAdaptor.Value(aInStart);
138 gp_Pnt aInPnt2 = aInAdaptor.Value(aInEnd);
140 if ((!aMyPnt1.IsEqual(aInPnt1, Precision::Confusion())) ||
141 (!aMyPnt2.IsEqual(aInPnt2, Precision::Confusion())))