Skip to content

Commit

Permalink
Add map tool rectangle 3 points where 3rd point is projected on segme…
Browse files Browse the repository at this point in the history
…nt p1-p2
  • Loading branch information
lbartoletti committed Nov 13, 2018
1 parent 7cce9b3 commit d40f884
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 76 deletions.
3 changes: 2 additions & 1 deletion images/images.qrc
Expand Up @@ -671,7 +671,8 @@
<file>themes/default/mActionEllipseCenterPoint.svg</file>
<file>themes/default/mActionEllipseExtent.svg</file>
<file>themes/default/mActionRectangleExtent.svg</file>
<file>themes/default/mActionRectangle3Points.svg</file>
<file>themes/default/mActionRectangle3PointsDistance.svg</file>
<file>themes/default/mActionRectangle3PointsProjected.svg</file>
<file>themes/default/mActionRectangleCenter.svg</file>
<file>themes/default/mActionRegularPolygonCenterCorner.svg</file>
<file>themes/default/mActionRegularPolygon2Points.svg</file>
Expand Down
122 changes: 122 additions & 0 deletions images/themes/default/mActionRectangle3PointsProjected.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 21 additions & 14 deletions src/app/qgisapp.cpp
@@ -1,12 +1,12 @@
/***************************************************************************
qgisapp.cpp - description
-------------------
qgisapp.cpp - description
-------------------

begin : Sat Jun 22 2002
copyright : (C) 2002 by Gary E.Sherman
email : sherman at mrcc.com
Romans 3:23=>Romans 6:23=>Romans 10:9,10=>Romans 12
***************************************************************************/
begin : Sat Jun 22 2002
copyright : (C) 2002 by Gary E.Sherman
email : sherman at mrcc.com
Romans 3:23=>Romans 6:23=>Romans 10:9,10=>Romans 12
***************************************************************************/

