#include <Geom_BSplineCurve.hxx>
#include <Geom_Line.hxx>
+#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <GeomAPI_ProjectPointOnCurve.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <ProjLib.hxx>
#include <ElSLib.hxx>
+#include <math.h>
+
#include "CurveCreator_ICurve.hxx"
const double LOCAL_SELECTION_TOLERANCE = 0.0001;
}
}
-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,
}
}
return isFoundPoint;
-}
+}*/
bool CurveCreator_Utils::pointOnObject( Handle(V3d_View) theView,
Handle(AIS_InteractiveObject) theObject,
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() )
int aXDelta = abs( aX - theX );
int anYDelta = abs( anY - theY );
+ theDelta = aXDelta*aXDelta + anYDelta*anYDelta;
isFound = aXDelta < SCENE_PIXEL_TOLERANCE && anYDelta < SCENE_PIXEL_TOLERANCE;
}
}
* \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
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
Handle(V3d_View) theView,
const int theX, const int theY,
const Handle(Geom_Curve)& theCurve,
- Standard_Real& theParameter );
+ Standard_Real& theParameter,
+ int& theDelta );
};