Skip to content

Commit 9b31f34

Browse files
committed
Use compound curve in capture tool to store captured geometry
1 parent 45d4dbe commit 9b31f34

File tree

2 files changed

+95
-15
lines changed

2 files changed

+95
-15
lines changed

src/app/qgsmaptoolcapture.cpp

Lines changed: 87 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
#include "qgscursors.h"
2020
#include "qgsgeometryvalidator.h"
2121
#include "qgslayertreeview.h"
22+
#include "qgslinestringv2.h"
2223
#include "qgslogger.h"
2324
#include "qgsmapcanvas.h"
2425
#include "qgsmapmouseevent.h"
2526
#include "qgsmaprenderer.h"
27+
#include "qgspolygonv2.h"
2628
#include "qgsrubberband.h"
2729
#include "qgsvectorlayer.h"
2830
#include "qgsvertexmarker.h"
@@ -188,7 +190,7 @@ int QgsMapToolCapture::addVertex( const QgsPoint& point )
188190
mRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QGis::Polygon : QGis::Line );
189191
}
190192
mRubberBand->addPoint( point );
191-
mCaptureList.append( layerPoint );
193+
mCaptureCurve.addVertex( QgsPointV2( layerPoint.x(), layerPoint.y() ) );
192194

193195
if ( !mTempRubberBand )
194196
{
@@ -215,14 +217,58 @@ int QgsMapToolCapture::addVertex( const QgsPoint& point )
215217
return 0;
216218
}
217219

220+
int QgsMapToolCapture::addCurve( QgsCurveV2* c )
221+
{
222+
return 1; //todo...
223+
224+
#if 0
225+
if ( !c )
226+
{
227+
return 1;
228+
}
229+
230+
if ( !mRubberBand )
231+
{
232+
mRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QGis::Polygon : QGis::Line );
233+
}
234+
235+
QgsLineStringV2* lineString = c->curveToLine();
236+
QList<QgsPointV2> linePoints;
237+
lineString->points( linePoints );
238+
delete lineString;
239+
QList<QgsPointV2>::const_iterator ptIt = linePoints.constBegin();
240+
for ( ; ptIt != linePoints.constEnd(); ++ptIt )
241+
{
242+
mRubberBand->addPoint( QgsPoint( ptIt->x(), ptIt->y() ) );
243+
}
244+
245+
if ( !mTempRubberBand )
246+
{
247+
mTempRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QGis::Polygon : QGis::Line, true );
248+
}
249+
else
250+
{
251+
mTempRubberBand->reset();
252+
}
253+
QgsPointV2 endPt = c->endPoint();
254+
mTempRubberBand->addPoint( QgsPoint( endPt.x(), endPt.y() ) ); //add last point of c
255+
256+
//const QgsCoordinateTransform* ct = mapCanvas()->mapSettings()->layerTransform( QgsMapLayer *layer ) const
257+
//c->transform( ct, QgsCoordinateTransform::ReverseTransform);
258+
//mCaptureCurve.addCurve( transformed curve );
259+
260+
return 0;
261+
#endif //0
262+
}
263+
218264

219265
void QgsMapToolCapture::undo()
220266
{
221267
if ( mRubberBand )
222268
{
223269
int rubberBandSize = mRubberBand->numberOfVertices();
224270
int tempRubberBandSize = mTempRubberBand->numberOfVertices();
225-
int captureListSize = mCaptureList.size();
271+
int captureListSize = size();
226272

227273
if ( rubberBandSize < 1 || captureListSize < 1 )
228274
{
@@ -244,7 +290,9 @@ void QgsMapToolCapture::undo()
244290
mTempRubberBand->reset( mCaptureMode == CapturePolygon ? true : false );
245291
}
246292

247-
mCaptureList.removeLast();
293+
QgsVertexId vertexToRemove;
294+
vertexToRemove.part = 0; vertexToRemove.ring = 0; vertexToRemove.vertex = size() - 1;
295+
mCaptureCurve.deleteVertex( vertexToRemove );
248296

249297
validateGeometry();
250298
}
@@ -298,7 +346,7 @@ void QgsMapToolCapture::stopCapturing()
298346
#endif
299347

300348
mCapturing = false;
301-
mCaptureList.clear();
349+
mCaptureCurve.clear();
302350
mCanvas->refresh();
303351
}
304352

@@ -313,7 +361,7 @@ void QgsMapToolCapture::deleteTempRubberBand()
313361

