Skip to content

Commit 221e9ef

Browse files
committedJan 22, 2015
dxf export: support line offsets
1 parent cce2eb5 commit 221e9ef

File tree

6 files changed

+61
-6
lines changed

6 files changed

+61
-6
lines changed
 

‎python/core/symbology-ng/qgssymbollayerv2.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class QgsSymbolLayerV2
142142
const QPointF& shift = QPointF( 0.0, 0.0 ) ) const;
143143

144144
virtual double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
145+
virtual double dxfOffset( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
145146

146147
virtual QColor dxfColor( const QgsSymbolV2RenderContext& context ) const;
147148

@@ -276,6 +277,7 @@ class QgsLineSymbolLayerV2 : QgsSymbolLayerV2
276277
void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );
277278

278279
virtual double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
280+
virtual double dxfOffset( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
279281

280282
protected:
281283
QgsLineSymbolLayerV2( bool locked = false );

‎src/core/dxf/qgsdxfexport.cpp

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3505,11 +3505,16 @@ void QgsDxfExport::addFeature( const QgsSymbolV2RenderContext& ctx, const QStrin
35053505
Qt::PenStyle penStyle( Qt::SolidLine );
35063506
Qt::BrushStyle brushStyle( Qt::NoBrush );
35073507
double width = -1;
3508+
double offset = 0.0;
35083509
if ( mSymbologyExport != NoSymbology && symbolLayer )
35093510
{
35103511
width = symbolLayer->dxfWidth( *this, ctx );
3512+
offset = symbolLayer->dxfOffset( *this, ctx );
35113513
penStyle = symbolLayer->dxfPenStyle();
35123514
brushStyle = symbolLayer->dxfBrushStyle();
3515+
3516+
if ( qgsDoubleNear( offset, 0.0 ) )
3517+
offset = 0.0;
35133518
}
35143519

35153520
QString lineStyleName = "CONTINUOUS";
@@ -3543,35 +3548,60 @@ void QgsDxfExport::addFeature( const QgsSymbolV2RenderContext& ctx, const QStrin
35433548
//single line
35443549
if ( geometryType == QGis::WKBLineString || geometryType == QGis::WKBLineString25D )
35453550
{
3546-
writePolyline( geom->asPolyline(), layer, lineStyleName, penColor, width, false );
3551+
QgsGeometry *offsetLine = offset == 0.0 ? geom : geom->offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 );
3552+
if ( !offsetLine )
3553+
offsetLine = geom;
3554+
3555+
writePolyline( offsetLine->asPolyline(), layer, lineStyleName, penColor, width, false );
3556+
3557+
if ( offsetLine != geom )
3558+
delete offsetLine;
35473559
}
35483560

35493561
//multiline
35503562
if ( geometryType == QGis::WKBMultiLineString || geometryType == QGis::WKBMultiLineString25D )
35513563
{
3552-
QgsMultiPolyline multiLine = geom->asMultiPolyline();
3564+
QgsGeometry *offsetLine = offset == 0.0 ? geom : geom->offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 );
3565+
if ( !offsetLine )
3566+
offsetLine = geom;
3567+
3568+
QgsMultiPolyline multiLine = offsetLine->asMultiPolyline();
35533569
QgsMultiPolyline::const_iterator lIt = multiLine.constBegin();
35543570
for ( ; lIt != multiLine.constEnd(); ++lIt )
35553571
{
35563572
writePolyline( *lIt, layer, lineStyleName, penColor, width, false );
35573573
}
3574+
3575+
if ( offsetLine != geom )
3576+
delete offsetLine;
35583577
}
35593578

35603579
//polygon
35613580
if ( geometryType == QGis::WKBPolygon || geometryType == QGis::WKBPolygon25D )
35623581
{
3563-
QgsPolygon polygon = geom->asPolygon();
3582+
QgsGeometry *offsetPolygon = offset == 0.0 ? geom : geom->buffer( -offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 );
3583+
if ( !offsetPolygon )
3584+
offsetPolygon = geom;
3585+
3586+
QgsPolygon polygon = offsetPolygon->asPolygon();
35643587
QgsPolygon::const_iterator polyIt = polygon.constBegin();
35653588
for ( ; polyIt != polygon.constEnd(); ++polyIt ) //iterate over rings
35663589
{
3567-
writePolyline( *polyIt, layer, lineStyleName, penColor, width, true );
3590+
writePolyline( geom->asPolyline(), layer, lineStyleName, penColor, width, false );
35683591
}
3592+
3593+
if ( offsetPolygon != geom )
3594+
delete offsetPolygon;
35693595
}
35703596

35713597
//multipolygon or polygon
35723598
if ( geometryType == QGis::WKBMultiPolygon || geometryType == QGis::WKBMultiPolygon25D )
35733599
{
3574-
QgsMultiPolygon mp = geom->asMultiPolygon();
3600+
QgsGeometry *offsetPolygon = offset == 0.0 ? geom : geom->buffer( -offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 );
3601+
if ( !offsetPolygon )
3602+
offsetPolygon = geom;
3603+
3604+
QgsMultiPolygon mp = offsetPolygon->asMultiPolygon();
35753605
QgsMultiPolygon::const_iterator mpIt = mp.constBegin();
35763606
for ( ; mpIt != mp.constEnd(); ++mpIt )
35773607
{
@@ -3581,6 +3611,9 @@ void QgsDxfExport::addFeature( const QgsSymbolV2RenderContext& ctx, const QStrin
35813611
writePolyline( *polyIt, layer, lineStyleName, penColor, width, true );
35823612
}
35833613
}
3614+
3615+
if ( offsetPolygon != geom )
3616+
delete offsetPolygon;
35843617
}
35853618
}
35863619

