Skip to content

Commit a75de2b

Browse files
committedDec 6, 2013
Draw default point symbol if dxf export not supported by marker symbol
1 parent 642b0d5 commit a75de2b

File tree

5 files changed

+54
-13
lines changed

5 files changed

+54
-13
lines changed
 

‎src/core/dxf/qgsdxfexport.cpp‎

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ void QgsDxfExport::endSection()
700700
writeGroup( 0, "ENDSEC" );
701701
}
702702

703-
void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, const QgsFeature* f, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol )
703+
void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, int color, const QgsFeature* f, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol )
704704
{
705705
#if 0
706706
//debug: draw rectangle for debugging
@@ -737,8 +737,12 @@ void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, const Q
737737
{
738738
QgsRenderContext ct;
739739
QgsSymbolV2RenderContext ctx( ct, QgsSymbolV2::MapUnit, symbol->alpha(), false, symbol->renderHints(), f );
740-
symbolLayer->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, msl->sizeUnit(), mMapUnits ), layer, &ctx, f, QPointF( pt.x(), pt.y() ) );
740+
if ( symbolLayer->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, msl->sizeUnit(), mMapUnits ), layer, &ctx, f, QPointF( pt.x(), pt.y() ) ) )
741+
{
742+
return;
743+
}
741744
}
745+
writePoint( layer, color, pt ); //write default point symbol
742746
}
743747
else
744748
{
@@ -782,6 +786,16 @@ void QgsDxfExport::writeLine( const QgsPoint& pt1, const QgsPoint& pt2, const QS
782786
writePolyline( line, layer, lineStyleName, color, width, false );
783787
}
784788

789+
void QgsDxfExport::writePoint( const QString& layer, int color, const QgsPoint& pt )
790+
{
791+
writeGroup( 0, "POINT" );
792+
writeGroup( 8, layer );
793+
writeGroup( 62, color );
794+
writeGroup( 10, pt.x() );
795+
writeGroup( 20, pt.y() );
796+
writeGroup( 30, 0.0 );
797+
}
798+
785799
void QgsDxfExport::writeSolid( const QString& layer, int color, const QgsPoint& pt1, const QgsPoint& pt2, const QgsPoint& pt3, const QgsPoint& pt4 )
786800
{
787801
writeGroup( 0, "SOLID" );
@@ -837,15 +851,34 @@ void QgsDxfExport::addFeature( const QgsFeature& fet, const QString& layer, cons
837851
QgsGeometry* geom = fet.geometry();
838852
if ( geom )
839853
{
840-
int c = colorFromSymbolLayer( symbolLayer );
854+
int c = 0;
855+
if ( mSymbologyExport != NoSymbology )
856+
{
857+
c = colorFromSymbolLayer( symbolLayer );
858+
}
841859
double width = widthFromSymbolLayer( symbolLayer );
842-
QString lineStyleName = lineStyleFromSymbolLayer( symbolLayer );
860+
QString lineStyleName = "CONTINUOUS";
861+
if ( mSymbologyExport != NoSymbology )
862+
{
863+
lineStyleFromSymbolLayer( symbolLayer );
864+
}
843865
QGis::WkbType geometryType = geom->wkbType();
844866

845867
//single point
846868
if ( geometryType == QGis::WKBPoint || geometryType == QGis::WKBPoint25D )
847869
{
848-
writePoint( geom->asPoint(), layer, &fet, symbolLayer, symbol );
870+
writePoint( geom->asPoint(), layer, c, &fet, symbolLayer, symbol );
871+
}
872+
873+
//multipoint
874+
if ( geometryType == QGis::WKBMultiPoint || geometryType == QGis::WKBMultiPoint25D )
875+
{
876+
QgsMultiPoint multiPoint = geom->asMultiPoint();
877+
QgsMultiPoint::const_iterator it = multiPoint.constBegin();
878+
for ( ; it != multiPoint.constEnd(); ++it )
879+
{
880+
writePoint( *it, layer, c, &fet, symbolLayer, symbol );
881+
}
849882
}
850883

851884
//single line

‎src/core/dxf/qgsdxfexport.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class QgsDxfExport
7676
//write line (as a polyline)
7777
void writeLine( const QgsPoint& pt1, const QgsPoint& pt2, const QString& layer, const QString& lineStyleName, int color, double width = -1 );
7878

79+
void writePoint( const QString& layer, int color, const QgsPoint& pt );
80+
7981
private:
8082

8183
QList< QgsMapLayer* > mLayers;
@@ -106,7 +108,7 @@ class QgsDxfExport
106108
void startSection();
107109
void endSection();
108110

109-
void writePoint( const QgsPoint& pt, const QString& layer, const QgsFeature* f, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol );
111+
void writePoint( const QgsPoint& pt, const QString& layer, int color, const QgsFeature* f, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol );
110112
void writeVertex( const QgsPoint& pt, const QString& layer );
111113
void writeDefaultLinestyles();
112114
void writeSymbolLayerLinestyle( const QgsSymbolLayerV2* symbolLayer );

‎src/core/symbology-ng/qgsmarkersymbollayerv2.cpp‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ void QgsSimpleMarkerSymbolLayerV2::drawMarker( QPainter* p, QgsSymbolV2RenderCon
702702
}
703703
}
704704

705-
void QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift ) const
705+
bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift ) const
706706
{
707707
//data defined size?
708708
double size = mSize;
@@ -805,6 +805,11 @@ void QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
805805
QPointF pt4 = t.map( QPointF( halfSize, 0 ) );
806806
e.writeSolid( layerName, colorIndex, QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt4.x(), pt4.y() ) );
807807
}
808+
else
809+
{
810+
return false;
811+
}
812+
return true;
808813
}
809814

