Skip to content
Permalink
Browse files

Z value from snapped point is kept

  • Loading branch information
pblottiere committed Feb 16, 2018
1 parent b4be0ce commit 53aafb48030d27036eee0093de0e8541e9e5eb23
@@ -102,14 +102,28 @@ convenient method to clean members

int fetchLayerPoint( const QgsPointLocator::Match &match, QgsPoint &layerPoint );

QgsPoint fromPointXY( const QgsPointXY &point ) const;
QgsPoint mapPoint( const QgsMapMouseEvent &e ) const;
%Docstring
Creates a QgsPoint with ZM support if necessary (according to the
WkbType of the current layer) from a :py:class:`QgsPointXY`.
WkbType of the current layer). If the point is snapped, then the Z
value is took from the snapped point.

:param point: A QgsPointXY to convert
:param e: A mouse event

:return: a point if ZM support if necessary
:return: a point with ZM support if necessary


.. versionadded:: 3.0
%End

QgsPoint mapPoint( const QgsPointXY &point ) const;
%Docstring
Creates a QgsPoint with ZM support if necessary (according to the
WkbType of the current layer).

:param point: A point in 2D

:return: a point with ZM support if necessary


.. versionadded:: 3.0
@@ -68,7 +68,21 @@ void QgsMapToolAddCircle::deactivate()
}

mParentTool->clearCurve();
mParentTool->addCurve( mCircle.toCircularString() );

// keep z value from the first snapped point
std::unique_ptr<QgsCircularString> lineString( mCircle.toCircularString() );
for ( const QgsPoint point : qgis::as_const( mPoints ) )
{
if ( QgsWkbTypes::hasZ( point.wkbType() ) &&
point.z() != defaultZValue() )
{
lineString->dropZValue();
lineString->addZValue( point.z() );
break;
}
}

mParentTool->addCurve( lineString.release() );
clean();

QgsMapToolCapture::deactivate();
@@ -68,7 +68,21 @@ void QgsMapToolAddEllipse::deactivate()
}

mParentTool->clearCurve();
mParentTool->addCurve( mEllipse.toLineString( segments() ) );

// keep z value from the first snapped point
std::unique_ptr<QgsLineString> ls( mEllipse.toLineString( segments() ) );
for ( const QgsPoint point : qgis::as_const( mPoints ) )
{
if ( QgsWkbTypes::hasZ( point.wkbType() ) &&
point.z() != defaultZValue() )
{
ls->dropZValue();
ls->addZValue( point.z() );
break;
}
}

mParentTool->addCurve( ls.release() );
clean();

QgsMapToolCapture::deactivate();
@@ -89,7 +89,7 @@ QgsLineString *QgsMapToolAddRectangle::rectangleToLinestring( const bool isOrien
return ext.release();
}

QgsPoint x0( mRectangle.xMinimum(), mRectangle.yMinimum(), mRectangle.zMinimum() );
QgsPoint x0( mRectangle.xMinimum(), mRectangle.yMinimum() );

QgsPoint x1, x2, x3;
if ( isOriented )
@@ -101,9 +101,9 @@ QgsLineString *QgsMapToolAddRectangle::rectangleToLinestring( const bool isOrien
}
else
{
x1 = QgsPoint( mRectangle.xMinimum(), mRectangle.yMaximum(), mRectangle.zMinimum() );
x2 = QgsPoint( mRectangle.xMaximum(), mRectangle.yMaximum(), mRectangle.zMinimum() );
x3 = QgsPoint( mRectangle.xMaximum(), mRectangle.yMinimum(), mRectangle.zMinimum() );
x1 = QgsPoint( mRectangle.xMinimum(), mRectangle.yMaximum() );
x2 = QgsPoint( mRectangle.xMaximum(), mRectangle.yMaximum() );
x3 = QgsPoint( mRectangle.xMaximum(), mRectangle.yMinimum() );
}

