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 )
58 if ( mPoints.size() < 4 )
60 return createNurbsCurve();
67bool QgsMapToolCaptureRubberBand::curveIsComplete()
const
79 mFirstPolygonPoint = firstPolygonPoint;
80 setStringType( stringType );
81 setRubberBandGeometryType( geomType );
84void QgsMapToolCaptureRubberBand::setRubberBandGeometryType(
Qgis::GeometryType geomType )
90void QgsMapToolCaptureRubberBand::addPoint(
const QgsPoint &point,
bool doUpdate )
92 if ( mPoints.size() == 0 )
94 mPoints.append( point );
95 mWeights.append( 1.0 );
98 mPoints.append( point );
99 mWeights.append( 1.0 );
105void QgsMapToolCaptureRubberBand::movePoint(
const QgsPoint &point )
107 if ( mPoints.size() > 0 )
108 mPoints.last() = point;
113void QgsMapToolCaptureRubberBand::movePoint(
int index,
const QgsPoint &point )
115 if ( mPoints.size() > 0 && mPoints.size() > index )
116 mPoints[index] = point;
121int QgsMapToolCaptureRubberBand::pointsCount()
const
123 return mPoints.size();
131void QgsMapToolCaptureRubberBand::setStringType(
Qgis::WkbType type )
139 mPoints.removeAt( 1 );
146QgsPoint QgsMapToolCaptureRubberBand::lastPoint()
const
148 if ( mPoints.empty() )
151 return mPoints.last();
154QgsPoint QgsMapToolCaptureRubberBand::pointFromEnd(
int posFromEnd )
const
156 if ( posFromEnd < mPoints.size() )
157 return mPoints.at( mPoints.size() - 1 - posFromEnd );
162void QgsMapToolCaptureRubberBand::removeLastPoint()
164 if ( mPoints.size() > 1 )
166 mPoints.removeLast();
167 if ( !mWeights.isEmpty() )
168 mWeights.removeLast();
179void QgsMapToolCaptureRubberBand::updateCurve()
181 std::unique_ptr<QgsCurve> curve;
182 switch ( mStringType )
185 curve.reset( createLinearString() );
188 curve.reset( createCircularString() );
191 curve.reset( createNurbsCurve() );
200 auto geom = std::make_unique<QgsCurvePolygon>();
201 geom->setExteriorRing( curve.release() );
202 setGeometry( geom.release() );
206 setGeometry( curve.release() );
210 updateControlPolygon();
213QgsCurve *QgsMapToolCaptureRubberBand::createLinearString()
215 auto curve = std::make_unique<QgsLineString>();
219 points.prepend( mFirstPolygonPoint );
220 curve->setPoints( points );
223 curve->setPoints( mPoints );
225 return curve.release();
228QgsCurve *QgsMapToolCaptureRubberBand::createCircularString()
230 auto curve = std::make_unique<QgsCircularString>();
231 curve->setPoints( mPoints );
235 auto polygonCurve = std::make_unique<QgsCompoundCurve>();
236 polygonCurve->addVertex( mFirstPolygonPoint );
237 if ( !mPoints.empty() )
238 polygonCurve->addVertex( mPoints.first() );
239 polygonCurve->addCurve( curve.release() );
240 return polygonCurve.release();
243 return curve.release();
246QgsCurve *QgsMapToolCaptureRubberBand::createNurbsCurve()
252 controlPoints.prepend( mFirstPolygonPoint );
254 controlPoints.append( mFirstPolygonPoint );
259 const int n = controlPoints.size();
262 if ( n < degree + 1 )
265 degree = std::max( 1, n - 1 );
276 QVector<double> weights;
280 weights.append( 1.0 );
281 weights.append( mWeights );
283 weights.append( 1.0 );
290 while ( weights.size() < n )
291 weights.append( 1.0 );
294 auto curve = std::make_unique<QgsNurbsCurve>( controlPoints, degree, knots, weights );
299 auto polygonCurve = std::make_unique<QgsCompoundCurve>();
300 polygonCurve->addCurve( curve.release() );
301 return polygonCurve.release();
304 return curve.release();
307void QgsMapToolCaptureRubberBand::updateControlPolygon()
309 if ( !mControlPolygonRubberBand )
316 mControlPolygonRubberBand->setVisible(
false );
326 controlPoints.prepend( mFirstPolygonPoint );
329 for (
const QgsPoint &pt : std::as_const( controlPoints ) )
331 mControlPolygonRubberBand->addPoint(
QgsPointXY( pt ) );
334 mControlPolygonRubberBand->setVisible(
true );
337double QgsMapToolCaptureRubberBand::weight(
int index )
const
339 if ( index < 0 || index >= mWeights.size() )
341 return mWeights[index];
344bool QgsMapToolCaptureRubberBand::setWeight(
int index,
double weight )
346 if ( index < 0 || index >= mWeights.size() )
351 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