From 4a417f26297d6a29659acaae76676cc633fed169 Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 13 May 2014 12:38:14 +0400 Subject: [PATCH] refs #30 - Sketch base GUI: create, draw lines In case when the first line point is on the line, using the projection of the second point to this line to approximate it to the line. --- src/PartSet/PartSet_OperationSketchLine.cpp | 2 +- src/PartSet/PartSet_Tools.cpp | 48 ++++++++++----------- src/PartSet/PartSet_Tools.h | 14 +++--- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index 1b36cb183..03912db52 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -90,7 +90,7 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3 PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, X1, Y1); double aX, anY; - PartSet_Tools::IntersectLines(X0, X1, X2, X3, Y0, Y1, Y2, Y3, aX, anY); + PartSet_Tools::IntersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, aX, anY); setLinePoint(aX, anY, LINE_ATTR_END); commit(); diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 5d97e7002..3caf619ca 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -4,19 +4,24 @@ #include -#include -#include -#include -#include - #include #include + #include #include + #include #include + #include +#include +#include +#include +#include +#include +#include + #ifdef _DEBUG #include #endif @@ -94,8 +99,8 @@ void PartSet_Tools::ConvertTo2D(const gp_Pnt& thePoint, boost::shared_ptrx() + aVec.Y() * anY->y() + aVec.Z() * anY->z(); } -void PartSet_Tools::IntersectLines(double theX0, double theX1, double theX2, double theX3, - double theY0, double theY1, double theY2, double theY3, +void PartSet_Tools::IntersectLines(double theX0, double theY0, double theX1, double theY1, + double theX2, double theY2, double theX3, double theY3, double& theX, double& theY) { double aV1 = theX1 - theX0, aV2 = theY1 - theY0; @@ -114,28 +119,23 @@ void PartSet_Tools::IntersectLines(double theX0, double theX1, double theX2, dou //It is not possible to use Precision::Confusion(), because it is e-0.8, but V is sometimes e-6 Standard_Real aPrec = PRECISION_TOLERANCE; if (fabs(theX - theX0) < aPrec && fabs(theY - theY0) < aPrec) { - ProjectPointOnLine(theX2, theX3, theY2, theY3, theX1, theY1, theX, theY); + ProjectPointOnLine(theX2, theY2, theX3, theY3, theX1, theY1, theX, theY); } } -void PartSet_Tools::ProjectPointOnLine(double theX1, double theX2, double theY1, double theY2, +void PartSet_Tools::ProjectPointOnLine(double theX1, double theY1, double theX2, double theY2, double thePointX, double thePointY, double& theX, double& theY) { - //GEOM_Line aLine(gp_Pnt(theX1, theY1), gp_Dir(gp_Vec(gp_Pnt(theX1, theY1), gp_Pnt(theX2, theY2)))); - //GeomAPI_ProjectPointOnCurve aProj(gp_Pnt(thePointX, thePointY)); - /* - Standard_Integer aNbPoint = aProj.NbPoints(); - if (aNbPoint > 0) { - for (Standard_Integer j = 1; j <= aNbPoint && !isFound; j++) { - gp_Pnt aNewPoint = aProj.Point( j ); - theParameter = aProj.Parameter( j ); + theX = theY = 0; - int aX, anY; - CurveCreator_Utils::ConvertPointToClick( aNewPoint, theView, aX, anY ); + Handle(Geom_Line) aLine = new Geom_Line(gp_Pnt(theX1, theY1, 0), + gp_Dir(gp_Vec(gp_Pnt(theX1, theY1, 0), gp_Pnt(theX2, theY2, 0)))); + GeomAPI_ProjectPointOnCurve aProj(gp_Pnt(thePointX, thePointY, 0), aLine); - isFound = isEqualPixels( aX, anY, theX, theY, SCENE_PIXEL_PROJECTION_TOLERANCE, theDelta ); - } + Standard_Integer aNbPoint = aProj.NbPoints(); + if (aNbPoint > 0) { + gp_Pnt aPoint = aProj.Point(1); + theX = aPoint.X(); + theY = aPoint.Y(); } - return isFound; - */ -} \ No newline at end of file +} diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 419ef4550..ecb28b744 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -39,27 +39,27 @@ public: /// Returns the point of intersection of the two lines, the first is (v0, v1), the second is (v2, v3), /// where vi - {xi,yi}. If the v0 is on the second line, the result is a projection of the v1 to this line /// \param theX0 the horizontal coordinate of 0 point - /// \param theX1 the horizontal coordinate of 1 point - /// \param theX2 the horizontal coordinate of 2 point - /// \param theX3 the horizontal coordinate of 3 point /// \param theY0 the vertical coordinate of 0 point + /// \param theX1 the horizontal coordinate of 1 point /// \param theY1 the vertical coordinate of 1 point + /// \param theX2 the horizontal coordinate of 2 point /// \param theY2 the vertical coordinate of 2 point + /// \param theX3 the horizontal coordinate of 3 point /// \param theY3 the vertical coordinate of 3 point /// \param theX the output horizontal coordinate of the intersection point /// \param theY the outpup vertical coordinate of the intersection point - static void IntersectLines(double theX0, double theX1, double theX2, double theX3, - double theY0, double theY1, double theY2, double theY3, + static void IntersectLines(double theX0, double theY0, double theX1, double theY1, + double theX2, double theY2, double theX3, double theY3, double& theX, double& theY); /// Returns the coordinates of projection of the point to the line /// \param thePointX the projected point horizontal coordinate /// \param thePointY the projected point vertictal coordinate /// \param theX1 the horizontal coordinate of the first line point - /// \param theX2 the horizontal coordinate of the second line point /// \param theY1 the vertical coordinate of the first line point + /// \param theX2 the horizontal coordinate of the second line point /// \param theY2 the vertical coordinate of the second line point - static void ProjectPointOnLine(double theX1, double theX2, double theY1, double theY2, + static void ProjectPointOnLine(double theX1, double theY1, double theX2, double theY2, double thePointX, double thePointY, double& theX, double& theY); }; -- 2.39.2