]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
It removes AIS curve presentation.
authornds <nds@opencascade.com>
Wed, 4 Dec 2013 13:18:10 +0000 (13:18 +0000)
committernds <nds@opencascade.com>
Wed, 4 Dec 2013 13:18:10 +0000 (13:18 +0000)
src/HYDROCurveCreator/CurveCreator_Utils.cxx
src/HYDROCurveCreator/CurveCreator_Utils.h
src/HYDROCurveCreator/CurveCreator_Widget.cxx

index fa5e741707e16e1e3f9bc9bd25d8ebfd0f2ee3de..e5809e49101c733205e13395d6d6b4eb95ef8fa8 100644 (file)
@@ -42,6 +42,7 @@
 #include <Geom_BSplineCurve.hxx>
 #include <Geom_Line.hxx>
 
+#include <TopExp.hxx>
 #include <TopExp_Explorer.hxx>
 #include <GeomAPI_ProjectPointOnCurve.hxx>
 #include <SelectMgr_EntityOwner.hxx>
@@ -60,6 +61,8 @@
 #include <ProjLib.hxx>
 #include <ElSLib.hxx>
 
+#include <math.h>
+
 #include "CurveCreator_ICurve.hxx"
 
 const double LOCAL_SELECTION_TOLERANCE = 0.0001;
@@ -327,7 +330,7 @@ void CurveCreator_Utils::setLocalPointContext(
   }
 }
 
-bool CurveCreator_Utils::getNeighbourPoints( Handle(AIS_InteractiveContext) theContext,
+/*bool CurveCreator_Utils::getNeighbourPoints( Handle(AIS_InteractiveContext) theContext,
                                              Handle(V3d_View) theView,
                                              const int theX, const int theY,
                                              gp_Pnt& thePoint, gp_Pnt& thePoint1,
@@ -354,7 +357,7 @@ bool CurveCreator_Utils::getNeighbourPoints( Handle(AIS_InteractiveContext) theC
     }
   }
   return isFoundPoint;
-}
+}*/
 
 bool CurveCreator_Utils::pointOnObject( Handle(V3d_View) theView,
                                         Handle(AIS_InteractiveObject) theObject,
@@ -362,78 +365,91 @@ bool CurveCreator_Utils::pointOnObject( Handle(V3d_View) theView,
                                         gp_Pnt& thePoint,
                                         gp_Pnt& thePoint1, gp_Pnt& thePoint2 )
 {
-  bool isFound = false;
+  bool isFullFound = false;
 
   if ( theObject.IsNull() || theView.IsNull() )
-    return isFound;
+    return isFullFound;
 
-  gp_Pnt aPoint;
+  gp_Pnt aPoint, aFoundPoint;
   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( theView, 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();
-
-      // in case of Geom line a projection is performed to the infinite line,
-      // so it is necessary to bound it by the line size
-      Bnd_Box aLineBox;
-      aLineBox.Set( aPnt1, gp_Vec( aPnt1, aPnt2 ) );
-      isFound = !aLineBox.IsOut( aPoint );
-    }
-  }
-  else {
+  gp_Pnt aPnt1, aPnt2, aFoundPnt1, aFoundPnt2;
+  bool isFound = false;
+  {
+    int aDelta, aMinDelta = 2*SCENE_PIXEL_TOLERANCE*SCENE_PIXEL_TOLERANCE;
     Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast( theObject );
     if ( !aShape.IsNull() ) {
-      const TopoDS_Wire& aWire = TopoDS::Wire( aShape->Shape() );
-      if ( !aWire.IsNull() ) {
-        TopExp_Explorer anExp( aWire, TopAbs_EDGE );
+      const TopoDS_Compound& aCompound = TopoDS::Compound( aShape->Shape() );
+      if ( !aCompound.IsNull() ) {
+        TopExp_Explorer anExp( aCompound, 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 );
-
-            if ( aCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) ) {
-              Handle(Geom_BSplineCurve) aBSplineCurve = Handle(Geom_BSplineCurve)::DownCast( aCurve );
-              if ( !aBSplineCurve.IsNull() ) {
-                isFound = hasProjectPointOnCurve( theView, 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 ) );
+          if ( anEdge.IsNull() )
+            continue;
+          Standard_Real aFirst, aLast;
+          Handle(Geom_Curve) aCurve = BRep_Tool::Curve( anEdge, aFirst, aLast );
+          if ( aCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) ) {
+            Handle(Geom_BSplineCurve) aBSplineCurve = Handle(Geom_BSplineCurve)::DownCast( aCurve );
+            if ( !aBSplineCurve.IsNull() ) {
+              isFound = hasProjectPointOnCurve( theView, theX, theY, aBSplineCurve,
+                                                aParameter, aDelta );
+              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 ) );
+              }
+            }
+          }
+          else { // usual curve
+            Handle(Geom_Line) aGLine = Handle(Geom_Line)::DownCast( aCurve );
+            if ( !aGLine.IsNull() ) {
+              isFound = hasProjectPointOnCurve( theView, theX, theY, aGLine, aParameter,
+                                                aDelta );
+              if ( isFound ) {
+                aPoint = aGLine->Value( aParameter );
+
+                TopoDS_Vertex V1, V2;
+                TopExp::Vertices(anEdge, V1, V2, Standard_True);
+                if (!V1.IsNull() && !V2.IsNull()) 
+                {
+                  aPnt1 = BRep_Tool::Pnt(V1);
+                  aPnt2 = BRep_Tool::Pnt(V2);
                 }
+                gp_Vec aVec1( aPnt1, aPoint );
+                gp_Vec aVec2( aPnt2, aPoint );
+                double anAngle = aVec1.Angle( aVec2 );
+                isFound = fabs( anAngle - M_PI ) < LOCAL_SELECTION_TOLERANCE;
               }
             }
           }
+          if ( isFound && aMinDelta >= aDelta ) {
+            isFullFound = true;
+            aMinDelta = aDelta;
+            aFoundPnt1 = aPnt1;
+            aFoundPnt2 = aPnt2;
+            aFoundPoint = aPoint;
+          }
         }
       }
     }
   }
