28
28
29
29
#include " qgsdxfexport.h"
30
30
#include " qgsdxfpallabeling.h"
31
+ #include " qgsgeometrygeneratorsymbollayerv2.h"
31
32
#include " qgsvectordataprovider.h"
32
33
#include " qgspoint.h"
33
34
#include " qgsrendererv2.h"
@@ -932,7 +933,7 @@ void QgsDxfExport::writeBlocks()
932
933
writeGroup ( 1 , " " );
933
934
934
935
// maplayer 0 -> block receives layer from INSERT statement
935
- ml->writeDxf ( *this , mapUnitScaleFactor ( mSymbologyScaleDenominator , ml->sizeUnit (), mMapUnits ), " 0" , ctx );
936
+ ml->writeDxf ( *this , mapUnitScaleFactor ( mSymbologyScaleDenominator , ml->sizeUnit (), mMapUnits , ctx. renderContext (). mapToPixel (). mapUnitsPerPixel () ), " 0" , ctx );
936
937
937
938
writeGroup ( 0 , " ENDBLK" );
938
939
writeHandle ();
@@ -967,6 +968,9 @@ void QgsDxfExport::writeEntities()
967
968
ctx.setScaleFactor ( 96.0 / 25.4 );
968
969
ctx.setMapToPixel ( QgsMapToPixel ( 1.0 / mFactor , mExtent .center ().x (), mExtent .center ().y (), mExtent .width () * mFactor , mExtent .height () * mFactor , 0 ) );
969
970
971
+ ctx.expressionContext ().appendScope ( QgsExpressionContextUtils::projectScope () );
972
+ ctx.expressionContext ().appendScope ( QgsExpressionContextUtils::globalScope () );
973
+
970
974
// label engine
971
975
QgsLabelingEngineV2 engine;
972
976
engine.readSettingsFromProject ();
@@ -1082,7 +1086,22 @@ void QgsDxfExport::writeEntities()
1082
1086
int nSymbolLayers = ( *symbolIt )->symbolLayerCount ();
1083
1087
for ( int i = 0 ; i < nSymbolLayers; ++i )
1084
1088
{
1085
- addFeature ( sctx, ct, lName, ( *symbolIt )->symbolLayer ( i ), *symbolIt );
1089
+ QgsSymbolLayerV2* sl = ( *symbolIt )->symbolLayer ( i );
1090
+ if ( !sl )
1091
+ {
1092
+ continue ;
1093
+ }
1094
+
1095
+ bool isGeometryGenerator = ( sl->layerType () == " GeometryGenerator" );
1096
+
1097
+ if ( isGeometryGenerator )
1098
+ {
1099
+ addGeometryGeneratorSymbolLayer ( sctx, ct, lName, sl, true );
1100
+ }
1101
+ else
1102
+ {
1103
+ addFeature ( sctx, ct, lName, sl, *symbolIt );
1104
+ }
1086
1105
}
1087
1106
}
1088
1107
}
@@ -1094,7 +1113,15 @@ void QgsDxfExport::writeEntities()
1094
1113
{
1095
1114
continue ;
1096
1115
}
1097
- addFeature ( sctx, ct, lName, s->symbolLayer ( 0 ), s );
1116
+
1117
+ if ( s->symbolLayer ( 0 )->layerType () == " GeometryGenerator" )
1118
+ {
1119
+ addGeometryGeneratorSymbolLayer ( sctx, ct, lName, s->symbolLayer ( 0 ), false );
1120
+ }
1121
+ else
1122
+ {
1123
+ addFeature ( sctx, ct, lName, s->symbolLayer ( 0 ), s );
1124
+ }
1098
1125
}
1099
1126
1100
1127
if ( lp )
@@ -3424,7 +3451,7 @@ void QgsDxfExport::writePoint( const QgsPointV2 &pt, const QString& layer, const
3424
3451
const QgsMarkerSymbolLayerV2* msl = dynamic_cast < const QgsMarkerSymbolLayerV2* >( symbolLayer );
3425
3452
if ( msl && symbol )
3426
3453
{
3427
- if ( symbolLayer->writeDxf ( *this , mapUnitScaleFactor ( mSymbologyScaleDenominator , msl->sizeUnit (), mMapUnits ), layer, ctx, QPointF ( pt.x (), pt.y () ) ) )
3454
+ if ( symbolLayer->writeDxf ( *this , mapUnitScaleFactor ( mSymbologyScaleDenominator , msl->sizeUnit (), mMapUnits , ctx. renderContext (). mapToPixel (). mapUnitsPerPixel () ), layer, ctx, QPointF ( pt.x (), pt.y () ) ) )
3428
3455
{
3429
3456
return ;
3430
3457
}
@@ -3956,6 +3983,46 @@ void QgsDxfExport::addFeature( QgsSymbolV2RenderContext& ctx, const QgsCoordinat
3956
3983
}
3957
3984
}
3958
3985
3986
+ void QgsDxfExport::addGeometryGeneratorSymbolLayer ( QgsSymbolV2RenderContext &ctx, const QgsCoordinateTransform *ct, const QString &layer, QgsSymbolLayerV2 *symbolLayer, bool allSymbolLayers )
3987
+ {
3988
+ QgsGeometryGeneratorSymbolLayerV2* gg = dynamic_cast <QgsGeometryGeneratorSymbolLayerV2*>( symbolLayer );
3989
+ if ( !gg )
3990
+ {
3991
+ return ;
3992
+ }
3993
+
3994
+ const QgsFeature* fet = ctx.feature ();
3995
+ if ( !fet )
3996
+ {
3997
+ return ;
3998
+ }
3999
+
4000
+ QgsFeature f = *fet;
4001
+
4002
+ QgsExpressionContext& expressionContext = ctx.renderContext ().expressionContext ();
4003
+ QgsExpression geomExpr ( gg->geometryExpression () );
4004
+ geomExpr.prepare ( &expressionContext );
4005
+ QgsGeometry geom = geomExpr.evaluate ( &expressionContext ).value <QgsGeometry>();
4006
+ f.setGeometry ( geom );
4007
+
4008
+ QgsSymbolV2* symbol = gg->subSymbol ();
4009
+ if ( symbol && symbol->symbolLayerCount () > 0 )
4010
+ {
4011
+ QgsExpressionContextScope* symbolExpressionContextScope = symbol->symbolRenderContext ()->expressionContextScope ();
4012
+ symbolExpressionContextScope->setFeature ( f );
4013
+
4014
+ ctx.setFeature ( &f );
4015
+
4016
+ int nSymbolLayers = allSymbolLayers ? symbol->symbolLayerCount () : 1 ;
4017
+ for ( int i = 0 ; i < nSymbolLayers; ++i )
4018
+ {
4019
+ addFeature ( ctx, ct, layer, symbol->symbolLayer ( i ), symbol );
4020
+ }
4021
+
4022
+ ctx.setFeature ( fet );
4023
+ }
4024
+ }
4025
+
3959
4026
QColor QgsDxfExport::colorFromSymbolLayer ( const QgsSymbolLayerV2* symbolLayer, QgsSymbolV2RenderContext &ctx )
3960
4027
{
3961
4028
if ( !symbolLayer )
@@ -4036,14 +4103,53 @@ QgsRenderContext QgsDxfExport::renderContext() const
4036
4103
return context;
4037
4104
}
4038
4105
4039
- double QgsDxfExport::mapUnitScaleFactor ( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits )
4106
+ double QgsDxfExport::mapUnitScaleFactor ( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits, double mapUnitsPerPixel )
4040
4107
{
4041
4108
if ( symbolUnits == QgsSymbolV2::MapUnit )
4042
4109
{
4043
4110
return 1.0 ;
4044
4111
}
4045
- // MM symbol unit
4046
- return scaleDenominator * QgsUnitTypes::fromUnitToUnitFactor ( QGis::Meters, mapUnits ) / 1000.0 ;
4112
+ else if ( symbolUnits == QgsSymbolV2::MM )
4113
+ {
4114
+ return ( scaleDenominator * QgsUnitTypes::fromUnitToUnitFactor ( QGis::Meters, mapUnits ) / 1000.0 );
4115
+ }
4116
+ else if ( symbolUnits == QgsSymbolV2::Pixel )
4117
+ {
4118
+ return mapUnitsPerPixel;
4119
+ }
4120
+ return 1.0 ;
4121
+ }
4122
+
4123
+ void QgsDxfExport::clipValueToMapUnitScale ( double & value, const QgsMapUnitScale& scale, double pixelToMMFactor ) const
4124
+ {
4125
+ if ( !scale.minSizeMMEnabled && !scale.maxSizeMMEnabled )
4126
+ {
4127
+ return ;
4128
+ }
4129
+
4130
+ double mapUnitsPerPixel = mMapSettings .mapToPixel ().mapUnitsPerPixel ();
4131
+
4132
+ double minSizeMU = -DBL_MAX;
4133
+ if ( scale.minSizeMMEnabled )
4134
+ {
4135
+ minSizeMU = scale.minSizeMM * pixelToMMFactor * mapUnitsPerPixel;
4136
+ }
4137
+ if ( !qgsDoubleNear ( scale.minScale , 0.0 ) )
4138
+ {
4139
+ minSizeMU = qMax ( minSizeMU, value );
4140
+ }
4141
+ value = qMax ( value, minSizeMU );
4142
+
4143
+ double maxSizeMU = DBL_MAX;
4144
+ if ( scale.maxSizeMMEnabled )
4145
+ {
4146
+ maxSizeMU = scale.maxSizeMM * pixelToMMFactor * mapUnitsPerPixel;
4147
+ }
4148
+ if ( !qgsDoubleNear ( scale.maxScale , 0.0 ) )
4149
+ {
4150
+ maxSizeMU = qMin ( maxSizeMU, value );
4151
+ }
4152
+ value = qMin ( value, maxSizeMU );
4047
4153
}
4048
4154
4049
4155
QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2* > > QgsDxfExport::symbolLayers ( QgsRenderContext &context )
@@ -4174,7 +4280,7 @@ void QgsDxfExport::writeLinetype( const QString& styleName, const QVector<qreal>
4174
4280
QVector<qreal>::const_iterator dashIt = pattern.constBegin ();
4175
4281
for ( ; dashIt != pattern.constEnd (); ++dashIt )
4176
4282
{
4177
- length += ( *dashIt * mapUnitScaleFactor ( mSymbologyScaleDenominator , u, mMapUnits ) );
4283
+ length += ( *dashIt * mapUnitScaleFactor ( mSymbologyScaleDenominator , u, mMapUnits , mMapSettings . mapToPixel (). mapUnitsPerPixel () ) );
4178
4284
}
4179
4285
4180
4286
writeGroup ( 0 , " LTYPE" );
@@ -4195,7 +4301,7 @@ void QgsDxfExport::writeLinetype( const QString& styleName, const QVector<qreal>
4195
4301
{
4196
4302
// map units or mm?
4197
4303
double segmentLength = ( isGap ? -*dashIt : *dashIt );
4198
- segmentLength *= mapUnitScaleFactor ( mSymbologyScaleDenominator , u, mMapUnits );
4304
+ segmentLength *= mapUnitScaleFactor ( mSymbologyScaleDenominator , u, mMapUnits , mMapSettings . mapToPixel (). mapUnitsPerPixel () );
4199
4305
writeGroup ( 49 , segmentLength );
4200
4306
writeGroup ( 74 , 0 );
4201
4307
isGap = !isGap;
0 commit comments