Skip to content

Commit cc3a053

Browse files
committedSep 11, 2016
dxf export: segmentize curves
1 parent 1cbb842 commit cc3a053

File tree

1 file changed

+95
-80
lines changed

1 file changed

+95
-80
lines changed
 

‎src/core/dxf/qgsdxfexport.cpp

Lines changed: 95 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -3778,110 +3778,125 @@ void QgsDxfExport::addFeature( QgsSymbolV2RenderContext& ctx, const QString& lay
37783778

37793779
if ( penStyle != Qt::NoPen )
37803780
{
3781-
// single line
3782-
if ( QgsWKBTypes::flatType( geometryType ) == QgsWKBTypes::LineString )
3783-
{
3784-
const QgsAbstractGeometryV2 *offsetGeom = geom;
3785-
if ( !qgsDoubleNear( offset, 0.0 ) )
3786-
{
3787-
QgsGeos geos( geom );
3788-
offsetGeom = geos.offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 );
3789-
if ( !offsetGeom )
3790-
offsetGeom = geom;
3791-
}
3792-
3793-
writePolyline( offsetGeom->coordinateSequence().at( 0 ).at( 0 ), layer, lineStyleName, penColor, width );
3794-
3795-
if ( offsetGeom != geom )
3796-
delete offsetGeom;
3797-
}
3781+
const QgsAbstractGeometryV2 *tempGeom = geom;
37983782

3799-
// multiline
3800-
if ( QgsWKBTypes::flatType( geometryType ) == QgsWKBTypes::MultiLineString )
3783+
switch ( QgsWKBTypes::flatType( geometryType ) )
38013784
{
3802-
const QgsAbstractGeometryV2 *offsetGeom = geom;
3785+
case QgsWKBTypes::CircularString:
3786+
case QgsWKBTypes::CompoundCurve:
3787+
tempGeom = geom->segmentize();
3788+
FALLTHROUGH;
3789+
case QgsWKBTypes::LineString:
3790+
if ( !qgsDoubleNear( offset, 0.0 ) )
3791+
{
3792+
QgsGeos geos( tempGeom );
3793+
if ( tempGeom != geom )
3794+
delete tempGeom;
3795+
tempGeom = geos.offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 );
3796+
if ( !tempGeom )
3797+
tempGeom = geom;
3798+
}
38033799

3804-
if ( !qgsDoubleNear( offset, 0.0 ) )
3805-
{
3806-
QgsGeos geos( geom );
3807-
offsetGeom = geos.offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 );
3808-
if ( !offsetGeom )
3809-
offsetGeom = geom;
3810-
}
3800+
writePolyline( tempGeom->coordinateSequence().at( 0 ).at( 0 ), layer, lineStyleName, penColor, width );
38113801

3812-
const QgsCoordinateSequenceV2 &cs = offsetGeom->coordinateSequence();
3813-
for ( int i = 0; i < cs.size(); i++ )
3814-
{
3815-
writePolyline( cs.at( i ).at( 0 ), layer, lineStyleName, penColor, width );
3816-
}
3802+
break;
38173803

3818-
if ( offsetGeom != geom )
3819-
delete offsetGeom;
3820-
}
3804+
case QgsWKBTypes::MultiCurve:
3805+
tempGeom = geom->segmentize();
3806+
FALLTHROUGH;
3807+
case QgsWKBTypes::MultiLineString:
3808+
{
3809+
if ( !qgsDoubleNear( offset, 0.0 ) )
3810+
{
3811+
QgsGeos geos( tempGeom );
3812+
if ( tempGeom != geom )
3813+
delete tempGeom;
3814+
tempGeom = geos.offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 );
3815+
if ( !tempGeom )
3816+
tempGeom = geom;
3817+
}
38213818

3822-
// polygon
3823-
if ( QgsWKBTypes::flatType( geometryType ) == QgsWKBTypes::Polygon )
3824-
{
3825-
const QgsAbstractGeometryV2 *bufferGeom = geom;
3819+
const QgsCoordinateSequenceV2 &cs = tempGeom->coordinateSequence();
3820+
for ( int i = 0; i < cs.size(); i++ )
3821+
{
3822+
writePolyline( cs.at( i ).at( 0 ), layer, lineStyleName, penColor, width );
3823+
}
38263824

3827-
if ( !qgsDoubleNear( offset, 0.0 ) )
3828-
{
3829-
QgsGeos geos( geom );
3830-
bufferGeom = geos.buffer( offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 );
3831-
if ( !bufferGeom )
3832-
bufferGeom = geom;
3825+
break;
38333826
}
38343827

3835-
const QgsCoordinateSequenceV2 &cs = bufferGeom->coordinateSequence();
3836-
for ( int i = 0; i < cs.at( 0 ).size(); i++ )
3828+
case QgsWKBTypes::CurvePolygon:
3829+
tempGeom = geom->segmentize();
3830+
FALLTHROUGH;
3831+
case QgsWKBTypes::Polygon:
38373832
{
3838-
writePolyline( cs.at( 0 ).at( i ), layer, lineStyleName, penColor, width );
3839-
}
3833+
if ( !qgsDoubleNear( offset, 0.0 ) )
3834+
{
3835+
QgsGeos geos( tempGeom );
3836+
if ( tempGeom != geom )
3837+
delete tempGeom;
3838+
tempGeom = geos.buffer( offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 );
3839+
if ( !tempGeom )
3840+
tempGeom = geom;
3841+
}
38403842

3841-
if ( bufferGeom != geom )
3842-
delete bufferGeom;
3843-
}
3843+
const QgsCoordinateSequenceV2 &cs = tempGeom->coordinateSequence();
3844+
for ( int i = 0; i < cs.at( 0 ).size(); i++ )
3845+
{
3846+
writePolyline( cs.at( 0 ).at( i ), layer, lineStyleName, penColor, width );
3847+
}
38443848

