Skip to content

Commit c577b65

Browse files
authoredApr 20, 2018
Merge pull request #6810 from mhugent/dxf_fixes_2_18
Dxf fixes for 2 18
2 parents 9bf55aa + 543f501 commit c577b65

File tree

9 files changed

+219
-44
lines changed

9 files changed

+219
-44
lines changed
 

‎python/core/dxf/qgsdxfexport.sip

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,17 @@ class QgsDxfExport
375375
//! @note added in 2.15
376376
void writeMText( const QString &layer, const QString &text, const QgsPointV2 &pt, double width, double angle, const QColor& color );
377377

378-
static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits );
378+
/** Returns scale factor for conversion to map units
379+
* @param scaleDenominator the map scale denominator
380+
* @param symbolUnits the symbol output units
381+
* @param mapUnits the map units
382+
* @param mapUnitsPerPixel Map units per pixel*/
383+
static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits, double mapUnitsPerPixel = 1.0 );
384+
/** Clips value to scale minimum/maximum
385+
@param value the value to clip
386+
@param scale the scale dependent minimum/maximum values
387+
@param pixelToMMFactor pixels per mm*/
388+
void clipValueToMapUnitScale( double& value, const QgsMapUnitScale& scale, double pixelToMMFactor ) const;
379389

380390
//! Return cleaned layer name for use in DXF
381391
static QString dxfLayerName( const QString &name );

‎src/core/dxf/qgsdxfexport.cpp

Lines changed: 115 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "qgsdxfexport.h"
3030
#include "qgsdxfpallabeling.h"
31+
#include "qgsgeometrygeneratorsymbollayerv2.h"
3132
#include "qgsvectordataprovider.h"
3233
#include "qgspoint.h"
3334
#include "qgsrendererv2.h"
@@ -932,7 +933,7 @@ void QgsDxfExport::writeBlocks()
932933
writeGroup( 1, "" );
933934

934935
// 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 );
936937

937938
writeGroup( 0, "ENDBLK" );
938939
writeHandle();
@@ -967,6 +968,9 @@ void QgsDxfExport::writeEntities()
967968
ctx.setScaleFactor( 96.0 / 25.4 );
968969
ctx.setMapToPixel( QgsMapToPixel( 1.0 / mFactor, mExtent.center().x(), mExtent.center().y(), mExtent.width() * mFactor, mExtent.height() * mFactor, 0 ) );
969970

971+
ctx.expressionContext().appendScope( QgsExpressionContextUtils::projectScope() );
972+
ctx.expressionContext().appendScope( QgsExpressionContextUtils::globalScope() );
973+
970974
// label engine
971975
QgsLabelingEngineV2 engine;
972976
engine.readSettingsFromProject();
@@ -1082,7 +1086,22 @@ void QgsDxfExport::writeEntities()
10821086
int nSymbolLayers = ( *symbolIt )->symbolLayerCount();
10831087
for ( int i = 0; i < nSymbolLayers; ++i )
10841088
{
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+
}
10861105
}
10871106
}
10881107
}
@@ -1094,7 +1113,15 @@ void QgsDxfExport::writeEntities()
10941113
{
10951114
continue;
10961115
}
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+
}
10981125
}
10991126

11001127
if ( lp )
@@ -3424,7 +3451,7 @@ void QgsDxfExport::writePoint( const QgsPointV2 &pt, const QString& layer, const
34243451
const QgsMarkerSymbolLayerV2* msl = dynamic_cast< const QgsMarkerSymbolLayerV2* >( symbolLayer );
34253452
if ( msl && symbol )
34263453
{
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() ) ) )
34283455
{
34293456
return;
34303457
}
@@ -3956,6 +3983,46 @@ void QgsDxfExport::addFeature( QgsSymbolV2RenderContext& ctx, const QgsCoordinat
39563983
}
39573984
}
39583985

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+
39594026
QColor QgsDxfExport::colorFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer, QgsSymbolV2RenderContext &ctx )
39604027
{
39614028
if ( !symbolLayer )
@@ -4036,14 +4103,53 @@ QgsRenderContext QgsDxfExport::renderContext() const
40364103
return context;
40374104
}
40384105

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 )
40404107
{
40414108
if ( symbolUnits == QgsSymbolV2::MapUnit )
40424109
{
40434110
return 1.0;
40444111
}
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 );
40474153
}
40484154