314362
void QgsMapToolCapture::closePolygon()
315363
{
316-
mCaptureList.append( mCaptureList[0] );
364+
mCaptureCurve.close();
317365
}
318366

319367
void QgsMapToolCapture::validateGeometry()
@@ -343,14 +391,18 @@ void QgsMapToolCapture::validateGeometry()
343391
case CapturePoint:
344392
return;
345393
case CaptureLine:
346-
if ( mCaptureList.size() < 2 )
394+
if ( size() < 2 )
347395
return;
348-
g = QgsGeometry::fromPolyline( mCaptureList.toVector() );
396+
g = new QgsGeometry( mCaptureCurve.curveToLine() );
349397
break;
350398
case CapturePolygon:
351-
if ( mCaptureList.size() < 3 )
399+
if ( size() < 3 )
352400
return;
353-
g = QgsGeometry::fromPolygon( QgsPolygon() << ( QgsPolyline() << mCaptureList.toVector() << mCaptureList[0] ) );
401+
QgsLineStringV2* exteriorRing = mCaptureCurve.curveToLine();
402+
exteriorRing->close();
403+
QgsPolygonV2* polygon = new QgsPolygonV2();
404+
polygon->setExteriorRing( exteriorRing );
405+
g = new QgsGeometry( polygon );
354406
break;
355407
}
356408

@@ -402,3 +454,29 @@ void QgsMapToolCapture::validationFinished()
402454
QStatusBar *sb = QgisApp::instance()->statusBar();
403455
sb->showMessage( tr( "Validation finished." ) );
404456
}
457+
458+
int QgsMapToolCapture::size()
459+
{
460+
return mCaptureCurve.numPoints();
461+
}
462+
463+
QList<QgsPoint> QgsMapToolCapture::points()
464+
{
465+
QList<QgsPointV2> pts;
466+
QList<QgsPoint> points;
467+
mCaptureCurve.points( pts );
468+
QgsGeometry::convertPointList( pts, points );
469+
return points;
470+
}
471+
472+
void QgsMapToolCapture::setPoints( const QList<QgsPoint>& pointList )
473+
{
474+
QList<QgsPointV2> pts;
475+
QgsGeometry::convertPointList( pointList, pts );
476+
477+
QgsLineStringV2* line = new QgsLineStringV2();
478+
line->setPoints( pts );
479+
480+
mCaptureCurve.clear();
481+
mCaptureCurve.addCurve( line );
482+
}

src/app/qgsmaptoolcapture.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919

2020
#include "qgsmaptooledit.h"
21+
#include "qgscompoundcurvev2.h"
2122
#include "qgspoint.h"
2223
#include "qgsgeometry.h"
2324

@@ -64,6 +65,9 @@ class APP_EXPORT QgsMapToolCapture : public QgsMapToolEdit
6465
@return 0 in case of success, 1 if current layer is not a vector layer, 2 if coordinate transformation failed*/
6566
int addVertex( const QgsPoint& point );
6667

68+
/** Adds a whole curve (e.g. circularstring) to the captured geometry. Curve must be in map CRS*/
69+
int addCurve( QgsCurveV2* c );
70+
6771
/** Removes the last vertex from mRubberBand and mCaptureList*/
6872
void undo();
6973

@@ -72,11 +76,9 @@ class APP_EXPORT QgsMapToolCapture : public QgsMapToolEdit
7276
void stopCapturing();
7377
void deleteTempRubberBand();
7478

75-
int size() { return mCaptureList.size(); }
76-
QList<QgsPoint>::iterator begin() { return mCaptureList.begin(); }
77-
QList<QgsPoint>::iterator end() { return mCaptureList.end(); }
78-
const QList<QgsPoint> &points() { return mCaptureList; }
79-
void setPoints( const QList<QgsPoint>& pointList ) { mCaptureList = pointList; }
79+
int size();
80+
QList<QgsPoint> points();
81+
void setPoints( const QList<QgsPoint>& pointList );
8082
void closePolygon();
8183

8284
private:
@@ -90,7 +92,7 @@ class APP_EXPORT QgsMapToolCapture : public QgsMapToolEdit
9092
QgsRubberBand* mTempRubberBand;
9193

9294
/** List to store the points of digitised lines and polygons (in layer coordinates)*/
93-
QList<QgsPoint> mCaptureList;
95+
QgsCompoundCurveV2 mCaptureCurve;
9496

9597
void validateGeometry();
9698
QString mTip;

0 commit comments

Comments
 (0)