Skip to content

Commit

Permalink
Implement write lines in dxf engine
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Nov 25, 2013
1 parent a10d675 commit 9abba40
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/core/dxf/qgsdxfexport.cpp
Expand Up @@ -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" );
Expand Down
4 changes: 4 additions & 0 deletions src/core/dxf/qgsdxfexport.h
Expand Up @@ -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;
Expand Down
31 changes: 26 additions & 5 deletions src/core/dxf/qgsdxfpaintengine.cpp
Expand Up @@ -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;
}
Expand All @@ -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 )
Expand All @@ -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
Expand All @@ -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();
}
1 change: 1 addition & 0 deletions src/core/dxf/qgsdxfpaintengine.h
Expand Up @@ -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.