Skip to content

Commit 0239b4d

Browse files
committed
Dxf export for ellipse symbol layer
1 parent 668403a commit 0239b4d

File tree

2 files changed

+139
-0
lines changed

2 files changed

+139
-0
lines changed

src/core/symbology-ng/qgsellipsesymbollayerv2.cpp

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* *
1414
***************************************************************************/
1515
#include "qgsellipsesymbollayerv2.h"
16+
#include "qgsdxfexport.h"
1617
#include "qgsexpression.h"
1718
#include "qgsfeature.h"
1819
#include "qgsrendercontext.h"
@@ -474,3 +475,139 @@ QgsSymbolV2::OutputUnit QgsEllipseSymbolLayerV2::outputUnit() const
474475
}
475476
return unit;
476477
}
478+
479+
bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift ) const
480+
{
481+
//width
482+
double symbolWidth = mSymbolWidth;
483+
QgsExpression* widthExpression = expression( "width" );
484+
if ( widthExpression ) //1. priority: data defined setting on symbol layer level
485+
{
486+
symbolWidth = widthExpression->evaluate( const_cast<QgsFeature*>( f ) ).toDouble();
487+
}
488+
else if ( context->renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
489+
{
490+
symbolWidth = mSize;
491+
}
492+
if ( mSymbolWidthUnit == QgsSymbolV2::MM )
493+
{
494+
symbolWidth *= mmMapUnitScaleFactor;
495+
}
496+
497+
//height
498+
double symbolHeight = mSymbolHeight;
499+
QgsExpression* heightExpression = expression( "height" );
500+
if ( heightExpression ) //1. priority: data defined setting on symbol layer level
501+
{
502+
symbolHeight = heightExpression->evaluate( const_cast<QgsFeature*>( f ) ).toDouble();
503+
}
504+
else if ( context->renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
505+
{
506+
symbolHeight = mSize;
507+
}
508+
if ( mSymbolHeightUnit == QgsSymbolV2::MM )
509+
{
510+
symbolHeight *= mmMapUnitScaleFactor;
511+
}
512+
513+
//outline width
514+
double outlineWidth = mOutlineWidth;
515+
QgsExpression* outlineWidthExpression = expression( "outline_width" );
516+
if ( outlineWidthExpression )
517+
{
518+
outlineWidth = outlineWidthExpression->evaluate( const_cast<QgsFeature*>( context->feature() ) ).toDouble();
519+
}
520+
if ( mOutlineWidthUnit == QgsSymbolV2::MM )
521+
{
522+
outlineWidth *= outlineWidth;
523+
}
524+
525+
//color
526+
QColor c = mFillColor;
527+
QgsExpression* fillColorExpression = expression( "fill_color" );
528+
if ( fillColorExpression )
529+
{
530+
c = QColor( fillColorExpression->evaluate( const_cast<QgsFeature*>( context->feature() ) ).toString() );
531+
}
532+
int colorIndex = e.closestColorMatch( c.rgb() );
533+
534+
//symbol name
535+
QString symbolName = mSymbolName;
536+
QgsExpression* symbolNameExpression = expression( "symbol_name" );
537+
if ( symbolNameExpression )
538+
{
539+
QgsExpression* symbolNameExpression = expression( "symbol_name" );
540+
symbolName = symbolNameExpression->evaluate( const_cast<QgsFeature*>( context->feature() ) ).toString();
541+
}
542+
543+
//offset
544+
double offsetX = 0;
545+
double offsetY = 0;
546+
markerOffset( *context, offsetX, offsetY );
547+
QPointF off( offsetX, offsetY );
548+
549+
//priority for rotation: 1. data defined symbol level, 2. symbol layer rotation (mAngle)
550+
double rotation = 0.0;
551+
QgsExpression* rotationExpression = expression( "rotation" );
552+
if ( rotationExpression )
553+
{
554+
rotation = rotationExpression->evaluate( const_cast<QgsFeature*>( context->feature() ) ).toDouble();
555+
}
556+
else if ( !qgsDoubleNear( mAngle, 0.0 ) )
557+
{
558+
rotation = mAngle;
559+
}
560+
rotation = -rotation; //rotation in Qt is counterclockwise
561+
if ( rotation )
562+
off = _rotatedOffset( off, rotation );
563+
564+
QTransform t;
565+
t.translate( shift.x() + offsetX, shift.y() + offsetY );
566+
567+
if ( rotation != 0 )
568+
t.rotate( rotation );
569+
570+
double halfWidth = symbolWidth / 2.0;
571+
double halfHeight = symbolHeight / 2.0;
572+
573+
if ( symbolName == "circle" )
574+
{
575+
//soon...
576+
}
577+
else if ( symbolName == "rectangle" )
578+
{
579+
QPointF pt1( t.map( QPointF( -halfWidth, -halfHeight ) ) );
580+
QPointF pt2( t.map( QPointF( halfWidth, -halfHeight ) ) );
581+
QPointF pt3( t.map( QPointF( -halfWidth, halfHeight ) ) );
582+
QPointF pt4( t.map( QPointF( halfWidth, halfHeight ) ) );
583+
e.writeSolid( layerName, colorIndex, QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt4.x(), pt4.y() ) );
584+
return true;
585+
}
586+
else if ( symbolName == "cross" )
587+
{
588+
QgsPolyline line1( 2 );
589+
QPointF pt1( t.map( QPointF( -halfWidth, 0 ) ) );
590+
QPointF pt2( t.map( QPointF( halfWidth, 0 ) ) );
591+
line1[0] = QgsPoint( pt1.x(), pt1.y() );
592+
line1[1] = QgsPoint( pt2.x(), pt2.y() );
593+
e.writePolyline( line1, layerName, "CONTINUOUS", colorIndex, outlineWidth, false );
594+
QgsPolyline line2( 2 );
595+
QPointF pt3( t.map( QPointF( 0, halfHeight ) ) );
596+
QPointF pt4( t.map( QPointF( 0, -halfHeight ) ) );
597+
line2[0] = QgsPoint( pt3.x(), pt3.y() );
598+
line2[1] = QgsPoint( pt3.x(), pt3.y() );
599+
e.writePolyline( line2, layerName, "CONTINUOUS", colorIndex, outlineWidth, false );
600+
return true;
601+
}
602+
else if ( symbolName == "triangle" )
603+
{
604+
QPointF pt1( t.map( QPointF( -halfWidth, -halfHeight ) ) );
605+
QPointF pt2( t.map( QPointF( halfWidth, -halfHeight ) ) );
606+
QPointF pt3( t.map( QPointF( 0, halfHeight ) ) );
607+
QPointF pt4( t.map( QPointF( 0, halfHeight ) ) );
608+
e.writeSolid( layerName, colorIndex, QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt4.x(), pt4.y() ) );
609+
return true;
610+
}
611+
612+
return false; //soon...
613+
}

src/core/symbology-ng/qgsellipsesymbollayerv2.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class CORE_EXPORT QgsEllipseSymbolLayerV2: public QgsMarkerSymbolLayerV2
4040
void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props ) const;
4141
void writeSldMarker( QDomDocument& doc, QDomElement &element, QgsStringMap props ) const;
4242

43+
bool writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift = QPointF( 0.0, 0.0 ) ) const;
44+
4345
void setSymbolName( const QString& name ) { mSymbolName = name; }
4446
QString symbolName() const { return mSymbolName; }
4547

0 commit comments

Comments
 (0)