Skip to content
Permalink
Browse files

Add map tool rectangle 3 points where 3rd point is projected on segme…

…nt p1-p2
  • Loading branch information
lbartoletti committed Nov 13, 2018
1 parent 7cce9b3 commit d40f884dfd0366f0aa8ba19e0e1d0aeae7131d03
@@ -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>
@@ -0,0 +1,122 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
height="24"
viewBox="0 0 24 24"
width="24"
version="1.1"
id="svg4016"
sodipodi:docname="mActionRectangle3PointsProjected.svg"
inkscape:version="0.92.3 (2405546, 2018-03-11)">
<metadata
id="metadata4022">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs4020" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1024"
id="namedview4018"
showgrid="false"
inkscape:zoom="31.083333"
inkscape:cx="12.637688"
inkscape:cy="11.065086"
inkscape:window-x="0"
inkscape:window-y="31"
inkscape:window-maximized="1"
inkscape:current-layer="svg4016"
inkscape:measure-start="7.94638,12.8686"
inkscape:measure-end="4.08579,12.8365" />
<linearGradient
gradientUnits="userSpaceOnUse"
x1="-10"
x2="-10"
y1="15"
y2="21"
id="linearGradient3996">
<stop
offset="0"
stop-color="#555753"
id="stop3992" />
<stop
offset="1"
stop-color="#555753"
stop-opacity="0"
id="stop3994" />
</linearGradient>
<g
id="g855">
<rect
y="5.1101041"
x="4.1102462"
height="11.779792"
width="15.779792"
id="rect5757"
style="fill:none;stroke:#8cbe8c;stroke-width:3.22020817;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<g
transform="translate(26.66234,-1.5120644)"
id="g4004">
<rect
height="11"
rx="2.0114901"
width="11"
x="-20"
y="13"
id="rect3998"
style="fill:#c4a000" />
<path
d="m -15,14 v 2.0625 c -0.537663,0.111041 -1.024662,0.383291 -1.375,0.78125 l -1.78125,-1.03125 -0.5,0.875 1.78125,1.03125 C -16.957063,17.966182 -17,18.225145 -17,18.5 c 0,0.274855 0.04294,0.533818 0.125,0.78125 l -1.78125,1.03125 0.5,0.875 1.78125,-1.03125 c 0.352503,0.40042 0.832682,0.670182 1.375,0.78125 V 23 h 1 v -2.0625 c 0.537663,-0.111041 1.024662,-0.383291 1.375,-0.78125 l 1.78125,1.03125 0.5,-0.875 -1.78125,-1.03125 C -12.042937,19.033818 -12,18.774855 -12,18.5 c 0,-0.274855 -0.04294,-0.533818 -0.125,-0.78125 l 1.78125,-1.03125 -0.5,-0.875 -1.78125,1.03125 C -12.977503,16.44333 -13.457682,16.173568 -14,16.0625 V 14 Z m 0.5,3.5 c 0.552,0 1,0.448 1,1 0,0.552 -0.448,1 -1,1 -0.552,0 -1,-0.448 -1,-1 0,-0.552 0.448,-1 1,-1 z"
id="path4000"
inkscape:connector-curvature="0"
style="fill:#fcffff" />
<path
d="m -19,19 9,-0.0096 c 0,0 0,0 0,-2 C -10,14 -11,14 -14.5,14 c -3.5,0 -4.5,0 -4.5,3 0,2 0,2 0,2 z"
id="path4002"
inkscape:connector-curvature="0"
style="opacity:0.3;fill:#fcffff;fill-rule:evenodd" />
</g>
<path
d="m 18.403627,3.6286861 h 3 v 3.0000002 h -3 z"
id="path4008"
inkscape:connector-curvature="0"
style="fill:#bebebe;stroke:#8c8c8c;stroke-width:0.99999994" />
<path
d="m 2.661,15.274799 h 3 v 3 h -3 z"
id="path4012"
inkscape:connector-curvature="0"
style="fill:#bebebe;stroke:#8c8c8c;stroke-width:1" />
<path
d="m 2.661,3.6286862 h 3 v 3 h -3 z"
id="path4012-3"
inkscape:connector-curvature="0"
style="fill:#bebebe;stroke:#8c8c8c;stroke-width:1" />
<path
d="m 18.403627,15.274799 h 3 v 3 h -3 z"
id="path4008-3"
inkscape:connector-curvature="0"
style="fill:#bebebe;stroke:#8c8c8c;stroke-width:0.99999994" />
</g>
</svg>
@@ -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
***************************************************************************/

/***************************************************************************
* *
@@ -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;
@@ -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 ); } );
@@ -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 );
@@ -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 );
@@ -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 );
@@ -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 );
@@ -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
***************************************************************************/

/***************************************************************************
* *
@@ -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;
@@ -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"
@@ -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 )
{
}

@@ -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() );
@@ -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
@@ -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.
You can’t perform that action at this time.