-
-
Notifications
You must be signed in to change notification settings - Fork 285
Use curve to digitize Polylines/Polygons #5842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
qsavoye
wants to merge
8
commits into
opengisch:master
Choose a base branch
from
qsavoye:add-curve-digitize-feature
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d6c3dcb
Rubberbound replace vector of qgspoint by qgscompoundcurve
552ae46
add circular string to rubberbound during digitizing
723d9a8
add curve to reshape, split, erase, fill
a7ad6d7
reset rubberband on confirm or cancel
265d605
set curve edition only for curve geometry
1e31c5c
Do not use during freehand digitizing
fda9ab1
Merge commit '6573c1ddd93ce7d84f5f36d5f6b0148de33d337b' into remark-f…
f0e0aeb
Merge commit 'fda9ab1fc75480468c877309b6e2f0857a620e11' into add-curv…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,28 +24,39 @@ RubberbandModel::RubberbandModel( QObject *parent ) | |
| : QObject( parent ) | ||
| , mLayer( nullptr ) | ||
| { | ||
| mPointList.insert( 0, QgsPoint() ); | ||
| mCompoundCurve.addVertex( QgsPoint() ); | ||
| } | ||
|
|
||
| int RubberbandModel::vertexCount() const | ||
| { | ||
| return mPointList.size(); | ||
| return mCompoundCurve.vertexCount( 0, 0 ); | ||
| } | ||
|
|
||
| bool RubberbandModel::isEmpty() const | ||
| { | ||
| return mPointList.isEmpty(); | ||
| return mCompoundCurve.isEmpty(); | ||
| } | ||
|
|
||
| QVector<QgsPoint> RubberbandModel::vertices() const | ||
| { | ||
| return mPointList; | ||
| QgsVertexIterator vertexIterator = mCompoundCurve.curveToLine( QSettings().value( "/QField/Digitizing/CurveTolerance", true ).toDouble(), QgsAbstractGeometry::SegmentationToleranceType::MaximumDifference )->vertices(); | ||
|
|
||
|
|
||
| // Create an empty QVector<QgsPoint> | ||
| QVector<QgsPoint> points; | ||
|
|
||
| // Iterate over the vertices and add them to the vector | ||
| while ( vertexIterator.hasNext() ) | ||
| { | ||
| points.append( vertexIterator.next() ); | ||
| } | ||
| return points; | ||
| } | ||
|
|
||
| QVector<QgsPoint> RubberbandModel::verticesCopy( bool skipCurrentPoint ) const | ||
| { | ||
| QVector<QgsPoint> points; | ||
| for ( const QgsPoint &pt : mPointList ) | ||
| for ( const QgsPoint &pt : vertices() ) | ||
| { | ||
| points << QgsPoint( pt ); | ||
| } | ||
|
|
@@ -60,7 +71,7 @@ QgsPointSequence RubberbandModel::pointSequence( const QgsCoordinateReferenceSys | |
| QgsPointSequence sequence; | ||
| QgsCoordinateTransform ct( mCrs, crs, QgsProject::instance()->transformContext() ); | ||
|
|
||
| for ( const QgsPoint &pt : mPointList ) | ||
| for ( const QgsPoint &pt : vertices() ) | ||
| { | ||
| //crs transformation of XY | ||
| QgsPointXY p1 = ct.transform( pt.x(), pt.y() ); | ||
|
|
@@ -97,7 +108,7 @@ QVector<QgsPointXY> RubberbandModel::flatPointSequence( const QgsCoordinateRefer | |
|
|
||
| QgsCoordinateTransform ct( mCrs, crs, QgsProject::instance()->transformContext() ); | ||
|
|
||
| for ( const QgsPoint &pt : mPointList ) | ||
| for ( const QgsPoint &pt : vertices() ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above. |
||
| { | ||
| sequence.append( ct.transform( pt.x(), pt.y() ) ); | ||
| } | ||
|
|
@@ -107,9 +118,10 @@ QVector<QgsPointXY> RubberbandModel::flatPointSequence( const QgsCoordinateRefer | |
|
|
||
| void RubberbandModel::setVertex( int index, QgsPoint coordinate ) | ||
| { | ||
| if ( mPointList.at( index ) != coordinate ) | ||
| QgsVertexId id = QgsVertexId( 0, 0, index ); | ||
| if ( mCompoundCurve.vertexAt( id ) != coordinate ) | ||
| { | ||
| mPointList.replace( index, coordinate ); | ||
| mCompoundCurve.moveVertex( id, coordinate ); | ||
| emit vertexChanged( index ); | ||
| } | ||
| } | ||
|
|
@@ -118,7 +130,8 @@ void RubberbandModel::insertVertices( int index, int count ) | |
| { | ||
| for ( int i = 0; i < count; ++i ) | ||
| { | ||
| mPointList.insert( index, currentCoordinate() ); | ||
| QgsVertexId id = QgsVertexId( 0, 0, index ); | ||
| mCompoundCurve.insertVertex( id, currentCoordinate() ); | ||
| } | ||
|
|
||
| emit verticesInserted( index, count ); | ||
|
|
@@ -127,14 +140,23 @@ void RubberbandModel::insertVertices( int index, int count ) | |
|
|
||
| void RubberbandModel::removeVertices( int index, int count ) | ||
| { | ||
| if ( mPointList.size() <= 1 ) | ||
| if ( vertexCount() <= 1 ) | ||
| return; | ||
|
|
||
| mPointList.remove( index, count ); | ||
| for ( int i = 0; i < count; ++i ) | ||
| { | ||
| QgsVertexId id = QgsVertexId( 0, 0, index ); | ||
| mCompoundCurve.deleteVertex( id ); | ||
| } | ||
|
|
||
| if ( vertexCount() == 0 ) | ||
| { | ||
| mCompoundCurve.addVertex( QgsPoint() ); | ||
| } | ||
|
|
||
| if ( mCurrentCoordinateIndex >= mPointList.size() ) | ||
| if ( mCurrentCoordinateIndex >= vertexCount() ) | ||
| { | ||
| setCurrentCoordinateIndex( mPointList.size() - 1 ); | ||
| setCurrentCoordinateIndex( vertexCount() - 1 ); | ||
| } | ||
|
|
||
| emit verticesRemoved( index, count ); | ||
|
|
@@ -162,8 +184,8 @@ void RubberbandModel::setCurrentCoordinateIndex( int currentCoordinateIndex ) | |
| QgsPoint RubberbandModel::currentPoint( const QgsCoordinateReferenceSystem &crs, Qgis::WkbType wkbType ) const | ||
| { | ||
| QgsCoordinateTransform ct( mCrs, crs, QgsProject::instance()->transformContext() ); | ||
|
|
||
| QgsPoint currentPt = mPointList.at( mCurrentCoordinateIndex ); | ||
| QgsVertexId id = QgsVertexId( 0, 0, mCurrentCoordinateIndex ); | ||
| QgsPoint currentPt = mCompoundCurve.vertexAt( id ); | ||
| double x = currentPt.x(); | ||
| double y = currentPt.y(); | ||
| double z = QgsWkbTypes::hasZ( currentPt.wkbType() ) ? currentPt.z() : 0; | ||
|
|
@@ -195,67 +217,97 @@ QgsPoint RubberbandModel::currentPoint( const QgsCoordinateReferenceSystem &crs, | |
|
|
||
| QgsPoint RubberbandModel::currentCoordinate() const | ||
| { | ||
| return mPointList.value( mCurrentCoordinateIndex ); | ||
| QgsVertexId id = QgsVertexId( 0, 0, mCurrentCoordinateIndex ); | ||
| return mCompoundCurve.vertexAt( id ); | ||
| } | ||
|
|
||
| QgsPoint RubberbandModel::firstCoordinate() const | ||
| { | ||
| if ( mPointList.isEmpty() ) | ||
| if ( mCompoundCurve.isEmpty() ) | ||
| return QgsPoint(); | ||
|
|
||
| return mPointList.at( 0 ); | ||
| QgsVertexId id = QgsVertexId( 0, 0, 0 ); | ||
| return mCompoundCurve.vertexAt( id ); | ||
| } | ||
|
|
||
| QgsPoint RubberbandModel::lastCoordinate() const | ||
| { | ||
| if ( mPointList.isEmpty() ) | ||
| if ( mCompoundCurve.isEmpty() ) | ||
| return QgsPoint(); | ||
|
|
||
| return mPointList.at( mCurrentCoordinateIndex > 0 ? mCurrentCoordinateIndex - 1 : 0 ); | ||
| QgsVertexId id = QgsVertexId( 0, 0, mCurrentCoordinateIndex > 0 ? mCurrentCoordinateIndex - 1 : 0 ); | ||
| return mCompoundCurve.vertexAt( id ); | ||
| } | ||
|
|
||
| QgsPoint RubberbandModel::penultimateCoordinate() const | ||
| { | ||
| if ( mPointList.size() < 3 ) | ||
| if ( mCompoundCurve.vertexCount( 0, 0 ) < 3 ) | ||
| return QgsPoint(); | ||
|
|
||
| return mPointList.at( mCurrentCoordinateIndex > 1 ? mCurrentCoordinateIndex - 2 : 0 ); | ||
| QgsVertexId id = QgsVertexId( 0, 0, mCurrentCoordinateIndex > 1 ? mCurrentCoordinateIndex - 2 : 0 ); | ||
| return mCompoundCurve.vertexAt( id ); | ||
| } | ||
|
|
||
| void RubberbandModel::setCurrentCoordinate( const QgsPoint ¤tCoordinate ) | ||
| { | ||
| // play safe, but try to find out | ||
| // Q_ASSERT( mPointList.count() != 0 ); | ||
| if ( mPointList.count() == 0 ) | ||
| if ( mCompoundCurve.isEmpty() ) | ||
| return; | ||
|
|
||
| if ( mPointList.at( mCurrentCoordinateIndex ) == currentCoordinate ) | ||
| QgsVertexId id = QgsVertexId( 0, 0, mCurrentCoordinateIndex ); | ||
| if ( mCompoundCurve.vertexAt( id ) == currentCoordinate ) | ||
| return; | ||
|
|
||
| if ( mFrozen ) | ||
| return; | ||
|
|
||
| mPointList.replace( mCurrentCoordinateIndex, currentCoordinate ); | ||
| if ( mDuringCurveDrawing == false ) | ||
| { | ||
| mCompoundCurve.moveVertex( id, currentCoordinate ); | ||
| } | ||
| else | ||
| { | ||
| QgsCircularString *curve = new QgsCircularString( mLastStartCurvePoint, mLastMiddleCurvePoint, currentCoordinate ); | ||
| if ( mCompoundCurve.nCurves() != 0 ) | ||
| { | ||
| const QgsCurve *lastSegment = mCompoundCurve.curveAt( mCompoundCurve.nCurves() - 1 ); | ||
| if ( lastSegment->hasCurvedSegments() == true ) | ||
| { | ||
| mCompoundCurve.removeCurve( mCompoundCurve.nCurves() - 1 ); | ||
| } | ||
| else | ||
| { | ||
| if ( lastSegment->vertexCount( 0, 0 ) > 2 ) | ||
| { | ||
| removeVertices( mCurrentCoordinateIndex - 1, 1 ); | ||
| setCurrentCoordinateIndex( mCurrentCoordinateIndex + 1 ); | ||
| } | ||
| else | ||
| { | ||
| mCompoundCurve.removeCurve( mCompoundCurve.nCurves() - 1 ); | ||
| } | ||
| } | ||
| } | ||
| mCompoundCurve.addCurve( curve, true ); | ||
| } | ||
|
|
||
| if ( !mLayer || QgsWkbTypes::hasM( mLayer->wkbType() ) ) | ||
| { | ||
| if ( !std::isnan( mMeasureValue ) ) | ||
| { | ||
| if ( QgsWkbTypes::hasM( mPointList[mCurrentCoordinateIndex].wkbType() ) ) | ||
| if ( QgsWkbTypes::hasM( mCompoundCurve.vertexAt( id ).wkbType() ) ) | ||
| { | ||
| mPointList[mCurrentCoordinateIndex].setM( mMeasureValue ); | ||
| mCompoundCurve.vertexAt( id ).setM( mMeasureValue ); | ||
| } | ||
| else | ||
| { | ||
| mPointList[mCurrentCoordinateIndex].addMValue( mMeasureValue ); | ||
| mCompoundCurve.vertexAt( id ).addMValue( mMeasureValue ); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| mPointList[mCurrentCoordinateIndex].dropMValue(); | ||
| mCompoundCurve.vertexAt( id ).dropMValue(); | ||
| } | ||
| } | ||
|
|
||
| mCurrentCoordinate = currentCoordinate; | ||
| emit currentCoordinateChanged(); | ||
| emit vertexChanged( mCurrentCoordinateIndex ); | ||
| } | ||
|
|
@@ -295,7 +347,7 @@ void RubberbandModel::setMeasureValue( const double measureValue ) | |
| void RubberbandModel::addVertex() | ||
| { | ||
| // Avoid double vertices accidentally | ||
| if ( mPointList.size() > 1 && *( mPointList.end() - 1 ) == *( mPointList.end() - 2 ) ) | ||
| if ( mCompoundCurve.vertexCount( 0, 0 ) > 1 && currentCoordinate() == penultimateCoordinate() ) | ||
| { | ||
| return; | ||
| } | ||
|
|
@@ -314,11 +366,53 @@ void RubberbandModel::removeVertex() | |
| { | ||
| setCurrentCoordinateIndex( mCurrentCoordinateIndex - 1 ); | ||
| removeVertices( mCurrentCoordinateIndex + 1, 1 ); | ||
| if ( QSettings().value( "/QField/Digitizing/CurveEdition", true ).toBool() ) | ||
| { | ||
| mDuringCurveDrawing = !mDuringCurveDrawing; | ||
| if ( mDuringCurveDrawing == false ) | ||
| { | ||
| mCompoundCurve.addVertex( mCurrentCoordinate ); | ||
| setCurrentCoordinateIndex( vertexCount() - 1 ); | ||
| emit vertexCountChanged(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void RubberbandModel::addCurve() | ||
| { | ||
| mDuringCurveDrawing = false; | ||
| QgsCircularString *curve = new QgsCircularString( mLastStartCurvePoint, mLastMiddleCurvePoint, mCurrentCoordinate ); | ||
| if ( mCompoundCurve.nCurves() != 0 ) | ||
| { | ||
| mCompoundCurve.removeCurve( mCompoundCurve.nCurves() - 1 ); | ||
| } | ||
|
|
||
| mCompoundCurve.addCurve( curve, true ); | ||
| mCompoundCurve.addVertex( mCurrentCoordinate ); | ||
| setCurrentCoordinateIndex( vertexCount() - 1 ); | ||
| emit vertexCountChanged(); | ||
| } | ||
|
|
||
| void RubberbandModel::addMiddlePointCurve() | ||
| { | ||
| mDuringCurveDrawing = true; | ||
| mLastMiddleCurvePoint = currentCoordinate(); | ||
| mLastStartCurvePoint = lastCoordinate(); | ||
| setCurrentCoordinateIndex( mCurrentCoordinateIndex + 1 ); | ||
| } | ||
|
|
||
| void RubberbandModel::removeCurve() | ||
| { | ||
| } | ||
|
|
||
| void RubberbandModel::reset() | ||
| { | ||
| removeVertices( 0, mPointList.size() - 1 ); | ||
| mCompoundCurve.clear(); | ||
| mDuringCurveDrawing = false; | ||
| mCompoundCurve.addVertex( mCurrentCoordinate ); | ||
| emit verticesRemoved( 0, vertexCount() - 1 ); | ||
| setCurrentCoordinateIndex( 0 ); | ||
| emit vertexCountChanged(); | ||
| mFrozen = false; | ||
| emit frozenChanged(); | ||
| } | ||
|
|
@@ -331,7 +425,7 @@ void RubberbandModel::setDataFromGeometry( QgsGeometry geometry, const QgsCoordi | |
| QgsCoordinateTransform ct( crs, mCrs, QgsProject::instance()->transformContext() ); | ||
| geometry.transform( ct ); | ||
|
|
||
| mPointList.clear(); | ||
| mCompoundCurve.clear(); | ||
| const QgsAbstractGeometry *abstractGeom = geometry.constGet(); | ||
| if ( !abstractGeom ) | ||
| return; | ||
|
|
@@ -344,22 +438,22 @@ void RubberbandModel::setDataFromGeometry( QgsGeometry geometry, const QgsCoordi | |
| { | ||
| break; | ||
| } | ||
| mPointList << pt; | ||
| mCompoundCurve.addVertex( pt ); | ||
| } | ||
|
|
||
| // for polygons, remove the last vertex which is a duplicate of the first vertex | ||
| if ( geometry.type() == Qgis::GeometryType::Polygon ) | ||
| { | ||
| mPointList.removeLast(); | ||
| mCompoundCurve.removeDuplicateNodes(); | ||
| } | ||
|
|
||
| // insert the last point twice so the resutling rubberband's current coordinate property being modified (by e.g. | ||
| // the GNSS position) will not replace the last vertex from the passed geometry | ||
| mPointList << mPointList.last(); | ||
| mCompoundCurve.addVertex( mCompoundCurve.endPoint() ); | ||
|
|
||
| mCurrentCoordinateIndex = mPointList.size() - 1; | ||
| mCurrentCoordinateIndex = mCompoundCurve.vertexCount( 0, 0 ) - 1; | ||
|
|
||
| emit verticesInserted( 0, mPointList.size() ); | ||
| emit verticesInserted( 0, mCompoundCurve.vertexCount( 0, 0 ) ); | ||
| emit vertexCountChanged(); | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do that instead.