Skip to content

Commit

Permalink
Merge pull request #57584 from nirvn/cad_construction_guides
Browse files Browse the repository at this point in the history
[advanced digitizing] Implement visual construction guides
  • Loading branch information
nirvn committed Jun 25, 2024
2 parents 02aa7af + 35784b2 commit 2fb1de2
Show file tree
Hide file tree
Showing 11 changed files with 388 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.40
%End

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

.. versionadded:: 3.40
%End

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

.. versionadded:: 3.40
%End

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

.. versionadded:: 3.40
%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.40
%End

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

.. versionadded:: 3.40
%End

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

.. versionadded:: 3.40
%End

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

.. versionadded:: 3.40
%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
27 changes: 23 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,27 @@ 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( QgsFeatureRequest().setNoAttributes().setFilterRect( mMapCanvas->mapSettings().visibleExtent() ) );
QgsFeature feature;
painter->setPen( mConstructionGuidesPen );
while ( it.nextFeature( feature ) )
{
QgsGeometry geom = feature.geometry();
geom.mapToPixel( *mMapCanvas->getCoordinateTransform() );
const QPolygonF polygon = geom.asQPolygonF();
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 +105,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 +245,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 2fb1de2

Please sign in to comment.