ext->addVertex( x0 );
@@ -112,6 +112,25 @@ QgsLineString *QgsMapToolAddRectangle::rectangleToLinestring( const bool isOrien
ext->addVertex( x3 );
ext->addVertex( x0 );

// keep z value from the first snapped point
for ( const QgsPoint point : qgis::as_const( mPoints ) )
{
if ( QgsWkbTypes::hasZ( point.wkbType() ) )
{
if ( point.z() != defaultZValue() )
{
ext->dropZValue();
ext->addZValue( point.z() );
break;
}
else
{
ext->dropZValue();
ext->addZValue( defaultZValue() );
}
}
}

return ext.release();
}

@@ -87,7 +87,21 @@ void QgsMapToolAddRegularPolygon::deactivate()
return;
}
mParentTool->clearCurve( );
mParentTool->addCurve( mRegularPolygon.toLineString() );

// keep z value from the first snapped point
std::unique_ptr<QgsLineString> ls( mRegularPolygon.toLineString() );
for ( const QgsPoint point : qgis::as_const( mPoints ) )
{
if ( QgsWkbTypes::hasZ( point.wkbType() ) &&
point.z() != defaultZValue() )
{
ls->dropZValue();
ls->addZValue( point.z() );
break;
}
}

mParentTool->addCurve( ls.release() );
clean();