40494155
QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2* > > QgsDxfExport::symbolLayers( QgsRenderContext &context )
@@ -4174,7 +4280,7 @@ void QgsDxfExport::writeLinetype( const QString& styleName, const QVector<qreal>
41744280
QVector<qreal>::const_iterator dashIt = pattern.constBegin();
41754281
for ( ; dashIt != pattern.constEnd(); ++dashIt )
41764282
{
4177-
length += ( *dashIt * mapUnitScaleFactor( mSymbologyScaleDenominator, u, mMapUnits ) );
4283+
length += ( *dashIt * mapUnitScaleFactor( mSymbologyScaleDenominator, u, mMapUnits, mMapSettings.mapToPixel().mapUnitsPerPixel() ) );
41784284
}
41794285

41804286
writeGroup( 0, "LTYPE" );
@@ -4195,7 +4301,7 @@ void QgsDxfExport::writeLinetype( const QString& styleName, const QVector<qreal>
41954301
{
41964302
// map units or mm?
41974303
double segmentLength = ( isGap ? -*dashIt : *dashIt );
4198-
segmentLength *= mapUnitScaleFactor( mSymbologyScaleDenominator, u, mMapUnits );
4304+
segmentLength *= mapUnitScaleFactor( mSymbologyScaleDenominator, u, mMapUnits, mMapSettings.mapToPixel().mapUnitsPerPixel() );
41994305
writeGroup( 49, segmentLength );
42004306
writeGroup( 74, 0 );
42014307
isGap = !isGap;

‎src/core/dxf/qgsdxfexport.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,17 @@ class CORE_EXPORT QgsDxfExport
402402
//! @note added in 2.15
403403
void writeMText( const QString &layer, const QString &text, const QgsPointV2 &pt, double width, double angle, const QColor& color );
404404

405-
static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits );
405+
/** Returns scale factor for conversion to map units
406+
* @param scaleDenominator the map scale denominator
407+
* @param symbolUnits the symbol output units
408+
* @param mapUnits the map units
409+
* @param mapUnitsPerPixel Map units per pixel*/
410+
static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits, double mapUnitsPerPixel = 1.0 );
411+
/** Clips value to scale minimum/maximum
412+
@param value the value to clip
413+
@param scale the scale dependent minimum/maximum values
414+
@param pixelToMMFactor pixels per mm*/
415+
void clipValueToMapUnitScale( double& value, const QgsMapUnitScale& scale, double pixelToMMFactor ) const;
406416

407417
//! Return cleaned layer name for use in DXF
408418
static QString dxfLayerName( const QString &name );
@@ -467,6 +477,13 @@ class CORE_EXPORT QgsDxfExport
467477
void writeLinetype( const QString &styleName, const QVector<qreal> &pattern, QgsSymbolV2::OutputUnit u );
468478

469479
void addFeature( QgsSymbolV2RenderContext &ctx, const QgsCoordinateTransform *ct, const QString &layer, const QgsSymbolLayerV2 *symbolLayer, const QgsSymbolV2 *symbol );
480+
/** Writes geometry generator symbol layer
481+
@param ctx the symbol render context
482+
@param ct the coordinate transform
483+
@param layer the layer name
484+
@param symbolLayer the symbollayer to write to the dxf file
485+
@param allSymbolLayers if true, all symbol layers of the subsymbol are writeen. If false, only the first one is written*/
486+
void addGeometryGeneratorSymbolLayer( QgsSymbolV2RenderContext &ctx, const QgsCoordinateTransform *ct, const QString &layer, QgsSymbolLayerV2 *symbolLayer, bool allSymbolLayers );
470487

471488
//returns dxf palette index from symbol layer color
472489
static QColor colorFromSymbolLayer( const QgsSymbolLayerV2 *symbolLayer, QgsSymbolV2RenderContext &ctx );

‎src/core/dxf/qgsdxfpaintengine.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ QgsDxfPaintEngine::QgsDxfPaintEngine( const QgsDxfPaintDevice* dxfDevice, QgsDxf
2424
: QPaintEngine( QPaintEngine::AllFeatures /*QPaintEngine::PainterPaths | QPaintEngine::PaintOutsidePaintEvent*/ )
2525
, mPaintDevice( dxfDevice )
2626
, mDxf( dxf )
27+
, mOpacity( 1.0 )
2728
{
2829
}
2930

@@ -64,6 +65,11 @@ void QgsDxfPaintEngine::updateState( const QPaintEngineState& state )
6465

6566
if ( state.state() & QPaintEngine::DirtyBrush )
6667
mBrush = state.brush();
68+
69+
if ( state.state() & QPaintEngine::DirtyOpacity )
70+
{
71+
mOpacity = state.opacity();
72+
}
6773
}
6874

6975
void QgsDxfPaintEngine::setRing( QgsPointSequenceV2 &polyline, const QPointF *points, int pointCount )
@@ -86,12 +92,12 @@ void QgsDxfPaintEngine::drawPolygon( const QPointF *points, int pointCount, Poly
8692
if ( mode == QPaintEngine::PolylineMode )
8793
{
8894
if ( mPen.style() != Qt::NoPen && mPen.brush().style() != Qt::NoBrush )
89-
mDxf->writePolyline( polygon.at( 0 ), mLayer, "CONTINUOUS", mPen.color(), currentWidth() );
95+
mDxf->writePolyline( polygon.at( 0 ), mLayer, "CONTINUOUS", penColor(), currentWidth() );
9096
}
9197
else
9298
{
9399
if ( mBrush.style() != Qt::NoBrush )
94-
mDxf->writePolygon( polygon, mLayer, "SOLID", mBrush.color() );
100+
mDxf->writePolygon( polygon, mLayer, "SOLID", brushColor() );
95101
}
96102
}
97103

@@ -122,7 +128,7 @@ void QgsDxfPaintEngine::drawPath( const QPainterPath& path )
122128
endPolygon();
123129

124130
if ( !mPolygon.isEmpty() && mBrush.style() != Qt::NoBrush )
125-
mDxf->writePolygon( mPolygon, mLayer, "SOLID", mBrush.color() );
131+
mDxf->writePolygon( mPolygon, mLayer, "SOLID", brushColor() );
126132

127133
mPolygon.clear();
128134
}
@@ -198,7 +204,7 @@ void QgsDxfPaintEngine::drawLines( const QLineF* lines, int lineCount )
198204
{
199205
mDxf->writeLine( toDxfCoordinates( lines[i].p1() ),
200206
toDxfCoordinates( lines[i].p2() ),
201-
mLayer, "CONTINUOUS", mPen.color(), currentWidth() );
207+
mLayer, "CONTINUOUS", penColor(), currentWidth() );
202208
}
203209
}
204210

