Skip to content
Permalink
Browse files

Add circle from 3 tangents

  • Loading branch information
lbartoletti committed Aug 2, 2017
1 parent 9a9cf3c commit c66b89391bc95f78a057408cc9a2c283bbdbcc96
@@ -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>
@@ -0,0 +1,116 @@
<?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="mActionCircle3Tangents.svg"
inkscape:version="0.92.1 r15371">
<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="1680"
inkscape:window-height="991"
id="namedview4018"
showgrid="false"
inkscape:zoom="31.083333"
inkscape:cx="6.1229429"
inkscape:cy="16.341225"
inkscape:window-x="0"
inkscape:window-y="0"
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="g4540">
<circle
r="7.430634"
style="fill:none;stroke:#8cbe8c;stroke-width:3.13873196;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
cy="11"
cx="10"
id="path4032" />
<g
transform="translate(33)"
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
inkscape:connector-curvature="0"
id="path4501"
d="M 1.1262266,9.8675838 7.8496448,2.1602508"
style="fill:none;stroke:#8c8c8c;stroke-width:3.139;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path
inkscape:connector-curvature="0"
id="path4501-3"
d="m 1.3903014,13.335342 7.707333,6.723419"
style="fill:none;stroke:#8c8c8c;stroke-width:3.13899994;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path
inkscape:connector-curvature="0"
id="path4501-6"
d="m 11.427835,2.3970039 7.707332,6.723418"
style="fill:none;stroke:#8c8c8c;stroke-width:3.13899994;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
</svg>
@@ -136,6 +136,7 @@ SET(QGIS_APP_SRCS
qgsmaptoolcircle2points.cpp
qgsmaptoolcircle3points.cpp
qgsmaptoolcirclecenterpoint.cpp
qgsmaptoolcircle3tangents.cpp
qgsmaptooladdellipse.cpp
qgsmaptoolellipsefoci.cpp
qgsmaptoolellipseextent.cpp
@@ -306,6 +307,7 @@ SET (QGIS_APP_MOC_HDRS
qgsmaptoolcircle2points.h
qgsmaptoolcircle3points.h
qgsmaptoolcirclecenterpoint.h
qgsmaptoolcircle3tangents.h
qgsmaptooladdellipse.h
qgsmaptoolellipsefoci.h
qgsmaptoolellipseextent.h
@@ -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"
@@ -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;
@@ -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 );
@@ -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 );
@@ -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 );
@@ -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 );
@@ -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 );
@@ -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 );
@@ -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 )
@@ -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
@@ -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 )
@@ -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;
@@ -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 );
}
}
}
@@ -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
@@ -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">
@@ -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"/>

0 comments on commit c66b893

Please sign in to comment.
You can’t perform that action at this time.