mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-05 00:05:57 -05:00
[cad] Fix snapping to line extensions for multi geometry as well as polygons
This commit is contained in:
parent
895193f2dd
commit
e77428eea9
@ -21,6 +21,8 @@
|
|||||||
#include "qgslogger.h"
|
#include "qgslogger.h"
|
||||||
#include "qgssnappingutils.h"
|
#include "qgssnappingutils.h"
|
||||||
#include "qgsgeometryutils.h"
|
#include "qgsgeometryutils.h"
|
||||||
|
#include "qgsgeometrycollection.h"
|
||||||
|
#include "qgscurvepolygon.h"
|
||||||
|
|
||||||
// tolerances for soft constraints (last values, and common angles)
|
// tolerances for soft constraints (last values, and common angles)
|
||||||
// for angles, both tolerance in pixels and degrees are used for better performance
|
// 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
|
// ---- Line Extension Constraint
|
||||||
|
|
||||||
|
QgsPointXY lineExtensionPt1;
|
||||||
|
QgsPointXY lineExtensionPt2;
|
||||||
if ( numberOfHardLock < 2 && ctx.lineExtensionConstraint.locked && ctx.lockedSnapVertices().length() != 0 )
|
if ( numberOfHardLock < 2 && ctx.lineExtensionConstraint.locked && ctx.lockedSnapVertices().length() != 0 )
|
||||||
{
|
{
|
||||||
const QgsPointLocator::Match snap = ctx.lockedSnapVertices().last();
|
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 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 ) );
|
QgsVertexId vertexId;
|
||||||
if ( checked )
|
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 ) );
|
bool checked = checkLineExtension( geom->vertexAt( previousVertexId ) );
|
||||||
if ( checked )
|
if ( checked )
|
||||||
{
|
{
|
||||||
res.softLockLineExtension = Qgis::LineExtensionSide::AfterVertex;
|
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 )
|
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 );
|
const bool intersect = QgsGeometryUtils::lineCircleIntersection( previousPt, ctx.distanceConstraint.value, lineExtensionPt1, lineExtensionPt2, point );
|
||||||
if ( !intersect )
|
if ( !intersect )
|
||||||
{
|
{
|
||||||
|
|||||||
@ -262,16 +262,26 @@ void QgsAdvancedDigitizingCanvasItem::paint( QPainter *painter )
|
|||||||
const QPointF snappedPoint = toCanvasCoordinates( snap.point() );
|
const QPointF snappedPoint = toCanvasCoordinates( snap.point() );
|
||||||
|
|
||||||
const QgsFeature feature = snap.layer()->getFeature( snap.featureId() );
|
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;
|
QgsPoint vertex;
|
||||||
if ( lineExtensionSide == Qgis::LineExtensionSide::BeforeVertex )
|
QgsVertexId vertexId;
|
||||||
|
geometry.vertexIdFromVertexNr( snap.vertexIndex(), vertexId );
|
||||||
|
if ( vertexId.isValid() )
|
||||||
{
|
{
|
||||||
vertex = geom.vertexAt( snap.vertexIndex() - 1 );
|
QgsVertexId previousVertexId;
|
||||||
}
|
QgsVertexId nextVertexId;
|
||||||
else
|
geom->adjacentVertices( vertexId, previousVertexId, nextVertexId );
|
||||||
{
|
|
||||||
vertex = geom.vertexAt( snap.vertexIndex() + 1 );
|
if ( lineExtensionSide == Qgis::LineExtensionSide::BeforeVertex )
|
||||||
|
{
|
||||||
|
vertex = geom->vertexAt( previousVertexId );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vertex = geom->vertexAt( nextVertexId );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !vertex.isEmpty() )
|
if ( !vertex.isEmpty() )
|
||||||
|
|||||||
@ -772,7 +772,6 @@ void QgsAdvancedDigitizingDockWidget::releaseLocks( bool releaseRepeatingLocks )
|
|||||||
mMConstraint->setValue( mCadPointList.constLast().m(), true );
|
mMConstraint->setValue( mCadPointList.constLast().m(), true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user