Skip to content
Permalink
Browse files

centerpoint-rubberband works w/ maptool circular by radius

  • Loading branch information
SebDieBln committed Dec 21, 2015
1 parent 931b3d1 commit 3cd93831a1d6b847295730154ad75a83fd56e9d1
Showing with 51 additions and 48 deletions.
  1. +50 −47 src/app/qgsmaptoolcircularstringradius.cpp
  2. +1 −1 src/app/qgsmaptoolcircularstringradius.h
@@ -29,7 +29,6 @@ QgsMapToolCircularStringRadius::QgsMapToolCircularStringRadius( QgsMapToolCaptur
: QgsMapToolAddCircularString( parentTool, canvas, mode ),
mTemporaryEndPointX( 0.0 ),
mTemporaryEndPointY( 0.0 ),
mRadiusMode( false ),
mRadius( 0.0 ),
mRadiusSpinBox( nullptr )
{
@@ -41,6 +40,12 @@ QgsMapToolCircularStringRadius::~QgsMapToolCircularStringRadius()

}

void QgsMapToolCircularStringRadius::deactivate()
{
deleteRadiusSpinBox();
QgsMapToolAddCircularString::deactivate();
}

void QgsMapToolCircularStringRadius::cadCanvasReleaseEvent( QgsMapMouseEvent* e )
{
QgsPointV2 mapPoint( e->mapPoint().x(), e->mapPoint().y() );
@@ -50,45 +55,41 @@ void QgsMapToolCircularStringRadius::cadCanvasReleaseEvent( QgsMapMouseEvent* e
if ( mPoints.isEmpty() )
{
mPoints.append( mapPoint );
return;
}

if ( mPoints.size() % 2 == 1 )
else
{
if ( !mRadiusMode )
if ( mPoints.size() % 2 )
{
mTemporaryEndPointX = mapPoint.x();
mTemporaryEndPointY = mapPoint.y();

//initial radius is distance( tempPoint - mPoints.last ) / 2.0
double minRadius = sqrt( QgsGeometryUtils::sqrDistance2D( mPoints.last(), QgsPointV2( mTemporaryEndPointX, mTemporaryEndPointY ) ) ) / 2.0;
mRadius = minRadius + minRadius / 10.0;
createRadiusSpinBox();
if ( mRadiusSpinBox )
{
mRadiusSpinBox->setMinimum( minRadius );
}
}
else
{

QgsPointV2 result;
if ( QgsGeometryUtils::segmentMidPoint( mPoints.last(), QgsPointV2( mTemporaryEndPointX, mTemporaryEndPointY ), result, mRadius, QgsPointV2( mapPoint.x(), mapPoint.y() ) ) )
{
mPoints.append( result );
mPoints.append( QgsPointV2( mTemporaryEndPointX, mTemporaryEndPointY ) );
createRadiusSpinBox();
if ( mRadiusSpinBox )
{
mRadiusSpinBox->setMinimum( minRadius );
}
}
}
else
{
mPoints.append( QgsPointV2( mTemporaryEndPointX, mTemporaryEndPointY ) );
deleteRadiusSpinBox();
}
mRadiusMode = !mRadiusMode;
recalculateCircularString();
}
else
{
//can we get there?
}
}
else if ( e->button() == Qt::RightButton )
{
if ( !( mPoints.size() % 2 ) )
mPoints.removeLast();
deactivate();
if ( mParentTool )
{
@@ -99,46 +100,48 @@ void QgsMapToolCircularStringRadius::cadCanvasReleaseEvent( QgsMapMouseEvent* e

void QgsMapToolCircularStringRadius::cadCanvasMoveEvent( QgsMapMouseEvent* e )
{
if ( !mPoints.isEmpty() && mRadiusMode )
if ( !mPoints.isEmpty() )
{
mLastMouseMapPos.setX( e->mapPoint().x() );
mLastMouseMapPos.setY( e->mapPoint().y() );
recalculateCircularString();
}
if ( !mPoints.isEmpty() && !mRadiusMode )
{
delete mTempRubberBand;
mTempRubberBand = createGeometryRubberBand(( mode() == CapturePolygon ) ? QGis::Polygon : QGis::Line, true );
QgsCircularStringV2* cString = new QgsCircularStringV2();
QList<QgsPointV2> rubberBandPoints;
rubberBandPoints.append( mPoints.last() );
rubberBandPoints.append( QgsPointV2( e->mapPoint() ) );
cString->setPoints( rubberBandPoints );
mTempRubberBand->setGeometry( cString );
mTempRubberBand->show();
updateCenterPointRubberBand( QgsPointV2( mTemporaryEndPointX, mTemporaryEndPointY ) );
}
}

void QgsMapToolCircularStringRadius::recalculateCircularString()
{
QgsCircularStringV2* cString2 = new QgsCircularStringV2();
cString2->setPoints( mPoints );
delete mRubberBand;
mRubberBand = createGeometryRubberBand(( mode() == CapturePolygon ) ? QGis::Polygon : QGis::Line );
mRubberBand->setGeometry( cString2 );
mRubberBand->show();

//new midpoint on circle segment
QgsPointV2 midPoint;
if ( !QgsGeometryUtils::segmentMidPoint( mPoints.last(), QgsPointV2( mTemporaryEndPointX, mTemporaryEndPointY ), midPoint, mRadius,
mLastMouseMapPos ) )
if ( mPoints.size() >= 3 )
{
return;
QgsCircularStringV2* cString = new QgsCircularStringV2();
int rubberBandSize = mPoints.size() - ( mPoints.size() + 1 ) % 2;
cString->setPoints( mPoints.mid( 0, rubberBandSize ) );
delete mRubberBand;
mRubberBand = createGeometryRubberBand(( mode() == CapturePolygon ) ? QGis::Polygon : QGis::Line );
mRubberBand->setGeometry( cString );
mRubberBand->show();
}

QList<QgsPointV2> rubberBandPoints = mPoints;
rubberBandPoints.append( midPoint );
rubberBandPoints.append( QgsPointV2( mTemporaryEndPointX, mTemporaryEndPointY ) );
QList<QgsPointV2> rubberBandPoints;
if ( !( mPoints.size() % 2 ) )
{
//recalculate midpoint on circle segment
QgsPointV2 midPoint;
if ( !QgsGeometryUtils::segmentMidPoint( mPoints.at( mPoints.size() - 2 ), QgsPointV2( mTemporaryEndPointX, mTemporaryEndPointY ), midPoint, mRadius,
mLastMouseMapPos ) )
{
return;
}
mPoints.replace( mPoints.size() - 1, midPoint );
rubberBandPoints.append( mPoints.at( mPoints.size() - 2 ) );
rubberBandPoints.append( mPoints.last() );
rubberBandPoints.append( QgsPointV2( mTemporaryEndPointX, mTemporaryEndPointY ) );
}
else
{
rubberBandPoints.append( mPoints.last() );
rubberBandPoints.append( mLastMouseMapPos );
}
QgsCircularStringV2* cString = new QgsCircularStringV2();
cString->setPoints( rubberBandPoints );
delete mTempRubberBand;
@@ -31,14 +31,14 @@ class QgsMapToolCircularStringRadius: public QgsMapToolAddCircularString

virtual void cadCanvasReleaseEvent( QgsMapMouseEvent* e ) override;
virtual void cadCanvasMoveEvent( QgsMapMouseEvent* e ) override;
virtual void deactivate() override;

private slots:
void updateRadiusFromSpinBox( double radius );

private:
double mTemporaryEndPointX;
double mTemporaryEndPointY;
bool mRadiusMode;
double mRadius;
QgsPointV2 mLastMouseMapPos;
QDoubleSpinBox* mRadiusSpinBox;

0 comments on commit 3cd9383

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