29 , mControlPolygonRubberBand( std::make_unique<
QgsRubberBand>( mapCanvas,
Qgis::GeometryType::Line ) )
31 setVertexDrawingEnabled(
false );
34 mControlPolygonRubberBand->setColor( QColor( 100, 100, 100, 150 ) );
35 mControlPolygonRubberBand->setWidth( 1 );
36 mControlPolygonRubberBand->setLineStyle( Qt::DashLine );
37 mControlPolygonRubberBand->setVisible(
false );
40QgsMapToolCaptureRubberBand::~QgsMapToolCaptureRubberBand() =
default;
42QgsCurve *QgsMapToolCaptureRubberBand::curve()
44 if ( mPoints.empty() )
47 switch ( mStringType )
53 if ( mPoints.size() != 3 )
62 if ( mPoints.size() < 4 )
64 return createNurbsCurve();
71bool QgsMapToolCaptureRubberBand::curveIsComplete()
const
84 mFirstPolygonPoint = firstPolygonPoint;
85 setStringType( stringType );
86 setRubberBandGeometryType( geomType );
89void QgsMapToolCaptureRubberBand::setRubberBandGeometryType(
Qgis::GeometryType geomType )
95void QgsMapToolCaptureRubberBand::addPoint(
const QgsPoint &point,
bool doUpdate )
97 if ( mPoints.size() == 0 )
99 mPoints.append( point );
100 mWeights.append( 1.0 );
103 mPoints.append( point );
104 mWeights.append( 1.0 );
110void QgsMapToolCaptureRubberBand::movePoint(
const QgsPoint &point )
112 if ( mPoints.size() > 0 )
113 mPoints.last() = point;
118void QgsMapToolCaptureRubberBand::movePoint(
int index,
const QgsPoint &point )
120 if ( mPoints.size() > 0 && mPoints.size() > index )
121 mPoints[index] = point;
126int QgsMapToolCaptureRubberBand::pointsCount()
const
128 return mPoints.size();
136void QgsMapToolCaptureRubberBand::setStringType(
Qgis::WkbType type )
144 mPoints.removeAt( 1 );
151QgsPoint QgsMapToolCaptureRubberBand::lastPoint()
const
153 if ( mPoints.empty() )
156 return mPoints.last();
159QgsPoint QgsMapToolCaptureRubberBand::pointFromEnd(
int posFromEnd )
const
161 if ( posFromEnd < mPoints.size() )
162 return mPoints.at( mPoints.size() - 1 - posFromEnd );
167void QgsMapToolCaptureRubberBand::removeLastPoint()
169 if ( mPoints.size() > 1 )
171 mPoints.removeLast();
172 if ( !mWeights.isEmpty() )
173 mWeights.removeLast();
184void QgsMapToolCaptureRubberBand::updateCurve()
186 std::unique_ptr<QgsCurve> curve;
187 switch ( mStringType )
190 curve.reset( createLinearString() );
193 curve.reset( createCircularString() );
196 curve.reset( createNurbsCurve() );
205 auto geom = std::make_unique<QgsCurvePolygon>();
206 geom->setExteriorRing( curve.release() );
207 setGeometry( geom.release() );
211 setGeometry( curve.release() );
215 updateControlPolygon();
218QgsCurve *QgsMapToolCaptureRubberBand::createLinearString()
220 auto curve = std::make_unique<QgsLineString>();
224 points.prepend( mFirstPolygonPoint );
225 curve->setPoints( points );
228 curve->setPoints( mPoints );
230 return curve.release();
233QgsCurve *QgsMapToolCaptureRubberBand::createCircularString()
235 auto curve = std::make_unique<QgsCircularString>();
236 curve->setPoints( mPoints );
240 auto polygonCurve = std::make_unique<QgsCompoundCurve>();
241 polygonCurve->addVertex( mFirstPolygonPoint );
242 if ( !mPoints.empty() )
243 polygonCurve->addVertex( mPoints.first() );
244 polygonCurve->addCurve( curve.release() );
245 return polygonCurve.release();
248 return curve.release();
251QgsCurve *QgsMapToolCaptureRubberBand::createNurbsCurve()
257 controlPoints.prepend( mFirstPolygonPoint );
259 controlPoints.append( mFirstPolygonPoint );
264 const int n = controlPoints.size();
267 if ( n < degree + 1 )
270 degree = std::max( 1, n - 1 );
281 QVector<double> weights;
285 weights.append( 1.0 );
286 weights.append( mWeights );
288 weights.append( 1.0 );
295 while ( weights.size() < n )
296 weights.append( 1.0 );
299 auto curve = std::make_unique<QgsNurbsCurve>( controlPoints, degree, knots, weights );
304 auto polygonCurve = std::make_unique<QgsCompoundCurve>();
305 polygonCurve->addCurve( curve.release() );
306 return polygonCurve.release();
309 return curve.release();
312void QgsMapToolCaptureRubberBand::updateControlPolygon()
314 if ( !mControlPolygonRubberBand )
321 mControlPolygonRubberBand->setVisible(
false );
331 controlPoints.prepend( mFirstPolygonPoint );
334 for (
const QgsPoint &pt : std::as_const( controlPoints ) )
336 mControlPolygonRubberBand->addPoint(
QgsPointXY( pt ) );
339 mControlPolygonRubberBand->setVisible(
true );
342double QgsMapToolCaptureRubberBand::weight(
int index )
const
344 if ( index < 0 || index >= mWeights.size() )
346 return mWeights[index];
349bool QgsMapToolCaptureRubberBand::setWeight(
int index,
double weight )
351 if ( index < 0 || index >= mWeights.size() )
356 mWeights[index] = weight;
Provides global constants and enumerations for use throughout the application.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
WkbType
The WKB type describes the number of dimensions a geometry has.
@ CircularString
CircularString.
Abstract base class for all geometries.
virtual void clear()=0
Clears the geometry, ie reset it to a null geometry.
Circular string geometry type.
Abstract base class for curved geometry type.
A rubberband class for QgsAbstractGeometry (considering curved geometries).
void setGeometryType(Qgis::GeometryType geometryType)
Sets which geometry is handled by the rubber band, polygon or line.
virtual void setGeometry(QgsAbstractGeometry *geom)
Sets geometry (takes ownership). Geometry is expected to be in map coordinates.
Line string geometry type, with support for z-dimension and m-values.
Map canvas is a class for displaying all GIS data types on a canvas.
static QVector< double > generateUniformKnots(int numControlPoints, int degree)
Generates a uniform clamped knot vector for a NURBS curve.
Point geometry type, with support for z-dimension and m-values.
Responsible for drawing transient features (e.g.
static const QgsSettingsEntryInteger * settingsDigitizingNurbsDegree
Settings entry digitizing NURBS curve degree.
static Q_INVOKABLE bool isNurbsType(Qgis::WkbType type)
Returns true if the WKB type is a NURBS curve type.
QVector< QgsPoint > QgsPointSequence