Skip to content
Permalink
Browse files

Bugfixes for dxf export

  • Loading branch information
mhugent committed Jan 15, 2014
1 parent 0ca7316 commit e721e7f71e4ddc6f8b4fac7dbcda858fa9716562
@@ -547,8 +547,9 @@ void QgsDxfExport::writeEntities()
continue;
}

QgsRenderContext ctx;
QgsRenderContext ctx = renderContext();
ctx.setRendererScale( mSymbologyScaleDenominator );
QgsSymbolV2RenderContext sctx( ctx, QgsSymbolV2::MM , 1.0, false, 0, 0 );
QgsFeatureRendererV2* renderer = vl->rendererV2();
renderer->startRender( ctx, vl );

@@ -569,9 +570,10 @@ void QgsDxfExport::writeEntities()
QgsFeature fet;
while ( featureIt.nextFeature( fet ) )
{
sctx.setFeature( &fet );
if ( mSymbologyExport == NoSymbology )
{
addFeature( fet, dxfLayerName( vl->name() ), 0, 0 ); //no symbology at all
addFeature( sctx, dxfLayerName( vl->name() ), 0, 0 ); //no symbology at all
}
else
{
@@ -593,7 +595,7 @@ void QgsDxfExport::writeEntities()
int nSymbolLayers = ( *symbolIt )->symbolLayerCount();
for ( int i = 0; i < nSymbolLayers; ++i )
{
addFeature( fet, dxfLayerName( vl->name() ), ( *symbolIt )->symbolLayer( i ), *symbolIt );
addFeature( sctx, dxfLayerName( vl->name() ), ( *symbolIt )->symbolLayer( i ), *symbolIt );
}
}
}
@@ -605,7 +607,7 @@ void QgsDxfExport::writeEntities()
{
continue;
}
addFeature( fet, dxfLayerName( vl->name() ), s->symbolLayer( 0 ), s );
addFeature( sctx, dxfLayerName( vl->name() ), s->symbolLayer( 0 ), s );
}
}
}
@@ -629,7 +631,9 @@ void QgsDxfExport::writeEntitiesSymbolLevels( QgsVectorLayer* layer )
}
QHash< QgsSymbolV2*, QList<QgsFeature> > features;

startRender( layer );
QgsRenderContext ctx = renderContext();
QgsSymbolV2RenderContext sctx( ctx, QgsSymbolV2::MM , 1.0, false, 0, 0 );
renderer->startRender( ctx, layer );

//get iterator
QgsFeatureRequest req;
@@ -695,11 +699,11 @@ void QgsDxfExport::writeEntitiesSymbolLevels( QgsVectorLayer* layer )
QList<QgsFeature>::iterator featureIt = featureList.begin();
for ( ; featureIt != featureList.end(); ++featureIt )
{
addFeature( *featureIt, layer->name(), levelIt.key()->symbolLayer( llayer ), levelIt.key() );
addFeature( sctx, layer->name(), levelIt.key()->symbolLayer( llayer ), levelIt.key() );
}
}
}
stopRender( layer );
renderer->stopRender( ctx );
}

void QgsDxfExport::writeEndFile()
@@ -874,17 +878,23 @@ QgsRectangle QgsDxfExport::dxfExtent() const
return extent;
}

