Skip to content

Commit

Permalink
Draw default point symbol if dxf export not supported by marker symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Dec 6, 2013
1 parent 642b0d5 commit a75de2b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 13 deletions.
43 changes: 38 additions & 5 deletions src/core/dxf/qgsdxfexport.cpp
Expand Up @@ -700,7 +700,7 @@ void QgsDxfExport::endSection()
writeGroup( 0, "ENDSEC" );
}

void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, const QgsFeature* f, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol )
void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, int color, const QgsFeature* f, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol )
{
#if 0
//debug: draw rectangle for debugging
Expand Down Expand Up @@ -737,8 +737,12 @@ void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, const Q
{
QgsRenderContext ct;
QgsSymbolV2RenderContext ctx( ct, QgsSymbolV2::MapUnit, symbol->alpha(), false, symbol->renderHints(), f );
symbolLayer->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, msl->sizeUnit(), mMapUnits ), layer, &ctx, f, QPointF( pt.x(), pt.y() ) );
if ( symbolLayer->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, msl->sizeUnit(), mMapUnits ), layer, &ctx, f, QPointF( pt.x(), pt.y() ) ) )
{
return;
}
}
writePoint( layer, color, pt ); //write default point symbol
}
else
{
Expand Down Expand Up @@ -782,6 +786,16 @@ void QgsDxfExport::writeLine( const QgsPoint& pt1, const QgsPoint& pt2, const QS
writePolyline( line, layer, lineStyleName, color, width, false );
}

void QgsDxfExport::writePoint( const QString& layer, int color, const QgsPoint& pt )
{
writeGroup( 0, "POINT" );
writeGroup( 8, layer );
writeGroup( 62, color );
writeGroup( 10, pt.x() );
writeGroup( 20, pt.y() );
writeGroup( 30, 0.0 );
}

void QgsDxfExport::writeSolid( const QString& layer, int color, const QgsPoint& pt1, const QgsPoint& pt2, const QgsPoint& pt3, const QgsPoint& pt4 )
{
writeGroup( 0, "SOLID" );
Expand Down Expand Up @@ -837,15 +851,34 @@ void QgsDxfExport::addFeature( const QgsFeature& fet, const QString& layer, cons
QgsGeometry* geom = fet.geometry();
if ( geom )
{
int c = colorFromSymbolLayer( symbolLayer );
int c = 0;
if ( mSymbologyExport != NoSymbology )
{
c = colorFromSymbolLayer( symbolLayer );
}
double width = widthFromSymbolLayer( symbolLayer );
QString lineStyleName = lineStyleFromSymbolLayer( symbolLayer );
QString lineStyleName = "CONTINUOUS";
if ( mSymbologyExport != NoSymbology )
{
lineStyleFromSymbolLayer( symbolLayer );
}
QGis::WkbType geometryType = geom->wkbType();

//single point
if ( geometryType == QGis::WKBPoint || geometryType == QGis::WKBPoint25D )
{
writePoint( geom->asPoint(), layer, &fet, symbolLayer, symbol );
writePoint( geom->asPoint(), layer, c, &fet, symbolLayer, symbol );
}

//multipoint
if ( geometryType == QGis::WKBMultiPoint || geometryType == QGis::WKBMultiPoint25D )
{
QgsMultiPoint multiPoint = geom->asMultiPoint();
QgsMultiPoint::const_iterator it = multiPoint.constBegin();
for ( ; it != multiPoint.constEnd(); ++it )
{
writePoint( *it, layer, c, &fet, symbolLayer, symbol );
}
}

//single line
Expand Down
4 changes: 3 additions & 1 deletion src/core/dxf/qgsdxfexport.h
Expand Up @@ -76,6 +76,8 @@ class QgsDxfExport
//write line (as a polyline)
void writeLine( const QgsPoint& pt1, const QgsPoint& pt2, const QString& layer, const QString& lineStyleName, int color, double width = -1 );

void writePoint( const QString& layer, int color, const QgsPoint& pt );

private:

QList< QgsMapLayer* > mLayers;
Expand Down Expand Up @@ -106,7 +108,7 @@ class QgsDxfExport
void startSection();
void endSection();

void writePoint( const QgsPoint& pt, const QString& layer, const QgsFeature* f, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol );
void writePoint( const QgsPoint& pt, const QString& layer, int color, const QgsFeature* f, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol );
void writeVertex( const QgsPoint& pt, const QString& layer );
void writeDefaultLinestyles();
void writeSymbolLayerLinestyle( const QgsSymbolLayerV2* symbolLayer );
Expand Down
12 changes: 9 additions & 3 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Expand Up @@ -702,7 +702,7 @@ void QgsSimpleMarkerSymbolLayerV2::drawMarker( QPainter* p, QgsSymbolV2RenderCon
}
}

void QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift ) const
bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift ) const
{
//data defined size?
double size = mSize;
Expand Down Expand Up @@ -805,6 +805,11 @@ void QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
QPointF pt4 = t.map( QPointF( halfSize, 0 ) );
e.writeSolid( layerName, colorIndex, QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt4.x(), pt4.y() ) );
}
else
{
return false;
}
return true;
}

//////////
Expand Down Expand Up @@ -1212,7 +1217,7 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::createFromSld( QDomElement &element
return m;
}

void QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f,
bool QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f,
const QPointF& shift ) const
{
Q_UNUSED( layerName );
Expand All @@ -1221,7 +1226,7 @@ void QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScale
QSvgRenderer r( mPath );
if ( !r.isValid() )
{
return;
return false;
}

QgsDxfPaintDevice pd( &e );
Expand Down Expand Up @@ -1296,6 +1301,7 @@ void QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScale
pd.setLayer( layerName );
r.render( &p );
p.end();
return true;
}

//////////
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.h
Expand Up @@ -76,7 +76,7 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
void setOutlineWidthUnit( QgsSymbolV2::OutputUnit u ) { mOutlineWidthUnit = u; }

void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift = QPointF( 0.0, 0.0 ) ) const;
bool writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift = QPointF( 0.0, 0.0 ) ) const;

protected:

Expand Down Expand Up @@ -159,7 +159,7 @@ class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
void setOutputUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit outputUnit() const;

void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift = QPointF( 0.0, 0.0 ) ) const;
bool writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift = QPointF( 0.0, 0.0 ) ) const;

protected:
QString mPath;
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgssymbollayerv2.h
Expand Up @@ -94,8 +94,8 @@ class CORE_EXPORT QgsSymbolLayerV2
virtual void removeDataDefinedProperties();
bool hasDataDefinedProperties() const { return mDataDefinedProperties.size() > 0; }

virtual void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift = QPointF( 0.0, 0.0 ) ) const
{ Q_UNUSED( e ); Q_UNUSED( mmMapUnitScaleFactor ); Q_UNUSED( layerName ); Q_UNUSED( context ); Q_UNUSED( f ); Q_UNUSED( shift ); }
virtual bool writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift = QPointF( 0.0, 0.0 ) ) const
{ Q_UNUSED( e ); Q_UNUSED( mmMapUnitScaleFactor ); Q_UNUSED( layerName ); Q_UNUSED( context ); Q_UNUSED( f ); Q_UNUSED( shift ); return false; }

protected:
QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false )
Expand Down

0 comments on commit a75de2b

Please sign in to comment.