diff --git a/src/core/dxf/qgsdxfexport.cpp b/src/core/dxf/qgsdxfexport.cpp index db449f419c0d..52db99898eaa 100644 --- a/src/core/dxf/qgsdxfexport.cpp +++ b/src/core/dxf/qgsdxfexport.cpp @@ -501,7 +501,7 @@ void QgsDxfExport::writeBlocks() writeGroup( 30, 0 ); writeGroup( 3, blockName ); - ml->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, ml->sizeUnit(), mMapUnits ) ); + ml->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, ml->sizeUnit(), mMapUnits ), "0" ); //maplayer 0 -> block receives layer from INSERT statement writeGroup( 0, "ENDBLK" ); writeGroup( 8, 0 ); @@ -676,6 +676,7 @@ void QgsDxfExport::endSection() void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, const QgsSymbolLayerV2* symbolLayer ) { +#if 0 //debug: draw rectangle for debugging const QgsMarkerSymbolLayerV2* msl = dynamic_cast< const QgsMarkerSymbolLayerV2* >( symbolLayer ); if ( msl ) @@ -698,6 +699,7 @@ void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, const Q writeGroup( 23, pt.y() + halfSize ); writeGroup( 33, 0.0 ); } +#endif //0 //insert block or write point directly? QHash< const QgsSymbolLayerV2*, QString >::const_iterator blockIt = mPointSymbolBlocks.find( symbolLayer ); @@ -739,6 +741,25 @@ void QgsDxfExport::writePolyline( const QgsPolyline& line, const QString& layer, writeGroup( 0, "SEQEND" ); } +void QgsDxfExport::writeSolid( const QString& layer, int color, const QgsPoint& pt1, const QgsPoint& pt2, const QgsPoint& pt3, const QgsPoint& pt4 ) +{ + writeGroup( 0, "SOLID" ); + writeGroup( 8, layer ); + writeGroup( 62, color ); + writeGroup( 10, pt1.x() ); + writeGroup( 20, pt1.y() ); + writeGroup( 30, 0.0 ); + writeGroup( 11, pt2.x() ); + writeGroup( 21, pt2.y() ); + writeGroup( 31, 0.0 ); + writeGroup( 12, pt3.x() ); + writeGroup( 22, pt3.y() ); + writeGroup( 32, 0.0 ); + writeGroup( 13, pt4.x() ); + writeGroup( 23, pt4.y() ); + writeGroup( 33, 0.0 ); +} + void QgsDxfExport::writeVertex( const QgsPoint& pt, const QString& layer ) { writeGroup( 0, "VERTEX" ); diff --git a/src/core/dxf/qgsdxfexport.h b/src/core/dxf/qgsdxfexport.h index db6d7a8f9b1d..61e315d03031 100644 --- a/src/core/dxf/qgsdxfexport.h +++ b/src/core/dxf/qgsdxfexport.h @@ -68,6 +68,8 @@ class QgsDxfExport void writePolyline( const QgsPolyline& line, const QString& layer, const QString& lineStyleName, int color, double width = -1, bool polygon = false ); + void writeSolid( const QString& layer, int color, const QgsPoint& pt1, const QgsPoint& pt2, const QgsPoint& pt3, const QgsPoint& pt4 ); + private: QList< QgsMapLayer* > mLayers; diff --git a/src/core/dxf/qgsdxfpaintdevice.cpp b/src/core/dxf/qgsdxfpaintdevice.cpp index bac69b3329ad..e3178f6fd7ab 100644 --- a/src/core/dxf/qgsdxfpaintdevice.cpp +++ b/src/core/dxf/qgsdxfpaintdevice.cpp @@ -81,4 +81,12 @@ QPointF QgsDxfPaintDevice::dxfCoordinates( const QPointF& pt ) const return QPointF( x, y ); } +void QgsDxfPaintDevice::setLayer( const QString& layer ) +{ + if ( mPaintEngine ) + { + mPaintEngine->setLayer( layer ); + } +} + diff --git a/src/core/dxf/qgsdxfpaintdevice.h b/src/core/dxf/qgsdxfpaintdevice.h index 02cc2c30cfd6..64b8a7094365 100644 --- a/src/core/dxf/qgsdxfpaintdevice.h +++ b/src/core/dxf/qgsdxfpaintdevice.h @@ -48,6 +48,8 @@ class QgsDxfPaintDevice: public QPaintDevice int metric( PaintDeviceMetric metric ) const; + void setLayer( const QString& layer ); + private: QgsDxfPaintEngine* mPaintEngine; diff --git a/src/core/dxf/qgsdxfpaintengine.cpp b/src/core/dxf/qgsdxfpaintengine.cpp index aea57a052d85..6d899e0b59d4 100644 --- a/src/core/dxf/qgsdxfpaintengine.cpp +++ b/src/core/dxf/qgsdxfpaintengine.cpp @@ -74,18 +74,32 @@ void QgsDxfPaintEngine::drawPolygon( const QPointF* points, int pointCount, Poly QgsPolyline polyline( pointCount ); for ( int i = 0; i < pointCount; ++i ) { - QPointF dxfCoord = mPaintDevice->dxfCoordinates( points[i] ); - polyline[i] = QgsPoint( dxfCoord.x(), dxfCoord.y() ); + polyline[i] = toDxfCoordinates( points[i] ); } - int color = mDxf->closestColorMatch( mPen.color().rgb() ); double width = mPen.widthF() * mPaintDevice->widthScaleFactor(); - mDxf->writePolyline( polyline, "0", "CONTINUOUS", color, width, mode != QPaintEngine::PolylineMode ); + mDxf->writePolyline( polyline, mLayer, "CONTINUOUS", currentPenColor(), width, mode != QPaintEngine::PolylineMode ); } -void QgsDxfPaintEngine::drawRects( const QRectF * rects, int rectCount ) +void QgsDxfPaintEngine::drawRects( const QRectF* rects, int rectCount ) { - QgsDebugMsg( "***********************Dxf paint engine: drawing rects*********************" ); + if ( !mDxf || !mPaintDevice ) + { + return; + } + + for ( int i = 0; i < rectCount; ++i ) + { + double left = rects[i].left(); + double right = rects[i].right(); + double top = rects[i].top(); + double bottom = rects[i].bottom(); + QgsPoint pt1 = toDxfCoordinates( QPointF( left, bottom ) ); + QgsPoint pt2 = toDxfCoordinates( QPointF( right, bottom ) ); + QgsPoint pt3 = toDxfCoordinates( QPointF( left, top ) ); + QgsPoint pt4 = toDxfCoordinates( QPointF( right, top ) ); + mDxf->writeSolid( mLayer, currentPenColor(), pt1, pt2, pt3, pt4 ); + } } void QgsDxfPaintEngine::drawEllipse( const QRectF& rect ) @@ -95,7 +109,6 @@ void QgsDxfPaintEngine::drawEllipse( const QRectF& rect ) void QgsDxfPaintEngine::drawPath( const QPainterPath& path ) { - QgsDebugMsg( "***********************Dxf paint engine: drawing path*********************" ); QList polygonList = path.toFillPolygons(); QList::const_iterator pIt = polygonList.constBegin(); for ( ; pIt != polygonList.constEnd(); ++pIt ) @@ -108,3 +121,24 @@ void QgsDxfPaintEngine::drawLines( const QLineF* lines, int lineCount ) { QgsDebugMsg( "***********************Dxf paint engine: drawing path*********************" ); } + +QgsPoint QgsDxfPaintEngine::toDxfCoordinates( const QPointF& pt ) const +{ + if ( !mPaintDevice || !mDxf ) + { + return QgsPoint( pt.x(), pt.y() ); + } + + QPointF dxfPt = mPaintDevice->dxfCoordinates( mTransform.map( pt ) ); + return QgsPoint( dxfPt.x(), dxfPt.y() ); +} + +int QgsDxfPaintEngine::currentPenColor() const +{ + if ( !mDxf ) + { + return 0; + } + + return mDxf->closestColorMatch( mPen.color().rgb() ); +} diff --git a/src/core/dxf/qgsdxfpaintengine.h b/src/core/dxf/qgsdxfpaintengine.h index 775ced3261b7..3514e1069143 100644 --- a/src/core/dxf/qgsdxfpaintengine.h +++ b/src/core/dxf/qgsdxfpaintengine.h @@ -22,6 +22,7 @@ class QgsDxfExport; class QgsDxfPaintDevice; +class QgsPoint; class QgsDxfPaintEngine: public QPaintEngine { @@ -42,6 +43,9 @@ class QgsDxfPaintEngine: public QPaintEngine void drawPath( const QPainterPath& path ); void drawLines( const QLineF* lines, int lineCount ); + void setLayer( const QString& layer ) { mLayer = layer; } + QString layer() const { return mLayer; } + private: const QgsDxfPaintDevice* mPaintDevice; QgsDxfExport* mDxf; @@ -49,6 +53,10 @@ class QgsDxfPaintEngine: public QPaintEngine //painter state information QTransform mTransform; QPen mPen; + QString mLayer; + + QgsPoint toDxfCoordinates( const QPointF& pt ) const; + int currentPenColor() const; }; #endif // QGSDXFPAINTENGINE_H diff --git a/src/core/symbology-ng/qgsmarkersymbollayerv2.cpp b/src/core/symbology-ng/qgsmarkersymbollayerv2.cpp index 5cddb26d0371..14c757c3d868 100644 --- a/src/core/symbology-ng/qgsmarkersymbollayerv2.cpp +++ b/src/core/symbology-ng/qgsmarkersymbollayerv2.cpp @@ -702,7 +702,7 @@ void QgsSimpleMarkerSymbolLayerV2::drawMarker( QPainter* p, QgsSymbolV2RenderCon } } -void QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor ) const +void QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName ) const { double size = mSize; if ( mSizeUnit == QgsSymbolV2::MM ) @@ -715,7 +715,7 @@ void QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc if ( mName == "circle" ) { e.writeGroup( 0, "CIRCLE" ); - e.writeGroup( 8, "0" ); + e.writeGroup( 8, layerName ); e.writeGroup( 62, colorIndex ); e.writeGroup( 10, halfSize ); @@ -725,39 +725,19 @@ void QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc } else if ( mName == "square" || mName == "rectangle" ) { - e.writeGroup( 0, "SOLID" ); - e.writeGroup( 8, "0" ); - e.writeGroup( 62, colorIndex ); - e.writeGroup( 10, 0.0 ); - e.writeGroup( 20, 0.0 ); - e.writeGroup( 30, 0.0 ); - e.writeGroup( 11, size ); - e.writeGroup( 21, 0.0 ); - e.writeGroup( 31, 0.0 ); - e.writeGroup( 12, 0 ); - e.writeGroup( 22, size ); - e.writeGroup( 32, 0.0 ); - e.writeGroup( 13, size ); - e.writeGroup( 23, size ); - e.writeGroup( 33, 0.0 ); + QgsPoint pt1( 0.0, 0.0 ); + QgsPoint pt2( size, 0.0 ); + QgsPoint pt3( 0.0, size ); + QgsPoint pt4( size, size ); + e.writeSolid( layerName, colorIndex, pt1, pt2, pt3, pt4 ); } else if ( mName == "diamond" ) { - e.writeGroup( 0, "SOLID" ); - e.writeGroup( 8, "0" ); - e.writeGroup( 62, colorIndex ); - e.writeGroup( 10, 0.0 ); - e.writeGroup( 20, halfSize ); - e.writeGroup( 30, 0.0 ); - e.writeGroup( 11, halfSize ); - e.writeGroup( 21, 0.0 ); - e.writeGroup( 31, 0.0 ); - e.writeGroup( 12, halfSize ); - e.writeGroup( 22, size ); - e.writeGroup( 32, 0.0 ); - e.writeGroup( 13, size ); - e.writeGroup( 23, halfSize ); - e.writeGroup( 33, 0.0 ); + QgsPoint pt1( 0.0, halfSize ); + QgsPoint pt2( halfSize, 0.0 ); + QgsPoint pt3( halfSize, size ); + QgsPoint pt4( size, halfSize ); + e.writeSolid( layerName, colorIndex, pt1, pt2, pt3, pt4 ); } } @@ -1166,8 +1146,10 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::createFromSld( QDomElement &element return m; } -void QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor ) const +void QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName ) const { + Q_UNUSED( layerName ); + QSvgRenderer r( mPath ); if ( !r.isValid() ) { @@ -1178,6 +1160,7 @@ void QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScale pd.setDrawingSize( QSizeF( r.defaultSize() ) ); double size = mSize * mmMapUnitScaleFactor ; pd.setOutputSize( QRectF( 0, 0, size, size ) ); + pd.setLayer( layerName ); QPainter p; p.begin( &pd ); diff --git a/src/core/symbology-ng/qgsmarkersymbollayerv2.h b/src/core/symbology-ng/qgsmarkersymbollayerv2.h index 86e0f2864100..965f7946e8bf 100644 --- a/src/core/symbology-ng/qgsmarkersymbollayerv2.h +++ b/src/core/symbology-ng/qgsmarkersymbollayerv2.h @@ -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; + void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName ) const; protected: @@ -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; + void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName ) const; protected: QString mPath; diff --git a/src/core/symbology-ng/qgssymbollayerv2.h b/src/core/symbology-ng/qgssymbollayerv2.h index 1e44716ffdb1..d73c806187ce 100644 --- a/src/core/symbology-ng/qgssymbollayerv2.h +++ b/src/core/symbology-ng/qgssymbollayerv2.h @@ -93,7 +93,7 @@ class CORE_EXPORT QgsSymbolLayerV2 virtual void removeDataDefinedProperty( const QString& property ); virtual void removeDataDefinedProperties(); - virtual void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor ) const { Q_UNUSED( e ); Q_UNUSED( mmMapUnitScaleFactor ); } + virtual void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName ) const { Q_UNUSED( e ); Q_UNUSED( mmMapUnitScaleFactor ); Q_UNUSED( layerName ); } protected: QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false )