Skip to content

Commit 74f10b9

Browse files
committed
dxf export: fix detection of close polylines
1 parent 2863f20 commit 74f10b9

File tree

5 files changed

+19
-21
lines changed

5 files changed

+19
-21
lines changed

python/core/dxf/qgsdxfexport.sip

+1-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ class QgsDxfExport
6666
int writeHandle( int code = 5, int handle = 0 );
6767

6868
//draw dxf primitives
69-
void writePolyline( const QgsPolyline &line, const QString &layer, const QString &lineStyleName, QColor color,
70-
double width = -1, bool polygon = false );
69+
void writePolyline( const QgsPolyline &line, const QString &layer, const QString &lineStyleName, QColor color, double width = -1 );
7170

7271
void writePolygon( const QgsPolygon &polygon, const QString &layer, const QString &hatchPattern, QColor color );
7372

src/core/dxf/qgsdxfexport.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -3338,8 +3338,7 @@ void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, QColor
33383338
}
33393339
}
33403340

3341-
void QgsDxfExport::writePolyline( const QgsPolyline& line, const QString& layer, const QString& lineStyleName, QColor color,
3342-
double width, bool polygon )
3341+
void QgsDxfExport::writePolyline( const QgsPolyline& line, const QString& layer, const QString& lineStyleName, QColor color, double width )
33433342
{
33443343
writeGroup( 0, "LWPOLYLINE" );
33453344
writeHandle();
@@ -3349,16 +3348,17 @@ void QgsDxfExport::writePolyline( const QgsPolyline& line, const QString& layer,
33493348
writeGroup( 6, lineStyleName );
33503349
writeGroup( color );
33513350

3352-
writeGroup( 90, line.size() );
3351+
bool polygon = line[0] == line[ line.size() - 1 ];
3352+
int n = line.size();
3353+
if ( polygon )
3354+
--n;
33533355

3356+
writeGroup( 90, n );
33543357
writeGroup( 70, polygon ? 1 : 0 );
33553358
writeGroup( 43, width );
33563359

3357-
QgsPolyline::const_iterator lineIt = line.constBegin();
3358-
for ( ; lineIt != line.constEnd(); ++lineIt )
3359-
{
3360-
writeGroup( 0, *lineIt );
3361-
}
3360+
for ( int i = 0; i < n; i++ )
3361+
writeGroup( 0, line[i] );
33623362
}
33633363

33643364
void QgsDxfExport::writePolygon( const QgsPolygon& polygon, const QString& layer, const QString& hatchPattern, QColor color )
@@ -3405,7 +3405,7 @@ void QgsDxfExport::writeLine( const QgsPoint& pt1, const QgsPoint& pt2, const QS
34053405
QgsPolyline line( 2 );
34063406
line[0] = pt1;
34073407
line[1] = pt2;
3408-
writePolyline( line, layer, lineStyleName, color, width, false );
3408+
writePolyline( line, layer, lineStyleName, color, width );
34093409
}
34103410

34113411
void QgsDxfExport::writePoint( const QString& layer, QColor color, const QgsPoint& pt )
@@ -3652,7 +3652,7 @@ void QgsDxfExport::addFeature( const QgsSymbolV2RenderContext& ctx, const QStrin
36523652
if ( !offsetLine )
36533653
offsetLine = nonConstGeom;
36543654

3655-
writePolyline( offsetLine->asPolyline(), layer, lineStyleName, penColor, width, false );
3655+
writePolyline( offsetLine->asPolyline(), layer, lineStyleName, penColor, width );
36563656

36573657
if ( offsetLine != nonConstGeom )
36583658
delete offsetLine;
@@ -3671,7 +3671,7 @@ void QgsDxfExport::addFeature( const QgsSymbolV2RenderContext& ctx, const QStrin
36713671
QgsMultiPolyline::const_iterator lIt = multiLine.constBegin();
36723672
for ( ; lIt != multiLine.constEnd(); ++lIt )
36733673
{
3674-
writePolyline( *lIt, layer, lineStyleName, penColor, width, false );
3674+
writePolyline( *lIt, layer, lineStyleName, penColor, width );
36753675
}
36763676

36773677
if ( offsetLine != nonConstGeom )
@@ -3691,7 +3691,7 @@ void QgsDxfExport::addFeature( const QgsSymbolV2RenderContext& ctx, const QStrin
36913691
QgsPolygon::const_iterator polyIt = polygon.constBegin();
36923692
for ( ; polyIt != polygon.constEnd(); ++polyIt ) // iterate over rings
36933693
{
3694-
writePolyline( *polyIt, layer, lineStyleName, penColor, width, false );
3694+
writePolyline( *polyIt, layer, lineStyleName, penColor, width );
36953695
}
36963696

36973697
if ( offsetPolygon != nonConstGeom )
@@ -3714,7 +3714,7 @@ void QgsDxfExport::addFeature( const QgsSymbolV2RenderContext& ctx, const QStrin
37143714
QgsPolygon::const_iterator polyIt = mpIt->constBegin();
37153715
for ( ; polyIt != mpIt->constEnd(); ++polyIt )
37163716
{
3717-
writePolyline( *polyIt, layer, lineStyleName, penColor, width, true );
3717+
writePolyline( *polyIt, layer, lineStyleName, penColor, width );
37183718
}
37193719
}
37203720

src/core/dxf/qgsdxfexport.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ class CORE_EXPORT QgsDxfExport
7979
int writeHandle( int code = 5, int handle = 0 );
8080

8181
//! draw dxf primitives
82-
void writePolyline( const QgsPolyline &line, const QString &layer, const QString &lineStyleName, QColor color,
83-
double width = -1, bool polygon = false );
82+
void writePolyline( const QgsPolyline &line, const QString &layer, const QString &lineStyleName, QColor color, double width = -1 );
8483

8584
void writePolygon( const QgsPolygon &polygon, const QString &layer, const QString &hatchPattern, QColor color );
8685

src/core/dxf/qgsdxfpaintengine.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void QgsDxfPaintEngine::drawPolygon( const QPointF *points, int pointCount, Poly
8686

8787
if ( mode == QPaintEngine::PolylineMode )
8888
{
89-
mDxf->writePolyline( polyline, mLayer, "CONTINUOUS", mPen.color(), currentWidth(), true );
89+
mDxf->writePolyline( polyline, mLayer, "CONTINUOUS", mPen.color(), currentWidth() );
9090
}
9191
else
9292
{

src/core/symbology-ng/qgsellipsesymbollayerv2.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
670670
}
671671
//close ellipse with first point
672672
line.push_back( line.at( 0 ) );
673-
e.writePolyline( line, layerName, "SOLID", oc, outlineWidth, true );
673+
e.writePolyline( line, layerName, "SOLID", oc, outlineWidth );
674674
}
675675
}
676676
else if ( symbolName == "rectangle" )
@@ -689,13 +689,13 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
689689
QPointF pt2( t.map( QPointF( halfWidth, 0 ) ) );
690690
line1[0] = pt1;
691691
line1[1] = pt2;
692-
e.writePolyline( line1, layerName, "CONTINUOUS", oc, outlineWidth, false );
692+
e.writePolyline( line1, layerName, "CONTINUOUS", oc, outlineWidth );
693693
QgsPolyline line2( 2 );
694694
QPointF pt3( t.map( QPointF( 0, halfHeight ) ) );
695695
QPointF pt4( t.map( QPointF( 0, -halfHeight ) ) );
696696
line2[0] = pt3;
697697
line2[1] = pt4;
698-
e.writePolyline( line2, layerName, "CONTINUOUS", oc, outlineWidth, false );
698+
e.writePolyline( line2, layerName, "CONTINUOUS", oc, outlineWidth );
699699
return true;
700700
}
701701
else if ( symbolName == "triangle" )

0 commit comments

Comments
 (0)