Skip to content
Permalink
Browse files

Reborn of QgsMapToolCircle3Tangents. Thanks Martin!

  • Loading branch information
lbartoletti committed Oct 2, 2017
1 parent 27b075f commit 4c8171d7703c18981904a01f58097c692e9ece62
@@ -134,6 +134,7 @@ SET(QGIS_APP_SRCS
qgsmaptooladdcircle.cpp
qgsmaptoolcircle2points.cpp
qgsmaptoolcircle3points.cpp
qgsmaptoolcircle3tangents.cpp
qgsmaptoolcirclecenterpoint.cpp
qgsmaptooladdellipse.cpp
qgsmaptoolellipsefoci.cpp
@@ -308,6 +309,7 @@ SET (QGIS_APP_MOC_HDRS
qgsmaptooladdcircle.h
qgsmaptoolcircle2points.h
qgsmaptoolcircle3points.h
qgsmaptoolcircle3tangents.h
qgsmaptoolcirclecenterpoint.h
qgsmaptooladdellipse.h
qgsmaptoolellipsefoci.h
@@ -337,6 +337,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgsmaptoolcircularstringradius.h"
#include "qgsmaptoolcircle2points.h"
#include "qgsmaptoolcircle3points.h"
#include "qgsmaptoolcircle3tangents.h"
#include "qgsmaptoolcirclecenterpoint.h"
#include "qgsmaptoolellipsecenter2points.h"
#include "qgsmaptoolellipsecenterpoint.h"
@@ -1301,6 +1302,7 @@ QgisApp::~QgisApp()
delete mMapTools.mCircularStringRadius;
delete mMapTools.mCircle2Points;
delete mMapTools.mCircle3Points;
delete mMapTools.mCircle3Tangents;
delete mMapTools.mCircleCenterPoint;
delete mMapTools.mEllipseCenter2Points;
delete mMapTools.mEllipseCenterPoint;
@@ -1776,6 +1778,7 @@ void QgisApp::createActions()
connect( mActionCircularStringRadius, &QAction::triggered, this, &QgisApp::circularStringRadius );
connect( mActionCircle2Points, &QAction::triggered, this, &QgisApp::circle2Points );
connect( mActionCircle3Points, &QAction::triggered, this, &QgisApp::circle3Points );
connect( mActionCircle3Tangents, &QAction::triggered, this, &QgisApp::circle3Tangents );
connect( mActionCircleCenterPoint, &QAction::triggered, this, &QgisApp::circleCenterPoint );
connect( mActionEllipseCenter2Points, &QAction::triggered, this, &QgisApp::ellipseCenter2Points );
connect( mActionEllipseCenterPoint, &QAction::triggered, this, &QgisApp::ellipseCenterPoint );
@@ -2063,6 +2066,7 @@ void QgisApp::createActionGroups()
mMapToolGroup->addAction( mActionCircularStringRadius );
mMapToolGroup->addAction( mActionCircle2Points );
mMapToolGroup->addAction( mActionCircle3Points );
mMapToolGroup->addAction( mActionCircle3Tangents );
mMapToolGroup->addAction( mActionCircleCenterPoint );
mMapToolGroup->addAction( mActionEllipseCenter2Points );
mMapToolGroup->addAction( mActionEllipseCenterPoint );
@@ -2587,6 +2591,7 @@ void QgisApp::createToolBars()
tbAddCircle->setPopupMode( QToolButton::MenuButtonPopup );
tbAddCircle->addAction( mActionCircle2Points );
tbAddCircle->addAction( mActionCircle3Points );
tbAddCircle->addAction( mActionCircle3Tangents );
tbAddCircle->addAction( mActionCircleCenterPoint );
tbAddCircle->setDefaultAction( mActionCircle2Points );
connect( tbAddCircle, &QToolButton::triggered, this, &QgisApp::toolButtonActionTriggered );
@@ -3196,6 +3201,8 @@ void QgisApp::createCanvasTools()
mMapTools.mCircle2Points->setAction( mActionCircle2Points );
mMapTools.mCircle3Points = new QgsMapToolCircle3Points( dynamic_cast<QgsMapToolAddFeature *>( mMapTools.mAddFeature ), mMapCanvas );
mMapTools.mCircle3Points->setAction( mActionCircle3Points );
mMapTools.mCircle3Tangents = new QgsMapToolCircle3Tangents( dynamic_cast<QgsMapToolAddFeature *>( mMapTools.mAddFeature ), mMapCanvas );
mMapTools.mCircle3Tangents->setAction( mActionCircle3Tangents );
mMapTools.mCircleCenterPoint = new QgsMapToolCircleCenterPoint( dynamic_cast<QgsMapToolAddFeature *>( mMapTools.mAddFeature ), mMapCanvas );
mMapTools.mCircleCenterPoint->setAction( mActionCircleCenterPoint );
mMapTools.mEllipseCenter2Points = new QgsMapToolEllipseCenter2Points( dynamic_cast<QgsMapToolAddFeature *>( mMapTools.mAddFeature ), mMapCanvas );
@@ -7794,6 +7801,11 @@ void QgisApp::circle3Points()
mMapCanvas->setMapTool( mMapTools.mCircle3Points );
}

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

void QgisApp::circleCenterPoint()
{
mMapCanvas->setMapTool( mMapTools.mCircleCenterPoint );
@@ -11189,6 +11201,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )
mActionCircularStringRadius->setEnabled( false );
mActionCircle2Points->setEnabled( false );
mActionCircle3Points->setEnabled( false );
mActionCircle3Tangents->setEnabled( false );
mActionCircleCenterPoint->setEnabled( false );
mActionEllipseCenter2Points->setEnabled( false );
mActionEllipseCenterPoint->setEnabled( false );
@@ -11339,6 +11352,8 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )
&& ( vlayer->geometryType() == QgsWkbTypes::LineGeometry || vlayer->geometryType() == QgsWkbTypes::PolygonGeometry ) );
mActionCircle3Points->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 ) );
mActionCircleCenterPoint->setEnabled( isEditable && ( canAddFeatures || canChangeGeometry )
&& ( vlayer->geometryType() == QgsWkbTypes::LineGeometry || vlayer->geometryType() == QgsWkbTypes::PolygonGeometry ) );
mActionEllipseCenter2Points->setEnabled( isEditable && ( canAddFeatures || canChangeGeometry )
@@ -1227,6 +1227,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void circle2Points();
//! activates the add circle from 3 points tool
void circle3Points();
//! activates the add circle from 3 tangents tool
void circle3Tangents();
//! activates the add circle from center and radius tool
void circleCenterPoint();
//! activates the add ellipse from center and 2 points tool
@@ -1820,6 +1822,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QgsMapTool *mCircularStringRadius = nullptr;
QgsMapTool *mCircle2Points = nullptr;
QgsMapTool *mCircle3Points = nullptr;
QgsMapTool *mCircle3Tangents = nullptr;
QgsMapTool *mCircleCenterPoint = nullptr;
QgsMapTool *mEllipseCenter2Points = nullptr;
QgsMapTool *mEllipseCenterPoint = nullptr;
@@ -0,0 +1,88 @@
/***************************************************************************
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 "qgsadvanceddigitizingdockwidget.h"
#include "qgslinestring.h"
#include "qgssnappingutils.h"
#include "qgsmapcanvas.h"
#include "qgspoint.h"
#include "qgisapp.h"
#include <QMouseEvent>

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

void QgsMapToolCircle3Tangents::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
{

QgsPoint mapPoint( e->mapPoint() );
EdgesOnlyFilter filter;
QgsPointLocator::Match match = mCanvas->snappingUtils()->snapToMap( mapPoint, &filter );

QgsPointXY p1, p2;

if ( e->button() == Qt::LeftButton )
{
if ( match.isValid() && ( mPoints.size() <= 2 * 2 ) )
{
match.edgePoints( p1, p2 );
mPoints.append( QgsPoint( p1 ) );
mPoints.append( QgsPoint( p2 ) );
}
if ( !mPoints.isEmpty() )
{
if ( !mTempRubberBand )
{
mTempRubberBand = createGeometryRubberBand( ( mode() == CapturePolygon ) ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true );
mTempRubberBand->show();
}
std::unique_ptr<QgsLineString> line( new QgsLineString() );

line->addVertex( QgsPoint( p1 ) );
line->addVertex( QgsPoint( p2 ) );

mTempRubberBand->setGeometry( line.release() );
}
}
else if ( e->button() == Qt::RightButton )
{
if ( match.isValid() && ( mPoints.size() == 4 ) )
{

match.edgePoints( p1, p2 );
mPoints.append( QgsPoint( p1 ) );
mPoints.append( QgsPoint( p2 ) );
mCircle = QgsCircle().from3Tangents( mPoints.at( 0 ), mPoints.at( 1 ), mPoints.at( 2 ), mPoints.at( 3 ), mPoints.at( 4 ), mPoints.at( 5 ) );
if ( mCircle.isEmpty() )
{
QgisApp::instance()->messageBar()->pushMessage( tr( "Error" ), tr( "At least two segments are parallels" ), QgsMessageBar::WARNING, QgisApp::instance()->messageTimeout() );
mPoints.clear();
delete mTempRubberBand;
mTempRubberBand = nullptr;
}
}
deactivate();
if ( mParentTool )
{
mParentTool->canvasReleaseEvent( e );
}
}
}
@@ -0,0 +1,39 @@
/***************************************************************************
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 "qgspointlocator.h"
#include "qgsmaptooladdcircle.h"

struct EdgesOnlyFilter : public QgsPointLocator::MatchFilter
{
bool acceptMatch( const QgsPointLocator::Match &m ) override { return m.hasEdge(); }
};

class QgsMapToolCircle3Tangents: public QgsMapToolAddCircle
{
Q_OBJECT

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

void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;

};

#endif // QGSMAPTOOLCIRCLE3TANGENTS_H
@@ -278,6 +278,7 @@
</property>
<addaction name="mActionCircle2Points"/>
<addaction name="mActionCircle3Points"/>
<addaction name="mActionCircle3Tangents"/>
<addaction name="mActionCircleCenterPoint"/>
</widget>
<widget class="QMenu" name="mMenuEllipse">

0 comments on commit 4c8171d

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