From: vsv Date: Wed, 20 Sep 2017 08:41:59 +0000 (+0300) Subject: Issue #2208: Fix for perpendicular constraint X-Git-Tag: V_2.9.0~23^2~9^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=73cb212f0d2d590830ad51f2ea53eeaac5644309;p=modules%2Fshaper.git Issue #2208: Fix for perpendicular constraint --- diff --git a/src/GeomAPI/GeomAPI_Lin.cpp b/src/GeomAPI/GeomAPI_Lin.cpp index 5d31b18df..d3f44a404 100644 --- a/src/GeomAPI/GeomAPI_Lin.cpp +++ b/src/GeomAPI/GeomAPI_Lin.cpp @@ -107,14 +107,21 @@ const std::shared_ptr GeomAPI_Lin::intersect( new GeomAPI_Pnt(aResult.X(), aResult.Y(), aResult.Z())); } -const std::shared_ptr GeomAPI_Lin::project( - const std::shared_ptr& thePoint) const +double GeomAPI_Lin::projParam( + const std::shared_ptr& thePoint) const { const gp_XYZ& aDir = MY_LIN->Direction().XYZ(); const gp_XYZ& aLoc = MY_LIN->Location().XYZ(); const gp_XYZ& aPnt = thePoint->impl().XYZ(); - double aParam = aDir.Dot(aPnt - aLoc); + return aDir.Dot(aPnt - aLoc); +} +const std::shared_ptr GeomAPI_Lin::project( + const std::shared_ptr& thePoint) const +{ + const gp_XYZ& aDir = MY_LIN->Direction().XYZ(); + const gp_XYZ& aLoc = MY_LIN->Location().XYZ(); + double aParam = projParam(thePoint); gp_XYZ aResult = aLoc + aDir * aParam; return std::shared_ptr(new GeomAPI_Pnt(aResult.X(), aResult.Y(), aResult.Z())); } diff --git a/src/GeomAPI/GeomAPI_Lin.h b/src/GeomAPI/GeomAPI_Lin.h index e8c91e2e4..71048019c 100644 --- a/src/GeomAPI/GeomAPI_Lin.h +++ b/src/GeomAPI/GeomAPI_Lin.h @@ -68,6 +68,10 @@ class GeomAPI_Lin : public GeomAPI_Interface const std::shared_ptr project( const std::shared_ptr& thePoint) const; + /// Returns parameter of the point projection + GEOMAPI_EXPORT + double projParam(const std::shared_ptr& thePoint) const; + /// \return true if this line contains thePoint, that is, /// if the distance between thePoint and this line /// is less than or equal to theLinearTolerance. diff --git a/src/SketcherPrs/SketcherPrs_Perpendicular.cpp b/src/SketcherPrs/SketcherPrs_Perpendicular.cpp index 16b553100..14cef6b26 100644 --- a/src/SketcherPrs/SketcherPrs_Perpendicular.cpp +++ b/src/SketcherPrs/SketcherPrs_Perpendicular.cpp @@ -78,14 +78,28 @@ bool SketcherPrs_Perpendicular::updateIfReadyToDisplay(double theStep, bool with std::shared_ptr aLin2 = aEdge2->line(); std::shared_ptr aPnt = aLin1->intersect(aLin2); + double aParam1 = aLin1->projParam(aPnt); + double aParam2 = aLin2->projParam(aPnt); + + GeomAPI_Curve aCurve1(aShp1); + GeomAPI_Curve aCurve2(aShp2); + bool isInside1 = ((aParam1 - aCurve1.startParam()) >= -Precision::Confusion()) && + ((aCurve1.endParam() - aParam1) >= Precision::Confusion()); + bool isInside2 = ((aParam2 - aCurve2.startParam()) >= -Precision::Confusion()) && + ((aCurve2.endParam() - aParam2) >= Precision::Confusion()); + + if (!(isInside1 && isInside2)) + aPnt = std::shared_ptr(); // Compute position of symbols SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep, aPnt); - //gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep); - myPntArray = new Graphic3d_ArrayOfPoints(1, withColor); + myPntArray = new Graphic3d_ArrayOfPoints(aPnt.get()? 1 : 2, withColor); myPntArray->AddVertex(aP1); - //myPntArray->AddVertex(aP2); + if (!aPnt.get()) { + gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep); + myPntArray->AddVertex(aP2); + } return true; } diff --git a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp index 65b1d0451..43e84107f 100644 --- a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp +++ b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include @@ -324,9 +325,16 @@ std::list getCurves(const GeomPointPtr& thePnt, const SketcherPrs_Sym GeomPnt2dPtr aPnt2 = aSPnt2->pnt(); if (aPnt1->isEqual(aPnt2d) || aPnt2->isEqual(aPnt2d)) { + // a point corresponds to one of the line end GeomShapePtr aShp = SketcherPrs_Tools::getShape(aFeature->firstResult()); GeomCurvePtr aCurv = std::shared_ptr(new GeomAPI_Curve(aShp)); aList.push_back(aFeature->firstResult()); + } else { + // Check that a point belongs to the curve + GeomAPI_Lin2d aLin2d(aPnt1, aPnt2); + double aDist = aLin2d.distance(aPnt2d); + if (aDist <= Precision::Confusion()) + aList.push_back(aFeature->firstResult()); } } else if ((aFeature->getKind() == SketchPlugin_Circle::ID()) || (aFeature->getKind() == SketchPlugin_Arc::ID())) {