Skip to content

Commit

Permalink
Cleanup code structure, move code to central functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Nov 25, 2013
1 parent 7867205 commit a10d675
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 44 deletions.
23 changes: 22 additions & 1 deletion src/core/dxf/qgsdxfexport.cpp
Expand Up @@ -501,7 +501,7 @@ void QgsDxfExport::writeBlocks()
writeGroup( 30, 0 );
writeGroup( 3, blockName );

ml->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, ml->sizeUnit(), mMapUnits ) );
ml->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, ml->sizeUnit(), mMapUnits ), "0" ); //maplayer 0 -> block receives layer from INSERT statement

writeGroup( 0, "ENDBLK" );
writeGroup( 8, 0 );
Expand Down Expand Up @@ -676,6 +676,7 @@ void QgsDxfExport::endSection()

void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, const QgsSymbolLayerV2* symbolLayer )
{
#if 0
//debug: draw rectangle for debugging
const QgsMarkerSymbolLayerV2* msl = dynamic_cast< const QgsMarkerSymbolLayerV2* >( symbolLayer );
if ( msl )
Expand All @@ -698,6 +699,7 @@ void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, const Q
writeGroup( 23, pt.y() + halfSize );
writeGroup( 33, 0.0 );
}
#endif //0

//insert block or write point directly?
QHash< const QgsSymbolLayerV2*, QString >::const_iterator blockIt = mPointSymbolBlocks.find( symbolLayer );
Expand Down Expand Up @@ -739,6 +741,25 @@ void QgsDxfExport::writePolyline( const QgsPolyline& line, const QString& layer,
writeGroup( 0, "SEQEND" );
}

void QgsDxfExport::writeSolid( const QString& layer, int color, const QgsPoint& pt1, const QgsPoint& pt2, const QgsPoint& pt3, const QgsPoint& pt4 )
{
writeGroup( 0, "SOLID" );
writeGroup( 8, layer );
writeGroup( 62, color );
writeGroup( 10, pt1.x() );
writeGroup( 20, pt1.y() );
writeGroup( 30, 0.0 );
writeGroup( 11, pt2.x() );
writeGroup( 21, pt2.y() );
writeGroup( 31, 0.0 );
writeGroup( 12, pt3.x() );
writeGroup( 22, pt3.y() );
writeGroup( 32, 0.0 );
writeGroup( 13, pt4.x() );
writeGroup( 23, pt4.y() );
writeGroup( 33, 0.0 );
}

void QgsDxfExport::writeVertex( const QgsPoint& pt, const QString& layer )
{
writeGroup( 0, "VERTEX" );
Expand Down
2 changes: 2 additions & 0 deletions src/core/dxf/qgsdxfexport.h
Expand Up @@ -68,6 +68,8 @@ class QgsDxfExport
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 );

private:

QList< QgsMapLayer* > mLayers;
Expand Down
8 changes: 8 additions & 0 deletions src/core/dxf/qgsdxfpaintdevice.cpp
Expand Up @@ -81,4 +81,12 @@ QPointF QgsDxfPaintDevice::dxfCoordinates( const QPointF& pt ) const
return QPointF( x, y );
}

void QgsDxfPaintDevice::setLayer( const QString& layer )
{
if ( mPaintEngine )
{
mPaintEngine->setLayer( layer );
}
}


2 changes: 2 additions & 0 deletions src/core/dxf/qgsdxfpaintdevice.h
Expand Up @@ -48,6 +48,8 @@ class QgsDxfPaintDevice: public QPaintDevice

int metric( PaintDeviceMetric metric ) const;

void setLayer( const QString& layer );


private:
QgsDxfPaintEngine* mPaintEngine;
Expand Down
48 changes: 41 additions & 7 deletions src/core/dxf/qgsdxfpaintengine.cpp
Expand Up @@ -74,18 +74,32 @@ void QgsDxfPaintEngine::drawPolygon( const QPointF* points, int pointCount, Poly
QgsPolyline polyline( pointCount );
for ( int i = 0; i < pointCount; ++i )
{
QPointF dxfCoord = mPaintDevice->dxfCoordinates( points[i] );
polyline[i] = QgsPoint( dxfCoord.x(), dxfCoord.y() );
polyline[i] = toDxfCoordinates( points[i] );
}

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

void QgsDxfPaintEngine::drawRects( const QRectF * rects, int rectCount )
void QgsDxfPaintEngine::drawRects( const QRectF* rects, int rectCount )
{
QgsDebugMsg( "***********************Dxf paint engine: drawing rects*********************" );
if ( !mDxf || !mPaintDevice )
{
return;
}

for ( int i = 0; i < rectCount; ++i )
{
double left = rects[i].left();
double right = rects[i].right();
double top = rects[i].top();
double bottom = rects[i].bottom();
QgsPoint pt1 = toDxfCoordinates( QPointF( left, bottom ) );
QgsPoint pt2 = toDxfCoordinates( QPointF( right, bottom ) );
QgsPoint pt3 = toDxfCoordinates( QPointF( left, top ) );
QgsPoint pt4 = toDxfCoordinates( QPointF( right, top ) );
mDxf->writeSolid( mLayer, currentPenColor(), pt1, pt2, pt3, pt4 );
}
}

void QgsDxfPaintEngine::drawEllipse( const QRectF& rect )
Expand All @@ -95,7 +109,6 @@ 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 )
Expand All @@ -108,3 +121,24 @@ void QgsDxfPaintEngine::drawLines( const QLineF* lines, int lineCount )
{
QgsDebugMsg( "***********************Dxf paint engine: drawing path*********************" );
}