‎src/core/symbology-ng/qgslinesymbollayerv2.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,17 @@ QColor QgsSimpleLineSymbolLayerV2::dxfColor( const QgsSymbolV2RenderContext& con
611611
return mColor;
612612
}
613613

614+
double QgsSimpleLineSymbolLayerV2::dxfOffset( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const
615+
{
616+
double offset = mOffset;
617+
QgsExpression* offsetExpression = expression( "offset" );
618+
if ( offsetExpression )
619+
{
620+
offset = offsetExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
621+
}
622+
return offset;
623+
}
624+
614625
/////////
615626

616627

‎src/core/symbology-ng/qgslinesymbollayerv2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class CORE_EXPORT QgsSimpleLineSymbolLayerV2 : public QgsLineSymbolLayerV2
112112
Qt::PenStyle dxfPenStyle() const override;
113113

114114
double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const override;
115+
double dxfOffset( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const override;
115116
QColor dxfColor( const QgsSymbolV2RenderContext& context ) const override;
116117

117118
protected:

‎src/core/symbology-ng/qgssymbollayerv2.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ double QgsSymbolLayerV2::dxfWidth( const QgsDxfExport& e, const QgsSymbolV2Rende
101101
return 1.0;
102102
}
103103

104+
double QgsSymbolLayerV2::dxfOffset( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const
105+
{
106+
Q_UNUSED( e );
107+
Q_UNUSED( context );
108+
return 0.0;
109+
}
110+
104111
QColor QgsSymbolLayerV2::dxfColor( const QgsSymbolV2RenderContext& context ) const
105112
{
106113
Q_UNUSED( context );
@@ -423,7 +430,7 @@ void QgsLineSymbolLayerV2::renderPolygonOutline( const QPolygonF& points, QList<
423430
double QgsLineSymbolLayerV2::dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const
424431
{
425432
Q_UNUSED( context );
426-
return ( width() * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() ) );
433+
return width() * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() );
427434
}
428435

429436

‎src/core/symbology-ng/qgssymbollayerv2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class CORE_EXPORT QgsSymbolLayerV2
123123
const QPointF& shift = QPointF( 0.0, 0.0 ) ) const;
124124

125125
virtual double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
126+
virtual double dxfOffset( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
126127

127128
virtual QColor dxfColor( const QgsSymbolV2RenderContext& context ) const;
128129

0 commit comments

Comments
 (0)
Please sign in to comment.