diff --git a/src/core/qgscadutils.cpp b/src/core/qgscadutils.cpp index a8ada491a61..de2f2a2a33c 100644 --- a/src/core/qgscadutils.cpp +++ b/src/core/qgscadutils.cpp @@ -21,6 +21,8 @@ #include "qgslogger.h" #include "qgssnappingutils.h" #include "qgsgeometryutils.h" +#include "qgsgeometrycollection.h" +#include "qgscurvepolygon.h" // tolerances for soft constraints (last values, and common angles) // for angles, both tolerance in pixels and degrees are used for better performance @@ -302,6 +304,8 @@ QgsCadUtils::AlignMapPointOutput QgsCadUtils::alignMapPoint( const QgsPointXY &o // ***************************** // ---- Line Extension Constraint + QgsPointXY lineExtensionPt1; + QgsPointXY lineExtensionPt2; if ( numberOfHardLock < 2 && ctx.lineExtensionConstraint.locked && ctx.lockedSnapVertices().length() != 0 ) { const QgsPointLocator::Match snap = ctx.lockedSnapVertices().last(); @@ -380,18 +384,32 @@ QgsCadUtils::AlignMapPointOutput QgsCadUtils::alignMapPoint( const QgsPointXY &o }; const QgsFeature feature = snap.layer()->getFeature( snap.featureId() ); - const QgsGeometry geom = feature.geometry(); + const QgsGeometry geometry = feature.geometry(); + const QgsAbstractGeometry *geom = geometry.constGet(); - bool checked = checkLineExtension( geom.vertexAt( snap.vertexIndex() - 1 ) ); - if ( checked ) + QgsVertexId vertexId; + geometry.vertexIdFromVertexNr( snap.vertexIndex(), vertexId ); + if ( vertexId.isValid() ) { - res.softLockLineExtension = Qgis::LineExtensionSide::BeforeVertex; - } + QgsVertexId previousVertexId; + QgsVertexId nextVertexId; + geom->adjacentVertices( vertexId, previousVertexId, nextVertexId ); - checked = checkLineExtension( geom.vertexAt( snap.vertexIndex() + 1 ) ); - if ( checked ) - { - res.softLockLineExtension = Qgis::LineExtensionSide::AfterVertex; + bool checked = checkLineExtension( geom->vertexAt( previousVertexId ) ); + if ( checked ) + { + res.softLockLineExtension = Qgis::LineExtensionSide::BeforeVertex; + lineExtensionPt1 = snap.point(); + lineExtensionPt2 = QgsPointXY( geom->vertexAt( previousVertexId ) ); + } + + checked = checkLineExtension( geom->vertexAt( nextVertexId ) ); + if ( checked ) + { + res.softLockLineExtension = Qgis::LineExtensionSide::AfterVertex; + lineExtensionPt1 = snap.point(); + lineExtensionPt2 = QgsPointXY( geom->vertexAt( nextVertexId ) ); + } } } } @@ -440,23 +458,6 @@ QgsCadUtils::AlignMapPointOutput QgsCadUtils::alignMapPoint( const QgsPointXY &o } else if ( res.softLockLineExtension != Qgis::LineExtensionSide::NoVertex ) { - const QgsPointLocator::Match snap = ctx.lockedSnapVertices().last(); - const QgsFeature feature = snap.layer()->getFeature( snap.featureId() ); - const QgsGeometry geom = feature.geometry(); - - - const QgsPointXY lineExtensionPt1 = snap.point(); - - QgsPointXY lineExtensionPt2; - if ( res.softLockLineExtension == Qgis::LineExtensionSide::AfterVertex ) - { - lineExtensionPt2 = QgsPointXY( geom.vertexAt( snap.vertexIndex() + 1 ) ); - } - else - { - lineExtensionPt2 = QgsPointXY( geom.vertexAt( snap.vertexIndex() - 1 ) ); - } - const bool intersect = QgsGeometryUtils::lineCircleIntersection( previousPt, ctx.distanceConstraint.value, lineExtensionPt1, lineExtensionPt2, point ); if ( !intersect ) { diff --git a/src/gui/qgsadvanceddigitizingcanvasitem.cpp b/src/gui/qgsadvanceddigitizingcanvasitem.cpp index c7534f2aa35..fc68b3d9f59 100644 --- a/src/gui/qgsadvanceddigitizingcanvasitem.cpp +++ b/src/gui/qgsadvanceddigitizingcanvasitem.cpp @@ -262,16 +262,26 @@ void QgsAdvancedDigitizingCanvasItem::paint( QPainter *painter ) const QPointF snappedPoint = toCanvasCoordinates( snap.point() ); const QgsFeature feature = snap.layer()->getFeature( snap.featureId() ); - const QgsGeometry geom = feature.geometry(); + const QgsGeometry geometry = feature.geometry(); + const QgsAbstractGeometry *geom = geometry.constGet(); QgsPoint vertex; - if ( lineExtensionSide == Qgis::LineExtensionSide::BeforeVertex ) + QgsVertexId vertexId; + geometry.vertexIdFromVertexNr( snap.vertexIndex(), vertexId ); + if ( vertexId.isValid() ) { - vertex = geom.vertexAt( snap.vertexIndex() - 1 ); - } - else - { - vertex = geom.vertexAt( snap.vertexIndex() + 1 ); + QgsVertexId previousVertexId; + QgsVertexId nextVertexId; + geom->adjacentVertices( vertexId, previousVertexId, nextVertexId ); + + if ( lineExtensionSide == Qgis::LineExtensionSide::BeforeVertex ) + { + vertex = geom->vertexAt( previousVertexId ); + } + else + { + vertex = geom->vertexAt( nextVertexId ); + } } if ( !vertex.isEmpty() ) diff --git a/src/gui/qgsadvanceddigitizingdockwidget.cpp b/src/gui/qgsadvanceddigitizingdockwidget.cpp index 3cc73d3ceaf..741448e2fdf 100644 --- a/src/gui/qgsadvanceddigitizingdockwidget.cpp +++ b/src/gui/qgsadvanceddigitizingdockwidget.cpp @@ -772,7 +772,6 @@ void QgsAdvancedDigitizingDockWidget::releaseLocks( bool releaseRepeatingLocks ) mMConstraint->setValue( mCadPointList.constLast().m(), true ); } } - } #if 0