Skip to content

Commit 0ba232d

Browse files
committed
dxf export: improve marker symbol export
1 parent 5996014 commit 0ba232d

File tree

6 files changed

+150
-64
lines changed

6 files changed

+150
-64
lines changed

python/core/dxf/qgsdxfexport.sip

+4-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class QgsDxfExport
6161
void writeDouble( double d );
6262
void writeString( const QString& s );
6363
void writeGroup( int code, const QgsPoint &p, double z = 0.0, bool skipz = false ) /PyName=writeGroupPoint/;
64-
void writeGroup( QColor color, int exactMatch = 62, int rgb = 420 );
64+
void writeGroup( QColor color, int exactMatch = 62, int rgbCode = 420, int transparencyCode = 440 );
6565

6666
int writeHandle( int code = 5, int handle = 0 );
6767

@@ -78,7 +78,9 @@ class QgsDxfExport
7878

7979
void writePoint( const QString& layer, QColor color, const QgsPoint& pt );
8080

81-
void writeCircle( const QString& layer, QColor color, const QgsPoint& pt, double radius );
81+
void writeFilledCircle( const QString &layer, QColor color, const QgsPoint &pt, double radius );
82+
83+
void writeCircle( const QString& layer, QColor color, const QgsPoint& pt, double radius, const QString &lineStyleName, double width );
8284

8385
void writeText( const QString& layer, const QString& text, const QgsPoint& pt, double size, double angle, QColor color );
8486

src/core/dxf/qgsdxfexport.cpp

+53-32
Original file line numberDiff line numberDiff line change
@@ -3327,45 +3327,66 @@ void QgsDxfExport::writePoint( const QString& layer, QColor color, const QgsPoin
33273327
writeGroup( 0, pt );
33283328
}
33293329

