Skip to content

Commit

Permalink
Add circle from 3 tangents
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoletti committed Aug 2, 2017
1 parent 9a9cf3c commit c66b893
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 0 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -576,6 +576,7 @@
<file>themes/default/mActionRegularPolygonCenterPoint.svg</file>
<file>themes/default/mActionRegularPolygon2Points.svg</file>
<file>themes/default/mActionSquareCenter.svg</file>
<file>themes/default/mActionCircle3Tangents.svg</file>
</qresource>
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
Expand Down
116 changes: 116 additions & 0 deletions images/themes/default/mActionCircle3Tangents.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -136,6 +136,7 @@ SET(QGIS_APP_SRCS
qgsmaptoolcircle2points.cpp
qgsmaptoolcircle3points.cpp
qgsmaptoolcirclecenterpoint.cpp
qgsmaptoolcircle3tangents.cpp
qgsmaptooladdellipse.cpp
qgsmaptoolellipsefoci.cpp
qgsmaptoolellipseextent.cpp
Expand Down Expand Up @@ -306,6 +307,7 @@ SET (QGIS_APP_MOC_HDRS
qgsmaptoolcircle2points.h
qgsmaptoolcircle3points.h
qgsmaptoolcirclecenterpoint.h
qgsmaptoolcircle3tangents.h
qgsmaptooladdellipse.h
qgsmaptoolellipsefoci.h
qgsmaptoolellipseextent.h
Expand Down
15 changes: 15 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -336,6 +336,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgsmaptoolcircle2points.h"
#include "qgsmaptoolcircle3points.h"
#include "qgsmaptoolcirclecenterpoint.h"
#include "qgsmaptoolcircle3tangents.h"
#include "qgsmaptoolellipsecenter2points.h"
#include "qgsmaptoolellipsecenterpoint.h"
#include "qgsmaptoolellipseextent.h"
Expand Down Expand Up @@ -1412,6 +1413,7 @@ QgisApp::~QgisApp()
delete mMapTools.mCircle2Points;
delete mMapTools.mCircle3Points;
delete mMapTools.mCircleCenterPoint;
delete mMapTools.mCircle3Tangents;
delete mMapTools.mEllipseCenter2Points;
delete mMapTools.mEllipseCenterPoint;
delete mMapTools.mEllipseExtent;
Expand Down Expand Up @@ -1870,6 +1872,7 @@ void QgisApp::createActions()
connect( mActionCircle2Points, &QAction::triggered, this, &QgisApp::circle2Points );
connect( mActionCircle3Points, &QAction::triggered, this, &QgisApp::circle3Points );
connect( mActionCircleCenterPoint, &QAction::triggered, this, &QgisApp::circleCenterPoint );
connect( mActionCircle3Tangents, &QAction::triggered, this, &QgisApp::circle3Tangents );
connect( mActionEllipseCenter2Points, &QAction::triggered, this, &QgisApp::ellipseCenter2Points );
connect( mActionEllipseCenterPoint, &QAction::triggered, this, &QgisApp::ellipseCenterPoint );
connect( mActionEllipseExtent, &QAction::triggered, this, &QgisApp::ellipseExtent );
Expand Down Expand Up @@ -2156,6 +2159,7 @@ void QgisApp::createActionGroups()
mMapToolGroup->addAction( mActionCircle2Points );
mMapToolGroup->addAction( mActionCircle3Points );
mMapToolGroup->addAction( mActionCircleCenterPoint );
mMapToolGroup->addAction( mActionCircle3Tangents );
mMapToolGroup->addAction( mActionEllipseCenter2Points );
mMapToolGroup->addAction( mActionEllipseCenterPoint );
mMapToolGroup->addAction( mActionEllipseExtent );
Expand Down Expand Up @@ -2703,6 +2707,7 @@ void QgisApp::createToolBars()
tbAddCircle->addAction( mActionCircle2Points );
tbAddCircle->addAction( mActionCircle3Points );
tbAddCircle->addAction( mActionCircleCenterPoint );
tbAddCircle->addAction( mActionCircle3Tangents );
tbAddCircle->setDefaultAction( mActionCircle2Points );
connect( tbAddCircle, &QToolButton::triggered, this, &QgisApp::toolButtonActionTriggered );
mRegularShapeDigitizeToolBar->insertWidget( mActionNodeTool, tbAddCircle );
Expand Down Expand Up @@ -3324,6 +3329,8 @@ void QgisApp::createCanvasTools()
mMapTools.mCircle3Points->setAction( mActionCircle3Points );
mMapTools.mCircleCenterPoint = new QgsMapToolCircleCenterPoint( dynamic_cast<QgsMapToolAddFeature *>( mMapTools.mAddFeature ), mMapCanvas );
mMapTools.mCircleCenterPoint->setAction( mActionCircleCenterPoint );
mMapTools.mCircle3Tangents = new QgsMapToolCircle3Tangents( dynamic_cast<QgsMapToolAddFeature *>( mMapTools.mAddFeature ), mMapCanvas );
mMapTools.mCircle3Tangents->setAction( mActionCircle3Tangents );
mMapTools.mEllipseCenter2Points = new QgsMapToolEllipseCenter2Points( dynamic_cast<QgsMapToolAddFeature *>( mMapTools.mAddFeature ), mMapCanvas );
mMapTools.mEllipseCenter2Points->setAction( mActionEllipseCenter2Points );
mMapTools.mEllipseCenterPoint = new QgsMapToolEllipseCenterPoint( dynamic_cast<QgsMapToolAddFeature *>( mMapTools.mAddFeature ), mMapCanvas );
Expand Down Expand Up @@ -7905,6 +7912,11 @@ void QgisApp::circleCenterPoint()
mMapCanvas->setMapTool( mMapTools.mCircleCenterPoint );
}

void QgisApp::circle3Tangents()
{
mMapCanvas->setMapTool( mMapTools.mCircle3Tangents );
}

void QgisApp::ellipseCenter2Points()
{
mMapCanvas->setMapTool( mMapTools.mEllipseCenter2Points );
Expand Down Expand Up @@ -11237,6 +11249,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )
mActionCircle2Points->setEnabled( false );
mActionCircle3Points->setEnabled( false );
mActionCircleCenterPoint->setEnabled( false );
mActionCircle3Tangents->setEnabled( false );
mActionEllipseCenter2Points->setEnabled( false );
mActionEllipseCenterPoint->setEnabled( false );
mActionEllipseExtent->setEnabled( false );
Expand Down Expand Up @@ -11387,6 +11400,8 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )
&& ( vlayer->geometryType() == QgsWkbTypes::LineGeometry || vlayer->geometryType() == QgsWkbTypes::PolygonGeometry ) );
mActionCircleCenterPoint->setEnabled( isEditable && ( canAddFeatures || canChangeGeometry )
&& ( vlayer->geometryType() == QgsWkbTypes::LineGeometry || vlayer->geometryType() == QgsWkbTypes::PolygonGeometry ) );
mActionCircle3Tangents->setEnabled( isEditable && ( canAddFeatures || canChangeGeometry )
&& ( vlayer->geometryType() == QgsWkbTypes::LineGeometry || vlayer->geometryType() == QgsWkbTypes::PolygonGeometry ) );
mActionEllipseCenter2Points->setEnabled( isEditable && ( canAddFeatures || canChangeGeometry )
&& ( vlayer->geometryType() == QgsWkbTypes::LineGeometry || vlayer->geometryType() == QgsWkbTypes::PolygonGeometry ) );
mActionEllipseCenterPoint->setEnabled( isEditable && ( canAddFeatures || canChangeGeometry )
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -1215,6 +1215,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void circle3Points();
//! activates the add circle from center and radius tool
void circleCenterPoint();
//! activates the add circle from 3 tangents tool
void circle3Tangents();
//! activates the add ellipse from center and 2 points tool
void ellipseCenter2Points();
//! activates the add ellipse from center point tool
Expand Down Expand Up @@ -1799,6 +1801,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
, mCircle2Points( nullptr )
, mCircle3Points( nullptr )
, mCircleCenterPoint( nullptr )
, mCircle3Tangents( nullptr )
, mEllipseCenter2Points( nullptr )
, mEllipseCenterPoint( nullptr )
, mEllipseExtent( nullptr )
Expand Down Expand Up @@ -1857,6 +1860,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QgsMapTool *mCircle2Points = nullptr;
QgsMapTool *mCircle3Points = nullptr;
QgsMapTool *mCircleCenterPoint = nullptr;
QgsMapTool *mCircle3Tangents = nullptr;
QgsMapTool *mEllipseCenter2Points = nullptr;
QgsMapTool *mEllipseCenterPoint = nullptr;
QgsMapTool *mEllipseExtent = nullptr;
Expand Down
70 changes: 70 additions & 0 deletions src/app/qgsmaptoolcircle3tangents.cpp
@@ -0,0 +1,70 @@
/***************************************************************************
qgsmaptoolcircle3tangents.h - map tool for adding circle
from 3 tangents
---------------------
begin : July 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsmaptoolcircle3tangents.h"
#include "qgsgeometryrubberband.h"
#include "qgslinestring.h"
#include "qgsmapcanvas.h"
#include "qgspoint.h"
#include <QMouseEvent>

QgsMapToolCircle3Tangents::QgsMapToolCircle3Tangents( QgsMapToolCapture *parentTool,
QgsMapCanvas *canvas, CaptureMode mode )
: QgsMapToolAddCircle( parentTool, canvas, mode )
{
}

QgsMapToolCircle3Tangents::~QgsMapToolCircle3Tangents()
{
}

void QgsMapToolCircle3Tangents::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
{

QList<QgsPointXY> segment = e->snapSegment( QgsMapMouseEvent::SnapProjectConfig );

if ( e->button() == Qt::LeftButton )
{
if ( ( mPoints.size() <= 2 * 2 ) )
{
mPoints.append( QgsPoint( segment.at( 0 ) ) );
mPoints.append( QgsPoint( segment.at( 1 ) ) );


}

if ( !mPoints.isEmpty() )
{
if ( !mTempRubberBand )
{
mTempRubberBand = createGeometryRubberBand( ( mode() == CapturePolygon ) ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true );
mTempRubberBand->show();
}
}
}
else if ( e->button() == Qt::RightButton )
{
if ( !segment.empty() && ( mPoints.size() == 6 ) )
{
mCircle = QgsCircle().from3Tangents( mPoints.at( 0 ), mPoints.at( 1 ), mPoints.at( 2 ), mPoints.at( 3 ), mPoints.at( 4 ), mPoints.at( 5 ) );
}
deactivate();
if ( mParentTool )
{
mParentTool->canvasReleaseEvent( e );
}
}
}
33 changes: 33 additions & 0 deletions src/app/qgsmaptoolcircle3tangents.h
@@ -0,0 +1,33 @@
/***************************************************************************
qgsmaptoolcircle3tangents.h - map tool for adding circle
from 3 tangents
---------------------
begin : July 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 QGSMAPTOOLCIRCLE3TANGENTS_H
#define QGSMAPTOOLCIRCLE3TANGENTS_H

#include "qgsmaptooladdcircle.h"

class QgsMapToolCircle3Tangents: public QgsMapToolAddCircle
{
Q_OBJECT

public:
QgsMapToolCircle3Tangents( QgsMapToolCapture *parentTool, QgsMapCanvas *canvas, CaptureMode mode = CaptureLine );
~QgsMapToolCircle3Tangents();

void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;
};

#endif // QGSMAPTOOLCIRCLE3TANGENTS_H
16 changes: 16 additions & 0 deletions src/ui/qgisapp.ui
Expand Up @@ -279,6 +279,7 @@
<addaction name="mActionCircle2Points"/>
<addaction name="mActionCircle3Points"/>
<addaction name="mActionCircleCenterPoint"/>
<addaction name="mActionCircle3Tangents"/>
</widget>
<widget class="QMenu" name="mMenuEllipse">
<property name="title">
Expand Down Expand Up @@ -2897,6 +2898,21 @@ Acts on currently active editable layer</string>
<string>Add regular polygon from 2 points</string>
</property>
</action>
<action name="mActionCircle3Tangents">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionCircle3Tangents.svg</normaloff>:/images/themes/default/mActionCircle3Tangents.svg</iconset>
</property>
<property name="text">
<string>Add Circle from 3 Tangents</string>
</property>
<property name="toolTip">
<string>Add circle from 3 tangents</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>
Expand Down

0 comments on commit c66b893

Please sign in to comment.