Skip to content

Commit 85fc47a

Browse files
committedApr 12, 2018
Support symbology width in pixels in dxf export
1 parent cbfdb3d commit 85fc47a

File tree

7 files changed

+24
-19
lines changed

7 files changed

+24
-19
lines changed
 

‎python/core/dxf/qgsdxfexport.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ 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+
static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits, double mapUnitsPerPixel = 1.0 );
379379

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

‎src/core/dxf/qgsdxfexport.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ void QgsDxfExport::writeBlocks()
932932
writeGroup( 1, "" );
933933

934934
// maplayer 0 -> block receives layer from INSERT statement
935-
ml->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, ml->sizeUnit(), mMapUnits ), "0", ctx );
935+
ml->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, ml->sizeUnit(), mMapUnits, ctx.renderContext().mapToPixel().mapUnitsPerPixel() ), "0", ctx );
936936

937937
writeGroup( 0, "ENDBLK" );
938938
writeHandle();
@@ -3427,7 +3427,7 @@ void QgsDxfExport::writePoint( const QgsPointV2 &pt, const QString& layer, const
34273427
const QgsMarkerSymbolLayerV2* msl = dynamic_cast< const QgsMarkerSymbolLayerV2* >( symbolLayer );
34283428
if ( msl && symbol )
34293429
{
3430-
if ( symbolLayer->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, msl->sizeUnit(), mMapUnits ), layer, ctx, QPointF( pt.x(), pt.y() ) ) )
3430+
if ( symbolLayer->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, msl->sizeUnit(), mMapUnits, ctx.renderContext().mapToPixel().mapUnitsPerPixel() ), layer, ctx, QPointF( pt.x(), pt.y() ) ) )
34313431
{
34323432
return;
34333433
}
@@ -4039,14 +4039,19 @@ QgsRenderContext QgsDxfExport::renderContext() const
40394039
return context;
40404040
}
40414041

4042-
double QgsDxfExport::mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits )
4042+
double QgsDxfExport::mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits, double mapUnitsPerPixel )
40434043
{
40444044
if ( symbolUnits == QgsSymbolV2::MapUnit )
40454045
{
40464046
return 1.0;
40474047
}
4048-
// MM symbol unit
4049-
return scaleDenominator * QgsUnitTypes::fromUnitToUnitFactor( QGis::Meters, mapUnits ) / 1000.0;
4048+
// MM or Pixel
4049+
double scaleFactor = scaleDenominator * QgsUnitTypes::fromUnitToUnitFactor( QGis::Meters, mapUnits ) / 1000.0;
4050+
if ( symbolUnits == QgsSymbolV2::Pixel )
4051+
{
4052+
scaleFactor *= mapUnitsPerPixel;
4053+
}
4054+
return scaleFactor;
40504055
}
40514056

40524057
QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2* > > QgsDxfExport::symbolLayers( QgsRenderContext &context )
@@ -4177,7 +4182,7 @@ void QgsDxfExport::writeLinetype( const QString& styleName, const QVector<qreal>
41774182
QVector<qreal>::const_iterator dashIt = pattern.constBegin();
41784183
for ( ; dashIt != pattern.constEnd(); ++dashIt )
41794184
{
4180-
length += ( *dashIt * mapUnitScaleFactor( mSymbologyScaleDenominator, u, mMapUnits ) );
4185+
length += ( *dashIt * mapUnitScaleFactor( mSymbologyScaleDenominator, u, mMapUnits, mMapSettings.mapToPixel().mapUnitsPerPixel() ) );
41814186
}
41824187

41834188
writeGroup( 0, "LTYPE" );
@@ -4198,7 +4203,7 @@ void QgsDxfExport::writeLinetype( const QString& styleName, const QVector<qreal>
41984203
{
41994204
// map units or mm?
42004205
double segmentLength = ( isGap ? -*dashIt : *dashIt );
4201-
segmentLength *= mapUnitScaleFactor( mSymbologyScaleDenominator, u, mMapUnits );
4206+
segmentLength *= mapUnitScaleFactor( mSymbologyScaleDenominator, u, mMapUnits, mMapSettings.mapToPixel().mapUnitsPerPixel() );
42024207
writeGroup( 49, segmentLength );
42034208
writeGroup( 74, 0 );
42044209
isGap = !isGap;

‎src/core/dxf/qgsdxfexport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ 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+
static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits, double mapUnitsPerPixel = 1.0 );
406406

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

‎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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,14 +620,14 @@ 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
}
625625
else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale )
626626
{
627627
width = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), mWidth, mWidthUnit, mWidthMapUnitScale );
628628
}
629629

630-
return width * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() );
630+
return width * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits(), context.renderContext().mapToPixel().mapUnitsPerPixel() );
631631
}
632632

633633
QColor QgsSimpleLineSymbolLayerV2::dxfColor( QgsSymbolV2RenderContext& context ) const

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
13001300
}
13011301
}
13021302

1303-
size *= e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mSizeUnit, e.mapUnits() );
1303+
size *= e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mSizeUnit, e.mapUnits(), context.renderContext().mapToPixel().mapUnitsPerPixel() );
13041304
double halfSize = size / 2.0;
13051305

13061306
//outlineWidth
@@ -1311,7 +1311,7 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
13111311
context.setOriginalValueVariable( mOutlineWidth );
13121312
outlineWidth = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH, context, mOutlineWidth ).toDouble();
13131313
}
1314-
outlineWidth *= e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mOutlineWidthUnit, e.mapUnits() );
1314+
outlineWidth *= e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mOutlineWidthUnit, e.mapUnits(), context.renderContext().mapToPixel().mapUnitsPerPixel() );
13151315

13161316
//color
13171317
QColor pc = mPen.color();
@@ -1364,7 +1364,7 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
13641364
if ( angle )
13651365
off = _rotatedOffset( off, angle );
13661366

1367-
off *= e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mSizeUnit, e.mapUnits() );
1367+
off *= e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mSizeUnit, e.mapUnits(), context.renderContext().mapToPixel().mapUnitsPerPixel() );
13681368

13691369
QTransform t;
13701370
t.translate( shift.x() + off.x(), shift.y() - off.y() );
@@ -2357,7 +2357,7 @@ bool QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScale
23572357
if ( angle )
23582358
outputOffset = _rotatedOffset( outputOffset, angle );
23592359

2360-
outputOffset *= e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mOffsetUnit, e.mapUnits() );
2360+
outputOffset *= e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mOffsetUnit, e.mapUnits(), context.renderContext().mapToPixel().mapUnitsPerPixel() );
23612361

23622362
QString path = mPath;
23632363
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_NAME ) )
@@ -2372,7 +2372,7 @@ bool QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScale
23722372
context.setOriginalValueVariable( mOutlineWidth );
23732373
outlineWidth = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH, context, mOutlineWidth ).toDouble();
23742374
}
2375-
outlineWidth *= e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mOutlineWidthUnit, e.mapUnits() );
2375+
outlineWidth *= e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mOutlineWidthUnit, e.mapUnits(), context.renderContext().mapToPixel().mapUnitsPerPixel() );
23762376

23772377
QColor fillColor = mColor;
23782378
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_FILL ) )

‎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.