Skip to content

Commit

Permalink
[convert to curve] ça marche !
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierdalang authored and nyalldawson committed Jun 18, 2021
1 parent 3a849d4 commit 82f93d0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
20 changes: 2 additions & 18 deletions src/app/vertextool/qgsvertextool.cpp
Expand Up @@ -2655,25 +2655,9 @@ void QgsVertexTool::toggleVertexCurve()
}
QgsCompoundCurve *compoundCurveCopy = (QgsCompoundCurve*)geomTmp;

layer->beginEditCommand( tr( "Converting vertex type" ) );

bool success = false;
if ( vId.type == QgsVertexId::CurveVertex ) {
layer->beginEditCommand( tr( "Converting vertex to linear" ) );
// layer->deleteVertex( fId, vNr );
// layer->insertVertex( vPt, fId, vNr );
// vId.type = QgsVertexId::CurveVertex;
// feature.setGeometry( QgsGeometry(compoundCurveCopy ));
success = compoundCurveCopy->convertVertex( vId, QgsVertexId::SegmentVertex );

} else {
layer->beginEditCommand( tr( "Converting vertex to curve" ) );
// layer->deleteVertex( fId, vNr );
// layer->insertVertex( vPt, fId, vNr );
// vId.type = QgsVertexId::SegmentVertex;
// feature.setGeometry( QgsGeometry(compoundCurveCopy ));
success = compoundCurveCopy->convertVertex( vId, QgsVertexId::CurveVertex );
}

bool success = compoundCurveCopy->convertVertex(vId );

if ( success )
{
Expand Down
32 changes: 22 additions & 10 deletions src/core/geometry/qgscompoundcurve.cpp
Expand Up @@ -915,7 +915,7 @@ QVector< QPair<int, QgsVertexId> > QgsCompoundCurve::curveVertexId( QgsVertexId
return curveIds;
}

bool QgsCompoundCurve::convertVertex( QgsVertexId position, QgsVertexId::VertexType type )
bool QgsCompoundCurve::convertVertex( QgsVertexId position )
{

// First we find out the sub-curves that are contain that vertex.
Expand Down Expand Up @@ -1011,19 +1011,31 @@ bool QgsCompoundCurve::convertVertex( QgsVertexId position, QgsVertexId::VertexT
}

// We merge consecutive LineStrings
// TODO ? : move this to a new mergeConsecutiveLineStrings() method;
// const QVector< QgsCurve * > curves = mCurves;
// int i = 0;
// lastCurve *curve
// for ( QgsCurve *curve : curves )
// {
// TODO ? : move this to a new QgsCompoundCurve::mergeConsecutiveLineStrings() method;
QgsLineString *lastLineString = nullptr;
QVector<QgsCurve *> newCurves;
for ( int i = 0; i < mCurves.size(); ++i )
{
QgsCurve *curve = mCurves.at( i );
QgsLineString *curveAsLineString = dynamic_cast<QgsLineString *>( curve );

if ( curveAsLineString != nullptr && lastLineString != nullptr )
{
// We append to previous
lastLineString->append( curveAsLineString );
}
else
{
// We keep as is
newCurves.append( curve );
lastLineString = curveAsLineString;
}
}

// }
mCurves = newCurves;

clearCache();

return true;

}


Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgscompoundcurve.h
Expand Up @@ -124,7 +124,7 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve
bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
bool deleteVertex( QgsVertexId position ) override;
bool convertVertex( QgsVertexId position, QgsVertexId::VertexType type );
bool convertVertex( QgsVertexId position );
double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * std::numeric_limits<double>::epsilon() ) const override;
bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const override;
void sumUpArea( double &sum SIP_OUT ) const override;
Expand Down

0 comments on commit 82f93d0

Please sign in to comment.