QgsPoint QgsDxfPaintEngine::toDxfCoordinates( const QPointF& pt ) const
{
if ( !mPaintDevice || !mDxf )
{
return QgsPoint( pt.x(), pt.y() );
}

QPointF dxfPt = mPaintDevice->dxfCoordinates( mTransform.map( pt ) );
return QgsPoint( dxfPt.x(), dxfPt.y() );
}

int QgsDxfPaintEngine::currentPenColor() const
{
if ( !mDxf )
{
return 0;
}

return mDxf->closestColorMatch( mPen.color().rgb() );
}
8 changes: 8 additions & 0 deletions src/core/dxf/qgsdxfpaintengine.h
Expand Up @@ -22,6 +22,7 @@

class QgsDxfExport;
class QgsDxfPaintDevice;
class QgsPoint;

class QgsDxfPaintEngine: public QPaintEngine
{
Expand All @@ -42,13 +43,20 @@ class QgsDxfPaintEngine: public QPaintEngine
void drawPath( const QPainterPath& path );
void drawLines( const QLineF* lines, int lineCount );

void setLayer( const QString& layer ) { mLayer = layer; }
QString layer() const { return mLayer; }

private:
const QgsDxfPaintDevice* mPaintDevice;
QgsDxfExport* mDxf;

//painter state information
QTransform mTransform;
QPen mPen;
QString mLayer;

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

#endif // QGSDXFPAINTENGINE_H
49 changes: 16 additions & 33 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Expand Up @@ -702,7 +702,7 @@ void QgsSimpleMarkerSymbolLayerV2::drawMarker( QPainter* p, QgsSymbolV2RenderCon
}
}

void QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor ) const
void QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName ) const
{
double size = mSize;
if ( mSizeUnit == QgsSymbolV2::MM )
Expand All @@ -715,7 +715,7 @@ void QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
if ( mName == "circle" )
{
e.writeGroup( 0, "CIRCLE" );
e.writeGroup( 8, "0" );
e.writeGroup( 8, layerName );

e.writeGroup( 62, colorIndex );
e.writeGroup( 10, halfSize );
Expand All @@ -725,39 +725,19 @@ void QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
}
else if ( mName == "square" || mName == "rectangle" )
{
e.writeGroup( 0, "SOLID" );
e.writeGroup( 8, "0" );
e.writeGroup( 62, colorIndex );
e.writeGroup( 10, 0.0 );
e.writeGroup( 20, 0.0 );
e.writeGroup( 30, 0.0 );
e.writeGroup( 11, size );
e.writeGroup( 21, 0.0 );
e.writeGroup( 31, 0.0 );
e.writeGroup( 12, 0 );
e.writeGroup( 22, size );
e.writeGroup( 32, 0.0 );
e.writeGroup( 13, size );
e.writeGroup( 23, size );
e.writeGroup( 33, 0.0 );
QgsPoint pt1( 0.0, 0.0 );
QgsPoint pt2( size, 0.0 );
QgsPoint pt3( 0.0, size );
QgsPoint pt4( size, size );
e.writeSolid( layerName, colorIndex, pt1, pt2, pt3, pt4 );
}
else if ( mName == "diamond" )
{
e.writeGroup( 0, "SOLID" );
e.writeGroup( 8, "0" );
e.writeGroup( 62, colorIndex );
e.writeGroup( 10, 0.0 );
e.writeGroup( 20, halfSize );
e.writeGroup( 30, 0.0 );
e.writeGroup( 11, halfSize );
e.writeGroup( 21, 0.0 );
e.writeGroup( 31, 0.0 );
e.writeGroup( 12, halfSize );
e.writeGroup( 22, size );
e.writeGroup( 32, 0.0 );
e.writeGroup( 13, size );
e.writeGroup( 23, halfSize );
e.writeGroup( 33, 0.0 );
QgsPoint pt1( 0.0, halfSize );
QgsPoint pt2( halfSize, 0.0 );
QgsPoint pt3( halfSize, size );
QgsPoint pt4( size, halfSize );
e.writeSolid( layerName, colorIndex, pt1, pt2, pt3, pt4 );
}
}

Expand Down Expand Up @@ -1166,8 +1146,10 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::createFromSld( QDomElement &element
return m;
}

void QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor ) const
void QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName ) const
{
Q_UNUSED( layerName );

QSvgRenderer r( mPath );
if ( !r.isValid() )
{
Expand All @@ -1178,6 +1160,7 @@ void QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScale
pd.setDrawingSize( QSizeF( r.defaultSize() ) );
double size = mSize * mmMapUnitScaleFactor ;
pd.setOutputSize( QRectF( 0, 0, size, size ) );
pd.setLayer( layerName );
QPainter p;

p.begin( &pd );
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.h
Expand Up @@ -76,7 +76,7 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
void setOutlineWidthUnit( QgsSymbolV2::OutputUnit u ) { mOutlineWidthUnit = u; }

void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor ) const;
void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName ) const;

protected:

Expand Down Expand Up @@ -159,7 +159,7 @@ class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
void setOutputUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit outputUnit() const;

void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor ) const;
void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName ) const;

protected:
QString mPath;
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgssymbollayerv2.h
Expand Up @@ -93,7 +93,7 @@ class CORE_EXPORT QgsSymbolLayerV2
virtual void removeDataDefinedProperty( const QString& property );
virtual void removeDataDefinedProperties();

virtual void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor ) const { Q_UNUSED( e ); Q_UNUSED( mmMapUnitScaleFactor ); }
virtual void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName ) const { Q_UNUSED( e ); Q_UNUSED( mmMapUnitScaleFactor ); Q_UNUSED( layerName ); }

protected:
QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false )
Expand Down

0 comments on commit a10d675

Please sign in to comment.