3330-
void QgsDxfExport::writeCircle( const QString& layer, QColor color, const QgsPoint& pt, double radius )
3330+
void QgsDxfExport::writeFilledCircle( const QString &layer, QColor color, const QgsPoint &pt, double radius )
33313331
{
3332-
writeGroup( 0, "CIRCLE" );
3332+
writeGroup( 0, "HATCH" ); // Entity type
33333333
writeHandle();
3334+
writeGroup( 330, mModelSpaceBR );
33343335
writeGroup( 100, "AcDbEntity" );
3335-
writeGroup( 100, "AcDbCircle" );
3336-
writeGroup( 8, layer );
3337-
writeGroup( color );
3338-
writeGroup( 0, pt );
3339-
writeGroup( 40, radius );
3336+
writeGroup( 100, "AcDbHatch" );
33403337

3341-
#if 0
3342-
writeGroup( 0, "HATCH" );
3338+
writeGroup( 8, layer ); // Layer name
3339+
writeGroup( 0, QgsPoint( 0, 0 ), 0.0 ); // Elevation point (in OCS)
3340+
writeGroup( 200, QgsPoint( 0, 0 ), 1.0 );
3341+
3342+
writeGroup( 2, "SOLID" ); // Hatch pattern name
3343+
writeGroup( 70, 1 ); // Solid fill flag (solid fill = 1; pattern fill = 0)
3344+
writeGroup( 71, 0 ); // Associativity flag (associative = 1; non-associative = 0)
3345+
3346+
writeGroup( color ); // Color (0 by block, 256 by layer)
3347+
3348+
writeGroup( 91, 1 ); // Number of boundary paths (loops)
3349+
3350+
writeGroup( 92, 7 ); // Boundary path type flag (bit coded): 0 = Default; 1 = External; 2 = Polyline 4 = Derived; 8 = Textbox; 16 = Outermost
3351+
writeGroup( 72, 2 );
3352+
writeGroup( 73, 1 ); // Is closed flag
3353+
writeGroup( 93, 2 ); // Number of polyline vertices
3354+
3355+
writeGroup( 0, QgsPoint( pt.x() - radius, pt.y() ) );
3356+
writeGroup( 42, 1.0 );
3357+
3358+
writeGroup( 0, QgsPoint( pt.x() + radius, pt.y() ) );
3359+
writeGroup( 42, 1.0 );
3360+
3361+
writeGroup( 97, 0 ); // Number of source boundary objects
3362+
3363+
writeGroup( 75, 1 ); // Hatch style: 0 = Hatch "odd parity" area (Normal style), 1 = Hatch outermost area only (Outer style), 2 = Hatch through entire area (Ignore style)
3364+
writeGroup( 76, 1 ); // Hatch pattern type: 0 = User-defined; 1 = Predefined; 2 = Custom
3365+
writeGroup( 47, 0.0059696789328105 ); // Pixel size
3366+
3367+
writeGroup( 98, 0 ); // Number of seed points
3368+
}
3369+
3370+
void QgsDxfExport::writeCircle( const QString& layer, QColor color, const QgsPoint& pt, double radius, const QString &lineStyleName, double width )
3371+
{
3372+
writeGroup( 0, "LWPOLYLINE" );
33433373
writeHandle();
33443374
writeGroup( 330, mModelSpaceBR );
3345-
writeGroup( 100, "AcDbEntity" );
3346-
writeGroup( 100, "AcDbHatch" );
33473375
writeGroup( 8, layer );
3376+
writeGroup( 100, "AcDbEntity" );
3377+
writeGroup( 100, "AcDbPolyline" );
3378+
writeGroup( 6, lineStyleName );
33483379
writeGroup( color );
3349-
writeGroup( 0, QgsPoint( 0.0, 0.0 ) ); // elevation point
3350-
writeGroup( 200, QgsPoint( 0, 0 ), 1.0 ); // Extrusion direction
3351-
writeGroup( 2, "SOLID" ); // hatch pattern
3352-
writeGroup( 70, 1 ); // solid fill flag
3353-
writeGroup( 71, 0 ); // non-associative
3354-
writeGroup( 91, 1 ); // 1 loop
3355-
writeGroup( 92, 0 ); // Default edge type
3356-
writeGroup( 72, 2 ); // Edge type Arc
3357-
writeGroup( 93, 1 ); // Is closed
3358-
3359-
writeGroup( 0, QgsPoint( pt.x(), pt.y() ), 0.0, false ); // center point
3360-
writeGroup( 40, radius ); // radius
3361-
writeGroup( 50, 0.0 ); // start angle
3362-
writeGroup( 51, 2*M_PI ); // end angle
3363-
3364-
writeGroup( 97, 0 ); // # of source boundary objects
3365-
writeGroup( 75, 1 ); // odd parity hatch style
3366-
writeGroup( 76, 1 ); // predefined hatch pattern
3367-
writeGroup( 98, 0 ); // # of seed points
3368-
#endif
3380+
3381+
writeGroup( 90, 2 );
3382+
3383+
writeGroup( 70, 1 );
3384+
writeGroup( 43, width );
3385+
3386+
writeGroup( 0, QgsPoint( pt.x() - radius, pt.y() ) );
3387+
writeGroup( 42, 1.0 );
3388+
writeGroup( 0, QgsPoint( pt.x() + radius, pt.y() ) );
3389+
writeGroup( 42, 1.0 );
33693390
}
33703391

