From 0239b4d6c7a9f1ce5c070ad225250f57421ab7bd Mon Sep 17 00:00:00 2001 From: Marco Hugentobler Date: Fri, 6 Dec 2013 15:05:05 +0100 Subject: [PATCH] Dxf export for ellipse symbol layer --- .../symbology-ng/qgsellipsesymbollayerv2.cpp | 137 ++++++++++++++++++ .../symbology-ng/qgsellipsesymbollayerv2.h | 2 + 2 files changed, 139 insertions(+) diff --git a/src/core/symbology-ng/qgsellipsesymbollayerv2.cpp b/src/core/symbology-ng/qgsellipsesymbollayerv2.cpp index 814dfd5bd7f5..a0f4bed2a184 100644 --- a/src/core/symbology-ng/qgsellipsesymbollayerv2.cpp +++ b/src/core/symbology-ng/qgsellipsesymbollayerv2.cpp @@ -13,6 +13,7 @@ * * ***************************************************************************/ #include "qgsellipsesymbollayerv2.h" +#include "qgsdxfexport.h" #include "qgsexpression.h" #include "qgsfeature.h" #include "qgsrendercontext.h" @@ -474,3 +475,139 @@ QgsSymbolV2::OutputUnit QgsEllipseSymbolLayerV2::outputUnit() const } return unit; } + +bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift ) const +{ + //width + double symbolWidth = mSymbolWidth; + QgsExpression* widthExpression = expression( "width" ); + if ( widthExpression ) //1. priority: data defined setting on symbol layer level + { + symbolWidth = widthExpression->evaluate( const_cast( f ) ).toDouble(); + } + else if ( context->renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level + { + symbolWidth = mSize; + } + if ( mSymbolWidthUnit == QgsSymbolV2::MM ) + { + symbolWidth *= mmMapUnitScaleFactor; + } + + //height + double symbolHeight = mSymbolHeight; + QgsExpression* heightExpression = expression( "height" ); + if ( heightExpression ) //1. priority: data defined setting on symbol layer level + { + symbolHeight = heightExpression->evaluate( const_cast( f ) ).toDouble(); + } + else if ( context->renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level + { + symbolHeight = mSize; + } + if ( mSymbolHeightUnit == QgsSymbolV2::MM ) + { + symbolHeight *= mmMapUnitScaleFactor; + } + + //outline width + double outlineWidth = mOutlineWidth; + QgsExpression* outlineWidthExpression = expression( "outline_width" ); + if ( outlineWidthExpression ) + { + outlineWidth = outlineWidthExpression->evaluate( const_cast( context->feature() ) ).toDouble(); + } + if ( mOutlineWidthUnit == QgsSymbolV2::MM ) + { + outlineWidth *= outlineWidth; + } + + //color + QColor c = mFillColor; + QgsExpression* fillColorExpression = expression( "fill_color" ); + if ( fillColorExpression ) + { + c = QColor( fillColorExpression->evaluate( const_cast( context->feature() ) ).toString() ); + } + int colorIndex = e.closestColorMatch( c.rgb() ); + + //symbol name + QString symbolName = mSymbolName; + QgsExpression* symbolNameExpression = expression( "symbol_name" ); + if ( symbolNameExpression ) + { + QgsExpression* symbolNameExpression = expression( "symbol_name" ); + symbolName = symbolNameExpression->evaluate( const_cast( context->feature() ) ).toString(); + } + + //offset + double offsetX = 0; + double offsetY = 0; + markerOffset( *context, offsetX, offsetY ); + QPointF off( offsetX, offsetY ); + + //priority for rotation: 1. data defined symbol level, 2. symbol layer rotation (mAngle) + double rotation = 0.0; + QgsExpression* rotationExpression = expression( "rotation" ); + if ( rotationExpression ) + { + rotation = rotationExpression->evaluate( const_cast( context->feature() ) ).toDouble(); + } + else if ( !qgsDoubleNear( mAngle, 0.0 ) ) + { + rotation = mAngle; + } + rotation = -rotation; //rotation in Qt is counterclockwise + if ( rotation ) + off = _rotatedOffset( off, rotation ); + + QTransform t; + t.translate( shift.x() + offsetX, shift.y() + offsetY ); + + if ( rotation != 0 ) + t.rotate( rotation ); + + double halfWidth = symbolWidth / 2.0; + double halfHeight = symbolHeight / 2.0; + + if ( symbolName == "circle" ) + { + //soon... + } + else if ( symbolName == "rectangle" ) + { + QPointF pt1( t.map( QPointF( -halfWidth, -halfHeight ) ) ); + QPointF pt2( t.map( QPointF( halfWidth, -halfHeight ) ) ); + QPointF pt3( t.map( QPointF( -halfWidth, halfHeight ) ) ); + QPointF pt4( t.map( QPointF( halfWidth, halfHeight ) ) ); + e.writeSolid( layerName, colorIndex, QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt4.x(), pt4.y() ) ); + return true; + } + else if ( symbolName == "cross" ) + { + QgsPolyline line1( 2 ); + QPointF pt1( t.map( QPointF( -halfWidth, 0 ) ) ); + QPointF pt2( t.map( QPointF( halfWidth, 0 ) ) ); + line1[0] = QgsPoint( pt1.x(), pt1.y() ); + line1[1] = QgsPoint( pt2.x(), pt2.y() ); + e.writePolyline( line1, layerName, "CONTINUOUS", colorIndex, outlineWidth, false ); + QgsPolyline line2( 2 ); + QPointF pt3( t.map( QPointF( 0, halfHeight ) ) ); + QPointF pt4( t.map( QPointF( 0, -halfHeight ) ) ); + line2[0] = QgsPoint( pt3.x(), pt3.y() ); + line2[1] = QgsPoint( pt3.x(), pt3.y() ); + e.writePolyline( line2, layerName, "CONTINUOUS", colorIndex, outlineWidth, false ); + return true; + } + else if ( symbolName == "triangle" ) + { + QPointF pt1( t.map( QPointF( -halfWidth, -halfHeight ) ) ); + QPointF pt2( t.map( QPointF( halfWidth, -halfHeight ) ) ); + QPointF pt3( t.map( QPointF( 0, halfHeight ) ) ); + QPointF pt4( t.map( QPointF( 0, halfHeight ) ) ); + e.writeSolid( layerName, colorIndex, QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt4.x(), pt4.y() ) ); + return true; + } + + return false; //soon... +} diff --git a/src/core/symbology-ng/qgsellipsesymbollayerv2.h b/src/core/symbology-ng/qgsellipsesymbollayerv2.h index c6ff8b204838..78c2755b6c58 100644 --- a/src/core/symbology-ng/qgsellipsesymbollayerv2.h +++ b/src/core/symbology-ng/qgsellipsesymbollayerv2.h @@ -40,6 +40,8 @@ class CORE_EXPORT QgsEllipseSymbolLayerV2: public QgsMarkerSymbolLayerV2 void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props ) const; void writeSldMarker( QDomDocument& doc, QDomElement &element, QgsStringMap props ) const; + bool writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift = QPointF( 0.0, 0.0 ) ) const; + void setSymbolName( const QString& name ) { mSymbolName = name; } QString symbolName() const { return mSymbolName; }