Skip to content

Commit

Permalink
Convert painterpath to polygons for dxf
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Nov 23, 2013
1 parent 78fbee3 commit a9d92cd
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/core/dxf/qgsdxfpaintdevice.cpp
Expand Up @@ -69,7 +69,7 @@ double QgsDxfPaintDevice::widthScaleFactor() const
return ( widthFactor + heightFactor ) / 2.0;
}

QPointF QgsDxfPaintDevice::dxfCoordinates( const QPointF& pt )
QPointF QgsDxfPaintDevice::dxfCoordinates( const QPointF& pt ) const
{
if ( !mDrawingSize.isValid() || mRectangle.isEmpty() )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/dxf/qgsdxfpaintdevice.h
Expand Up @@ -41,7 +41,7 @@ class QgsDxfPaintDevice: public QPaintDevice
double widthScaleFactor() const;

/**Converts a point from device coordinates to dxf coordinates*/
QPointF dxfCoordinates( const QPointF& pt );
QPointF dxfCoordinates( const QPointF& pt ) const;

/*int height() const { return mDrawingSize.height(); }
int width() const { return mDrawingSize.width(); }*/
Expand Down
23 changes: 22 additions & 1 deletion src/core/dxf/qgsdxfpaintengine.cpp
Expand Up @@ -17,6 +17,7 @@

#include "qgsdxfpaintengine.h"
#include "qgsdxfexport.h"
#include "qgsdxfpaintdevice.h"
#include "qgslogger.h"

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

void QgsDxfPaintEngine::drawPolygon( const QPointF* points, int pointCount, PolygonDrawMode mode )
{
QgsDebugMsg( "***********************Dxf paint engine: drawing polygon*********************" );
if ( !mDxf || !mPaintDevice )
{
return;
}

QgsPolyline polyline( pointCount );
for ( int i = 0; i < pointCount; ++i )
{
QPointF dxfCoord = mPaintDevice->dxfCoordinates( points[i] );
polyline[i] = QgsPoint( dxfCoord.x(), dxfCoord.y() );
}

int color = mDxf->closestColorMatch( mPen.color().rgb() );
double width = mPen.widthF() * mPaintDevice->widthScaleFactor();
mDxf->writePolyline( polyline, "0", "CONTINUOUS", color, width, mode != QPaintEngine::PolylineMode );
}

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

void QgsDxfPaintEngine::drawLines( const QLineF* lines, int lineCount )
Expand Down
23 changes: 23 additions & 0 deletions src/core/qgsdxfexport.cpp
Expand Up @@ -676,6 +676,29 @@ void QgsDxfExport::endSection()

void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, const QgsSymbolLayerV2* symbolLayer )
{
//debug: draw rectangle for debugging
const QgsMarkerSymbolLayerV2* msl = dynamic_cast< const QgsMarkerSymbolLayerV2* >( symbolLayer );
if ( msl )
{
double halfSize = msl->size() * mapUnitScaleFactor( mSymbologyScaleDenominator,
msl->sizeUnit(), mMapUnits ) / 2.0;
writeGroup( 0, "SOLID" );
writeGroup( 8, layer );
writeGroup( 62, 1 );
writeGroup( 10, pt.x() - halfSize );
writeGroup( 20, pt.y() - halfSize );
writeGroup( 30, 0.0 );
writeGroup( 11, pt.x() + halfSize );
writeGroup( 21, pt.y() - halfSize );
writeGroup( 31, 0.0 );
writeGroup( 12, pt.x() - halfSize );
writeGroup( 22, pt.y() + halfSize );
writeGroup( 32, 0.0 );
writeGroup( 13, pt.x() + halfSize );
writeGroup( 23, pt.y() + halfSize );
writeGroup( 33, 0.0 );
}

//insert block or write point directly?
QHash< const QgsSymbolLayerV2*, QString >::const_iterator blockIt = mPointSymbolBlocks.find( symbolLayer );
if ( !symbolLayer || blockIt == mPointSymbolBlocks.constEnd() )
Expand Down
5 changes: 3 additions & 2 deletions src/core/qgsdxfexport.h
Expand Up @@ -65,6 +65,9 @@ class QgsDxfExport
void writeDouble( double d );
void writeString( const QString& s );

void writePolyline( const QgsPolyline& line, const QString& layer, const QString& lineStyleName, int color,
double width = -1, bool polygon = false );

private:

QList< QgsMapLayer* > mLayers;
Expand Down Expand Up @@ -98,8 +101,6 @@ class QgsDxfExport
void endSection();

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

0 comments on commit a9d92cd

Please sign in to comment.