Skip to content

Commit

Permalink
Support symbology width in pixels in dxf export
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Apr 12, 2018
1 parent cbfdb3d commit 85fc47a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion python/core/dxf/qgsdxfexport.sip
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ class QgsDxfExport
//! @note added in 2.15
void writeMText( const QString &layer, const QString &text, const QgsPointV2 &pt, double width, double angle, const QColor& color );

static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits );
static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits, double mapUnitsPerPixel = 1.0 );

//! Return cleaned layer name for use in DXF
static QString dxfLayerName( const QString &name );
Expand Down
19 changes: 12 additions & 7 deletions src/core/dxf/qgsdxfexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ void QgsDxfExport::writeBlocks()
writeGroup( 1, "" );

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

writeGroup( 0, "ENDBLK" );
writeHandle();
Expand Down Expand Up @@ -3427,7 +3427,7 @@ void QgsDxfExport::writePoint( const QgsPointV2 &pt, const QString& layer, const
const QgsMarkerSymbolLayerV2* msl = dynamic_cast< const QgsMarkerSymbolLayerV2* >( symbolLayer );
if ( msl && symbol )
{
if ( symbolLayer->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, msl->sizeUnit(), mMapUnits ), layer, ctx, QPointF( pt.x(), pt.y() ) ) )
if ( symbolLayer->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, msl->sizeUnit(), mMapUnits, ctx.renderContext().mapToPixel().mapUnitsPerPixel() ), layer, ctx, QPointF( pt.x(), pt.y() ) ) )
{
return;
}
Expand Down Expand Up @@ -4039,14 +4039,19 @@ QgsRenderContext QgsDxfExport::renderContext() const
return context;
}

double QgsDxfExport::mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits )
double QgsDxfExport::mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits, double mapUnitsPerPixel )
{
if ( symbolUnits == QgsSymbolV2::MapUnit )
{
return 1.0;
}
// MM symbol unit
return scaleDenominator * QgsUnitTypes::fromUnitToUnitFactor( QGis::Meters, mapUnits ) / 1000.0;
// MM or Pixel
double scaleFactor = scaleDenominator * QgsUnitTypes::fromUnitToUnitFactor( QGis::Meters, mapUnits ) / 1000.0;
if ( symbolUnits == QgsSymbolV2::Pixel )
{
scaleFactor *= mapUnitsPerPixel;
}
return scaleFactor;
}

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

writeGroup( 0, "LTYPE" );
Expand All @@ -4198,7 +4203,7 @@ void QgsDxfExport::writeLinetype( const QString& styleName, const QVector<qreal>
{
// map units or mm?
double segmentLength = ( isGap ? -*dashIt : *dashIt );
segmentLength *= mapUnitScaleFactor( mSymbologyScaleDenominator, u, mMapUnits );
segmentLength *= mapUnitScaleFactor( mSymbologyScaleDenominator, u, mMapUnits, mMapSettings.mapToPixel().mapUnitsPerPixel() );
writeGroup( 49, segmentLength );
writeGroup( 74, 0 );
isGap = !isGap;
Expand Down
2 changes: 1 addition & 1 deletion src/core/dxf/qgsdxfexport.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ class CORE_EXPORT QgsDxfExport
//! @note added in 2.15
void writeMText( const QString &layer, const QString &text, const QgsPointV2 &pt, double width, double angle, const QColor& color );

static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits );
static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits, double mapUnitsPerPixel = 1.0 );

//! Return cleaned layer name for use in DXF
static QString dxfLayerName( const QString &name );
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ double QgsSimpleFillSymbolLayerV2::dxfWidth( const QgsDxfExport& e, QgsSymbolV2R
context.setOriginalValueVariable( mBorderWidth );
width = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH_BORDER, context, mBorderWidth ).toDouble();
}
return width * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mBorderWidthUnit, e.mapUnits() );
return width * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mBorderWidthUnit, e.mapUnits(), context.renderContext().mapToPixel().mapUnitsPerPixel() );
}

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

QColor QgsImageFillSymbolLayer::dxfColor( QgsSymbolV2RenderContext &context ) const
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgslinesymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,14 +620,14 @@ double QgsSimpleLineSymbolLayerV2::dxfWidth( const QgsDxfExport& e, QgsSymbolV2R
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH ) )
{
context.setOriginalValueVariable( mWidth );
width = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH, context, mWidth ).toDouble() * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() );
width = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH, context, mWidth ).toDouble();
}
else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale )
{
width = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), mWidth, mWidthUnit, mWidthMapUnitScale );
}

return width * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() );
return width * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits(), context.renderContext().mapToPixel().mapUnitsPerPixel() );
}

QColor QgsSimpleLineSymbolLayerV2::dxfColor( QgsSymbolV2RenderContext& context ) const
Expand Down
10 changes: 5 additions & 5 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
}
}

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

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

//color
QColor pc = mPen.color();
Expand Down Expand Up @@ -1364,7 +1364,7 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
if ( angle )
off = _rotatedOffset( off, angle );

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

QTransform t;
t.translate( shift.x() + off.x(), shift.y() - off.y() );
Expand Down Expand Up @@ -2357,7 +2357,7 @@ bool QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScale
if ( angle )
outputOffset = _rotatedOffset( outputOffset, angle );

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

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

QColor fillColor = mColor;
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_FILL ) )
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgssymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ void QgsLineSymbolLayerV2::renderPolygonOutline( const QPolygonF& points, QList<
double QgsLineSymbolLayerV2::dxfWidth( const QgsDxfExport& e, QgsSymbolV2RenderContext &context ) const
{
Q_UNUSED( context );
return width() * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() );
return width() * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits(), context.renderContext().mapToPixel().mapUnitsPerPixel() );
}


Expand Down

0 comments on commit 85fc47a

Please sign in to comment.