Skip to content

Commit

Permalink
dxf export: support line offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jan 22, 2015
1 parent cce2eb5 commit 221e9ef
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 6 deletions.
2 changes: 2 additions & 0 deletions python/core/symbology-ng/qgssymbollayerv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class QgsSymbolLayerV2
const QPointF& shift = QPointF( 0.0, 0.0 ) ) const;

virtual double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
virtual double dxfOffset( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;

virtual QColor dxfColor( const QgsSymbolV2RenderContext& context ) const;

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

virtual double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
virtual double dxfOffset( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;

protected:
QgsLineSymbolLayerV2( bool locked = false );
Expand Down
43 changes: 38 additions & 5 deletions src/core/dxf/qgsdxfexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3505,11 +3505,16 @@ void QgsDxfExport::addFeature( const QgsSymbolV2RenderContext& ctx, const QStrin
Qt::PenStyle penStyle( Qt::SolidLine );
Qt::BrushStyle brushStyle( Qt::NoBrush );
double width = -1;
double offset = 0.0;
if ( mSymbologyExport != NoSymbology && symbolLayer )
{
width = symbolLayer->dxfWidth( *this, ctx );
offset = symbolLayer->dxfOffset( *this, ctx );
penStyle = symbolLayer->dxfPenStyle();
brushStyle = symbolLayer->dxfBrushStyle();

if ( qgsDoubleNear( offset, 0.0 ) )
offset = 0.0;
}

QString lineStyleName = "CONTINUOUS";
Expand Down Expand Up @@ -3543,35 +3548,60 @@ void QgsDxfExport::addFeature( const QgsSymbolV2RenderContext& ctx, const QStrin
//single line
if ( geometryType == QGis::WKBLineString || geometryType == QGis::WKBLineString25D )
{
writePolyline( geom->asPolyline(), layer, lineStyleName, penColor, width, false );
QgsGeometry *offsetLine = offset == 0.0 ? geom : geom->offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 );
if ( !offsetLine )
offsetLine = geom;

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

if ( offsetLine != geom )
delete offsetLine;
}

//multiline
if ( geometryType == QGis::WKBMultiLineString || geometryType == QGis::WKBMultiLineString25D )
{
QgsMultiPolyline multiLine = geom->asMultiPolyline();
QgsGeometry *offsetLine = offset == 0.0 ? geom : geom->offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 );
if ( !offsetLine )
offsetLine = geom;

QgsMultiPolyline multiLine = offsetLine->asMultiPolyline();
QgsMultiPolyline::const_iterator lIt = multiLine.constBegin();
for ( ; lIt != multiLine.constEnd(); ++lIt )
{
writePolyline( *lIt, layer, lineStyleName, penColor, width, false );
}

if ( offsetLine != geom )
delete offsetLine;
}

//polygon
if ( geometryType == QGis::WKBPolygon || geometryType == QGis::WKBPolygon25D )
{
QgsPolygon polygon = geom->asPolygon();
QgsGeometry *offsetPolygon = offset == 0.0 ? geom : geom->buffer( -offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 );
if ( !offsetPolygon )
offsetPolygon = geom;

QgsPolygon polygon = offsetPolygon->asPolygon();
QgsPolygon::const_iterator polyIt = polygon.constBegin();
for ( ; polyIt != polygon.constEnd(); ++polyIt ) //iterate over rings
{
writePolyline( *polyIt, layer, lineStyleName, penColor, width, true );
writePolyline( geom->asPolyline(), layer, lineStyleName, penColor, width, false );
}

if ( offsetPolygon != geom )
delete offsetPolygon;
}

//multipolygon or polygon
if ( geometryType == QGis::WKBMultiPolygon || geometryType == QGis::WKBMultiPolygon25D )
{
QgsMultiPolygon mp = geom->asMultiPolygon();
QgsGeometry *offsetPolygon = offset == 0.0 ? geom : geom->buffer( -offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 );
if ( !offsetPolygon )
offsetPolygon = geom;

QgsMultiPolygon mp = offsetPolygon->asMultiPolygon();
QgsMultiPolygon::const_iterator mpIt = mp.constBegin();
for ( ; mpIt != mp.constEnd(); ++mpIt )
{
Expand All @@ -3581,6 +3611,9 @@ void QgsDxfExport::addFeature( const QgsSymbolV2RenderContext& ctx, const QStrin
writePolyline( *polyIt, layer, lineStyleName, penColor, width, true );
}
}

if ( offsetPolygon != geom )
delete offsetPolygon;
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/core/symbology-ng/qgslinesymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,17 @@ QColor QgsSimpleLineSymbolLayerV2::dxfColor( const QgsSymbolV2RenderContext& con
return mColor;
}

double QgsSimpleLineSymbolLayerV2::dxfOffset( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const
{
double offset = mOffset;
QgsExpression* offsetExpression = expression( "offset" );
if ( offsetExpression )
{
offset = offsetExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
}
return offset;
}

/////////


Expand Down
1 change: 1 addition & 0 deletions src/core/symbology-ng/qgslinesymbollayerv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class CORE_EXPORT QgsSimpleLineSymbolLayerV2 : public QgsLineSymbolLayerV2
Qt::PenStyle dxfPenStyle() const override;

double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const override;
double dxfOffset( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const override;
QColor dxfColor( const QgsSymbolV2RenderContext& context ) const override;

protected:
Expand Down
9 changes: 8 additions & 1 deletion src/core/symbology-ng/qgssymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ double QgsSymbolLayerV2::dxfWidth( const QgsDxfExport& e, const QgsSymbolV2Rende
return 1.0;
}

double QgsSymbolLayerV2::dxfOffset( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const
{
Q_UNUSED( e );
Q_UNUSED( context );
return 0.0;
}

QColor QgsSymbolLayerV2::dxfColor( const QgsSymbolV2RenderContext& context ) const
{
Q_UNUSED( context );
Expand Down Expand Up @@ -423,7 +430,7 @@ void QgsLineSymbolLayerV2::renderPolygonOutline( const QPolygonF& points, QList<
double QgsLineSymbolLayerV2::dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const
{
Q_UNUSED( context );
return ( width() * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() ) );
return width() * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() );
}


Expand Down
1 change: 1 addition & 0 deletions src/core/symbology-ng/qgssymbollayerv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class CORE_EXPORT QgsSymbolLayerV2
const QPointF& shift = QPointF( 0.0, 0.0 ) ) const;

virtual double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
virtual double dxfOffset( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;

virtual QColor dxfColor( const QgsSymbolV2RenderContext& context ) const;

Expand Down

0 comments on commit 221e9ef

Please sign in to comment.