Skip to content
Permalink
Browse files
[convert to curve] ça marche !
  • Loading branch information
olivierdalang authored and nyalldawson committed Jun 18, 2021
1 parent 3a849d4 commit 82f93d0537daca2f30472728a63dc272dfa4a7f5
Showing with 25 additions and 29 deletions.
  1. +2 −18 src/app/vertextool/qgsvertextool.cpp
  2. +22 −10 src/core/geometry/qgscompoundcurve.cpp
  3. +1 −1 src/core/geometry/qgscompoundcurve.h
@@ -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 )
{
@@ -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.
@@ -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;

}


@@ -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;

0 comments on commit 82f93d0

Please sign in to comment.