Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add flag for common angle/feature snapping priority
The flag allows to ignore common angle snapping when
there is a feature snapping match

Fixes #52333
  • Loading branch information
elpaso authored and nyalldawson committed May 25, 2023
1 parent caadb7d commit b14482f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
2 changes: 2 additions & 0 deletions python/core/auto_generated/qgscadutils.sip.in
Expand Up @@ -102,6 +102,8 @@ Defines constraints for the :py:func:`QgsCadUtils.alignMapPoint()` method.
QgsCadUtils::AlignMapPointConstraint lineExtensionConstraint;
QgsCadUtils::AlignMapPointConstraint xyVertexConstraint;

bool snappingToFeaturesOverridesCommonAngle;


QList< QgsPoint > cadPoints() const;
%Docstring
Expand Down
5 changes: 4 additions & 1 deletion src/core/qgscadutils.cpp
Expand Up @@ -162,7 +162,10 @@ QgsCadUtils::AlignMapPointOutput QgsCadUtils::alignMapPoint( const QgsPointXY &o

// *****************************
// ---- Common Angle constraint
if ( numberOfHardLock < 2 && !ctx.angleConstraint.locked && ctx.cadPoints().count() >= 2 && ctx.commonAngleConstraint.locked && ctx.commonAngleConstraint.value != 0 )
if ( numberOfHardLock < 2 && !ctx.angleConstraint.locked && ctx.cadPoints().count() >= 2 && ctx.commonAngleConstraint.locked && ctx.commonAngleConstraint.value != 0
// Skip common angle constraint if the snapping to features has priority
&& ( ! snapMatch.isValid() || ! ctx.snappingToFeaturesOverridesCommonAngle )
)
{
const double commonAngle = ctx.commonAngleConstraint.value * M_PI / 180;
// see if soft common angle constraint should be performed
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgscadutils.h
Expand Up @@ -134,6 +134,12 @@ class CORE_EXPORT QgsCadUtils
QgsCadUtils::AlignMapPointConstraint lineExtensionConstraint;
QgsCadUtils::AlignMapPointConstraint xyVertexConstraint;

/**
* Flag to set snapping to features priority over common angle.
* \since QGIS 3.32
*/
bool snappingToFeaturesOverridesCommonAngle = false;

/**
* Dumps the context's properties, for debugging.
* \note Not available in Python bindings.
Expand Down
17 changes: 16 additions & 1 deletion src/gui/qgsadvanceddigitizingdockwidget.cpp
Expand Up @@ -36,7 +36,6 @@
#include "qgsmapmouseevent.h"
#include "qgsmeshlayer.h"
#include "qgsunittypes.h"
#include "qgslocaldefaultsettings.h"

#include <QActionGroup>

Expand Down Expand Up @@ -144,6 +143,21 @@ QgsAdvancedDigitizingDockWidget::QgsAdvancedDigitizingDockWidget( QgsMapCanvas *
{
commonAngles << QPair<double, QString>( *it, formatCommonAngleSnapping( *it ) );
}

{
QAction *action = new QAction( tr( "Snapping to features has priority over common angles" ), mCommonAngleActionsMenu );
action->setCheckable( true );
mCommonAngleActionsMenu->addAction( action );
connect( action, &QAction::changed, this, [ = ]
{
mSnappingToFeaturesOverridesCommonAngle = action->isChecked();
QgsSettings().setValue( QStringLiteral( "/Cad/SnappingToFeaturesOverridesCommonAngle" ), action->isChecked() );
} );
action->setChecked( QgsSettings().value( QStringLiteral( "/Cad/SnappingToFeaturesOverridesCommonAngle" ), false ).toBool() );
}

mCommonAngleActionsMenu->addSeparator();

for ( QList< QPair<double, QString > >::const_iterator it = commonAngles.constBegin(); it != commonAngles.constEnd(); ++it )
{
QAction *action = new QAction( it->second, mCommonAngleActionsMenu );
Expand Down Expand Up @@ -1181,6 +1195,7 @@ bool QgsAdvancedDigitizingDockWidget::applyConstraints( QgsMapMouseEvent *e )
context.mConstraint = _constraint( mMConstraint.get() );
context.distanceConstraint = _constraint( mDistanceConstraint.get() );
context.angleConstraint = _constraint( mAngleConstraint.get() );
context.snappingToFeaturesOverridesCommonAngle = mSnappingToFeaturesOverridesCommonAngle;

context.lineExtensionConstraint = _constraint( mLineExtensionConstraint.get() );
context.xyVertexConstraint = _constraint( mXyVertexConstraint.get() );
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsadvanceddigitizingdockwidget.h
Expand Up @@ -1051,6 +1051,9 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
Qgis::BetweenLineConstraint mBetweenLineConstraint;
double mCommonAngleConstraint; // if 0: do not snap to common angles

//! Flag that controls whether snapping to features has priority over common angle
bool mSnappingToFeaturesOverridesCommonAngle = false;

// point list and current snap point / segment
QList<QgsPoint> mCadPointList;
QList<QgsPointXY> mSnappedSegment;
Expand Down

0 comments on commit b14482f

Please sign in to comment.