From: nds Date: Tue, 19 Nov 2013 14:40:13 +0000 (+0000) Subject: Insert a new point on a segment functionality. Fix for a bug with a point addition... X-Git-Tag: BR_hydro_v_0_3_1~61 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=57c75fe61de1cf26cd56083955714b1b57b1d30e;p=modules%2Fhydro.git Insert a new point on a segment functionality. Fix for a bug with a point addition on a spline. A new point is inserted between incorrect points. --- diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.cxx b/src/HYDROCurveCreator/CurveCreator_Widget.cxx index ac5b638f..fa6217e9 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Widget.cxx @@ -52,6 +52,8 @@ #include #include #include +#include +#include #include #include @@ -1395,16 +1397,21 @@ bool CurveCreator_Widget::pointOnObject( Handle(AIS_InteractiveObject) theObject return isFound; gp_Pnt aPoint; + Standard_Real aParameter; gp_Pnt aPnt1, aPnt2; Handle(AIS_Line) aLine = Handle(AIS_Line)::DownCast( theObject ); if ( !aLine.IsNull() ) { const Handle(Geom_Line) aGLine = aLine->Line(); + isFound = hasProjectPointOnCurve( theX, theY, aGLine, aParameter ); + if ( isFound ) { + aPoint = aGLine->Value( aParameter ); + Handle(Geom_Point) aPStart; Handle(Geom_Point) aPEnd; aLine->Points( aPStart, aPEnd ); aPnt1 = aPStart->Pnt(); aPnt2 = aPEnd->Pnt(); - isFound = hasProjectPointOnCurve( theX, theY, aGLine, aPoint ); + } } else { Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast( theObject ); @@ -1418,9 +1425,21 @@ bool CurveCreator_Widget::pointOnObject( Handle(AIS_InteractiveObject) theObject 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 ( aCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) ) { + Handle(Geom_BSplineCurve) aBSplineCurve = Handle(Geom_BSplineCurve)::DownCast( aCurve ); + if ( !aBSplineCurve.IsNull() ) { + isFound = hasProjectPointOnCurve( theX, theY, aCurve, aParameter ); + if ( isFound ) { + aPoint = aBSplineCurve->Value( aParameter ); + Standard_Integer anI1, anI2; + aBSplineCurve->LocateU( aParameter, LOCAL_SELECTION_TOLERANCE, anI1, anI2 ); + + aPnt1 = aBSplineCurve->Value( aBSplineCurve->Knot( anI1 ) ); + aPnt2 = aBSplineCurve->Value( aBSplineCurve->Knot( anI2 ) ); + } + } + } } } } @@ -1444,7 +1463,7 @@ bool CurveCreator_Widget::pointOnObject( Handle(AIS_InteractiveObject) theObject */ bool CurveCreator_Widget::hasProjectPointOnCurve( const int theX, const int theY, const Handle(Geom_Curve)& theCurve, - gp_Pnt& theOutPoint ) + Standard_Real& theParameter ) { bool isFound = false; OCCViewer_Viewer* aViewer = getOCCViewer(); @@ -1460,7 +1479,8 @@ bool CurveCreator_Widget::hasProjectPointOnCurve( const int theX, const int theY Standard_Integer aNbPoint = aProj.NbPoints(); if (aNbPoint > 0) { for (Standard_Integer j = 1; j <= aNbPoint && !isFound; j++) { - gp_Pnt aNewPoint = aProj.Point(j); + gp_Pnt aNewPoint = aProj.Point( j ); + theParameter = aProj.Parameter( j ); int aX, anY; CurveCreator_Utils::ConvertPointToClick( aNewPoint, aView, aX, anY ); @@ -1468,9 +1488,6 @@ bool CurveCreator_Widget::hasProjectPointOnCurve( const int theX, const int theY int aXDelta = abs( aX - theX ); int anYDelta = abs( anY - theY ); isFound = aXDelta < SCENE_PIXEL_TOLERANCE && anYDelta < SCENE_PIXEL_TOLERANCE; - if ( isFound ) { - theOutPoint = aNewPoint; - } } } return isFound; diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.h b/src/HYDROCurveCreator/CurveCreator_Widget.h index 39e752d8..5ca56c67 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.h +++ b/src/HYDROCurveCreator/CurveCreator_Widget.h @@ -164,7 +164,7 @@ private: gp_Pnt& thePoint, int& thePoint1, int& thePoint2 ); bool hasProjectPointOnCurve( const int theX, const int theY, const Handle(Geom_Curve)& theCurve, - gp_Pnt& theOutPoint ); + Standard_Real& theParameter ); private: QMap myActionMap;