810815
//////////
@@ -1212,7 +1217,7 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::createFromSld( QDomElement &element
12121217
return m;
12131218
}
12141219

1215-
void QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f,
1220+
bool QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f,
12161221
const QPointF& shift ) const
12171222
{
12181223
Q_UNUSED( layerName );
@@ -1221,7 +1226,7 @@ void QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScale
12211226
QSvgRenderer r( mPath );
12221227
if ( !r.isValid() )
12231228
{
1224-
return;
1229+
return false;
12251230
}
12261231

12271232
QgsDxfPaintDevice pd( &e );
@@ -1296,6 +1301,7 @@ void QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScale
12961301
pd.setLayer( layerName );
12971302
r.render( &p );
12981303
p.end();
1304+
return true;
12991305
}
13001306

13011307
//////////

‎src/core/symbology-ng/qgsmarkersymbollayerv2.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
7676
QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
7777
void setOutlineWidthUnit( QgsSymbolV2::OutputUnit u ) { mOutlineWidthUnit = u; }
7878

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

8181
protected:
8282

@@ -159,7 +159,7 @@ class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
159159
void setOutputUnit( QgsSymbolV2::OutputUnit unit );
160160
QgsSymbolV2::OutputUnit outputUnit() const;
161161

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

164164
protected:
165165
QString mPath;

‎src/core/symbology-ng/qgssymbollayerv2.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ class CORE_EXPORT QgsSymbolLayerV2
9494
virtual void removeDataDefinedProperties();
9595
bool hasDataDefinedProperties() const { return mDataDefinedProperties.size() > 0; }
9696

97-
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
98-
{ Q_UNUSED( e ); Q_UNUSED( mmMapUnitScaleFactor ); Q_UNUSED( layerName ); Q_UNUSED( context ); Q_UNUSED( f ); Q_UNUSED( shift ); }
97+
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
98+
{ Q_UNUSED( e ); Q_UNUSED( mmMapUnitScaleFactor ); Q_UNUSED( layerName ); Q_UNUSED( context ); Q_UNUSED( f ); Q_UNUSED( shift ); return false; }
9999

100100
protected:
101101
QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false )

0 commit comments

Comments
 (0)
Please sign in to comment.