@@ -291,3 +297,25 @@ int QgsDxfPaintEngine::faculty( int n )
291297

292298
return result;
293299
}
300+
301+
QColor QgsDxfPaintEngine::penColor() const
302+
{
303+
if ( qgsDoubleNear( mOpacity, 1.0 ) )
304+
{
305+
return mPen.color();
306+
}
307+
QColor c = mPen.color();
308+
c.setAlphaF( c.alphaF() * mOpacity );
309+
return c;
310+
}
311+
312+
QColor QgsDxfPaintEngine::brushColor() const
313+
{
314+
if ( qgsDoubleNear( mOpacity, 1.0 ) )
315+
{
316+
return mBrush.color();
317+
}
318+
QColor c = mBrush.color();
319+
c.setAlphaF( c.alphaF() * mOpacity );
320+
return c;
321+
}

‎src/core/dxf/qgsdxfpaintengine.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class CORE_EXPORT QgsDxfPaintEngine: public QPaintEngine
6161
QTransform mTransform;
6262
QPen mPen;
6363
QBrush mBrush;
64+
/** Opacity*/
65+
double mOpacity;
6466
QString mLayer;
6567
QPointF mShift;
6668
QgsRingSequenceV2 mPolygon;
@@ -84,6 +86,11 @@ class CORE_EXPORT QgsDxfPaintEngine: public QPaintEngine
8486
static int lower( int n, int i );
8587
static double power( double a, int b );
8688
static int faculty( int n );
89+
90+
/** Returns current pen color*/
91+
QColor penColor() const;
92+
/** Returns current brush color*/
93+
QColor brushColor() const;
8794
};
8895

8996
#endif // QGSDXFPAINTENGINE_H

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ double QgsSimpleFillSymbolLayerV2::dxfWidth( const QgsDxfExport& e, QgsSymbolV2R
416416
context.setOriginalValueVariable( mBorderWidth );
417417
width = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH_BORDER, context, mBorderWidth ).toDouble();
418418
}
419-
return width * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mBorderWidthUnit, e.mapUnits() );
419+
return width * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mBorderWidthUnit, e.mapUnits(), context.renderContext().mapToPixel().mapUnitsPerPixel() );
420420
}
421421

