Skip to content
Permalink
Browse files

Consider QgsMapUnitScale in dxf export and fix QgsDxfExport::mapUnitS…

…caleFactor
  • Loading branch information
mhugent committed Apr 12, 2018
1 parent 85fc47a commit 505822f1cd293763f6d176a0e8d399bf2184ebe0
Showing with 43 additions and 5 deletions.
  1. +38 −5 src/core/dxf/qgsdxfexport.cpp
  2. +1 −0 src/core/dxf/qgsdxfexport.h
  3. +4 −0 src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
@@ -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 )
@@ -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 );
@@ -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

0 comments on commit 505822f

Please sign in to comment.
You can’t perform that action at this time.