Skip to content
Permalink
Browse files

Add Z support for AddCircle map tools

  • Loading branch information
pblottiere committed Feb 16, 2018
1 parent 7a698f2 commit 4e7291783fe3c97273e1ecfb2848ddb8abe4e589
@@ -28,7 +28,7 @@ QgsMapToolCircle2Points::QgsMapToolCircle2Points( QgsMapToolCapture *parentTool,

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

if ( e->button() == Qt::LeftButton )
{
@@ -52,7 +52,7 @@ void QgsMapToolCircle2Points::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

void QgsMapToolCircle2Points::cadCanvasMoveEvent( QgsMapMouseEvent *e )
{
QgsPoint mapPoint( e->mapPoint() );
QgsPoint mapPoint = pointFromPointXY( e->mapPoint() );
if ( mTempRubberBand )
{
mCircle = QgsCircle().from2Points( mPoints.at( 0 ), mapPoint );
@@ -43,7 +43,7 @@ QgsMapToolCircle2TangentsPoint::~QgsMapToolCircle2TangentsPoint()
void QgsMapToolCircle2TangentsPoint::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
{

QgsPoint mapPoint( e->mapPoint() );
QgsPoint mapPoint = pointFromPointXY( e->mapPoint() );
EdgesOnlyFilter filter;
QgsPointLocator::Match match = mCanvas->snappingUtils()->snapToMap( mapPoint, &filter );

@@ -56,8 +56,8 @@ void QgsMapToolCircle2TangentsPoint::cadCanvasReleaseEvent( QgsMapMouseEvent *e
if ( match.isValid() )
{
match.edgePoints( p1, p2 );
mPoints.append( QgsPoint( p1 ) );
mPoints.append( QgsPoint( p2 ) );
mPoints.append( pointFromPointXY( p1 ) );
mPoints.append( pointFromPointXY( p2 ) );
}
}
if ( mPoints.size() == 4 )
@@ -100,7 +100,7 @@ void QgsMapToolCircle2TangentsPoint::cadCanvasReleaseEvent( QgsMapMouseEvent *e

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

@@ -123,8 +123,8 @@ void QgsMapToolCircle2TangentsPoint::cadCanvasMoveEvent( QgsMapMouseEvent *e )
match.edgePoints( p1, p2 );
std::unique_ptr<QgsLineString> line( new QgsLineString() );

line->addVertex( QgsPoint( p1 ) );
line->addVertex( QgsPoint( p2 ) );
line->addVertex( pointFromPointXY( p1 ) );
line->addVertex( pointFromPointXY( p2 ) );

mTempRubberBand->setGeometry( line.release() );
mTempRubberBand->show();
@@ -49,7 +49,7 @@ class QgsMapToolCircle2TangentsPoint: public QgsMapToolAddCircle
QSpinBox *mRadiusSpinBox = nullptr;

int mRadius = 0;
QVector<QgsPointXY> mCenters;
QVector<QgsPoint> mCenters;
QVector<QgsGeometryRubberBand *> mRubberBands;
};

@@ -29,7 +29,7 @@ QgsMapToolCircle3Points::QgsMapToolCircle3Points( QgsMapToolCapture *parentTool,

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

if ( e->button() == Qt::LeftButton )
{
@@ -53,7 +53,7 @@ void QgsMapToolCircle3Points::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

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

if ( mTempRubberBand )
{
@@ -32,7 +32,7 @@ QgsMapToolCircle3Tangents::QgsMapToolCircle3Tangents( QgsMapToolCapture *parentT

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

@@ -43,17 +43,17 @@ void QgsMapToolCircle3Tangents::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
if ( match.isValid() && ( mPoints.size() <= 2 * 2 ) )
{
match.edgePoints( p1, p2 );
mPoints.append( QgsPoint( p1 ) );
mPoints.append( QgsPoint( p2 ) );
mPoints.append( pointFromPointXY( p1 ) );
mPoints.append( pointFromPointXY( p2 ) );
}
}
else if ( e->button() == Qt::RightButton )
{
if ( match.isValid() && ( mPoints.size() == 4 ) )
{
match.edgePoints( p1, p2 );
mPoints.append( QgsPoint( p1 ) );
mPoints.append( QgsPoint( p2 ) );
mPoints.append( pointFromPointXY( p1 ) );
mPoints.append( pointFromPointXY( 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,7 +73,7 @@ void QgsMapToolCircle3Tangents::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

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

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

line->addVertex( QgsPoint( p1 ) );
line->addVertex( QgsPoint( p2 ) );
line->addVertex( pointFromPointXY( p1 ) );
line->addVertex( pointFromPointXY( p2 ) );

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

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

if ( e->button() == Qt::LeftButton )
{
@@ -54,7 +54,7 @@ void QgsMapToolCircleCenterPoint::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

void QgsMapToolCircleCenterPoint::cadCanvasMoveEvent( QgsMapMouseEvent *e )
{
QgsPoint mapPoint( e->mapPoint() );
QgsPoint mapPoint = pointFromPointXY( e->mapPoint() );
if ( mTempRubberBand )
{
mCircle = QgsCircle().fromCenterPoint( mPoints.at( 0 ), mapPoint );
@@ -138,6 +138,27 @@ QgsCircle QgsCircle::from3Points( const QgsPoint &pt1, const QgsPoint &pt2, cons
double aSlope = yDelta_a / xDelta_a;
double bSlope = yDelta_b / xDelta_b;

// set z cooridnate for center
double z = std::numeric_limits<double>::quiet_NaN();
if ( p1.is3D() )
{
z = p1.z();
}
else if ( p2.is3D() )
{
z = p2.z();
}
else if ( p3.is3D() )
{
z = p3.z();
}

if ( ! std::isnan( z ) )
{
center.convertTo( QgsWkbTypes::addZ( center.wkbType() ) );
center.setZ( z );
}

if ( ( std::fabs( xDelta_a ) <= epsilon ) && ( std::fabs( yDelta_b ) <= epsilon ) )
{
center.setX( 0.5 * ( p2.x() + p3.x() ) );
@@ -249,10 +270,10 @@ void QgsCircle::setSemiMinorAxis( const double semiMinorAxis )
QVector<QgsPoint> QgsCircle::northQuadrant() const
{
QVector<QgsPoint> quad;
quad.append( QgsPoint( mCenter.x(), mCenter.y() + mSemiMajorAxis ) );
quad.append( QgsPoint( mCenter.x() + mSemiMajorAxis, mCenter.y() ) );
quad.append( QgsPoint( mCenter.x(), mCenter.y() - mSemiMajorAxis ) );
quad.append( QgsPoint( mCenter.x() - mSemiMajorAxis, mCenter.y() ) );
quad.append( QgsPoint( mCenter.x(), mCenter.y() + mSemiMajorAxis, mCenter.z() ) );
quad.append( QgsPoint( mCenter.x() + mSemiMajorAxis, mCenter.y(), mCenter.z() ) );
quad.append( QgsPoint( mCenter.x(), mCenter.y() - mSemiMajorAxis, mCenter.z() ) );
quad.append( QgsPoint( mCenter.x() - mSemiMajorAxis, mCenter.y(), mCenter.z() ) );

return quad;
}
@@ -248,6 +248,24 @@ bool QgsGeometryUtils::lineIntersection( const QgsPoint &p1, QgsVector v1, const

intersection = QgsPoint( p1.x() + v1.x() * k, p1.y() + v1.y() * k );

// z support for inter point
double z = std::numeric_limits<double>::quiet_NaN();
if ( p1.is3D() )
{
z = p1.z();
}
else if ( q1.is3D() )
{
z = q1.z();
}

if ( ! std::isnan( z ) )
{
inter.convertTo( QgsWkbTypes::addZ( inter.wkbType() ) );
inter.setZ( z );
}


return true;
}

@@ -606,20 +624,25 @@ bool QgsGeometryUtils::segmentMidPoint( const QgsPoint &p1, const QgsPoint &p2,
result = possibleMidPoints.at( minDistIndex );

// add z support if necessary
double z = std::numeric_limits<double>::quiet_NaN();

if ( p1.is3D() && p2.is3D() )
{
result.convertTo( p1.wkbType() );
result.setZ( ( p1.z() + p2.z() ) / 2. );
z = ( p1.z() + p2.z() ) / 2.;
}
else if ( p1.is3D() && !p2.is3D() )
{
result.convertTo( p1.wkbType() );
result.setZ( p1.z() );
z = p1.z();
}
else if ( !p1.is3D() && p2.is3D() )
{
result.convertTo( p2.wkbType() );
result.setZ( p2.z() );
z = p2.z();
}

if ( ! std::isnan( z ) )
{
result.convertTo( QgsWkbTypes::addZ( result.wkbType() ) );
result.setZ( z );
}

return true;
@@ -574,7 +574,28 @@ QgsPoint QgsTriangle::inscribedCenter() const
l.at( 1 ) * vertexAt( 0 ).y() +
l.at( 2 ) * vertexAt( 1 ).y() ) / perimeter();

return QgsPoint( x, y );
double z = std::numeric_limits<double>::quiet_NaN();
if ( vertexAt( 0 ).is3D() )
{
z = vertexAt( 0 ).z();
}
else if ( vertexAt( 1 ).is3D() )
{
z = vertexAt( 1 ).z();
}
else if ( vertexAt( 2 ).is3D() )
{
z = vertexAt( 2 ).z();
}

QgsPoint center( x, y );
if ( !std::isnan( z ) )
{
center.convertTo( QgsWkbTypes::PointZ );
center.setZ( z );
}

return center;
}

double QgsTriangle::inscribedRadius() const
@@ -590,6 +611,3 @@ QgsCircle QgsTriangle::inscribedCircle() const
return QgsCircle();
return QgsCircle( inscribedCenter(), inscribedRadius() );
}



0 comments on commit 4e72917

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