422422
QColor QgsSimpleFillSymbolLayerV2::dxfColor( QgsSymbolV2RenderContext &context ) const
@@ -1702,7 +1702,7 @@ double QgsImageFillSymbolLayer::dxfWidth( const QgsDxfExport& e, QgsSymbolV2Rend
17021702
context.setOriginalValueVariable( mOutlineWidth );
17031703
width = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH, context, mOutlineWidth ).toDouble();
17041704
}
1705-
return width * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mOutlineWidthUnit, e.mapUnits() );
1705+
return width * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mOutlineWidthUnit, e.mapUnits(), context.renderContext().mapToPixel().mapUnitsPerPixel() );
17061706
}
17071707

17081708
QColor QgsImageFillSymbolLayer::dxfColor( QgsSymbolV2RenderContext &context ) const

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -620,14 +620,15 @@ double QgsSimpleLineSymbolLayerV2::dxfWidth( const QgsDxfExport& e, QgsSymbolV2R
620620
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH ) )
621621
{
622622
context.setOriginalValueVariable( mWidth );
623-
width = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH, context, mWidth ).toDouble() * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() );
623+
width = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH, context, mWidth ).toDouble();
624624
}
625-
else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale )
625+
626+
width *= e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits(), context.renderContext().mapToPixel().mapUnitsPerPixel() );
627+
if ( mWidthUnit == QgsSymbolV2::MapUnit )
626628
{
627-
width = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), mWidth, mWidthUnit, mWidthMapUnitScale );
629+
e.clipValueToMapUnitScale( width, mWidthMapUnitScale, context.renderContext().scaleFactor() );
628630
}
629-
630-
return width * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() );
631+
return width;
631632
}
632633

633634
QColor QgsSimpleLineSymbolLayerV2::dxfColor( QgsSymbolV2RenderContext& context ) const
@@ -653,7 +654,13 @@ double QgsSimpleLineSymbolLayerV2::dxfOffset( const QgsDxfExport& e, QgsSymbolV2
653654
context.setOriginalValueVariable( mOffset );
654655
offset = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OFFSET, context, mOffset ).toDouble();
655656
}
656-
return offset;
657+
658+
offset *= e.mapUnitScaleFactor( e.symbologyScaleDenominator(), offsetUnit(), e.mapUnits(), context.renderContext().mapToPixel().mapUnitsPerPixel() );
659+
if ( mOffsetUnit == QgsSymbolV2::MapUnit )
660+
{
661+
e.clipValueToMapUnitScale( offset, mOffsetMapUnitScale, context.renderContext().scaleFactor() );
662+
}
663+
return -offset; //direction seems to be inverse to symbology offset
657664
}
658665

659666
/////////

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,8 @@ void QgsSimpleMarkerSymbolLayerV2::drawMarker( QPainter* p, QgsSymbolV2RenderCon
12701270

12711271
bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, QgsSymbolV2RenderContext &context, QPointF shift ) const
12721272
{
1273+
Q_UNUSED( mmMapUnitScaleFactor );
1274+
12731275
//data defined size?
12741276
double size = mSize;
12751277

@@ -1296,12 +1298,12 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
12961298
break;
12971299
}
12981300
}
1299-
1300-
size = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), size, mSizeUnit, mSizeMapUnitScale );
13011301
}
1302-
if ( mSizeUnit == QgsSymbolV2::MM )
1302+
1303+
size *= e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mSizeUnit, e.mapUnits(), context.renderContext().mapToPixel().mapUnitsPerPixel() );
1304+
if ( mSizeUnit == QgsSymbolV2::MapUnit )
13031305
{
1304-
size *= mmMapUnitScaleFactor;
1306+
e.clipValueToMapUnitScale( size, mSizeMapUnitScale, context.renderContext().scaleFactor() );
13051307
}
13061308
double halfSize = size / 2.0;
13071309

@@ -1313,9 +1315,10 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
13131315
context.setOriginalValueVariable( mOutlineWidth );
13141316
outlineWidth = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH, context, mOutlineWidth ).toDouble();
13151317
}
1316-
if ( mSizeUnit == QgsSymbolV2::MM )
1318+
outlineWidth *= e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mOutlineWidthUnit, e.mapUnits(), context.renderContext().mapToPixel().mapUnitsPerPixel() );
1319+
if ( mOutlineWidthUnit == QgsSymbolV2::MapUnit )
13171320
{
1318-
outlineWidth *= mmMapUnitScaleFactor;
1321+
e.clipValueToMapUnitScale( outlineWidth, mOutlineWidthMapUnitScale, context.renderContext().scaleFactor() );
13191322
}
13201323

