Skip to content
Permalink
Browse files

Convert painterpath to polygons for dxf

  • Loading branch information
mhugent committed Nov 23, 2013
1 parent 78fbee3 commit a9d92cdcf47de6c669683bcd3688c0fc52ec10e2
@@ -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() )
{
@@ -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(); }*/
@@ -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*/ )
@@ -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 )
@@ -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 )
@@ -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() )
@@ -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;
@@ -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 );

0 comments on commit a9d92cd

Please sign in to comment.
You can’t perform that action at this time.