/***************************************************************************
* *
Expand Down Expand Up @@ -1530,7 +1530,8 @@ QgisApp::~QgisApp()
delete mMapTools.mEllipseFoci;
delete mMapTools.mRectangleCenterPoint;
delete mMapTools.mRectangleExtent;
delete mMapTools.mRectangle3Points;
delete mMapTools.mRectangle3PointsDistance;
delete mMapTools.mRectangle3PointsProjected;
delete mMapTools.mRegularPolygon2Points;
delete mMapTools.mRegularPolygonCenterPoint;
delete mMapTools.mRegularPolygonCenterCorner;
Expand Down Expand Up @@ -2090,7 +2091,8 @@ void QgisApp::createActions()
connect( mActionEllipseFoci, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mEllipseFoci, true ); } );
connect( mActionRectangleCenterPoint, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRectangleCenterPoint, true ); } );
connect( mActionRectangleExtent, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRectangleExtent, true ); } );
connect( mActionRectangle3Points, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRectangle3Points, true ); } );
connect( mActionRectangle3PointsDistance, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRectangle3PointsDistance, true ); } );
connect( mActionRectangle3PointsProjected, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRectangle3PointsProjected, true ); } );
connect( mActionRegularPolygon2Points, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRegularPolygon2Points, true ); } );
connect( mActionRegularPolygonCenterPoint, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRegularPolygonCenterPoint, true ); } );
connect( mActionRegularPolygonCenterCorner, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRegularPolygonCenterCorner, true ); } );
Expand Down Expand Up @@ -2375,7 +2377,8 @@ void QgisApp::createActionGroups()
mMapToolGroup->addAction( mActionEllipseFoci );
mMapToolGroup->addAction( mActionRectangleCenterPoint );
mMapToolGroup->addAction( mActionRectangleExtent );
mMapToolGroup->addAction( mActionRectangle3Points );
mMapToolGroup->addAction( mActionRectangle3PointsDistance );
mMapToolGroup->addAction( mActionRectangle3PointsProjected );
mMapToolGroup->addAction( mActionRegularPolygon2Points );
mMapToolGroup->addAction( mActionRegularPolygonCenterPoint );
mMapToolGroup->addAction( mActionRegularPolygonCenterCorner );
Expand Down Expand Up @@ -2934,7 +2937,8 @@ void QgisApp::createToolBars()
tbAddRectangle->setPopupMode( QToolButton::MenuButtonPopup );
tbAddRectangle->addAction( mActionRectangleCenterPoint );
tbAddRectangle->addAction( mActionRectangleExtent );
tbAddRectangle->addAction( mActionRectangle3Points );
tbAddRectangle->addAction( mActionRectangle3PointsDistance );
tbAddRectangle->addAction( mActionRectangle3PointsProjected );
tbAddRectangle->setDefaultAction( mActionRectangleCenterPoint );
connect( tbAddRectangle, &QToolButton::triggered, this, &QgisApp::toolButtonActionTriggered );
mShapeDigitizeToolBar->insertWidget( mActionVertexTool, tbAddRectangle );
Expand Down Expand Up @@ -3574,8 +3578,10 @@ void QgisApp::createCanvasTools()
mMapTools.mRectangleCenterPoint->setAction( mActionRectangleCenterPoint );
mMapTools.mRectangleExtent = new QgsMapToolRectangleExtent( mMapTools.mAddFeature, mMapCanvas );
mMapTools.mRectangleExtent->setAction( mActionRectangleExtent );
mMapTools.mRectangle3Points = new QgsMapToolRectangle3Points( mMapTools.mAddFeature, mMapCanvas );
mMapTools.mRectangle3Points->setAction( mActionRectangle3Points );
mMapTools.mRectangle3PointsDistance = new QgsMapToolRectangle3Points( mMapTools.mAddFeature, mMapCanvas, QgsMapToolRectangle3Points::DistanceMode );
mMapTools.mRectangle3PointsDistance->setAction( mActionRectangle3PointsDistance );
mMapTools.mRectangle3PointsProjected = new QgsMapToolRectangle3Points( mMapTools.mAddFeature, mMapCanvas, QgsMapToolRectangle3Points::ProjectedMode );
mMapTools.mRectangle3PointsProjected->setAction( mActionRectangle3PointsProjected );
mMapTools.mRegularPolygon2Points = new QgsMapToolRegularPolygon2Points( mMapTools.mAddFeature, mMapCanvas );
mMapTools.mRegularPolygon2Points->setAction( mActionRegularPolygon2Points );
mMapTools.mRegularPolygonCenterPoint = new QgsMapToolRegularPolygonCenterPoint( mMapTools.mAddFeature, mMapCanvas );
Expand Down Expand Up @@ -12532,7 +12538,8 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )
mActionEllipseFoci->setEnabled( enableShapeTools );
mActionRectangleCenterPoint->setEnabled( enableShapeTools );
mActionRectangleExtent->setEnabled( enableShapeTools );
mActionRectangle3Points->setEnabled( enableShapeTools );
mActionRectangle3PointsDistance->setEnabled( enableShapeTools );
mActionRectangle3PointsProjected->setEnabled( enableShapeTools );
mActionRegularPolygon2Points->setEnabled( enableShapeTools );
mActionRegularPolygonCenterPoint->setEnabled( enableShapeTools );
mActionRegularPolygonCenterCorner->setEnabled( enableShapeTools );
Expand Down
15 changes: 8 additions & 7 deletions src/app/qgisapp.h
@@ -1,10 +1,10 @@
/***************************************************************************
qgisapp.h - description
-------------------
begin : Sat Jun 22 2002
copyright : (C) 2002 by Gary E.Sherman
email : sherman at mrcc.com
***************************************************************************/
qgisapp.h - description
-------------------
begin : Sat Jun 22 2002
copyright : (C) 2002 by Gary E.Sherman
email : sherman at mrcc.com
***************************************************************************/

