+ const TopoDS_Wire& aWire = TopoDS::Wire( aShape->Shape() );
+ if ( !aWire.IsNull() ) {
+ TopExp_Explorer anExp( aWire, TopAbs_EDGE );
+ for ( ; anExp.More(); anExp.Next())
+ {
+ const TopoDS_Edge& anEdge = TopoDS::Edge(anExp.Current());
+ if ( !anEdge.IsNull() ) {
+ Standard_Real aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve( anEdge, aFirst, aLast );
+ aCurve->D0(aFirst,aPnt1);
+ aCurve->D0(aLast,aPnt2);
+ isFound = hasProjectPointOnCurve( theX, theY, aCurve, aPoint );
+ }
+ }
+ }
+ }
+ }
+ if ( isFound ) {
+ thePoint = aPoint;
+ thePoint1 = findLocalPointIndex( 0, aPnt1.X(), aPnt1.Y() );
+ thePoint2 = findLocalPointIndex( 0, aPnt2.X(), aPnt2.Y() );
+ isFound = thePoint1 >= 0 && thePoint2 >= 0;
+ }
+ return isFound;
+}
+
+/**
+ * Returns whether the clicked point belong to the curve or has a very near projection
+ * \param theX the X coordinate of a point clicked in the OCC viewer
+ * \param theY the Y coordinate of a point clicked in the OCC viewer
+ * \param theCurve a geometry curve
+ * \param theOutPoint a found projected point on the curve
+ */
+bool CurveCreator_Widget::hasProjectPointOnCurve( const int theX, const int theY,
+ const Handle(Geom_Curve)& theCurve,
+ gp_Pnt& theOutPoint )
+{
+ bool isFound = false;
+ OCCViewer_Viewer* aViewer = getOCCViewer();
+ if ( !aViewer )
+ return isFound;
+
+ OCCViewer_ViewWindow* aWindow =
+ (OCCViewer_ViewWindow*)aViewer->getViewManager()->getActiveView();
+ Handle(V3d_View) aView = aWindow->getViewPort()->getView();
+ gp_Pnt aPoint = CurveCreator_Utils::ConvertClickToPoint( theX, theY, aView );
+
+ GeomAPI_ProjectPointOnCurve aProj( aPoint, theCurve );
+ Standard_Integer aNbPoint = aProj.NbPoints();
+ if (aNbPoint > 0) {
+ for (Standard_Integer j = 1; j <= aNbPoint && !isFound; j++) {
+ gp_Pnt aNewPoint = aProj.Point(j);
+
+ int aX, anY;
+ CurveCreator_Utils::ConvertPointToClick( aNewPoint, aView, aX, anY );
+
+ int aXDelta = abs( aX - theX );
+ int anYDelta = abs( anY - theY );
+ isFound = aXDelta < SCENE_PIXEL_TOLERANCE && anYDelta < SCENE_PIXEL_TOLERANCE;
+ if ( isFound ) {
+ theOutPoint = aNewPoint;
+ }