void QgsDxfExport::addFeature( const QgsFeature& fet, const QString& layer, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol )
void QgsDxfExport::addFeature( const QgsSymbolV2RenderContext& ctx, const QString& layer, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol )
{
QgsGeometry* geom = fet.geometry();
const QgsFeature* fet = ctx.feature();
if ( !fet )
{
return;
}

QgsGeometry* geom = fet->geometry();
if ( geom )
{
int c = 0;
if ( mSymbologyExport != NoSymbology )
{
c = colorFromSymbolLayer( symbolLayer );
c = colorFromSymbolLayer( symbolLayer, ctx );
}
double width = symbolLayer->dxfWidth( *this );;
double width = symbolLayer->dxfWidth( *this, ctx );
QString lineStyleName = "CONTINUOUS";
if ( mSymbologyExport != NoSymbology )
{
@@ -895,7 +905,7 @@ void QgsDxfExport::addFeature( const QgsFeature& fet, const QString& layer, cons
//single point
if ( geometryType == QGis::WKBPoint || geometryType == QGis::WKBPoint25D )
{
writePoint( geom->asPoint(), layer, c, &fet, symbolLayer, symbol );
writePoint( geom->asPoint(), layer, c, fet, symbolLayer, symbol );
}

//multipoint
@@ -905,7 +915,7 @@ void QgsDxfExport::addFeature( const QgsFeature& fet, const QString& layer, cons
QgsMultiPoint::const_iterator it = multiPoint.constBegin();
for ( ; it != multiPoint.constEnd(); ++it )
{
writePoint( *it, layer, c, &fet, symbolLayer, symbol );
writePoint( *it, layer, c, fet, symbolLayer, symbol );
}
}

@@ -974,14 +984,14 @@ double QgsDxfExport::scaleToMapUnits( double value, QgsSymbolV2::OutputUnit symb
return value;
}

int QgsDxfExport::colorFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer )
int QgsDxfExport::colorFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2RenderContext& ctx )
{
if ( !symbolLayer )
{
return 0;
}

QColor c = symbolLayer->dxfColor();
QColor c = symbolLayer->dxfColor( ctx );
return closestColorMatch( c.rgba() );
}

@@ -1046,40 +1056,6 @@ QgsRenderContext QgsDxfExport::renderContext() const
return context;
}

void QgsDxfExport::startRender( QgsVectorLayer* vl ) const
{
if ( !vl )
{
return;
}

QgsFeatureRendererV2* renderer = vl->rendererV2();
if ( !renderer )
{
return;
}

QgsRenderContext ctx = renderContext();
renderer->startRender( ctx, vl );
}

void QgsDxfExport::stopRender( QgsVectorLayer* vl ) const
{
if ( !vl )
{
return;
}

QgsFeatureRendererV2* renderer = vl->rendererV2();
if ( !renderer )
{
return;
}

QgsRenderContext ctx = renderContext();
renderer->stopRender( ctx );
}

double QgsDxfExport::mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits )
{
if ( symbolUnits == QgsSymbolV2::MapUnit )
@@ -1188,9 +1164,9 @@ void QgsDxfExport::writeSymbolLayerLinestyle( const QgsSymbolLayerV2* symbolLaye

QgsSymbolV2::OutputUnit unit;
QVector<qreal> customLinestyle = symbolLayer->dxfCustomDashPattern( unit );
if ( customLinestyle.size() < 0 )
if ( customLinestyle.size() > 0 )
{
QString name = QString( "symbolLayer%1" ).arg( mSymbolLayerCounter );
QString name = QString( "symbolLayer%1" ).arg( mSymbolLayerCounter++ );
writeLinestyle( name, customLinestyle, unit );
mLineStyles.insert( symbolLayer, name );
}
@@ -1220,7 +1196,7 @@ void QgsDxfExport::writeLinestyle( const QString& styleName, const QVector<qreal
QVector<qreal>::const_iterator dashIt = pattern.constBegin();
for ( ; dashIt != pattern.constEnd(); ++dashIt )
{
length += *dashIt;
length += ( *dashIt * mapUnitScaleFactor( mSymbologyScaleDenominator, u, mMapUnits ) );
}

writeGroup( 0, "LTYPE" );
@@ -137,11 +137,11 @@ class CORE_EXPORT QgsDxfExport

QgsRectangle dxfExtent() const;

void addFeature( const QgsFeature& fet, const QString& layer, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol );
void addFeature( const QgsSymbolV2RenderContext& ctx, const QString& layer, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol );
double scaleToMapUnits( double value, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits ) const;

//returns dxf palette index from symbol layer color
static int colorFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer );
static int colorFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2RenderContext& ctx );
QString lineStyleFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer );

//functions for dxf palette
@@ -150,8 +150,6 @@ class CORE_EXPORT QgsDxfExport

//helper functions for symbology export
QgsRenderContext renderContext() const;
void startRender( QgsVectorLayer* vl ) const;
void stopRender( QgsVectorLayer* vl ) const;

QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2* > > symbolLayers();
static int nLineTypes( const QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2*> >& symbolLayers );
@@ -289,19 +289,35 @@ double QgsSimpleFillSymbolLayerV2::estimateMaxBleed() const
return penBleed + offsetBleed;
}

double QgsSimpleFillSymbolLayerV2::dxfWidth( const QgsDxfExport& e ) const
double QgsSimpleFillSymbolLayerV2::dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const
{
return mBorderWidth * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mBorderWidthUnit, e.mapUnits() );
double width = mBorderWidth;
QgsExpression* widthBorderExpression = expression( "width_border" );
if ( widthBorderExpression )
{
width = widthBorderExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
}
return width * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mBorderWidthUnit, e.mapUnits() );
}

QColor QgsSimpleFillSymbolLayerV2::dxfColor() const
QColor QgsSimpleFillSymbolLayerV2::dxfColor( const QgsSymbolV2RenderContext& context ) const
{
if ( mBrushStyle == Qt::NoBrush )
{
QgsExpression* colorBorderExpression = expression( "color_border" );
if ( colorBorderExpression )
{
return QgsSymbolLayerV2Utils::decodeColor( colorBorderExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() );
}
return mBorderColor;
}
else
{
QgsExpression* colorExpression = expression( "color" );
if ( colorExpression )
{
return QgsSymbolLayerV2Utils::decodeColor( colorExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() );
}
return mColor;
}
}
@@ -858,12 +874,18 @@ double QgsImageFillSymbolLayer::estimateMaxBleed() const
return subLayerBleed;
}

