Skip to content
Permalink
Browse files

Add Z support for AddRectangle map tools

  • Loading branch information
pblottiere committed Feb 16, 2018
1 parent 79cdaa6 commit 4c6d03cac63b626cafad42113f9d3f707906a971
@@ -84,12 +84,12 @@ void QgsMapToolAddRectangle::keyReleaseEvent( QKeyEvent *e )
QgsLineString *QgsMapToolAddRectangle::rectangleToLinestring( const bool isOriented ) const
{
std::unique_ptr<QgsLineString> ext( new QgsLineString() );
if ( mRectangle.isEmpty() )
if ( mRectangle.toRectangle().isEmpty() )
{
return ext.release();
}

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

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

ext->addVertex( x0 );
ext->addVertex( x1 );
ext->addVertex( x2 );
@@ -117,7 +118,7 @@ QgsLineString *QgsMapToolAddRectangle::rectangleToLinestring( const bool isOrien
QgsPolygon *QgsMapToolAddRectangle::rectangleToPolygon( const bool isOriented ) const
{
std::unique_ptr<QgsPolygon> polygon( new QgsPolygon() );
if ( mRectangle.isEmpty() )
if ( mRectangle.toRectangle().isEmpty() )
{
return polygon.release();
}
@@ -129,7 +130,7 @@ QgsPolygon *QgsMapToolAddRectangle::rectangleToPolygon( const bool isOriented )

void QgsMapToolAddRectangle::deactivate( const bool isOriented )
{
if ( !mParentTool || mRectangle.isEmpty() )
if ( !mParentTool || mRectangle.toRectangle().isEmpty() )
{
return;
}
@@ -162,5 +163,5 @@ void QgsMapToolAddRectangle::clean()
mParentTool->deleteTempRubberBand();
}

mRectangle = QgsRectangle();
mRectangle = QgsBox3d();
}
@@ -17,8 +17,8 @@
#define QGSMAPTOOLADDRECTANGLE_H

#include "qgspolygon.h"
#include "qgsrectangle.h"
#include "qgsmaptoolcapture.h"
#include "qgsbox3d.h"

class QgsPolygon;

@@ -51,7 +51,7 @@ class QgsMapToolAddRectangle: public QgsMapToolCapture
//! The rubberband to show the rectangle currently working on
QgsGeometryRubberBand *mTempRubberBand = nullptr;
//! Rectangle
QgsRectangle mRectangle;
QgsBox3d mRectangle;

//! Convenient method to export a QgsRectangle to a LineString
QgsLineString *rectangleToLinestring( const bool isOriented = false ) const;
@@ -31,7 +31,7 @@ QgsMapToolRectangle3Points::QgsMapToolRectangle3Points( QgsMapToolCapture *paren

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

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

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

if ( mTempRubberBand )
{
@@ -82,14 +82,15 @@ void QgsMapToolRectangle3Points::cadCanvasMoveEvent( QgsMapMouseEvent *e )

setSide( side < 0 ? -1 : 1 );

double xMin = mPoints.at( 0 ).x();
double xMax = mPoints.at( 0 ).x() + distance2( );
const double xMin = mPoints.at( 0 ).x();
const double xMax = mPoints.at( 0 ).x() + distance2( );

double yMin = mPoints.at( 0 ).y();
double yMax = mPoints.at( 0 ).y() + distance1();
const double yMin = mPoints.at( 0 ).y();
const double yMax = mPoints.at( 0 ).y() + distance1();

mRectangle = QgsRectangle( xMin, yMin,
xMax, yMax );
const double z = mPoints.at( 0 ).z();

mRectangle = QgsBox3d( xMin, yMin, z, xMax, yMax, z );


mTempRubberBand->setGeometry( QgsMapToolAddRectangle::rectangleToPolygon( true ) );
@@ -31,7 +31,7 @@ QgsMapToolRectangleCenter::QgsMapToolRectangleCenter( QgsMapToolCapture *parentT

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

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

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

if ( mTempRubberBand )
{
@@ -68,7 +68,7 @@ void QgsMapToolRectangleCenter::cadCanvasMoveEvent( QgsMapMouseEvent *e )
double xOffset = fabs( mapPoint.x() - mPoints.at( 0 ).x() );
double yOffset = fabs( mapPoint.y() - mPoints.at( 0 ).y() );

mRectangle = QgsRectangle( QgsPoint( mPoints.at( 0 ).x() - xOffset, mPoints.at( 0 ).y() - yOffset ), QgsPoint( mPoints.at( 0 ).x() + xOffset, mPoints.at( 0 ).y() + yOffset ) );
mRectangle = QgsBox3d( QgsPoint( mPoints.at( 0 ).x() - xOffset, mPoints.at( 0 ).y() - yOffset, mPoints.at( 0 ).z() ), QgsPoint( mPoints.at( 0 ).x() + xOffset, mPoints.at( 0 ).y() + yOffset, mPoints.at( 0 ).z() ) );

mTempRubberBand->setGeometry( QgsMapToolAddRectangle::rectangleToPolygon() );
}
@@ -77,7 +77,7 @@ void QgsMapToolRectangleCenter::cadCanvasMoveEvent( QgsMapMouseEvent *e )
double dist = mPoints.at( 0 ).distance( mapPoint );
double angle = mPoints.at( 0 ).azimuth( mapPoint );

mRectangle = QgsRectangle( mPoints.at( 0 ).project( -dist, angle ), mPoints.at( 0 ).project( dist, angle ) );
mRectangle = QgsBox3d( mPoints.at( 0 ).project( -dist, angle ), mPoints.at( 0 ).project( dist, angle ) );
mTempRubberBand->setGeometry( QgsMapToolAddRectangle::rectangleToPolygon() );
}
}
@@ -31,7 +31,7 @@ QgsMapToolRectangleExtent::QgsMapToolRectangleExtent( QgsMapToolCapture *parentT

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

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

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

if ( mTempRubberBand )
{
@@ -65,15 +65,15 @@ void QgsMapToolRectangleExtent::cadCanvasMoveEvent( QgsMapMouseEvent *e )
{
if ( qgsDoubleNear( mCanvas->rotation(), 0.0 ) )
{
mRectangle = QgsRectangle( mPoints.at( 0 ), mapPoint );
mRectangle = QgsBox3d( mPoints.at( 0 ), mapPoint );
mTempRubberBand->setGeometry( QgsMapToolAddRectangle::rectangleToPolygon( ) );
}
else
{
double dist = mPoints.at( 0 ).distance( mapPoint );
double angle = mPoints.at( 0 ).azimuth( mapPoint );

mRectangle = QgsRectangle( mPoints.at( 0 ), mPoints.at( 0 ).project( dist, angle ) );
mRectangle = QgsBox3d( mPoints.at( 0 ), mPoints.at( 0 ).project( dist, angle ) );
mTempRubberBand->setGeometry( QgsMapToolAddRectangle::rectangleToPolygon() );
}
}

0 comments on commit 4c6d03c

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