Salome HOME
Fix for the issue #2753 : error when dump/load script
[modules/shaper.git] / src / GeomAPI / GeomAPI_Edge.cpp
index b5d0de4b673c35ad38c0d532e3b8cbf8df7d87b3..01c98124c438de5cc5fd096a8412f0a68d49526d 100644 (file)
@@ -35,6 +35,7 @@
 #include <BRep_Builder.hxx>
 #include <BRep_Tool.hxx>
 #include <ElCLib.hxx>
+#include <GCPnts_UniformAbscissa.hxx>
 #include <Geom_Curve.hxx>
 #include <Geom_Line.hxx>
 #include <Geom_Circle.hxx>
@@ -216,16 +217,16 @@ bool GeomAPI_Edge::isEqual(const std::shared_ptr<GeomAPI_Shape> theEdge) const
   double aInStart, aInEnd;
   Handle(Geom_Curve) aInCurve = BRep_Tool::Curve(TopoDS::Edge(aInShape), aInStart, aInEnd);
 
+  // Check that end point parameters are the same
+  if ((aMyStart != aInStart) || (aMyEnd != aInEnd))
+    return false;
+
   // Check that curves a the same type
   GeomAdaptor_Curve aMyAdaptor(aMyCurve);
   GeomAdaptor_Curve aInAdaptor(aInCurve);
   if (aMyAdaptor.GetType() != aInAdaptor.GetType())
     return false;
 
-  // Check that end point parameters are the same
-  if ((aMyStart != aInStart) || (aMyEnd != aInEnd))
-    return false;
-
   // Check that end points are equal
   gp_Pnt aMyPnt1 = aMyAdaptor.Value(aMyStart);
   gp_Pnt aMyPnt2 = aMyAdaptor.Value(aMyEnd);
@@ -361,3 +362,25 @@ void GeomAPI_Edge::setLastPointTolerance(const double theTolerance)
   TopExp::Vertices(anEdge, aVFirst, aVLast);
   BRep_Builder().UpdateVertex(aVLast, theTolerance);
 }
+
+GeomPointPtr GeomAPI_Edge::middlePoint() const
+{
+  GeomPointPtr aMiddlePoint;
+
+  const TopoDS_Edge& anEdge = impl<TopoDS_Edge>();
+  if (anEdge.IsNull())
+    return aMiddlePoint;
+  double aFirst, aLast;
+  Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+  if (aCurve.IsNull())
+    return aMiddlePoint;
+
+  static const int NB_POINTS = 3;
+  GeomAdaptor_Curve aCurveAdaptor(aCurve, aFirst, aLast);
+  GCPnts_UniformAbscissa anAlgo(aCurveAdaptor, NB_POINTS);
+  if (anAlgo.IsDone()) {
+    gp_Pnt aPnt = aCurveAdaptor.Value(anAlgo.Parameter(2));
+    aMiddlePoint = GeomPointPtr(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z()));
+  }
+  return aMiddlePoint;
+}