-  if ( isFound ) {
+  if ( isFullFound ) {
     thePoint = aPoint;
-    thePoint1 = aPnt1;
-    thePoint2 = aPnt2;
+    thePoint = aFoundPoint;
+    thePoint1 = aFoundPnt1;
+    thePoint2 = aFoundPnt2;
   }
-  return isFound;
+  return isFullFound;
 }
 
 bool CurveCreator_Utils::hasProjectPointOnCurve( Handle(V3d_View) theView,
                                                  const int theX, const int theY,
                                                  const Handle(Geom_Curve)& theCurve,
-                                                 Standard_Real& theParameter )
+                                                 Standard_Real& theParameter,
+                                                 int& theDelta )
 {
   bool isFound = false;
   if ( theView.IsNull() )
@@ -453,6 +469,7 @@ bool CurveCreator_Utils::hasProjectPointOnCurve( Handle(V3d_View) theView,
 
       int aXDelta = abs( aX - theX );
       int anYDelta = abs( anY - theY );
+      theDelta = aXDelta*aXDelta + anYDelta*anYDelta;
       isFound = aXDelta < SCENE_PIXEL_TOLERANCE && anYDelta < SCENE_PIXEL_TOLERANCE;
     }
   }
index ab4a3503fe2447636b1ed52b670916de76699b57..29253437ba8b92d1b9c001d4ad7e95612836e7dd 100644 (file)
@@ -106,14 +106,13 @@ public:
    * \param thePoint1 the output point to bound the line where a new point should be inserted
    * \param thePoint2 the output point to bound the line where a new point should be inserted
    */
-  CURVECREATOR_EXPORT static bool getNeighbourPoints(
+  /*CURVECREATOR_EXPORT static bool getNeighbourPoints(
                                         Handle(AIS_InteractiveContext) theContext,
                                         Handle(V3d_View) theView,
                                         const int theX, const int theY,
                                         gp_Pnt& thePoint, gp_Pnt& thePoint1,
-                                        gp_Pnt& thePoint2 );
+                                        gp_Pnt& thePoint2 );*/
 
-protected:
   /**
    * Checks whether the point belongs to the OCC object
    * \param theObject a line or shape with a bspline inside
@@ -129,6 +128,7 @@ protected:
                                                  gp_Pnt& thePoint, gp_Pnt& thePoint1,
                                                  gp_Pnt& thePoint2 );
 
+protected:
   /*
    * 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
@@ -140,7 +140,8 @@ protected:
                                                  Handle(V3d_View) theView,
                                                  const int theX, const int theY,
                                                  const Handle(Geom_Curve)& theCurve,
-                                                 Standard_Real& theParameter );
+                                                 Standard_Real& theParameter,
+                                                 int& theDelta );
 
 };
 
index ea0b5098a0cdff39cf4e25d4d25090589c7a3449..97258a625eb25364f4b11d58761c0c0914fe97bd 100644 (file)
@@ -1135,8 +1135,11 @@ void CurveCreator_Widget::insertPointToSelectedSegment( const int theX,
     return;
   gp_Pnt aPoint;
   gp_Pnt aPoint1, aPoint2;
-  bool isFoundPoint = CurveCreator_Utils::getNeighbourPoints( aContext, aView, theX, theY,
-                                                              aPoint, aPoint1, aPoint2 );
+  //bool isFoundPoint = CurveCreator_Utils::getNeighbourPoints( aContext, aView, theX, theY,
+  //                                                            aPoint, aPoint1, aPoint2 );
+  Handle(AIS_InteractiveObject) anAISObject = myCurve->getAISObject();
+  bool isFoundPoint = CurveCreator_Utils::pointOnObject( aView, anAISObject, theX, theY,
+                                                         aPoint, aPoint1, aPoint2 );
   if ( !isFoundPoint )
     return;