Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Consider QgsMapUnitScale in dxf export and fix QgsDxfExport::mapUnitS…
…caleFactor
  • Loading branch information
mhugent committed Apr 12, 2018
1 parent 85fc47a commit 505822f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
43 changes: 38 additions & 5 deletions src/core/dxf/qgsdxfexport.cpp
Expand Up @@ -4045,13 +4045,46 @@ double QgsDxfExport::mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::O
{
return 1.0;
}
// MM or Pixel
double scaleFactor = scaleDenominator * QgsUnitTypes::fromUnitToUnitFactor( QGis::Meters, mapUnits ) / 1000.0;
if ( symbolUnits == QgsSymbolV2::Pixel )
else if ( symbolUnits == QgsSymbolV2::MM )
{
scaleFactor *= mapUnitsPerPixel;
return ( scaleDenominator * QgsUnitTypes::fromUnitToUnitFactor( QGis::Meters, mapUnits ) / 1000.0 );
}
return scaleFactor;
else if ( symbolUnits == QgsSymbolV2::Pixel )
{
return mapUnitsPerPixel;
}
}

void QgsDxfExport::clipValueToMapUnitScale( double& value, const QgsMapUnitScale& scale, double pixelToMMFactor ) const
{
if ( !scale.minSizeMMEnabled && !scale.maxSizeMMEnabled )
{
return;
}

double mapUnitsPerPixel = mMapSettings.mapToPixel().mapUnitsPerPixel();

double minSizeMU = -DBL_MAX;
if ( scale.minSizeMMEnabled )
{
minSizeMU = scale.minSizeMM * pixelToMMFactor * mapUnitsPerPixel;
}
if ( !qgsDoubleNear( scale.minScale, 0.0 ) )
{
minSizeMU = qMax( minSizeMU, value );
}
value = qMax( value, minSizeMU );

double maxSizeMU = DBL_MAX;
if ( scale.maxSizeMMEnabled )
{
maxSizeMU = scale.maxSizeMM * pixelToMMFactor * mapUnitsPerPixel;
}
if ( !qgsDoubleNear( scale.maxScale, 0.0 ) )
{
maxSizeMU = qMin( maxSizeMU, value );
}
value = qMin( value, maxSizeMU );
}

QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2* > > QgsDxfExport::symbolLayers( QgsRenderContext &context )
Expand Down
1 change: 1 addition & 0 deletions src/core/dxf/qgsdxfexport.h
Expand Up @@ -403,6 +403,7 @@ class CORE_EXPORT QgsDxfExport
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, double mapUnitsPerPixel = 1.0 );
void clipValueToMapUnitScale( double& value, const QgsMapUnitScale& scale, double pixelToMMFactor ) const;

//! Return cleaned layer name for use in DXF
static QString dxfLayerName( const QString &name );
Expand Down
4 changes: 4 additions & 0 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Expand Up @@ -1301,6 +1301,10 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
}

size *= e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mSizeUnit, e.mapUnits(), context.renderContext().mapToPixel().mapUnitsPerPixel() );
if ( mSizeUnit == QgsSymbolV2::MapUnit )
{
e.clipValueToMapUnitScale( size, mSizeMapUnitScale, context.renderContext().scaleFactor() );
}
double halfSize = size / 2.0;

//outlineWidth
Expand Down

0 comments on commit 505822f

Please sign in to comment.