Skip to content

Commit

Permalink
[cad] Implement locked distance logic for 2-circle intersection tool
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jul 31, 2024
1 parent e739843 commit 99c1c1d
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,13 @@ Returns the X value of the X soft lock. The value is NaN is the constraint isn't
double softLockY() const;
%Docstring
Returns the Y value of the Y soft lock. The value is NaN is the constraint isn't magnetized to a line
%End

void toggleConstraintDistance();
%Docstring
Toggles the distance constraint.

.. versionadded:: 3.40
%End

QgsPointLocator::Match mapPointMatch() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ Handles canvas release event.
Requests a new painting event to the advanced digitizing canvas item.
%End

protected:

};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,13 @@ Returns the X value of the X soft lock. The value is NaN is the constraint isn't
double softLockY() const;
%Docstring
Returns the Y value of the Y soft lock. The value is NaN is the constraint isn't magnetized to a line
%End

void toggleConstraintDistance();
%Docstring
Toggles the distance constraint.

.. versionadded:: 3.40
%End

QgsPointLocator::Match mapPointMatch() const;
Expand Down
2 changes: 2 additions & 0 deletions python/gui/auto_generated/qgsadvanceddigitizingtools.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ Handles canvas release event.
Requests a new painting event to the advanced digitizing canvas item.
%End

protected:

};


Expand Down
11 changes: 8 additions & 3 deletions src/gui/qgsadvanceddigitizingdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,13 @@ void QgsAdvancedDigitizingDockWidget::setPoints( const QList<QgsPointXY> &points
}
}

void QgsAdvancedDigitizingDockWidget::toggleConstraintDistance()
{
mDistanceConstraint->toggleLocked();
emit lockDistanceChanged( mDistanceConstraint->isLocked() );
emit pointChangedV2( mCadPointList.value( 0 ) );
}

bool QgsAdvancedDigitizingDockWidget::eventFilter( QObject *obj, QEvent *event )
{
if ( !cadEnabled() )
Expand Down Expand Up @@ -1965,9 +1972,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
{
if ( mCapacities.testFlag( RelativeCoordinates ) && mCapacities.testFlag( Distance ) )
{
mDistanceConstraint->toggleLocked();
emit lockDistanceChanged( mDistanceConstraint->isLocked() );
emit pointChangedV2( mCadPointList.value( 0 ) );
toggleConstraintDistance();
e->accept();
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgsadvanceddigitizingdockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,12 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
//! Returns the Y value of the Y soft lock. The value is NaN is the constraint isn't magnetized to a line
double softLockY() const { return mSoftLockY; }

/**
* Toggles the distance constraint.
* \since QGIS 3.40
*/
void toggleConstraintDistance();

/**
* Returns the point locator match
* \since QGIS 3.4
Expand Down
31 changes: 30 additions & 1 deletion src/gui/qgsadvanceddigitizingtools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,34 @@ QWidget *QgsAdvancedDigitizingCirclesIntersectionTool::createWidget()
connect( mCircle2Y, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, [ = ]( double ) { processParameters(); } );
connect( mCircle2Distance, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, [ = ]( double ) { processParameters(); } );

mCircle1Digitize->setChecked( true );

bool focusOnCircle2 = false;
if ( mCadDockWidget )
{
if ( mCadDockWidget->constraintDistance()->isLocked() )
{
QgsPoint point = mCadDockWidget->previousPointV2();
if ( !point.isEmpty() )
{
whileBlocking( mCircle1Distance )->setValue( mCadDockWidget->constraintDistance()->value() );
whileBlocking( mCircle1X )->setValue( point.x() );
whileBlocking( mCircle1Y )->setValue( point.y() );
mP1 = point;
focusOnCircle2 = true;

mCadDockWidget->toggleConstraintDistance();
}
}
}

if ( focusOnCircle2 )
{
mCircle2Digitize->setChecked( true );
}
else
{
mCircle1Digitize->setChecked( true );
}

mToolWidget = toolWidget;
return toolWidget;
Expand Down Expand Up @@ -187,6 +214,7 @@ void QgsAdvancedDigitizingCirclesIntersectionTool::canvasReleaseEvent( QgsMapMou
mCircle1Y->setValue( event->mapPoint().y() );
mCircle1Digitize->setChecked( false );
mCircle1Distance->setFocus();
mCircle1Distance->selectAll();
event->setAccepted( false );
return;
}
Expand All @@ -196,6 +224,7 @@ void QgsAdvancedDigitizingCirclesIntersectionTool::canvasReleaseEvent( QgsMapMou
mCircle2Y->setValue( event->mapPoint().y() );
mCircle2Digitize->setChecked( false );
mCircle2Distance->setFocus();
mCircle2Distance->selectAll();
event->setAccepted( false );
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsadvanceddigitizingtools.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class GUI_EXPORT QgsAdvancedDigitizingTool : public QObject
*/
void paintRequested();

private:
protected:

QgsMapCanvas *mMapCanvas = nullptr;
QPointer< QgsAdvancedDigitizingDockWidget > mCadDockWidget;
Expand Down

0 comments on commit 99c1c1d

Please sign in to comment.