]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Insert a new point on a segment functionality. Fix for a bug with a point addition...
authornds <nds@opencascade.com>
Tue, 19 Nov 2013 14:40:13 +0000 (14:40 +0000)
committernds <nds@opencascade.com>
Tue, 19 Nov 2013 14:40:13 +0000 (14:40 +0000)
src/HYDROCurveCreator/CurveCreator_Widget.cxx
src/HYDROCurveCreator/CurveCreator_Widget.h

index ac5b638f90122df6179ca83dbe1f12179527b56d..fa6217e9d89496c13ace7edaf80c27459c07e65e 100644 (file)
@@ -52,6 +52,8 @@
 #include <AIS_Point.hxx>
 #include <AIS_Line.hxx>
 #include <Geom_Point.hxx>
+#include <Geom_BSplineCurve.hxx>
+#include <Geom_Line.hxx>
 #include <StdSelect_BRepOwner.hxx>
 
 #include <QHBoxLayout>
@@ -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;
index 39e752d8440dc9f22c03eb612c0170aaa05c6855..5ca56c675ea76857cc389f4927f1b74174886477 100644 (file)
@@ -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<ActionId, QAction*>    myActionMap;