Skip to content

Commit a9d92cd

Browse files
committedNov 23, 2013
Convert painterpath to polygons for dxf
1 parent 78fbee3 commit a9d92cd

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed
 

‎src/core/dxf/qgsdxfpaintdevice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ double QgsDxfPaintDevice::widthScaleFactor() const
6969
return ( widthFactor + heightFactor ) / 2.0;
7070
}
7171

72-
QPointF QgsDxfPaintDevice::dxfCoordinates( const QPointF& pt )
72+
QPointF QgsDxfPaintDevice::dxfCoordinates( const QPointF& pt ) const
7373
{
7474
if ( !mDrawingSize.isValid() || mRectangle.isEmpty() )
7575
{

‎src/core/dxf/qgsdxfpaintdevice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class QgsDxfPaintDevice: public QPaintDevice
4141
double widthScaleFactor() const;
4242

4343
/**Converts a point from device coordinates to dxf coordinates*/
44-
QPointF dxfCoordinates( const QPointF& pt );
44+
QPointF dxfCoordinates( const QPointF& pt ) const;
4545

4646
/*int height() const { return mDrawingSize.height(); }
4747
int width() const { return mDrawingSize.width(); }*/

‎src/core/dxf/qgsdxfpaintengine.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "qgsdxfpaintengine.h"
1919
#include "qgsdxfexport.h"
20+
#include "qgsdxfpaintdevice.h"
2021
#include "qgslogger.h"
2122

2223
QgsDxfPaintEngine::QgsDxfPaintEngine( const QgsDxfPaintDevice* dxfDevice, QgsDxfExport* dxf ): QPaintEngine( QPaintEngine::AllFeatures /*QPaintEngine::PainterPaths | QPaintEngine::PaintOutsidePaintEvent*/ )
@@ -65,7 +66,21 @@ void QgsDxfPaintEngine::updateState( const QPaintEngineState& state )
6566

6667
void QgsDxfPaintEngine::drawPolygon( const QPointF* points, int pointCount, PolygonDrawMode mode )
6768
{
68-
QgsDebugMsg( "***********************Dxf paint engine: drawing polygon*********************" );
69+
if ( !mDxf || !mPaintDevice )
70+
{
71+
return;
72+
}
73+
74+
QgsPolyline polyline( pointCount );
75+
for ( int i = 0; i < pointCount; ++i )
76+
{
77+
QPointF dxfCoord = mPaintDevice->dxfCoordinates( points[i] );
78+
polyline[i] = QgsPoint( dxfCoord.x(), dxfCoord.y() );
79+
}
80+
81+
int color = mDxf->closestColorMatch( mPen.color().rgb() );
82+
double width = mPen.widthF() * mPaintDevice->widthScaleFactor();
83+
mDxf->writePolyline( polyline, "0", "CONTINUOUS", color, width, mode != QPaintEngine::PolylineMode );
6984
}
7085

7186
void QgsDxfPaintEngine::drawRects( const QRectF * rects, int rectCount )
@@ -81,6 +96,12 @@ void QgsDxfPaintEngine::drawEllipse( const QRectF& rect )
8196
void QgsDxfPaintEngine::drawPath( const QPainterPath& path )
8297
{
8398
QgsDebugMsg( "***********************Dxf paint engine: drawing path*********************" );
99+
QList<QPolygonF> polygonList = path.toFillPolygons();
100+
QList<QPolygonF>::const_iterator pIt = polygonList.constBegin();
101+
for ( ; pIt != polygonList.constEnd(); ++pIt )
102+
{
103+
drawPolygon( pIt->constData(), pIt->size(), pIt->isClosed() ? QPaintEngine::OddEvenMode : QPaintEngine::PolylineMode );
104+
}
84105
}
85106

86107
void QgsDxfPaintEngine::drawLines( const QLineF* lines, int lineCount )

‎src/core/qgsdxfexport.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,29 @@ void QgsDxfExport::endSection()
676676

677677
void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, const QgsSymbolLayerV2* symbolLayer )
678678
{
679+
//debug: draw rectangle for debugging
680+
const QgsMarkerSymbolLayerV2* msl = dynamic_cast< const QgsMarkerSymbolLayerV2* >( symbolLayer );
681+
if ( msl )
682+
{
683+
double halfSize = msl->size() * mapUnitScaleFactor( mSymbologyScaleDenominator,
684+
msl->sizeUnit(), mMapUnits ) / 2.0;
685+
writeGroup( 0, "SOLID" );
686+
writeGroup( 8, layer );
687+
writeGroup( 62, 1 );
688+
writeGroup( 10, pt.x() - halfSize );
689+
writeGroup( 20, pt.y() - halfSize );
690+
writeGroup( 30, 0.0 );
691+
writeGroup( 11, pt.x() + halfSize );
692+
writeGroup( 21, pt.y() - halfSize );
693+
writeGroup( 31, 0.0 );
694+
writeGroup( 12, pt.x() - halfSize );
695+
writeGroup( 22, pt.y() + halfSize );
696+
writeGroup( 32, 0.0 );
697+
writeGroup( 13, pt.x() + halfSize );
698+
writeGroup( 23, pt.y() + halfSize );
699+
writeGroup( 33, 0.0 );
700+
}
701+
679702
//insert block or write point directly?
680703
QHash< const QgsSymbolLayerV2*, QString >::const_iterator blockIt = mPointSymbolBlocks.find( symbolLayer );
681704
if ( !symbolLayer || blockIt == mPointSymbolBlocks.constEnd() )

‎src/core/qgsdxfexport.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ class QgsDxfExport
6565
void writeDouble( double d );
6666
void writeString( const QString& s );
6767

68+
void writePolyline( const QgsPolyline& line, const QString& layer, const QString& lineStyleName, int color,
69+
double width = -1, bool polygon = false );
70+
6871
private:
6972

7073
QList< QgsMapLayer* > mLayers;
@@ -98,8 +101,6 @@ class QgsDxfExport
98101
void endSection();
99102

100103
void writePoint( const QgsPoint& pt, const QString& layer, const QgsSymbolLayerV2* symbolLayer );
101-
void writePolyline( const QgsPolyline& line, const QString& layer, const QString& lineStyleName, int color,
102-
double width = -1, bool polygon = false );
103104
void writeVertex( const QgsPoint& pt, const QString& layer );
104105
void writeSymbolLayerLinestyle( const QgsSymbolLayerV2* symbolLayer );
105106
void writeLinestyle( const QString& styleName, const QVector<qreal>& pattern, QgsSymbolV2::OutputUnit u );

0 commit comments

Comments
 (0)
Please sign in to comment.