bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift ) const { //width double symbolWidth = mSymbolWidth; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH ) ) //1. priority: data defined setting on symbol layer le { symbolWidth = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH, f, mSymbolWidth ).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; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_HEIGHT ) ) //1. priority: data defined setting on symbol layer level { symbolHeight = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_HEIGHT, f, mSymbolHeight ).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; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH ) ) { outlineWidth = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH, f, mOutlineWidth ).toDouble(); } if ( mOutlineWidthUnit == QgsSymbolV2::MM ) { outlineWidth *= outlineWidth; } //fill color bool ok; QColor fc = mFillColor; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_FILL_COLOR ) ) { QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_FILL_COLOR, f, QVariant(), &ok ).toString(); if ( ok ) fc = QColor( colorString ); } //outline color QColor oc = mOutlineColor; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_COLOR ) ) { QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_COLOR, f, QVariant(), &ok ).toString(); if ( ok ) oc = QColor( colorString ); } //symbol name QString symbolName = mSymbolName; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_SYMBOL_NAME ) ) { symbolName = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_SYMBOL_NAME, f, mSymbolName ).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; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_ROTATION ) ) { rotation = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_ROTATION, f, mAngle ).toDouble() + mLineAngle; } else if ( !qgsDoubleNear( mAngle + mLineAngle, 0.0 ) ) { rotation = mAngle + mLineAngle; } 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" ) { if ( qgsDoubleNear( halfWidth, halfHeight ) ) { QPointF pt( t.map( QPointF( 0, 0 ) ) ); e.writeFilledCircle( layerName, oc, pt, 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( pt ); } //close ellipse with first point line.push_back( line.at( 0 ) ); if ( mBrush.style() != Qt::NoBrush ) e.writePolygon( QgsPolygon() << line, layerName, "SOLID", fc ); if ( mPen.style() != Qt::NoPen ) e.writePolyline( line, layerName, "CONTINUOUS", oc, outlineWidth ); } } 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 ) ) ); if ( mBrush.style() != Qt::NoBrush ) e.writeSolid( layerName, fc, pt1, pt2, pt3, pt4 ); QgsPolyline line( 5 ); line[0] = pt1; line[1] = pt2; line[2] = pt3; line[3] = pt4; line[4] = pt1; if ( mPen.style() != Qt::NoPen ) e.writePolyline( line, layerName, "CONTINUOUS", oc, outlineWidth ); return true; } else if ( symbolName == "cross" && mPen.style() != Qt::NoPen ) { QgsPolyline line1( 2 ); QPointF pt1( t.map( QPointF( -halfWidth, 0 ) ) ); QPointF pt2( t.map( QPointF( halfWidth, 0 ) ) ); line1[0] = pt1; line1[1] = pt2; e.writePolyline( line1, layerName, "CONTINUOUS", oc, outlineWidth ); QgsPolyline line2( 2 ); QPointF pt3( t.map( QPointF( 0, halfHeight ) ) ); QPointF pt4( t.map( QPointF( 0, -halfHeight ) ) ); line2[0] = pt3; line2[1] = pt4; e.writePolyline( line2, layerName, "CONTINUOUS", oc, outlineWidth ); 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 ) ) ); if ( mBrush.style() != Qt::NoBrush ) e.writeSolid( layerName, fc, pt1, pt2, pt3, pt4 ); if ( mPen.style() != Qt::NoPen ) { QgsPolyline line( 4 ); line[0] = pt1; line[1] = pt2; line[2] = pt3; line[3] = pt4; e.writePolyline( line, layerName, "CONTINUOUS", oc, outlineWidth ); } return true; } return false; //soon... }
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<QgsFeature*>( 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<QgsFeature*>( 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<QgsFeature*>( 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<QgsFeature*>( 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<QgsFeature*>( 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<QgsFeature*>( 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... }
bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift ) const { //data defined size? double size = mSize; QgsExpression *sizeExpression = expression( "size" ); bool hasDataDefinedSize = false; if ( context ) { hasDataDefinedSize = context->renderHints() & QgsSymbolV2::DataDefinedSizeScale || sizeExpression; } //data defined size if ( hasDataDefinedSize ) { if ( sizeExpression ) { size = sizeExpression->evaluate( const_cast<QgsFeature*>( context->feature() ) ).toDouble(); } size *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( context->renderContext(), mSizeUnit ); switch ( mScaleMethod ) { case QgsSymbolV2::ScaleArea: size = sqrt( size ); break; case QgsSymbolV2::ScaleDiameter: break; } } if ( mSizeUnit == QgsSymbolV2::MM ) { size *= mmMapUnitScaleFactor; } double halfSize = size / 2.0; QColor c = mPen.color(); if ( mPen.style() == Qt::NoPen ) { c = mBrush.color(); } QgsExpression* colorExpression = expression( "color" ); if ( colorExpression ) { c = QgsSymbolLayerV2Utils::decodeColor( colorExpression->evaluate( *f ).toString() ); } int colorIndex = QgsDxfExport::closestColorMatch( c.rgb() ); //offset double offsetX = 0; double offsetY = 0; markerOffset( *context, offsetX, offsetY ); QPointF off( offsetX, offsetY ); //angle double angle = mAngle; QgsExpression* angleExpression = expression( "angle" ); if ( angleExpression ) { angle = angleExpression->evaluate( const_cast<QgsFeature*>( context->feature() ) ).toDouble(); } angle = -angle; //rotation in Qt is counterclockwise if ( angle ) off = _rotatedOffset( off, angle ); if ( mSizeUnit == QgsSymbolV2::MM ) { off *= mmMapUnitScaleFactor; } QTransform t; t.translate( shift.x() + offsetX, shift.y() + offsetY ); if ( angle != 0 ) t.rotate( angle ); //data defined symbol name if ( mName == "circle" ) { e.writeGroup( 0, "CIRCLE" ); e.writeGroup( 8, layerName ); e.writeGroup( 62, colorIndex ); e.writeGroup( 10, halfSize + shift.x() ); e.writeGroup( 20, halfSize + shift.y() ); e.writeGroup( 30, 0.0 ); e.writeGroup( 40, halfSize ); } else if ( mName == "square" || mName == "rectangle" ) { QPointF pt1 = t.map( QPointF( -halfSize, -halfSize ) ); QPointF pt2 = t.map( QPointF( halfSize, -halfSize ) ); QPointF pt3 = t.map( QPointF( -halfSize, halfSize ) ); QPointF pt4 = t.map( QPointF( halfSize, halfSize ) ); e.writeSolid( layerName, colorIndex, QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt4.x(), pt4.y() ) ); } else if ( mName == "diamond" ) { QPointF pt1 = t.map( QPointF( -halfSize, 0 ) ); QPointF pt2 = t.map( QPointF( 0, -halfSize ) ); QPointF pt3 = t.map( QPointF( 0, halfSize ) ); QPointF pt4 = t.map( QPointF( halfSize, 0 ) ); e.writeSolid( layerName, colorIndex, QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt4.x(), pt4.y() ) ); } else { return false; } return true; }