Skip to content

Commit

Permalink
Fix ellipse marker dxf export
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jun 5, 2014
1 parent a04ebf9 commit 041acd6
Showing 1 changed file with 41 additions and 11 deletions.
52 changes: 41 additions & 11 deletions src/core/symbology-ng/qgsellipsesymbollayerv2.cpp
Expand Up @@ -615,14 +615,24 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
outlineWidth *= outlineWidth;
}

//color
QColor c = mFillColor;
//fill color
QColor fc = mFillColor;
QgsExpression* fillColorExpression = expression( "fill_color" );
if ( fillColorExpression )
{
c = QColor( fillColorExpression->evaluate( const_cast<QgsFeature*>( context->feature() ) ).toString() );
fc = QColor( fillColorExpression->evaluate( const_cast<QgsFeature*>( context->feature() ) ).toString() );
}
int colorIndex = e.closestColorMatch( c.rgb() );
int fillColorIndex = e.closestColorMatch( fc.rgb() );

//outline color
QColor oc = mOutlineColor;
QgsExpression* outlineColorExpression = expression( "outline_color" );
if ( outlineColorExpression )
{
oc = QColor( outlineColorExpression->evaluate( const_cast<QgsFeature*>( context->feature() ) ).toString() );
}
int outlineColorIndex = e.closestColorMatch( oc.rgb() );


//symbol name
QString symbolName = mSymbolName;
Expand Down Expand Up @@ -665,15 +675,35 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa

if ( symbolName == "circle" )
{
//soon...
if ( qgsDoubleNear( halfWidth, halfHeight ) )
{
QPointF pt( t.map( QPointF( 0, 0 ) ) );
e.writeCircle( layerName, outlineColorIndex, QgsPoint( pt.x(), pt.y() ), halfWidth );
}
else
{
QgsPolyline line;
double stepsize = 2 * M_PI / 40;
for ( int i = 0; i < 39; ++i )
{
double angle = stepsize * i;
double x = halfWidth * cos( angle );
double y = halfHeight * sin( angle );
QPointF pt( t.map( QPointF( x, y ) ) );
line.push_back( QgsPoint( pt.x(), pt.y() ) );
}
//close ellipse with first point
line.push_back( line.at( 0 ) );
e.writePolyline( line, layerName, "solid", outlineColorIndex, outlineWidth, true );
}
}
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() ) );
e.writeSolid( layerName, fillColorIndex, 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" )
Expand All @@ -683,13 +713,13 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
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 );
e.writePolyline( line1, layerName, "CONTINUOUS", outlineColorIndex, outlineWidth, false );
QgsPolyline line2( 2 );
QPointF pt3( t.map( QPointF( 0, halfHeight ) ) );
// QPointF pt4( 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 );
line2[1] = QgsPoint( pt4.x(), pt4.y() );
e.writePolyline( line2, layerName, "CONTINUOUS", outlineColorIndex, outlineWidth, false );
return true;
}
else if ( symbolName == "triangle" )
Expand All @@ -698,7 +728,7 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
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() ) );
e.writeSolid( layerName, fillColorIndex, QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt4.x(), pt4.y() ) );
return true;
}

Expand Down

0 comments on commit 041acd6

Please sign in to comment.