From e69e9019dfbcbfae796ddec4cd522c5bb5b29fb3 Mon Sep 17 00:00:00 2001 From: Florian Foinant-Willig Date: Sun, 14 May 2023 21:57:23 +0200 Subject: [PATCH] Sketcher: fix Circle to Line distance constraint display --- .../Gui/EditModeConstraintCoinManager.cpp | 25 ++++++------------- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 20 ++++++++++++--- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp index fe46cae776..52296edee8 100644 --- a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp +++ b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp @@ -657,36 +657,27 @@ Restart: pnt1 = geolistfacade.getPoint(Constr->First, Constr->FirstPos); pnt2 = geolistfacade.getPoint(Constr->Second, Constr->SecondPos); } else if (Constr->Second != GeoEnum::GeoUndef) { - pnt1 = geolistfacade.getPoint(Constr->First, Constr->FirstPos); - const Part::Geometry *geo = geolistfacade.getGeometryFromGeoId(Constr->Second); if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + const Part::GeomLineSegment *lineSeg = static_cast(geo); + Base::Vector3d l2p1 = lineSeg->getStartPoint(); + Base::Vector3d l2p2 = lineSeg->getEndPoint(); if (Constr->FirstPos != Sketcher::PointPos::none) { // point to line distance - const Part::GeomLineSegment *lineSeg = static_cast(geo); - Base::Vector3d l2p1 = lineSeg->getStartPoint(); - Base::Vector3d l2p2 = lineSeg->getEndPoint(); + pnt1 = geolistfacade.getPoint(Constr->First, Constr->FirstPos); // calculate the projection of p1 onto line2 pnt2.ProjectToLine(pnt1-l2p1, l2p2-l2p1); pnt2 += pnt1; } else { const Part::Geometry *geo1 = geolistfacade.getGeometryFromGeoId(Constr->First); if (geo1->getTypeId() == Part::GeomCircle::getClassTypeId()) { // circle to line distance - const Part::GeomLineSegment *lineSeg = static_cast(geo); const Part::GeomCircle *circleSeg = static_cast(geo1); Base::Vector3d ct = circleSeg->getCenter(); - Base::Vector3d l2p1 = lineSeg->getStartPoint(); - Base::Vector3d l2p2 = lineSeg->getEndPoint(); double radius = circleSeg->getRadius(); - pnt2.ProjectToLine(ct-l2p1, l2p2-l2p1); //project on the line translated to origin - Base::Vector3d dir = pnt2; + pnt1.ProjectToLine(ct-l2p1, l2p2-l2p1); //project on the line translated to origin + Base::Vector3d dir = pnt1; dir.Normalize(); - pnt1 = ct + dir * radius; - pnt2 += ct; - Base::Vector3d d = l2p2 - l2p1; - double ActDist = std::abs(-ct.x*d.y+ct.y*d.x+l2p1.x*l2p2.y-l2p2.x*l2p1.y) / d.Length() - radius; - if (ActDist < 0) { - std::swap(pnt1, pnt2); - } + pnt1 += ct; + pnt2 = ct + dir * radius; } } diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 67a55fddd9..dd840bd780 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -1391,13 +1391,25 @@ void ViewProviderSketch::moveConstraint(int constNum, const Base::Vector2d &toPo } else if (Constr->Second != GeoEnum::GeoUndef) { p1 = getSolvedSketch().getPoint(Constr->First, Constr->FirstPos); const Part::Geometry *geo = GeoList::getGeometryFromGeoId (geomlist, Constr->Second); - if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { // point to line distance + if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { const Part::GeomLineSegment *lineSeg = static_cast(geo); Base::Vector3d l2p1 = lineSeg->getStartPoint(); Base::Vector3d l2p2 = lineSeg->getEndPoint(); - // calculate the projection of p1 onto line2 - p2.ProjectToLine(p1-l2p1, l2p2-l2p1); - p2 += p1; + if (Constr->FirstPos != Sketcher::PointPos::none) { // point to line distance + // calculate the projection of p1 onto line2 + p2.ProjectToLine(p1-l2p1, l2p2-l2p1); + p2 += p1; + } else { + const Part::Geometry *geo1 = GeoList::getGeometryFromGeoId (geomlist, Constr->First); + const Part::GeomCircle *circleSeg = static_cast(geo1); + Base::Vector3d ct = circleSeg->getCenter(); + double radius = circleSeg->getRadius(); + p1.ProjectToLine(ct-l2p1, l2p2-l2p1); //project on the line translated to origin + Base::Vector3d dir = p1; + dir.Normalize(); + p1 += ct; + p2 = ct + dir * radius; + } } else if (geo->getTypeId() == Part::GeomCircle::getClassTypeId()) { // circle to circle distance const Part::Geometry *geo1 = GeoList::getGeometryFromGeoId (geomlist, Constr->First); if (geo1->getTypeId() == Part::GeomCircle::getClassTypeId()) {