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
219265void 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
314362void QgsMapToolCapture::closePolygon ()
315363{
316- mCaptureList . append ( mCaptureList [ 0 ] );
364+ mCaptureCurve . close ( );
317365}
318366
319367void 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+ }
0 commit comments