QgsMapToolCapture::deactivate();
@@ -28,11 +28,11 @@ QgsMapToolCircle2Points::QgsMapToolCircle2Points( QgsMapToolCapture *parentTool,

void QgsMapToolCircle2Points::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
{
QgsPoint mapPoint = fromPointXY( e->mapPoint() );
QgsPoint point = mapPoint( *e );

if ( e->button() == Qt::LeftButton )
{
mPoints.append( mapPoint );
mPoints.append( point );

if ( !mPoints.isEmpty() && !mTempRubberBand )
{
@@ -42,6 +42,8 @@ void QgsMapToolCircle2Points::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
}
else if ( e->button() == Qt::RightButton )
{
mPoints.append( point );

deactivate();
if ( mParentTool )
{
@@ -52,10 +54,10 @@ void QgsMapToolCircle2Points::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

void QgsMapToolCircle2Points::cadCanvasMoveEvent( QgsMapMouseEvent *e )
{
QgsPoint mapPoint = fromPointXY( e->mapPoint() );
QgsPoint point = mapPoint( *e );
if ( mTempRubberBand )
{
mCircle = QgsCircle().from2Points( mPoints.at( 0 ), mapPoint );
mCircle = QgsCircle().from2Points( mPoints.at( 0 ), point );
mTempRubberBand->setGeometry( mCircle.toCircularString( true ) );
}
}
@@ -29,12 +29,12 @@ QgsMapToolCircle3Points::QgsMapToolCircle3Points( QgsMapToolCapture *parentTool,

void QgsMapToolCircle3Points::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
{
QgsPoint mapPoint = fromPointXY( e->mapPoint() );
QgsPoint point = mapPoint( *e );

if ( e->button() == Qt::LeftButton )
{
if ( mPoints.size() < 2 )
mPoints.append( mapPoint );
mPoints.append( point );
if ( !mPoints.isEmpty() && !mTempRubberBand )
{
mTempRubberBand = createGeometryRubberBand( ( mode() == CapturePolygon ) ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true );
@@ -53,7 +53,7 @@ void QgsMapToolCircle3Points::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

void QgsMapToolCircle3Points::cadCanvasMoveEvent( QgsMapMouseEvent *e )
{
QgsPoint mapPoint = fromPointXY( e->mapPoint() );
QgsPoint point = mapPoint( *e );

if ( mTempRubberBand )
{
@@ -63,13 +63,13 @@ void QgsMapToolCircle3Points::cadCanvasMoveEvent( QgsMapMouseEvent *e )
{
std::unique_ptr<QgsLineString> line( new QgsLineString() );
line->addVertex( mPoints.at( 0 ) );
line->addVertex( mapPoint );
line->addVertex( point );
mTempRubberBand->setGeometry( line.release() );
}
break;
case 2:
{
mCircle = QgsCircle().from3Points( mPoints.at( 0 ), mPoints.at( 1 ), mapPoint );
mCircle = QgsCircle().from3Points( mPoints.at( 0 ), mPoints.at( 1 ), point );
mTempRubberBand->setGeometry( mCircle.toCircularString( true ) );
}
break;
@@ -32,9 +32,9 @@ QgsMapToolCircle3Tangents::QgsMapToolCircle3Tangents( QgsMapToolCapture *parentT

void QgsMapToolCircle3Tangents::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
{
QgsPoint mapPoint = fromPointXY( e->mapPoint() );
QgsPoint point = mapPoint( *e );
EdgesOnlyFilter filter;
QgsPointLocator::Match match = mCanvas->snappingUtils()->snapToMap( mapPoint, &filter );
QgsPointLocator::Match match = mCanvas->snappingUtils()->snapToMap( point, &filter );

QgsPointXY p1, p2;

@@ -43,17 +43,17 @@ void QgsMapToolCircle3Tangents::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
if ( match.isValid() && ( mPoints.size() <= 2 * 2 ) )
{
match.edgePoints( p1, p2 );
mPoints.append( fromPointXY( p1 ) );
mPoints.append( fromPointXY( p2 ) );
mPoints.append( mapPoint( p1 ) );
mPoints.append( mapPoint( p2 ) );
}
}
else if ( e->button() == Qt::RightButton )
{
if ( match.isValid() && ( mPoints.size() == 4 ) )
{
match.edgePoints( p1, p2 );
mPoints.append( fromPointXY( p1 ) );
mPoints.append( fromPointXY( p2 ) );
mPoints.append( mapPoint( p1 ) );
mPoints.append( mapPoint( p2 ) );
mCircle = QgsCircle().from3Tangents( mPoints.at( 0 ), mPoints.at( 1 ), mPoints.at( 2 ), mPoints.at( 3 ), mPoints.at( 4 ), mPoints.at( 5 ) );
if ( mCircle.isEmpty() )
{
@@ -73,9 +73,9 @@ void QgsMapToolCircle3Tangents::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

void QgsMapToolCircle3Tangents::cadCanvasMoveEvent( QgsMapMouseEvent *e )
{
QgsPoint mapPoint = fromPointXY( e->mapPoint() );
QgsPoint point = mapPoint( *e );
EdgesOnlyFilter filter;
QgsPointLocator::Match match = mCanvas->snappingUtils()->snapToMap( mapPoint, &filter );
QgsPointLocator::Match match = mCanvas->snappingUtils()->snapToMap( point, &filter );

if ( !mTempRubberBand )
{
@@ -94,8 +94,8 @@ void QgsMapToolCircle3Tangents::cadCanvasMoveEvent( QgsMapMouseEvent *e )
match.edgePoints( p1, p2 );
std::unique_ptr<QgsLineString> line( new QgsLineString() );

line->addVertex( fromPointXY( p1 ) );
line->addVertex( fromPointXY( p2 ) );
line->addVertex( mapPoint( p1 ) );
line->addVertex( mapPoint( p2 ) );

mTempRubberBand->setGeometry( line.release() );
mTempRubberBand->show();
@@ -29,11 +29,11 @@ QgsMapToolCircleCenterPoint::QgsMapToolCircleCenterPoint( QgsMapToolCapture *par

void QgsMapToolCircleCenterPoint::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
{
QgsPoint mapPoint = fromPointXY( e->mapPoint() );
QgsPoint point = mapPoint( *e );

if ( e->button() == Qt::LeftButton )
{
mPoints.append( mapPoint );
mPoints.append( point );

if ( !mPoints.isEmpty() && !mTempRubberBand )
{
@@ -44,6 +44,8 @@ void QgsMapToolCircleCenterPoint::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
}
else if ( e->button() == Qt::RightButton )
{
mPoints.append( point );

deactivate();
if ( mParentTool )
{
@@ -54,10 +56,10 @@ void QgsMapToolCircleCenterPoint::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

void QgsMapToolCircleCenterPoint::cadCanvasMoveEvent( QgsMapMouseEvent *e )
{
QgsPoint mapPoint = fromPointXY( e->mapPoint() );
QgsPoint point = mapPoint( *e );
if ( mTempRubberBand )
{
mCircle = QgsCircle().fromCenterPoint( mPoints.at( 0 ), mapPoint );
mCircle = QgsCircle().fromCenterPoint( mPoints.at( 0 ), point );
mTempRubberBand->setGeometry( mCircle.toCircularString( true ) );
}
}
@@ -29,11 +29,11 @@ QgsMapToolCircularStringCurvePoint::QgsMapToolCircularStringCurvePoint( QgsMapTo

void QgsMapToolCircularStringCurvePoint::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
{
QgsPoint mapPoint = fromPointXY( e->mapPoint() );
QgsPoint point = mapPoint( *e );

if ( e->button() == Qt::LeftButton )
{
mPoints.append( mapPoint );
mPoints.append( point );
if ( !mCenterPointRubberBand && mShowCenterPointRubberBand )
{
createCenterPointRubberBand();
@@ -49,7 +49,7 @@ void QgsMapToolCircularStringCurvePoint::cadCanvasReleaseEvent( QgsMapMouseEvent

QgsCircularString *c = new QgsCircularString();
QgsPointSequence rubberBandPoints = mPoints.mid( mPoints.size() - 1 - ( mPoints.size() + 1 ) % 2 );
rubberBandPoints.append( mapPoint );
rubberBandPoints.append( point );
c->setPoints( rubberBandPoints );
mTempRubberBand->setGeometry( c );
}
@@ -63,7 +63,7 @@ void QgsMapToolCircularStringCurvePoint::cadCanvasReleaseEvent( QgsMapMouseEvent

QgsCircularString *c = new QgsCircularString();
QgsPointSequence rubberBandPoints = mPoints;
rubberBandPoints.append( mapPoint );
rubberBandPoints.append( point );
c->setPoints( rubberBandPoints );
mRubberBand->setGeometry( c );
removeCenterPointRubberBand();
@@ -43,26 +43,26 @@ void QgsMapToolCircularStringRadius::deactivate()

void QgsMapToolCircularStringRadius::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
{
QgsPoint mapPoint = fromPointXY( e->mapPoint() );
QgsPoint point = mapPoint( *e );

if ( e->button() == Qt::LeftButton )
{
if ( mPoints.isEmpty() )
{
mPoints.append( mapPoint );
mPoints.append( point );
}
else
{
if ( mPoints.size() % 2 )
{
mTemporaryEndPoint = fromPointXY( mapPoint );
mTemporaryEndPoint = point;

//initial radius is distance( tempPoint - mPoints.last ) / 2.0
double minRadius = std::sqrt( QgsGeometryUtils::sqrDistance2D( mPoints.last(), mTemporaryEndPoint ) ) / 2.0;
mRadius = minRadius + minRadius / 10.0;

QgsPoint result;
if ( QgsGeometryUtils::segmentMidPoint( mPoints.last(), mTemporaryEndPoint, result, mRadius, QgsPoint( mapPoint.x(), mapPoint.y() ) ) )
if ( QgsGeometryUtils::segmentMidPoint( mPoints.last(), mTemporaryEndPoint, result, mRadius, QgsPoint( point.x(), point.y() ) ) )
{
mPoints.append( result );
createRadiusSpinBox();
@@ -136,7 +136,7 @@ void QgsMapToolCircularStringRadius::recalculateTempRubberBand( const QgsPointXY
else
{
rubberBandPoints.append( mPoints.last() );
rubberBandPoints.append( fromPointXY( mousePosition ) );
rubberBandPoints.append( mapPoint( mousePosition ) );
}
QgsCircularString *cString = new QgsCircularString();
cString->setPoints( rubberBandPoints );

0 comments on commit 53aafb4

Please sign in to comment.
You can’t perform that action at this time.