double QgsImageFillSymbolLayer::dxfWidth( const QgsDxfExport& e ) const
double QgsImageFillSymbolLayer::dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const
{
return mOutlineWidth * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mOutlineWidthUnit, e.mapUnits() );
double width = mOutlineWidth;
QgsExpression* widthExpression = expression( "width" );
if ( widthExpression )
{
width = widthExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
}
return width * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mOutlineWidthUnit, e.mapUnits() );
}

QColor QgsImageFillSymbolLayer::dxfColor() const
QColor QgsImageFillSymbolLayer::dxfColor( const QgsSymbolV2RenderContext& context ) const
{
if ( !mOutline )
{
@@ -99,8 +99,8 @@ class CORE_EXPORT QgsSimpleFillSymbolLayerV2 : public QgsFillSymbolLayerV2

double estimateMaxBleed() const;

double dxfWidth( const QgsDxfExport& e ) const;
QColor dxfColor() const;
double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
QColor dxfColor( const QgsSymbolV2RenderContext& context ) const;
Qt::PenStyle dxfPenStyle() const;

protected:
@@ -287,8 +287,8 @@ class CORE_EXPORT QgsImageFillSymbolLayer: public QgsFillSymbolLayerV2

double estimateMaxBleed() const;

virtual double dxfWidth( const QgsDxfExport& e ) const;
virtual QColor dxfColor() const;
virtual double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
virtual QColor dxfColor( const QgsSymbolV2RenderContext& context ) const;
virtual Qt::PenStyle dxfPenStyle() const;

protected:
@@ -14,6 +14,7 @@
***************************************************************************/

#include "qgslinesymbollayerv2.h"
#include "qgsdxfexport.h"
#include "qgssymbollayerv2utils.h"
#include "qgsexpression.h"
#include "qgsrendercontext.h"
@@ -395,6 +396,32 @@ QVector<qreal> QgsSimpleLineSymbolLayerV2::dxfCustomDashPattern( QgsSymbolV2::Ou
return mUseCustomDashPattern ? mCustomDashVector : QVector<qreal>() ;
}

double QgsSimpleLineSymbolLayerV2::dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const
{
double width = mWidth;
QgsExpression* strokeWidthExpression = expression( "width" );
if ( strokeWidthExpression )
{
width = strokeWidthExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble() * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() );
}
else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale )
{
width = mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit );
}

return width * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() );
}

QColor QgsSimpleLineSymbolLayerV2::dxfColor( const QgsSymbolV2RenderContext& context ) const
{
QgsExpression* strokeColorExpression = expression( "color" );
if ( strokeColorExpression )
{
return ( QgsSymbolLayerV2Utils::decodeColor( strokeColorExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
}
return mColor;
}

/////////


@@ -93,6 +93,9 @@ class CORE_EXPORT QgsSimpleLineSymbolLayerV2 : public QgsLineSymbolLayerV2

QVector<qreal> dxfCustomDashPattern( QgsSymbolV2::OutputUnit& unit ) const;

double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
QColor dxfColor( const QgsSymbolV2RenderContext& context ) const;

protected:
Qt::PenStyle mPenStyle;
Qt::PenJoinStyle mPenJoinStyle;
@@ -94,14 +94,16 @@ bool QgsSymbolLayerV2::writeDxf( QgsDxfExport& e,
return false;
}

double QgsSymbolLayerV2::dxfWidth( const QgsDxfExport& e ) const
double QgsSymbolLayerV2::dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const
{
Q_UNUSED( e );
Q_UNUSED( context );
return 1.0;
}

QColor QgsSymbolLayerV2::dxfColor() const
QColor QgsSymbolLayerV2::dxfColor( const QgsSymbolV2RenderContext& context ) const
{
Q_UNUSED( context );
return color();
}

@@ -363,8 +365,9 @@ void QgsLineSymbolLayerV2::renderPolygonOutline( const QPolygonF& points, QList<
}
}

double QgsLineSymbolLayerV2::dxfWidth( const QgsDxfExport& e ) const
double QgsLineSymbolLayerV2::dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const
{
Q_UNUSED( context );
return ( width() * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() ) );
}

@@ -119,9 +119,9 @@ class CORE_EXPORT QgsSymbolLayerV2
const QgsFeature* f,
const QPointF& shift = QPointF( 0.0, 0.0 ) ) const;

virtual double dxfWidth( const QgsDxfExport& e ) const;
virtual double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;

virtual QColor dxfColor() const;
virtual QColor dxfColor( const QgsSymbolV2RenderContext& context ) const;

virtual QVector<qreal> dxfCustomDashPattern( QgsSymbolV2::OutputUnit& unit ) const;
virtual Qt::PenStyle dxfPenStyle() const;
@@ -254,7 +254,7 @@ class CORE_EXPORT QgsLineSymbolLayerV2 : public QgsSymbolLayerV2

void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );

virtual double dxfWidth( const QgsDxfExport& e ) const;
virtual double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;

protected:
QgsLineSymbolLayerV2( bool locked = false );

0 comments on commit e721e7f

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