From 8db2d905c84a7596e0e3e027ae8e415d5c5166d9 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 4 Dec 2013 13:18:10 +0000 Subject: [PATCH] It removes AIS curve presentation. --- src/HYDROCurveCreator/CurveCreator_Utils.cxx | 117 ++++++++++-------- src/HYDROCurveCreator/CurveCreator_Utils.h | 9 +- src/HYDROCurveCreator/CurveCreator_Widget.cxx | 7 +- 3 files changed, 77 insertions(+), 56 deletions(-) diff --git a/src/HYDROCurveCreator/CurveCreator_Utils.cxx b/src/HYDROCurveCreator/CurveCreator_Utils.cxx index fa5e7417..e5809e49 100644 --- a/src/HYDROCurveCreator/CurveCreator_Utils.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Utils.cxx @@ -42,6 +42,7 @@ #include #include +#include #include #include #include @@ -60,6 +61,8 @@ #include #include +#include + #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; } } diff --git a/src/HYDROCurveCreator/CurveCreator_Utils.h b/src/HYDROCurveCreator/CurveCreator_Utils.h index ab4a3503..29253437 100644 --- a/src/HYDROCurveCreator/CurveCreator_Utils.h +++ b/src/HYDROCurveCreator/CurveCreator_Utils.h @@ -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 ); }; diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.cxx b/src/HYDROCurveCreator/CurveCreator_Widget.cxx index ea0b5098..97258a62 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Widget.cxx @@ -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; -- 2.39.2