3845-
// multipolygon or polygon
3846-
if ( QgsWKBTypes::flatType( geometryType ) == QgsWKBTypes::MultiPolygon )
3847-
{
3848-
const QgsAbstractGeometryV2 *bufferGeom = geom;
3849+
break;
3850+
}
38493851

3850-
if ( !qgsDoubleNear( offset, 0.0 ) )
3852+
case QgsWKBTypes::MultiPolygon:
38513853
{
3852-
QgsGeos geos( geom );
3853-
bufferGeom = geos.buffer( offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 );
3854-
if ( !bufferGeom )
3855-
bufferGeom = geom;
3856-
}
3854+
if ( !qgsDoubleNear( offset, 0.0 ) )
3855+
{
3856+
QgsGeos geos( tempGeom );
3857+
if ( tempGeom != geom )
3858+
delete tempGeom;
3859+
tempGeom = geos.buffer( offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 );
3860+
if ( !tempGeom )
3861+
tempGeom = geom;
3862+
}
38573863

3858-
const QgsCoordinateSequenceV2 &cs = bufferGeom->coordinateSequence();
3859-
for ( int i = 0; i < cs.size(); i++ )
3860-
for ( int j = 0; j < cs.at( i ).size(); j++ )
3861-
writePolyline( cs.at( i ).at( j ), layer, lineStyleName, penColor, width );
3864+
const QgsCoordinateSequenceV2 &cs = tempGeom->coordinateSequence();
3865+
for ( int i = 0; i < cs.size(); i++ )
3866+
for ( int j = 0; j < cs.at( i ).size(); j++ )
3867+
writePolyline( cs.at( i ).at( j ), layer, lineStyleName, penColor, width );
38623868

3863-
if ( bufferGeom != geom )
3864-
delete bufferGeom;
3869+
break;
3870+
}
38653871
}
3872+
3873+
if ( tempGeom != geom )
3874+
delete tempGeom;
38663875
}
38673876

38683877
if ( brushStyle != Qt::NoBrush )
38693878
{
3870-
// polygon
3871-
if ( QgsWKBTypes::flatType( geometryType ) == QgsWKBTypes::Polygon )
3872-
{
3873-
writePolygon( geom->coordinateSequence().at( 0 ), layer, "SOLID", brushColor );
3874-
}
3879+
const QgsAbstractGeometryV2 *tempGeom = geom;
38753880

3876-
// multipolygon or polygon
3877-
if ( QgsWKBTypes::flatType( geometryType ) == QgsWKBTypes::MultiPolygon )
3881+
switch ( QgsWKBTypes::flatType( geometryType ) )
38783882
{
3879-
const QgsCoordinateSequenceV2 &cs = geom->coordinateSequence();
3880-
for ( int i = 0; i < cs.size(); i++ )
3881-
{
3882-
writePolygon( cs.at( i ), layer, "SOLID", brushColor );
3883-
}
3883+
case QgsWKBTypes::CurvePolygon:
3884+
tempGeom = tempGeom->segmentize();
3885+
FALLTHROUGH;
3886+
case QgsWKBTypes::Polygon:
3887+
writePolygon( tempGeom->coordinateSequence().at( 0 ), layer, "SOLID", brushColor );
3888+
break;
3889+
3890+
case QgsWKBTypes::MultiPolygon:
3891+
const QgsCoordinateSequenceV2 &cs = geom->coordinateSequence();
3892+
for ( int i = 0; i < cs.size(); i++ )
3893+
{
3894+
writePolygon( cs.at( i ), layer, "SOLID", brushColor );
3895+
}
38843896
}
3897+
3898+
if ( tempGeom != geom )
3899+
delete tempGeom;
38853900
}
38863901
}
38873902

0 commit comments

Comments
 (0)
Please sign in to comment.