Skip to content

Commit 4c8171d

Browse files
committed
Reborn of QgsMapToolCircle3Tangents. Thanks Martin!
1 parent 27b075f commit 4c8171d

File tree

6 files changed

+148
-0
lines changed

6 files changed

+148
-0
lines changed

src/app/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ SET(QGIS_APP_SRCS
134134
qgsmaptooladdcircle.cpp
135135
qgsmaptoolcircle2points.cpp
136136
qgsmaptoolcircle3points.cpp
137+
qgsmaptoolcircle3tangents.cpp
137138
qgsmaptoolcirclecenterpoint.cpp
138139
qgsmaptooladdellipse.cpp
139140
qgsmaptoolellipsefoci.cpp
@@ -308,6 +309,7 @@ SET (QGIS_APP_MOC_HDRS
308309
qgsmaptooladdcircle.h
309310
qgsmaptoolcircle2points.h
310311
qgsmaptoolcircle3points.h
312+
qgsmaptoolcircle3tangents.h
311313
qgsmaptoolcirclecenterpoint.h
312314
qgsmaptooladdellipse.h
313315
qgsmaptoolellipsefoci.h

src/app/qgisapp.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
337337
#include "qgsmaptoolcircularstringradius.h"
338338
#include "qgsmaptoolcircle2points.h"
339339
#include "qgsmaptoolcircle3points.h"
340+
#include "qgsmaptoolcircle3tangents.h"
340341
#include "qgsmaptoolcirclecenterpoint.h"
341342
#include "qgsmaptoolellipsecenter2points.h"
342343
#include "qgsmaptoolellipsecenterpoint.h"
@@ -1301,6 +1302,7 @@ QgisApp::~QgisApp()
13011302
delete mMapTools.mCircularStringRadius;
13021303
delete mMapTools.mCircle2Points;
13031304
delete mMapTools.mCircle3Points;
1305+
delete mMapTools.mCircle3Tangents;
13041306
delete mMapTools.mCircleCenterPoint;
13051307
delete mMapTools.mEllipseCenter2Points;
13061308
delete mMapTools.mEllipseCenterPoint;
@@ -1776,6 +1778,7 @@ void QgisApp::createActions()
17761778
connect( mActionCircularStringRadius, &QAction::triggered, this, &QgisApp::circularStringRadius );
17771779
connect( mActionCircle2Points, &QAction::triggered, this, &QgisApp::circle2Points );
17781780
connect( mActionCircle3Points, &QAction::triggered, this, &QgisApp::circle3Points );
1781+
connect( mActionCircle3Tangents, &QAction::triggered, this, &QgisApp::circle3Tangents );
17791782
connect( mActionCircleCenterPoint, &QAction::triggered, this, &QgisApp::circleCenterPoint );
17801783
connect( mActionEllipseCenter2Points, &QAction::triggered, this, &QgisApp::ellipseCenter2Points );
17811784
connect( mActionEllipseCenterPoint, &QAction::triggered, this, &QgisApp::ellipseCenterPoint );
@@ -2063,6 +2066,7 @@ void QgisApp::createActionGroups()
20632066
mMapToolGroup->addAction( mActionCircularStringRadius );
20642067
mMapToolGroup->addAction( mActionCircle2Points );
20652068
mMapToolGroup->addAction( mActionCircle3Points );
2069+
mMapToolGroup->addAction( mActionCircle3Tangents );
20662070
mMapToolGroup->addAction( mActionCircleCenterPoint );
20672071
mMapToolGroup->addAction( mActionEllipseCenter2Points );
20682072
mMapToolGroup->addAction( mActionEllipseCenterPoint );
@@ -2587,6 +2591,7 @@ void QgisApp::createToolBars()
25872591
tbAddCircle->setPopupMode( QToolButton::MenuButtonPopup );
25882592
tbAddCircle->addAction( mActionCircle2Points );
25892593
tbAddCircle->addAction( mActionCircle3Points );
2594+
tbAddCircle->addAction( mActionCircle3Tangents );
25902595
tbAddCircle->addAction( mActionCircleCenterPoint );
25912596
tbAddCircle->setDefaultAction( mActionCircle2Points );
25922597
connect( tbAddCircle, &QToolButton::triggered, this, &QgisApp::toolButtonActionTriggered );
@@ -3196,6 +3201,8 @@ void QgisApp::createCanvasTools()
31963201
mMapTools.mCircle2Points->setAction( mActionCircle2Points );
31973202
mMapTools.mCircle3Points = new QgsMapToolCircle3Points( dynamic_cast<QgsMapToolAddFeature *>( mMapTools.mAddFeature ), mMapCanvas );
31983203
mMapTools.mCircle3Points->setAction( mActionCircle3Points );
3204+
mMapTools.mCircle3Tangents = new QgsMapToolCircle3Tangents( dynamic_cast<QgsMapToolAddFeature *>( mMapTools.mAddFeature ), mMapCanvas );
3205+
mMapTools.mCircle3Tangents->setAction( mActionCircle3Tangents );
31993206
mMapTools.mCircleCenterPoint = new QgsMapToolCircleCenterPoint( dynamic_cast<QgsMapToolAddFeature *>( mMapTools.mAddFeature ), mMapCanvas );
32003207
mMapTools.mCircleCenterPoint->setAction( mActionCircleCenterPoint );
32013208
mMapTools.mEllipseCenter2Points = new QgsMapToolEllipseCenter2Points( dynamic_cast<QgsMapToolAddFeature *>( mMapTools.mAddFeature ), mMapCanvas );
@@ -7794,6 +7801,11 @@ void QgisApp::circle3Points()
77947801
mMapCanvas->setMapTool( mMapTools.mCircle3Points );
77957802
}
77967803

7804+
void QgisApp::circle3Tangents()
7805+
{
7806+
mMapCanvas->setMapTool( mMapTools.mCircle3Tangents );
7807+
}
7808+
77977809
void QgisApp::circleCenterPoint()
77987810
{
77997811
mMapCanvas->setMapTool( mMapTools.mCircleCenterPoint );
@@ -11189,6 +11201,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )
1118911201
mActionCircularStringRadius->setEnabled( false );
1119011202
mActionCircle2Points->setEnabled( false );
1119111203
mActionCircle3Points->setEnabled( false );
11204+
mActionCircle3Tangents->setEnabled( false );
1119211205
mActionCircleCenterPoint->setEnabled( false );
1119311206
mActionEllipseCenter2Points->setEnabled( false );
1119411207
mActionEllipseCenterPoint->setEnabled( false );
@@ -11339,6 +11352,8 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )
1133911352
&& ( vlayer->geometryType() == QgsWkbTypes::LineGeometry || vlayer->geometryType() == QgsWkbTypes::PolygonGeometry ) );
1134011353
mActionCircle3Points->setEnabled( isEditable && ( canAddFeatures || canChangeGeometry )
1134111354
&& ( vlayer->geometryType() == QgsWkbTypes::LineGeometry || vlayer->geometryType() == QgsWkbTypes::PolygonGeometry ) );
11355+
mActionCircle3Tangents->setEnabled( isEditable && ( canAddFeatures || canChangeGeometry )
11356+
&& ( vlayer->geometryType() == QgsWkbTypes::LineGeometry || vlayer->geometryType() == QgsWkbTypes::PolygonGeometry ) );
1134211357
mActionCircleCenterPoint->setEnabled( isEditable && ( canAddFeatures || canChangeGeometry )
1134311358
&& ( vlayer->geometryType() == QgsWkbTypes::LineGeometry || vlayer->geometryType() == QgsWkbTypes::PolygonGeometry ) );
1134411359
mActionEllipseCenter2Points->setEnabled( isEditable && ( canAddFeatures || canChangeGeometry )

src/app/qgisapp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
12271227
void circle2Points();
12281228
//! activates the add circle from 3 points tool
12291229
void circle3Points();
1230+
//! activates the add circle from 3 tangents tool
1231+
void circle3Tangents();
12301232
//! activates the add circle from center and radius tool
12311233
void circleCenterPoint();
12321234
//! activates the add ellipse from center and 2 points tool
@@ -1820,6 +1822,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
18201822
QgsMapTool *mCircularStringRadius = nullptr;
18211823
QgsMapTool *mCircle2Points = nullptr;
18221824
QgsMapTool *mCircle3Points = nullptr;
1825+
QgsMapTool *mCircle3Tangents = nullptr;
18231826
QgsMapTool *mCircleCenterPoint = nullptr;
18241827
QgsMapTool *mEllipseCenter2Points = nullptr;
18251828
QgsMapTool *mEllipseCenterPoint = nullptr;
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/***************************************************************************
2+
qgsmaptoolcircle3tangents.h - map tool for adding circle
3+
from 3 tangents
4+
---------------------
5+
begin : July 2017
6+
copyright : (C) 2017 by Loïc Bartoletti
7+
email : lbartoletti at tuxfamily dot org
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#include "qgsmaptoolcircle3tangents.h"
18+
#include "qgsgeometryrubberband.h"
19+
#include "qgsadvanceddigitizingdockwidget.h"
20+
#include "qgslinestring.h"
21+
#include "qgssnappingutils.h"
22+
#include "qgsmapcanvas.h"
23+
#include "qgspoint.h"
24+
#include "qgisapp.h"
25+
#include <QMouseEvent>
26+
27+
QgsMapToolCircle3Tangents::QgsMapToolCircle3Tangents( QgsMapToolCapture *parentTool,
28+
QgsMapCanvas *canvas, CaptureMode mode )
29+
: QgsMapToolAddCircle( parentTool, canvas, mode )
30+
{
31+
}
32+
33+
void QgsMapToolCircle3Tangents::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
34+
{
35+
36+
QgsPoint mapPoint( e->mapPoint() );
37+
EdgesOnlyFilter filter;
38+
QgsPointLocator::Match match = mCanvas->snappingUtils()->snapToMap( mapPoint, &filter );
39+
40+
QgsPointXY p1, p2;
41+
42+
if ( e->button() == Qt::LeftButton )
43+
{
44+
if ( match.isValid() && ( mPoints.size() <= 2 * 2 ) )
45+
{
46+
match.edgePoints( p1, p2 );
47+
mPoints.append( QgsPoint( p1 ) );
48+
mPoints.append( QgsPoint( p2 ) );
49+
}
50+
if ( !mPoints.isEmpty() )
51+
{
52+
if ( !mTempRubberBand )
53+
{
54+
mTempRubberBand = createGeometryRubberBand( ( mode() == CapturePolygon ) ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true );
55+
mTempRubberBand->show();
56+
}
57+
std::unique_ptr<QgsLineString> line( new QgsLineString() );
58+
59+
line->addVertex( QgsPoint( p1 ) );
60+
line->addVertex( QgsPoint( p2 ) );
61+
62+
mTempRubberBand->setGeometry( line.release() );
63+
}
64+
}
65+
else if ( e->button() == Qt::RightButton )
66+
{
67+
if ( match.isValid() && ( mPoints.size() == 4 ) )
68+
{
69+
70+
match.edgePoints( p1, p2 );
71+
mPoints.append( QgsPoint( p1 ) );
72+
mPoints.append( QgsPoint( p2 ) );
73+
mCircle = QgsCircle().from3Tangents( mPoints.at( 0 ), mPoints.at( 1 ), mPoints.at( 2 ), mPoints.at( 3 ), mPoints.at( 4 ), mPoints.at( 5 ) );
74+
if ( mCircle.isEmpty() )
75+
{
76+
QgisApp::instance()->messageBar()->pushMessage( tr( "Error" ), tr( "At least two segments are parallels" ), QgsMessageBar::WARNING, QgisApp::instance()->messageTimeout() );
77+
mPoints.clear();
78+
delete mTempRubberBand;
79+
mTempRubberBand = nullptr;
80+
}
81+
}
82+
deactivate();
83+
if ( mParentTool )
84+
{
85+
mParentTool->canvasReleaseEvent( e );
86+
}
87+
}
88+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/***************************************************************************
2+
qgsmaptoolcircle3tangents.h - map tool for adding circle
3+
from 3 tangents
4+
---------------------
5+
begin : July 2017
6+
copyright : (C) 2017 by Loïc Bartoletti
7+
email : lbartoletti at tuxfamily dot org
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 3 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#ifndef QGSMAPTOOLCIRCLE3TANGENTS_H
18+
#define QGSMAPTOOLCIRCLE3TANGENTS_H
19+
20+
#include "qgspointlocator.h"
21+
#include "qgsmaptooladdcircle.h"
22+
23+
struct EdgesOnlyFilter : public QgsPointLocator::MatchFilter
24+
{
25+
bool acceptMatch( const QgsPointLocator::Match &m ) override { return m.hasEdge(); }
26+
};
27+
28+
class QgsMapToolCircle3Tangents: public QgsMapToolAddCircle
29+
{
30+
Q_OBJECT
31+
32+
public:
33+
QgsMapToolCircle3Tangents( QgsMapToolCapture *parentTool, QgsMapCanvas *canvas, CaptureMode mode = CaptureLine );
34+
35+
void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;
36+
37+
};
38+
39+
#endif // QGSMAPTOOLCIRCLE3TANGENTS_H

src/ui/qgisapp.ui

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@
278278
</property>
279279
<addaction name="mActionCircle2Points"/>
280280
<addaction name="mActionCircle3Points"/>
281+
<addaction name="mActionCircle3Tangents"/>
281282
<addaction name="mActionCircleCenterPoint"/>
282283
</widget>
283284
<widget class="QMenu" name="mMenuEllipse">

0 commit comments

Comments
 (0)