Skip to content
Permalink
Browse files

Implement write lines in dxf engine

  • Loading branch information
mhugent committed Nov 25, 2013
1 parent a10d675 commit 9abba4021a87ee5523da836e1781b6197c34e36f
@@ -741,6 +741,14 @@ void QgsDxfExport::writePolyline( const QgsPolyline& line, const QString& layer,
writeGroup( 0, "SEQEND" );
}

void QgsDxfExport::writeLine( const QgsPoint& pt1, const QgsPoint& pt2, const QString& layer, const QString& lineStyleName, int color, double width )
{
QgsPolyline line( 2 );
line[0] = pt1;
line[1] = pt2;
writePolyline( line, layer, lineStyleName, color, width, false );
}

void QgsDxfExport::writeSolid( const QString& layer, int color, const QgsPoint& pt1, const QgsPoint& pt2, const QgsPoint& pt3, const QgsPoint& pt4 )
{
writeGroup( 0, "SOLID" );
@@ -65,11 +65,15 @@ class QgsDxfExport
void writeDouble( double d );
void writeString( const QString& s );

//draw dxf primitives
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 );

//write line (as a polyline)
void writeLine( const QgsPoint& pt1, const QgsPoint& pt2, const QString& layer, const QString& lineStyleName, int color, double width = -1 );

private:

QList< QgsMapLayer* > mLayers;
@@ -77,13 +77,12 @@ void QgsDxfPaintEngine::drawPolygon( const QPointF* points, int pointCount, Poly
polyline[i] = toDxfCoordinates( points[i] );
}

double width = mPen.widthF() * mPaintDevice->widthScaleFactor();
mDxf->writePolyline( polyline, mLayer, "CONTINUOUS", currentPenColor(), width, mode != QPaintEngine::PolylineMode );
mDxf->writePolyline( polyline, mLayer, "CONTINUOUS", currentPenColor(), currentWidth(), mode != QPaintEngine::PolylineMode );
}

void QgsDxfPaintEngine::drawRects( const QRectF* rects, int rectCount )
{
if ( !mDxf || !mPaintDevice )
if ( !mDxf || !mPaintDevice || !rects )
{
return;
}
@@ -104,7 +103,9 @@ void QgsDxfPaintEngine::drawRects( const QRectF* rects, int rectCount )

void QgsDxfPaintEngine::drawEllipse( const QRectF& rect )
{
QgsDebugMsg( "***********************Dxf paint engine: drawing ellipse*********************" );
//map to circle in case of square?

//todo: create polyline for real ellises
}

void QgsDxfPaintEngine::drawPath( const QPainterPath& path )
@@ -119,7 +120,17 @@ void QgsDxfPaintEngine::drawPath( const QPainterPath& path )

void QgsDxfPaintEngine::drawLines( const QLineF* lines, int lineCount )
{
QgsDebugMsg( "***********************Dxf paint engine: drawing path*********************" );
if ( !mDxf || !mPaintDevice || !lines )
{
return;
}

for ( int i = 0; i < lineCount; ++i )
{
QgsPoint pt1 = toDxfCoordinates( lines[i].p1() );
QgsPoint pt2 = toDxfCoordinates( lines[i].p2() );
mDxf->writeLine( pt1, pt2, mLayer, "CONTINUOUS", currentPenColor(), currentWidth() );
}
}

QgsPoint QgsDxfPaintEngine::toDxfCoordinates( const QPointF& pt ) const
@@ -142,3 +153,13 @@ int QgsDxfPaintEngine::currentPenColor() const

return mDxf->closestColorMatch( mPen.color().rgb() );
}

double QgsDxfPaintEngine::currentWidth() const
{
if ( !mPaintDevice )
{
return 1;
}

return mPen.widthF() * mPaintDevice->widthScaleFactor();
}
@@ -57,6 +57,7 @@ class QgsDxfPaintEngine: public QPaintEngine

QgsPoint toDxfCoordinates( const QPointF& pt ) const;
int currentPenColor() const;
double currentWidth() const;
};

#endif // QGSDXFPAINTENGINE_H

0 comments on commit 9abba40

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