/***************************************************************************
* *
Expand Down Expand Up @@ -2044,7 +2044,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QgsMapTool *mEllipseFoci = nullptr;
QgsMapTool *mRectangleCenterPoint = nullptr;
QgsMapTool *mRectangleExtent = nullptr;
QgsMapTool *mRectangle3Points = nullptr;
QgsMapTool *mRectangle3PointsDistance = nullptr;
QgsMapTool *mRectangle3PointsProjected = nullptr;
QgsMapTool *mRegularPolygon2Points = nullptr;
QgsMapTool *mRegularPolygonCenterPoint = nullptr;
QgsMapTool *mRegularPolygonCenterCorner = nullptr;
Expand Down
39 changes: 22 additions & 17 deletions src/app/qgsmaptoolrectangle3points.cpp
@@ -1,18 +1,18 @@
/***************************************************************************
qgsmaptoolrectangle3points.cpp - map tool for adding rectangle
from 3 points
---------------------
begin : September 2017
copyright : (C) 2017 by Loïc Bartoletti
email : lbartoletti at tuxfamily dot org
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
qgsmaptoolrectangle3points.cpp - map tool for adding rectangle
from 3 points
---------------------
begin : September 2017
copyright : (C) 2017 by Loïc Bartoletti
email : lbartoletti at tuxfamily dot org
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsmaptoolrectangle3points.h"
#include "qgsgeometryrubberband.h"
Expand All @@ -25,8 +25,9 @@
#include "qgssnapindicator.h"

QgsMapToolRectangle3Points::QgsMapToolRectangle3Points( QgsMapToolCapture *parentTool,
QgsMapCanvas *canvas, CaptureMode mode )
: QgsMapToolAddRectangle( parentTool, canvas, mode )
QgsMapCanvas *canvas, CreateMode createMode, CaptureMode mode )
: QgsMapToolAddRectangle( parentTool, canvas, mode ),
mCreateMode( createMode )
{
}

Expand Down Expand Up @@ -77,7 +78,11 @@ void QgsMapToolRectangle3Points::cadCanvasMoveEvent( QgsMapMouseEvent *e )
break;
case 2:
{
setDistance2( mPoints.at( 1 ).distance( point ) );
if ( mCreateMode == DistanceMode )
setDistance2( mPoints.at( 1 ).distance( point ) );
else if ( mCreateMode == ProjectedMode )
setDistance2( QgsGeometryUtils::perpendicularSegment( point, mPoints.at( 0 ), mPoints.at( 1 ) ).length() );

int side = QgsGeometryUtils::leftOfLine( point.x(), point.y(),
mPoints.at( 0 ).x(), mPoints.at( 0 ).y(),
mPoints.at( 1 ).x(), mPoints.at( 1 ).y() );
Expand Down
38 changes: 23 additions & 15 deletions src/app/qgsmaptoolrectangle3points.h
@@ -1,18 +1,18 @@
/***************************************************************************
qgsmaptoolrectangle3points.h - map tool for adding rectangle
from 3 points
---------------------
begin : September 2017
copyright : (C) 2017 by Loïc Bartoletti
email : lbartoletti at tuxfamily dot org
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
qgsmaptoolrectangle3points.h - map tool for adding rectangle
from 3 points
---------------------
begin : September 2017
copyright : (C) 2017 by Loïc Bartoletti
email : lbartoletti at tuxfamily dot org
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSMAPTOOLRECTANGLE3POINTS_H
#define QGSMAPTOOLRECTANGLE3POINTS_H
Expand All @@ -25,11 +25,19 @@ class APP_EXPORT QgsMapToolRectangle3Points: public QgsMapToolAddRectangle
Q_OBJECT

public:
QgsMapToolRectangle3Points( QgsMapToolCapture *parentTool, QgsMapCanvas *canvas, CaptureMode mode = CaptureLine );
enum CreateMode
{
DistanceMode,
ProjectedMode,
};
QgsMapToolRectangle3Points( QgsMapToolCapture *parentTool, QgsMapCanvas *canvas, CreateMode createMode, CaptureMode mode = CaptureLine );

void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;
void cadCanvasMoveEvent( QgsMapMouseEvent *e ) override;

private:
CreateMode mCreateMode;

};

#endif // QGSMAPTOOLRECTANGLE3POINTS_H

0 comments on commit d40f884

Please sign in to comment.