Skip to content

Commit c66b893

Browse files
committedAug 2, 2017
Add circle from 3 tangents
1 parent 9a9cf3c commit c66b893

File tree

8 files changed

+257
-0
lines changed

8 files changed

+257
-0
lines changed
 

‎images/images.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@
576576
<file>themes/default/mActionRegularPolygonCenterPoint.svg</file>
577577
<file>themes/default/mActionRegularPolygon2Points.svg</file>
578578
<file>themes/default/mActionSquareCenter.svg</file>
579+
<file>themes/default/mActionCircle3Tangents.svg</file>
579580
</qresource>
580581
<qresource prefix="/images/tips">
581582
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
Lines changed: 116 additions & 0 deletions
Loading

‎src/app/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ SET(QGIS_APP_SRCS
136136
qgsmaptoolcircle2points.cpp
137137
qgsmaptoolcircle3points.cpp
138138
qgsmaptoolcirclecenterpoint.cpp
139+
qgsmaptoolcircle3tangents.cpp
139140
qgsmaptooladdellipse.cpp
140141
qgsmaptoolellipsefoci.cpp
141142
qgsmaptoolellipseextent.cpp
@@ -306,6 +307,7 @@ SET (QGIS_APP_MOC_HDRS
306307
qgsmaptoolcircle2points.h
307308
qgsmaptoolcircle3points.h
308309
qgsmaptoolcirclecenterpoint.h
310+
qgsmaptoolcircle3tangents.h
309311
qgsmaptooladdellipse.h
310312
qgsmaptoolellipsefoci.h
311313
qgsmaptoolellipseextent.h

‎src/app/qgisapp.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
336336
#include "qgsmaptoolcircle2points.h"
337337
#include "qgsmaptoolcircle3points.h"
338338
#include "qgsmaptoolcirclecenterpoint.h"
339+
#include "qgsmaptoolcircle3tangents.h"
339340
#include "qgsmaptoolellipsecenter2points.h"
340341
#include "qgsmaptoolellipsecenterpoint.h"
341342
#include "qgsmaptoolellipseextent.h"
@@ -1412,6 +1413,7 @@ QgisApp::~QgisApp()
14121413
delete mMapTools.mCircle2Points;
14131414
delete mMapTools.mCircle3Points;
14141415
delete mMapTools.mCircleCenterPoint;
1416+
delete mMapTools.mCircle3Tangents;
14151417
delete mMapTools.mEllipseCenter2Points;
14161418
delete mMapTools.mEllipseCenterPoint;
14171419
delete mMapTools.mEllipseExtent;
@@ -1870,6 +1872,7 @@ void QgisApp::createActions()
18701872
connect( mActionCircle2Points, &QAction::triggered, this, &QgisApp::circle2Points );
18711873
connect( mActionCircle3Points, &QAction::triggered, this, &QgisApp::circle3Points );
18721874
connect( mActionCircleCenterPoint, &QAction::triggered, this, &QgisApp::circleCenterPoint );
1875+
connect( mActionCircle3Tangents, &QAction::triggered, this, &QgisApp::circle3Tangents );
18731876
connect( mActionEllipseCenter2Points, &QAction::triggered, this, &QgisApp::ellipseCenter2Points );
18741877
connect( mActionEllipseCenterPoint, &QAction::triggered, this, &QgisApp::ellipseCenterPoint );
18751878
connect( mActionEllipseExtent, &QAction::triggered, this, &QgisApp::ellipseExtent );
@@ -2156,6 +2159,7 @@ void QgisApp::createActionGroups()
21562159
mMapToolGroup->addAction( mActionCircle2Points );
21572160
mMapToolGroup->addAction( mActionCircle3Points );
21582161
mMapToolGroup->addAction( mActionCircleCenterPoint );
2162+
mMapToolGroup->addAction( mActionCircle3Tangents );
21592163
mMapToolGroup->addAction( mActionEllipseCenter2Points );
21602164
mMapToolGroup->addAction( mActionEllipseCenterPoint );
21612165
mMapToolGroup->addAction( mActionEllipseExtent );
@@ -2703,6 +2707,7 @@ void QgisApp::createToolBars()
27032707
tbAddCircle->addAction( mActionCircle2Points );
27042708
tbAddCircle->addAction( mActionCircle3Points );
27052709
tbAddCircle->addAction( mActionCircleCenterPoint );
2710+
tbAddCircle->addAction( mActionCircle3Tangents );
27062711
tbAddCircle->setDefaultAction( mActionCircle2Points );
27072712
connect( tbAddCircle, &QToolButton::triggered, this, &QgisApp::toolButtonActionTriggered );
27082713
mRegularShapeDigitizeToolBar->insertWidget( mActionNodeTool, tbAddCircle );
@@ -3324,6 +3329,8 @@ void QgisApp::createCanvasTools()
33243329
mMapTools.mCircle3Points->setAction( mActionCircle3Points );
33253330
mMapTools.mCircleCenterPoint = new QgsMapToolCircleCenterPoint( dynamic_cast<QgsMapToolAddFeature *>( mMapTools.mAddFeature ), mMapCanvas );
33263331
mMapTools.mCircleCenterPoint->setAction( mActionCircleCenterPoint );
3332+
mMapTools.mCircle3Tangents = new QgsMapToolCircle3Tangents( dynamic_cast<QgsMapToolAddFeature *>( mMapTools.mAddFeature ), mMapCanvas );
3333+
mMapTools.mCircle3Tangents->setAction( mActionCircle3Tangents );
33273334
mMapTools.mEllipseCenter2Points = new QgsMapToolEllipseCenter2Points( dynamic_cast<QgsMapToolAddFeature *>( mMapTools.mAddFeature ), mMapCanvas );
33283335
mMapTools.mEllipseCenter2Points->setAction( mActionEllipseCenter2Points );
33293336
mMapTools.mEllipseCenterPoint = new QgsMapToolEllipseCenterPoint( dynamic_cast<QgsMapToolAddFeature *>( mMapTools.mAddFeature ), mMapCanvas );
@@ -7905,6 +7912,11 @@ void QgisApp::circleCenterPoint()
79057912
mMapCanvas->setMapTool( mMapTools.mCircleCenterPoint );
79067913
}
79077914

7915+
void QgisApp::circle3Tangents()
7916+
{
7917+
mMapCanvas->setMapTool( mMapTools.mCircle3Tangents );
7918+
}
7919+
79087920
void QgisApp::ellipseCenter2Points()
79097921
{
79107922
mMapCanvas->setMapTool( mMapTools.mEllipseCenter2Points );
@@ -11237,6 +11249,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )
1123711249
mActionCircle2Points->setEnabled( false );
1123811250
mActionCircle3Points->setEnabled( false );
1123911251
mActionCircleCenterPoint->setEnabled( false );
11252+
mActionCircle3Tangents->setEnabled( false );
1124011253
mActionEllipseCenter2Points->setEnabled( false );
1124111254
mActionEllipseCenterPoint->setEnabled( false );
1124211255
mActionEllipseExtent->setEnabled( false );
@@ -11387,6 +11400,8 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )
1138711400
&& ( vlayer->geometryType() == QgsWkbTypes::LineGeometry || vlayer->geometryType() == QgsWkbTypes::PolygonGeometry ) );
1138811401
mActionCircleCenterPoint->setEnabled( isEditable && ( canAddFeatures || canChangeGeometry )
1138911402
&& ( vlayer->geometryType() == QgsWkbTypes::LineGeometry || vlayer->geometryType() == QgsWkbTypes::PolygonGeometry ) );
11403+
mActionCircle3Tangents->setEnabled( isEditable && ( canAddFeatures || canChangeGeometry )
11404+
&& ( vlayer->geometryType() == QgsWkbTypes::LineGeometry || vlayer->geometryType() == QgsWkbTypes::PolygonGeometry ) );
1139011405
mActionEllipseCenter2Points->setEnabled( isEditable && ( canAddFeatures || canChangeGeometry )
1139111406
&& ( vlayer->geometryType() == QgsWkbTypes::LineGeometry || vlayer->geometryType() == QgsWkbTypes::PolygonGeometry ) );
1139211407
mActionEllipseCenterPoint->setEnabled( isEditable && ( canAddFeatures || canChangeGeometry )

‎src/app/qgisapp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
12151215
void circle3Points();
12161216
//! activates the add circle from center and radius tool
12171217
void circleCenterPoint();
1218+
//! activates the add circle from 3 tangents tool
1219+
void circle3Tangents();
12181220
//! activates the add ellipse from center and 2 points tool
12191221
void ellipseCenter2Points();
12201222
//! activates the add ellipse from center point tool
@@ -1799,6 +1801,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
17991801
, mCircle2Points( nullptr )
18001802
, mCircle3Points( nullptr )
18011803
, mCircleCenterPoint( nullptr )
1804+
, mCircle3Tangents( nullptr )
18021805
, mEllipseCenter2Points( nullptr )
18031806
, mEllipseCenterPoint( nullptr )
18041807
, mEllipseExtent( nullptr )
@@ -1857,6 +1860,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
18571860
QgsMapTool *mCircle2Points = nullptr;
18581861
QgsMapTool *mCircle3Points = nullptr;
18591862
QgsMapTool *mCircleCenterPoint = nullptr;
1863+
QgsMapTool *mCircle3Tangents = nullptr;
18601864
QgsMapTool *mEllipseCenter2Points = nullptr;
18611865
QgsMapTool *mEllipseCenterPoint = nullptr;
18621866
QgsMapTool *mEllipseExtent = nullptr;

‎src/app/qgsmaptoolcircle3tangents.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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 "qgslinestring.h"
20+
#include "qgsmapcanvas.h"
21+
#include "qgspoint.h"
22+
#include <QMouseEvent>
23+
24+
QgsMapToolCircle3Tangents::QgsMapToolCircle3Tangents( QgsMapToolCapture *parentTool,
25+
QgsMapCanvas *canvas, CaptureMode mode )
26+
: QgsMapToolAddCircle( parentTool, canvas, mode )
27+
{
28+
}
29+
30+
QgsMapToolCircle3Tangents::~QgsMapToolCircle3Tangents()
31+
{
32+
}
33+
34+
void QgsMapToolCircle3Tangents::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
35+
{
36+
37+
QList<QgsPointXY> segment = e->snapSegment( QgsMapMouseEvent::SnapProjectConfig );
38+
39+
if ( e->button() == Qt::LeftButton )
40+
{
41+
if ( ( mPoints.size() <= 2 * 2 ) )
42+
{
43+
mPoints.append( QgsPoint( segment.at( 0 ) ) );
44+
mPoints.append( QgsPoint( segment.at( 1 ) ) );
45+
46+
47+
}
48+
49+
if ( !mPoints.isEmpty() )
50+
{
51+
if ( !mTempRubberBand )
52+
{
53+
mTempRubberBand = createGeometryRubberBand( ( mode() == CapturePolygon ) ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true );
54+
mTempRubberBand->show();
55+
}
56+
}
57+
}
58+
else if ( e->button() == Qt::RightButton )
59+
{
60+
if ( !segment.empty() && ( mPoints.size() == 6 ) )
61+
{
62+
mCircle = QgsCircle().from3Tangents( mPoints.at( 0 ), mPoints.at( 1 ), mPoints.at( 2 ), mPoints.at( 3 ), mPoints.at( 4 ), mPoints.at( 5 ) );
63+
}
64+
deactivate();
65+
if ( mParentTool )
66+
{
67+
mParentTool->canvasReleaseEvent( e );
68+
}
69+
}
70+
}

‎src/app/qgsmaptoolcircle3tangents.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 "qgsmaptooladdcircle.h"
21+
22+
class QgsMapToolCircle3Tangents: public QgsMapToolAddCircle
23+
{
24+
Q_OBJECT
25+
26+
public:
27+
QgsMapToolCircle3Tangents( QgsMapToolCapture *parentTool, QgsMapCanvas *canvas, CaptureMode mode = CaptureLine );
28+
~QgsMapToolCircle3Tangents();
29+
30+
void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;
31+
};
32+
33+
#endif // QGSMAPTOOLCIRCLE3TANGENTS_H

‎src/ui/qgisapp.ui

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@
279279
<addaction name="mActionCircle2Points"/>
280280
<addaction name="mActionCircle3Points"/>
281281
<addaction name="mActionCircleCenterPoint"/>
282+
<addaction name="mActionCircle3Tangents"/>
282283
</widget>
283284
<widget class="QMenu" name="mMenuEllipse">
284285
<property name="title">
@@ -2897,6 +2898,21 @@ Acts on currently active editable layer</string>
28972898
<string>Add regular polygon from 2 points</string>
28982899
</property>
28992900
</action>
2901+
<action name="mActionCircle3Tangents">
2902+
<property name="checkable">
2903+
<bool>true</bool>
2904+
</property>
2905+
<property name="icon">
2906+
<iconset resource="../../images/images.qrc">
2907+
<normaloff>:/images/themes/default/mActionCircle3Tangents.svg</normaloff>:/images/themes/default/mActionCircle3Tangents.svg</iconset>
2908+
</property>
2909+
<property name="text">
2910+
<string>Add Circle from 3 Tangents</string>
2911+
</property>
2912+
<property name="toolTip">
2913+
<string>Add circle from 3 tangents</string>
2914+
</property>
2915+
</action>
29002916
</widget>
29012917
<resources>
29022918
<include location="../../images/images.qrc"/>

0 commit comments

Comments
 (0)
Please sign in to comment.