33713392
void QgsDxfExport::writeText( const QString& layer, const QString& text, const QgsPoint& pt, double size, double angle, QColor color )
@@ -3403,7 +3424,7 @@ void QgsDxfExport::writeMText( const QString& layer, const QString& text, const
34033424
writeGroup( 1, text );
34043425

34053426
writeGroup( 50, angle ); // Rotation angle in radians
3406-
writeGroup( 41, width ); // Reference rectangle width
3427+
writeGroup( 41, width * 1.1 ); // Reference rectangle width
34073428

34083429
// Attachment point:
34093430
// 1 2 3

src/core/dxf/qgsdxfexport.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class CORE_EXPORT QgsDxfExport
7474
void writeDouble( double d );
7575
void writeString( const QString& s );
7676
void writeGroup( int code, const QgsPoint &p, double z = 0.0, bool skipz = false );
77-
void writeGroup( QColor color, int exactMatch = 62, int rgbCode = 420, int tranparencyCode = 440 );
77+
void writeGroup( QColor color, int exactMatch = 62, int rgbCode = 420, int transparencyCode = 440 );
7878

7979
int writeHandle( int code = 5, int handle = 0 );
8080

@@ -91,7 +91,9 @@ class CORE_EXPORT QgsDxfExport
9191

9292
void writePoint( const QString& layer, QColor color, const QgsPoint& pt );
9393

94-
void writeCircle( const QString& layer, QColor color, const QgsPoint& pt, double radius );
94+
void writeFilledCircle( const QString &layer, QColor color, const QgsPoint &pt, double radius );
95+
96+
void writeCircle( const QString& layer, QColor color, const QgsPoint& pt, double radius, const QString &lineStyleName, double width );
9597

9698
void writeText( const QString& layer, const QString& text, const QgsPoint& pt, double size, double angle, QColor color );
9799

src/core/dxf/qgsdxfpaintengine.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
#include "qgsdxfpaintdevice.h"
2121
#include "qgslogger.h"
2222

23-
QgsDxfPaintEngine::QgsDxfPaintEngine( const QgsDxfPaintDevice* dxfDevice, QgsDxfExport* dxf ): QPaintEngine( QPaintEngine::AllFeatures /*QPaintEngine::PainterPaths | QPaintEngine::PaintOutsidePaintEvent*/ )
23+
QgsDxfPaintEngine::QgsDxfPaintEngine( const QgsDxfPaintDevice* dxfDevice, QgsDxfExport* dxf )
24+
: QPaintEngine( QPaintEngine::AllFeatures /*QPaintEngine::PainterPaths | QPaintEngine::PaintOutsidePaintEvent*/ )
2425
, mPaintDevice( dxfDevice ), mDxf( dxf )
2526
{
2627

@@ -76,14 +77,16 @@ void QgsDxfPaintEngine::drawPolygon( const QPointF* points, int pointCount, Poly
7677
return;
7778
}
7879

79-
QgsPolyline polyline( pointCount );
80+
QgsPolygon polygon( 1 );
81+
polygon[0].resize( pointCount );
82+
83+
QgsPolyline &polyline = polygon[0];
8084
for ( int i = 0; i < pointCount; ++i )
8185
{
8286
polyline[i] = toDxfCoordinates( points[i] );
8387
}
8488

85-
bool closed = ( pointCount > 3 && points[0] == points[pointCount - 1] );
86-
mDxf->writePolyline( polyline, mLayer, "CONTINUOUS", currentColor(), currentWidth(), closed );
89+
mDxf->writePolygon( polygon, mLayer, "SOLID", currentColor() );
8790
}
8891

8992
void QgsDxfPaintEngine::drawRects( const QRectF* rects, int rectCount )
@@ -297,7 +300,6 @@ double QgsDxfPaintEngine::power( double a, int b )
297300
double tmp = a;
298301
for ( int i = 2; i <= qAbs(( double )b ); i++ )
299302
{
300-
301303
a *= tmp;
302304
}
303305
if ( b > 0 )
@@ -306,7 +308,7 @@ double QgsDxfPaintEngine::power( double a, int b )
306308
}
307309
else
308310
{
309-
return ( 1.0 / a );
311+
return 1.0 / a;
310312
}
311313
}
312314

src/core/symbology-ng/qgsellipsesymbollayerv2.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
696696
if ( qgsDoubleNear( halfWidth, halfHeight ) )
697697
{
698698
QPointF pt( t.map( QPointF( 0, 0 ) ) );
699-
e.writeCircle( layerName, oc, QgsPoint( pt.x(), pt.y() ), halfWidth );
699+
e.writeFilledCircle( layerName, oc, QgsPoint( pt.x(), pt.y() ), halfWidth );
700700
}
701701
else
702702
{

src/core/symbology-ng/qgsmarkersymbollayerv2.cpp

+80-21
Original file line numberDiff line numberDiff line change
@@ -841,15 +841,19 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
841841
}
842842

843843
//color
844-
QColor c = mPen.color();
845-
if ( mPen.style() == Qt::NoPen )
846-
{
847-
c = mBrush.color();
848-
}
844+
QColor pc = mPen.color();
845+
QColor bc = mBrush.color();
846+
849847
QgsExpression* colorExpression = expression( "color" );
850848
if ( colorExpression )
851849
{
852-
c = QgsSymbolLayerV2Utils::decodeColor( colorExpression->evaluate( *f ).toString() );
850+
bc = QgsSymbolLayerV2Utils::decodeColor( colorExpression->evaluate( *f ).toString() );
851+
}
852+
853+
QgsExpression* outlinecolorExpression = expression( "outline_color" );
854+
if ( outlinecolorExpression )
855+
{
856+
pc = QgsSymbolLayerV2Utils::decodeColor( outlinecolorExpression->evaluate( *f ).toString() );
853857
}
854858

