Skip to content

Commit

Permalink
Support geometry generator in dxf output
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent authored and nyalldawson committed Jun 17, 2018
1 parent 1d111ce commit aa47dbe
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
67 changes: 65 additions & 2 deletions src/core/dxf/qgsdxfexport.cpp
Expand Up @@ -28,6 +28,7 @@

#include "qgsdxfexport.h"
#include "qgsdxfpallabeling.h"
#include "qgsgeometrygeneratorsymbollayer.h"
#include "qgsvectordataprovider.h"
#include "qgspointxy.h"
#include "qgsproject.h"
Expand Down Expand Up @@ -1076,7 +1077,21 @@ void QgsDxfExport::writeEntities()
int nSymbolLayers = ( *symbolIt )->symbolLayerCount();
for ( int i = 0; i < nSymbolLayers; ++i )
{
addFeature( sctx, ct, lName, ( *symbolIt )->symbolLayer( i ), *symbolIt );
QgsSymbolLayer *sl = ( *symbolIt )->symbolLayer( i );
if ( !sl )
{
continue;
}

bool isGeometryGenerator = ( sl->layerType() == "GeometryGenerator" );
if ( isGeometryGenerator )
{
addGeometryGeneratorSymbolLayer( sctx, ct, lName, sl, true );
}
else
{
addFeature( sctx, ct, lName, sl, *symbolIt );
}
}
}
}
Expand All @@ -1088,7 +1103,15 @@ void QgsDxfExport::writeEntities()
{
continue;
}
addFeature( sctx, ct, lName, s->symbolLayer( 0 ), s );

if ( s->symbolLayer( 0 )->layerType() == "GeometryGenerator" )
{
addGeometryGeneratorSymbolLayer( sctx, ct, lName, s->symbolLayer( 0 ), false );
}
else
{
addFeature( sctx, ct, lName, s->symbolLayer( 0 ), s );
}
}

if ( lp )
Expand Down Expand Up @@ -4127,6 +4150,46 @@ void QgsDxfExport::writeLinetype( const QString &styleName, const QVector<qreal>
}
}

void QgsDxfExport::addGeometryGeneratorSymbolLayer( QgsSymbolRenderContext &ctx, const QgsCoordinateTransform &ct, const QString &layer, QgsSymbolLayer *symbolLayer, bool allSymbolLayers )
{
QgsGeometryGeneratorSymbolLayer *gg = dynamic_cast<QgsGeometryGeneratorSymbolLayer *>( symbolLayer );
if ( !gg )
{
return;
}

const QgsFeature *fet = ctx.feature();
if ( !fet )
{
return;
}

QgsFeature f = *fet;

QgsExpressionContext &expressionContext = ctx.renderContext().expressionContext();
QgsExpression geomExpr( gg->geometryExpression() );
geomExpr.prepare( &expressionContext );
QgsGeometry geom = geomExpr.evaluate( &expressionContext ).value<QgsGeometry>();
f.setGeometry( geom );

QgsSymbol *symbol = gg->subSymbol();
if ( symbol && symbol->symbolLayerCount() > 0 )
{
QgsExpressionContextScope *symbolExpressionContextScope = symbol->symbolRenderContext()->expressionContextScope();
symbolExpressionContextScope->setFeature( f );

ctx.setFeature( &f );

int nSymbolLayers = allSymbolLayers ? symbol->symbolLayerCount() : 1;
for ( int i = 0; i < nSymbolLayers; ++i )
{
addFeature( ctx, ct, layer, symbol->symbolLayer( i ), symbol );
}

ctx.setFeature( fet );
}
}

bool QgsDxfExport::hasDataDefinedProperties( const QgsSymbolLayer *sl, const QgsSymbol *symbol )
{
if ( !sl || !symbol )
Expand Down
9 changes: 9 additions & 0 deletions src/core/dxf/qgsdxfexport.h
Expand Up @@ -454,6 +454,15 @@ class CORE_EXPORT QgsDxfExport
void writeSymbolLayerLinetype( const QgsSymbolLayer *symbolLayer );
void writeLinetype( const QString &styleName, const QVector<qreal> &pattern, QgsUnitTypes::RenderUnit u );

/**
* Writes geometry generator symbol layer
@param ctx the symbol render context
@param ct the coordinate transform
@param layer the layer name
@param symbolLayer the symbollayer to write to the dxf file
@param allSymbolLayers if true, all symbol layers of the subsymbol are writeen. If false, only the first one is written*/
void addGeometryGeneratorSymbolLayer( QgsSymbolRenderContext &ctx, const QgsCoordinateTransform &ct, const QString &layer, QgsSymbolLayer *symbolLayer, bool allSymbolLayers );

void addFeature( QgsSymbolRenderContext &ctx, const QgsCoordinateTransform &ct, const QString &layer, const QgsSymbolLayer *symbolLayer, const QgsSymbol *symbol );

//returns dxf palette index from symbol layer color
Expand Down

0 comments on commit aa47dbe

Please sign in to comment.