Skip to content
Permalink
Browse files

fix #36585 where snapping on segments with a constraint snapped to ed…

…ges instead of vertices
  • Loading branch information
olivierdalang committed May 21, 2020
1 parent 66ebe34 commit 2942312865beb0ad9915bb0ec5ea8a8242b653d9
Showing with 24 additions and 15 deletions.
  1. +15 −12 src/core/qgscadutils.cpp
  2. +7 −1 src/core/qgscadutils.h
  3. +2 −2 src/gui/qgsadvanceddigitizingdockwidget.cpp
@@ -42,16 +42,19 @@ QgsCadUtils::AlignMapPointOutput QgsCadUtils::alignMapPoint( const QgsPointXY &o

// try to snap to anything
QgsPointLocator::Match snapMatch = ctx.snappingUtils->snapToMap( originalMapPoint, nullptr, true );
res.snapMatch = snapMatch;
QgsPointXY point = snapMatch.isValid() ? snapMatch.point() : originalMapPoint;

// try to snap explicitly to a segment - useful for some constraints
QgsPointXY edgePt0, edgePt1;
EdgesOnlyFilter edgesOnlyFilter;
QgsPointLocator::Match edgeMatch = ctx.snappingUtils->snapToMap( originalMapPoint, &edgesOnlyFilter, true );
if ( edgeMatch.hasEdge() )
edgeMatch.edgePoints( edgePt0, edgePt1 );

res.edgeMatch = edgeMatch;
if ( snapMatch.hasEdge() )
{
snapMatch.edgePoints( edgePt0, edgePt1 );
// note : res.edgeMatch should be removed, as we can just check snapMatch.hasEdge()
res.edgeMatch = snapMatch;
}
else
{
res.edgeMatch = QgsPointLocator::Match();
}

QgsPointXY previousPt, penultimatePt;
if ( ctx.cadPointList.count() >= 2 )
@@ -71,7 +74,7 @@ QgsCadUtils::AlignMapPointOutput QgsCadUtils::alignMapPoint( const QgsPointXY &o
{
point.setX( previousPt.x() + ctx.xConstraint.value );
}
if ( edgeMatch.hasEdge() && !ctx.yConstraint.locked )
if ( snapMatch.hasEdge() && !ctx.yConstraint.locked )
{
// intersect with snapped segment line at X coordinate
const double dx = edgePt1.x() - edgePt0.x();
@@ -99,7 +102,7 @@ QgsCadUtils::AlignMapPointOutput QgsCadUtils::alignMapPoint( const QgsPointXY &o
{
point.setY( previousPt.y() + ctx.yConstraint.value );
}
if ( edgeMatch.hasEdge() && !ctx.xConstraint.locked )
if ( snapMatch.hasEdge() && !ctx.xConstraint.locked )
{
// intersect with snapped segment line at Y coordinate
const double dy = edgePt1.y() - edgePt0.y();
@@ -224,7 +227,7 @@ QgsCadUtils::AlignMapPointOutput QgsCadUtils::alignMapPoint( const QgsPointXY &o
point.setY( previousPt.y() + sina * v );
}

if ( edgeMatch.hasEdge() && !ctx.distanceConstraint.locked )
if ( snapMatch.hasEdge() && !ctx.distanceConstraint.locked )
{
// magnetize to the intersection of the snapped segment and the lockedAngle

@@ -287,7 +290,7 @@ QgsCadUtils::AlignMapPointOutput QgsCadUtils::alignMapPoint( const QgsPointXY &o
previousPt.y() + ( point.y() - previousPt.y() ) * vP );
}

if ( edgeMatch.hasEdge() && !ctx.angleConstraint.locked )
if ( snapMatch.hasEdge() && !ctx.angleConstraint.locked )
{
// we will magnietize to the intersection of that segment and the lockedDistance !
res.valid &= QgsGeometryUtils::lineCircleIntersection( previousPt, ctx.distanceConstraint.value, edgePt0, edgePt1, point );
@@ -92,7 +92,13 @@ class CORE_EXPORT QgsCadUtils
//! map point aligned according to the constraints
QgsPointXY finalMapPoint;

//! Snapped segment - only valid if actually used for something
//! Snapped point - only valid if actually used for something
QgsPointLocator::Match snapMatch;

/**
* Snapped segment - only valid if actually used for something
* \deprecated will be removed in QGIS 4.0 - use snapMatch instead
*/
QgsPointLocator::Match edgeMatch;

//! Angle (in degrees) to which we have soft-locked ourselves (if not set it is -1)
@@ -648,10 +648,10 @@ bool QgsAdvancedDigitizingDockWidget::applyConstraints( QgsMapMouseEvent *e )
bool res = output.valid;
QgsPointXY point = output.finalMapPoint;
mSnappedSegment.clear();
if ( output.edgeMatch.hasEdge() )
if ( output.snapMatch.hasEdge() )
{
QgsPointXY edgePt0, edgePt1;
output.edgeMatch.edgePoints( edgePt0, edgePt1 );
output.snapMatch.edgePoints( edgePt0, edgePt1 );
mSnappedSegment << edgePt0 << edgePt1;
}
if ( mAngleConstraint->lockMode() != CadConstraint::HardLock )

0 comments on commit 2942312

Please sign in to comment.
You can’t perform that action at this time.