Skip to content

Commit

Permalink
allow mix digitizing curve and digitizing trace
Browse files Browse the repository at this point in the history
  • Loading branch information
vcloarec committed Jul 29, 2020
1 parent 938c3ff commit 488efcb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
38 changes: 29 additions & 9 deletions src/gui/qgsmaptoolcapture.cpp
Expand Up @@ -171,9 +171,6 @@ QgsPointXY QgsMapToolCapture::tracingStartPoint()

bool QgsMapToolCapture::tracingMouseMove( QgsMapMouseEvent *e )
{
mTempRubberBand->reset( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, QgsWkbTypes::LineString, firstCapturedMapPoint() );
mTempRubberBand->addPoint( lastCapturedMapPoint() );

if ( !e->isSnapped() )
return false;

Expand All @@ -193,6 +190,9 @@ bool QgsMapToolCapture::tracingMouseMove( QgsMapMouseEvent *e )
return false;
}

mTempRubberBand->reset( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, QgsWkbTypes::LineString, firstCapturedMapPoint() );
mTempRubberBand->addPoint( lastCapturedMapPoint() );

// if there is offset, we need to fix the rubber bands to make sure they are aligned correctly.
// There are two cases we need to sort out:
// 1. the last point of mRubberBand may need to be moved off the traced curve to respect the offset
Expand Down Expand Up @@ -373,9 +373,34 @@ void QgsMapToolCapture::cadCanvasMoveEvent( QgsMapMouseEvent *e )
if ( mCaptureMode != CapturePoint && mTempRubberBand && mCapturing )
{
bool hasTrace = false;


if ( tracingEnabled() && mCaptureCurve.numPoints() != 0 )
{
// Store the intermediate point for circular string to retrieve after tracing mouse move if
// the digitizing type is circular and the temp rubber band is effectivly circular and if this point is existing
// Store an empty point if the digitizing type is linear ot the point is not existing (curve not complete)
if ( mDigitizingType == QgsWkbTypes::CircularString &&
mTempRubberBand->stringType() == QgsWkbTypes::CircularString &&
mTempRubberBand->curveIsComplete() )
mCircularItermediatePoint = mTempRubberBand->pointFromEnd( 1 );
else if ( mDigitizingType == QgsWkbTypes::LineString ||
!mTempRubberBand->curveIsComplete() )
mCircularItermediatePoint = QgsPoint();

hasTrace = tracingMouseMove( e );

if ( !hasTrace )
{
// Restore the temp rubber band
mTempRubberBand->reset( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, mDigitizingType, firstCapturedMapPoint() );
mTempRubberBand->addPoint( lastCapturedMapPoint() );
if ( !mCircularItermediatePoint.isEmpty() )
{
mTempRubberBand->movePoint( mCircularItermediatePoint );
mTempRubberBand->addPoint( mCircularItermediatePoint );
}
}
}

if ( !hasTrace )
Expand Down Expand Up @@ -540,8 +565,6 @@ int QgsMapToolCapture::addVertex( const QgsPointXY &point, const QgsPointLocator
bool traceCreated = false;
if ( tracingEnabled() )
{
mDigitizingType = QgsWkbTypes::LineString;
mTempRubberBand->setStringType( QgsWkbTypes::LineString );
traceCreated = tracingAddVertex( mapPoint );
}

Expand Down Expand Up @@ -698,9 +721,6 @@ void QgsMapToolCapture::undo()

updateExtraSnapLayer();

std::cout << "*************************** remaining vertices " << mCaptureCurve.numPoints() << std::endl;
std::cout << "*************************** remaining matches " << mSnappingMatches.count() << std::endl;

resetRubberBand();

mTempRubberBand->reset( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, mDigitizingType, firstCapturedMapPoint() );
Expand Down Expand Up @@ -1018,9 +1038,9 @@ void QgsMapToolCaptureRubberband::reset( QgsWkbTypes::GeometryType geomType, Qgs
if ( !( geomType == QgsWkbTypes::LineGeometry || geomType == QgsWkbTypes::PolygonGeometry ) )
return;

mStringType = stringType;
mPoints.clear();
mFirstPolygonPoint = firstPolygonPoint;
setStringType( stringType );
setRubberBandGeometryType( geomType );
}

Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgsmaptoolcapture.h
Expand Up @@ -404,7 +404,8 @@ class GUI_EXPORT QgsMapToolCapture : public QgsMapToolAdvancedDigitizing
QgsCompoundCurve mCaptureCurve;

QList<QgsPointLocator::Match> mSnappingMatches;
QgsPointLocator::Match mCircularIntermediateMatch = QgsPointLocator::Match();
QgsPointLocator::Match mCircularIntermediateMatch;
QgsPoint mCircularItermediatePoint;

void validateGeometry();
QgsGeometryValidator *mValidator = nullptr;
Expand Down

0 comments on commit 488efcb

Please sign in to comment.