855859
//offset
@@ -884,78 +888,133 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
884888

885889
if ( mName == "circle" )
886890
{
887-
e.writeCircle( layerName, c, QgsPoint( shift.x(), shift.y() ), halfSize );
891+
if ( mBrush.style() != Qt::NoBrush )
892+
e.writeFilledCircle( layerName, bc, QgsPoint( shift.x(), shift.y() ), halfSize );
893+
if ( mPen.style() != Qt::NoPen )
894+
e.writeCircle( layerName, pc, QgsPoint( shift.x(), shift.y() ), halfSize, "CONTINUOUS", outlineWidth );
888895
}
889896
else if ( mName == "square" || mName == "rectangle" )
890897
{
898+
// pt1 pt2
899+
// pt3 pt4
891900
QPointF pt1 = t.map( QPointF( -halfSize, -halfSize ) );
892901
QPointF pt2 = t.map( QPointF( halfSize, -halfSize ) );
893902
QPointF pt3 = t.map( QPointF( -halfSize, halfSize ) );
894903
QPointF pt4 = t.map( QPointF( halfSize, halfSize ) );
895-
e.writeSolid( layerName, c, QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt4.x(), pt4.y() ) );
904+
905+
if ( mBrush.style() != Qt::NoBrush )
906+
e.writeSolid( layerName, bc, QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt4.x(), pt4.y() ) );
907+
908+
if ( mPen.style() != Qt::NoPen )
909+
{
910+
e.writeLine( pt1, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
911+
e.writeLine( pt2, pt4, layerName, "CONTINUOUS", pc, outlineWidth );
912+
e.writeLine( pt4, pt3, layerName, "CONTINUOUS", pc, outlineWidth );
913+
e.writeLine( pt3, pt1, layerName, "CONTINUOUS", pc, outlineWidth );
914+
}
896915
}
897916
else if ( mName == "diamond" )
898917
{
899918
QPointF pt1 = t.map( QPointF( -halfSize, 0 ) );
900919
QPointF pt2 = t.map( QPointF( 0, -halfSize ) );
901920
QPointF pt3 = t.map( QPointF( 0, halfSize ) );
902921
QPointF pt4 = t.map( QPointF( halfSize, 0 ) );
903-
e.writeSolid( layerName, c, QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt4.x(), pt4.y() ) );
922+
923+
if ( mBrush.style() != Qt::NoBrush )
924+
e.writeSolid( layerName, bc, QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt4.x(), pt4.y() ) );
925+
926+
if ( mPen.style() != Qt::NoPen )
927+
{
928+
e.writeLine( pt1, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
929+
e.writeLine( pt2, pt3, layerName, "CONTINUOUS", pc, outlineWidth );
930+
e.writeLine( pt3, pt4, layerName, "CONTINUOUS", pc, outlineWidth );
931+
e.writeLine( pt4, pt1, layerName, "CONTINUOUS", pc, outlineWidth );
932+
}
904933
}
905934
else if ( mName == "triangle" )
906935
{
907936
QPointF pt1 = t.map( QPointF( -halfSize, -halfSize ) );
908937
QPointF pt2 = t.map( QPointF( halfSize, -halfSize ) );
909938
QPointF pt3 = t.map( QPointF( 0, halfSize ) );
910-
e.writeSolid( layerName, c, QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt3.x(), pt3.y() ) );
939+
940+
if ( mBrush.style() != Qt::NoBrush )
941+
e.writeSolid( layerName, bc, QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt3.x(), pt3.y() ) );
942+
943+
if ( mPen.style() != Qt::NoPen )
944+
{
945+
e.writeLine( pt1, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
946+
e.writeLine( pt2, pt3, layerName, "CONTINUOUS", pc, outlineWidth );
947+
e.writeLine( pt3, pt1, layerName, "CONTINUOUS", pc, outlineWidth );
948+
}
911949
}
912-
/*else if( mName == "equilateral_triangle" )
950+
#if 0
951+
else if ( mName == "equilateral_triangle" )
913952
{
914953

915-
}*/
954+
}
955+
#endif
916956
else if ( mName == "line" )
917957
{
918958
QPointF pt1 = t.map( QPointF( 0, halfSize ) );
919959
QPointF pt2 = t.map( QPointF( 0, -halfSize ) );
920-
e.writeLine( QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), layerName, "CONTINUOUS", c, outlineWidth );
960+
961+
if ( mPen.style() != Qt::NoPen )
962+
e.writeLine( QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), layerName, "CONTINUOUS", pc, outlineWidth );
921963
}
922-
else if ( mName == "coss" )
964+
else if ( mName == "cross" )
923965
{
924966
QPointF pt1 = t.map( QPointF( -halfSize, 0 ) );
925967
QPointF pt2 = t.map( QPointF( halfSize, 0 ) );
926968
QPointF pt3 = t.map( QPointF( 0, -halfSize ) );
927969
QPointF pt4 = t.map( QPointF( 0, halfSize ) );
928-
e.writeLine( QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), layerName, "CONTINUOUS", c, outlineWidth );
929-
e.writeLine( QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt4.x(), pt4.y() ), layerName, "CONTINUOUS", c, outlineWidth );
970+
971+
if ( mPen.style() != Qt::NoPen )
972+
{
973+
e.writeLine( QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), layerName, "CONTINUOUS", pc, outlineWidth );
974+
e.writeLine( QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt4.x(), pt4.y() ), layerName, "CONTINUOUS", pc, outlineWidth );
975+
}
930976
}
931977
else if ( mName == "x" || mName == "cross2" )
932978
{
933979
QPointF pt1 = t.map( QPointF( -halfSize, -halfSize ) );
934980
QPointF pt2 = t.map( QPointF( halfSize, halfSize ) );
935981
QPointF pt3 = t.map( QPointF( -halfSize, halfSize ) );
936982
QPointF pt4 = t.map( QPointF( halfSize, -halfSize ) );
937-
e.writeLine( QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), layerName, "CONTINUOUS", c, outlineWidth );
938-
e.writeLine( QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt4.x(), pt4.y() ), layerName, "CONTINUOUS", c, outlineWidth );
983+
984+
if ( mPen.style() != Qt::NoPen )
985+
{
986+
e.writeLine( QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), layerName, "CONTINUOUS", pc, outlineWidth );
987+
e.writeLine( QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt4.x(), pt4.y() ), layerName, "CONTINUOUS", pc, outlineWidth );
988+
}
939989
}
940990
else if ( mName == "arrowhead" )
941991
{
942992
QPointF pt1 = t.map( QPointF( -halfSize, halfSize ) );
943993
QPointF pt2 = t.map( QPointF( 0, 0 ) );
944994
QPointF pt3 = t.map( QPointF( -halfSize, -halfSize ) );
945-
e.writeLine( QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), layerName, "CONTINUOUS", c, outlineWidth );
946-
e.writeLine( QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt2.x(), pt2.y() ), layerName, "CONTINUOUS", c, outlineWidth );
995+
996+
if ( mPen.style() != Qt::NoPen )
997+
{
998+
e.writeLine( QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), layerName, "CONTINUOUS", pc, outlineWidth );
999+
e.writeLine( QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt2.x(), pt2.y() ), layerName, "CONTINUOUS", pc, outlineWidth );
1000+
}
9471001
}
9481002
else if ( mName == "filled_arrowhead" )
9491003
{
9501004
QPointF pt1 = t.map( QPointF( -halfSize, halfSize ) );
9511005
QPointF pt2 = t.map( QPointF( 0, 0 ) );
9521006
QPointF pt3 = t.map( QPointF( -halfSize, -halfSize ) );
953-
e.writeSolid( layerName, c, QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt3.x(), pt3.y() ) );
1007+
1008+
if ( mBrush.style() != Qt::NoBrush )
1009+
{
1010+
e.writeSolid( layerName, bc, QgsPoint( pt1.x(), pt1.y() ), QgsPoint( pt2.x(), pt2.y() ), QgsPoint( pt3.x(), pt3.y() ), QgsPoint( pt3.x(), pt3.y() ) );
1011+
}
9541012
}
9551013
else
9561014
{
9571015
return false;
9581016
}
1017+
9591018
return true;
9601019
}
9611020

0 commit comments

Comments
 (0)