Skip to content

Commit

Permalink
[advanced digitizing] Implement visual construction guides
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed May 28, 2024
1 parent e77428e commit b5f0d09
Show file tree
Hide file tree
Showing 10 changed files with 341 additions and 17 deletions.
1 change: 0 additions & 1 deletion python/PyQt6/core/auto_generated/qgscadutils.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ Returns the recent CAD point at the specified ``index`` (in map coordinates).

.. versionadded:: 3.22
%End

%Property( name = cadPointList, get = _cadPointList, set = _setCadPointList )
void _setCadPointList( const QList< QgsPointXY > &list );
QList< QgsPointXY > _cadPointList() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,36 @@ Sets whether M is enabled

bool constructionMode() const;
%Docstring
construction mode is used to draw intermediate points. These points won't be given any further (i.e. to the map tools)
Returns whether the construction mode is activated. The construction mode is used to draw intermediate
points that will not be part of a geometry being digitized.
%End

QgsVectorLayer *constructionGuidesLayer() const;
%Docstring
Returns the vector layer within which construction guides are stored.

.. versionadded:: 3.38
%End

bool showConstructionGuides() const;
%Docstring
Returns whether the construction guides are visible.

.. versionadded:: 3.38
%End

bool snapToConstructionGuides() const;
%Docstring
Returns whether points should snap to construction guides.

.. versionadded:: 3.38
%End

bool recordConstructionGuides() const;
%Docstring
Returns whether construction guides are being recorded.

.. versionadded:: 3.38
%End

Qgis::BetweenLineConstraint betweenLineConstraint() const;
Expand Down
1 change: 0 additions & 1 deletion python/core/auto_generated/qgscadutils.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ Returns the recent CAD point at the specified ``index`` (in map coordinates).

.. versionadded:: 3.22
%End

%Property( name = cadPointList, get = _cadPointList, set = _setCadPointList )
void _setCadPointList( const QList< QgsPointXY > &list );
QList< QgsPointXY > _cadPointList() const;
Expand Down
31 changes: 30 additions & 1 deletion python/gui/auto_generated/qgsadvanceddigitizingdockwidget.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,36 @@ Sets whether M is enabled

bool constructionMode() const;
%Docstring
construction mode is used to draw intermediate points. These points won't be given any further (i.e. to the map tools)
Returns whether the construction mode is activated. The construction mode is used to draw intermediate
points that will not be part of a geometry being digitized.
%End

QgsVectorLayer *constructionGuidesLayer() const;
%Docstring
Returns the vector layer within which construction guides are stored.

.. versionadded:: 3.38
%End

bool showConstructionGuides() const;
%Docstring
Returns whether the construction guides are visible.

.. versionadded:: 3.38
%End

bool snapToConstructionGuides() const;
%Docstring
Returns whether points should snap to construction guides.

.. versionadded:: 3.38
%End

bool recordConstructionGuides() const;
%Docstring
Returns whether construction guides are being recorded.

.. versionadded:: 3.38
%End

Qgis::BetweenLineConstraint betweenLineConstraint() const;
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgscadutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ QgsCadUtils::AlignMapPointOutput QgsCadUtils::alignMapPoint( const QgsPointXY &o
res.softLockX = std::numeric_limits<double>::quiet_NaN();
res.softLockY = std::numeric_limits<double>::quiet_NaN();

// try to snap to anything
const QgsPointLocator::Match snapMatch = ctx.snappingUtils->snapToMap( originalMapPoint, nullptr, true );
// try to snap to project layer(s) as well as visible construction guides
QgsPointLocator::Match snapMatch = ctx.snappingUtils->snapToMap( originalMapPoint, nullptr, true );
res.snapMatch = snapMatch;
QgsPointXY point = snapMatch.isValid() ? snapMatch.point() : originalMapPoint;
QgsPointXY edgePt0, edgePt1;
Expand Down
1 change: 0 additions & 1 deletion src/core/qgscadutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ class CORE_EXPORT QgsCadUtils
*/
QQueue< QgsPointLocator::Match > lockedSnapVertices() const { return mLockedSnapVertices; } SIP_SKIP;


#ifdef SIP_RUN
SIP_PROPERTY( name = cadPointList, get = _cadPointList, set = _setCadPointList )
#endif
Expand Down
31 changes: 27 additions & 4 deletions src/gui/qgsadvanceddigitizingcanvasitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ QgsAdvancedDigitizingCanvasItem::QgsAdvancedDigitizingCanvasItem( QgsMapCanvas *
, mSnapPen( QPen( QColor( 127, 0, 0, 150 ), 1 ) )
, mSnapLinePen( QPen( QColor( 127, 0, 0, 150 ), 1, Qt::DashLine ) )
, mCursorPen( QPen( QColor( 127, 127, 127, 255 ), 1 ) )
, mConstructionGuidesPen( QPen( QColor( 20, 210, 150 ), 1, Qt::DashLine ) )
, mAdvancedDigitizingDockWidget( cadDockWidget )
{
}
Expand All @@ -37,6 +38,31 @@ void QgsAdvancedDigitizingCanvasItem::paint( QPainter *painter )
if ( !mAdvancedDigitizingDockWidget->cadEnabled() )
return;

painter->setRenderHint( QPainter::Antialiasing );
painter->setCompositionMode( QPainter::CompositionMode_Difference );

// Draw construction guides
if ( mAdvancedDigitizingDockWidget->showConstructionGuides() )
{
if ( QgsVectorLayer *constructionGuidesLayer = mAdvancedDigitizingDockWidget->constructionGuidesLayer() )
{
QgsFeatureIterator it = constructionGuidesLayer->getFeatures( mMapCanvas->mapSettings().visibleExtent() );
QgsFeature feature;
painter->setPen( mConstructionGuidesPen );
while ( it.nextFeature( feature ) )
{
QgsPolylineXY line = feature.geometry().asPolyline();
QPolygonF polygon( line.size() );
for ( int i = 0; i < line.size(); i++ )
{
polygon[i] = toCanvasCoordinates( line[i] );
}

painter->drawPolyline( polygon );
}
}
}

// Use visible polygon rather than extent to properly handle rotated maps
QPolygonF mapPoly = mMapCanvas->mapSettings().visiblePolygon();
const double canvasWidth = QLineF( mapPoly[0], mapPoly[1] ).length();
Expand Down Expand Up @@ -83,9 +109,6 @@ void QgsAdvancedDigitizingCanvasItem::paint( QPainter *painter )
snapSegmentPix2 = toCanvasCoordinates( snappedSegment[1] );
}

painter->setRenderHint( QPainter::Antialiasing );
painter->setCompositionMode( QPainter::CompositionMode_Difference );

// Draw point snap
if ( curPointExist && snappedToVertex )
{
Expand Down Expand Up @@ -226,7 +249,7 @@ void QgsAdvancedDigitizingCanvasItem::paint( QPainter *painter )
}
}

// Draw constr
// Draw constraints
if ( mAdvancedDigitizingDockWidget->betweenLineConstraint() == Qgis::BetweenLineConstraint::NoConstraint )
{
if ( curPointExist && previousPointExist )
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsadvanceddigitizingcanvasitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class GUI_EXPORT QgsAdvancedDigitizingCanvasItem : public QgsMapCanvasItem
QPen mSnapPen;
QPen mSnapLinePen;
QPen mCursorPen;
QPen mConstructionGuidesPen;
QgsAdvancedDigitizingDockWidget *mAdvancedDigitizingDockWidget = nullptr;
};

Expand Down
Loading

0 comments on commit b5f0d09

Please sign in to comment.