13211324
//color
@@ -1340,6 +1343,8 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
13401343
double offsetX = 0;
13411344
double offsetY = 0;
13421345
markerOffset( context, offsetX, offsetY );
1346+
offsetX *= context.renderContext().mapToPixel().mapUnitsPerPixel();
1347+
offsetY *= context.renderContext().mapToPixel().mapUnitsPerPixel();
13431348

13441349
QPointF off( offsetX, offsetY );
13451350

@@ -1364,17 +1369,13 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
13641369
}
13651370
}
13661371

1367-
angle = -angle; //rotation in Qt is counterclockwise
13681372
if ( angle )
13691373
off = _rotatedOffset( off, angle );
13701374

1371-
if ( mSizeUnit == QgsSymbolV2::MM )
1372-
{
1373-
off *= mmMapUnitScaleFactor;
1374-
}
1375+
off *= e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mSizeUnit, e.mapUnits(), context.renderContext().mapToPixel().mapUnitsPerPixel() );
13751376

13761377
QTransform t;
1377-
t.translate( shift.x() + offsetX, shift.y() + offsetY );
1378+
t.translate( shift.x() + off.x(), shift.y() - off.y() );
13781379

13791380
if ( !qgsDoubleNear( angle, 0.0 ) )
13801381
t.rotate( angle );
@@ -1388,8 +1389,9 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
13881389

13891390
QgsPointSequenceV2 p;
13901391
for ( int i = 0; i < polygon.size(); i++ )
1392+
{
13911393
p << QgsPointV2( polygon[i] );
1392-
p << p[0];
1394+
}
13931395

13941396
if ( mBrush.style() != Qt::NoBrush )
13951397
e.writePolygon( QgsRingSequenceV2() << p, layerName, "SOLID", bc );
@@ -1398,6 +1400,7 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
13981400
}
13991401
else if ( shape == Circle )
14001402
{
1403+
shift += QPointF( off.x(), -off.y() );
14011404
if ( mBrush.style() != Qt::NoBrush )
14021405
e.writeFilledCircle( layerName, bc, QgsPointV2( shift ), halfSize );
14031406
if ( mPen.style() != Qt::NoPen )
@@ -2349,11 +2352,6 @@ bool QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScale
23492352
}
23502353
double offsetX = offset.x();
23512354
double offsetY = offset.y();
2352-
if ( mSizeUnit == QgsSymbolV2::MM )
2353-
{
2354-
offsetX *= mmMapUnitScaleFactor;
2355-
offsetY *= mmMapUnitScaleFactor;
2356-
}
23572355

23582356
QPointF outputOffset( offsetX, offsetY );
23592357

@@ -2367,6 +2365,8 @@ bool QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScale
23672365
if ( angle )
23682366
outputOffset = _rotatedOffset( outputOffset, angle );
23692367

2368+
outputOffset *= e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mOffsetUnit, e.mapUnits(), context.renderContext().mapToPixel().mapUnitsPerPixel() );
2369+
23702370
QString path = mPath;
23712371
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_NAME ) )
23722372
{
@@ -2380,7 +2380,7 @@ bool QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScale
23802380
context.setOriginalValueVariable( mOutlineWidth );
23812381
outlineWidth = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH, context, mOutlineWidth ).toDouble();
23822382
}
2383-
outlineWidth = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), outlineWidth, mOutlineWidthUnit, mOutlineWidthMapUnitScale );
2383+
outlineWidth *= e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mOutlineWidthUnit, e.mapUnits(), context.renderContext().mapToPixel().mapUnitsPerPixel() );
23842384

23852385
QColor fillColor = mColor;
23862386
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_FILL ) )
@@ -2424,7 +2424,7 @@ bool QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScale
24242424
p.rotate( angle );
24252425
p.translate( -r.defaultSize().width() / 2.0, -r.defaultSize().height() / 2.0 );
24262426
}
2427-
pd.setShift( shift );
2427+
pd.setShift( shift + QPointF( outputOffset.x(), -outputOffset.y() ) );
24282428
pd.setOutputSize( QRectF( -halfSize, -halfSize, size, size ) );
24292429
pd.setLayer( layerName );
24302430
r.render( &p );

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ void QgsLineSymbolLayerV2::renderPolygonOutline( const QPolygonF& points, QList<
709709
double QgsLineSymbolLayerV2::dxfWidth( const QgsDxfExport& e, QgsSymbolV2RenderContext &context ) const
710710
{
711711
Q_UNUSED( context );
712-
return width() * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() );
712+
return width() * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits(), context.renderContext().mapToPixel().mapUnitsPerPixel() );
713713
}
714714

715715

0 commit comments

Comments
 (0)
Please sign in to comment.