Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
dxf export: fix detection of close polylines
  • Loading branch information
jef-n committed May 11, 2015
1 parent 2863f20 commit 74f10b9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
3 changes: 1 addition & 2 deletions python/core/dxf/qgsdxfexport.sip
Expand Up @@ -66,8 +66,7 @@ class QgsDxfExport
int writeHandle( int code = 5, int handle = 0 );

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

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

Expand Down
26 changes: 13 additions & 13 deletions src/core/dxf/qgsdxfexport.cpp
Expand Up @@ -3338,8 +3338,7 @@ void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, QColor
}
}

void QgsDxfExport::writePolyline( const QgsPolyline& line, const QString& layer, const QString& lineStyleName, QColor color,
double width, bool polygon )
void QgsDxfExport::writePolyline( const QgsPolyline& line, const QString& layer, const QString& lineStyleName, QColor color, double width )
{
writeGroup( 0, "LWPOLYLINE" );
writeHandle();
Expand All @@ -3349,16 +3348,17 @@ void QgsDxfExport::writePolyline( const QgsPolyline& line, const QString& layer,
writeGroup( 6, lineStyleName );
writeGroup( color );

writeGroup( 90, line.size() );
bool polygon = line[0] == line[ line.size() - 1 ];
int n = line.size();
if ( polygon )
--n;

writeGroup( 90, n );
writeGroup( 70, polygon ? 1 : 0 );
writeGroup( 43, width );

QgsPolyline::const_iterator lineIt = line.constBegin();
for ( ; lineIt != line.constEnd(); ++lineIt )
{
writeGroup( 0, *lineIt );
}
for ( int i = 0; i < n; i++ )
writeGroup( 0, line[i] );
}

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

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

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

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

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

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

Expand Down
3 changes: 1 addition & 2 deletions src/core/dxf/qgsdxfexport.h
Expand Up @@ -79,8 +79,7 @@ class CORE_EXPORT QgsDxfExport
int writeHandle( int code = 5, int handle = 0 );

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/core/dxf/qgsdxfpaintengine.cpp
Expand Up @@ -86,7 +86,7 @@ void QgsDxfPaintEngine::drawPolygon( const QPointF *points, int pointCount, Poly

if ( mode == QPaintEngine::PolylineMode )
{
mDxf->writePolyline( polyline, mLayer, "CONTINUOUS", mPen.color(), currentWidth(), true );
mDxf->writePolyline( polyline, mLayer, "CONTINUOUS", mPen.color(), currentWidth() );
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions src/core/symbology-ng/qgsellipsesymbollayerv2.cpp
Expand Up @@ -670,7 +670,7 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
}
//close ellipse with first point
line.push_back( line.at( 0 ) );
e.writePolyline( line, layerName, "SOLID", oc, outlineWidth, true );
e.writePolyline( line, layerName, "SOLID", oc, outlineWidth );
}
}
else if ( symbolName == "rectangle" )
Expand All @@ -689,13 +689,13 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
QPointF pt2( t.map( QPointF( halfWidth, 0 ) ) );
line1[0] = pt1;
line1[1] = pt2;
e.writePolyline( line1, layerName, "CONTINUOUS", oc, outlineWidth, false );
e.writePolyline( line1, layerName, "CONTINUOUS", oc, outlineWidth );
QgsPolyline line2( 2 );
QPointF pt3( t.map( QPointF( 0, halfHeight ) ) );
QPointF pt4( t.map( QPointF( 0, -halfHeight ) ) );
line2[0] = pt3;
line2[1] = pt4;
e.writePolyline( line2, layerName, "CONTINUOUS", oc, outlineWidth, false );
e.writePolyline( line2, layerName, "CONTINUOUS", oc, outlineWidth );
return true;
}
else if ( symbolName == "triangle" )
Expand Down

0 comments on commit 74f10b9

Please sign in to comment.