Skip to content

Commit 7031cfb

Browse files
committed
dxf export: deprecate writeSolid (replaced with writePolygon) and add some doxymentation
1 parent 38a247f commit 7031cfb

File tree

5 files changed

+113
-108
lines changed

5 files changed

+113
-108
lines changed

python/core/dxf/qgsdxfexport.sip

+14-3
Original file line numberDiff line numberDiff line change
@@ -63,30 +63,41 @@ class QgsDxfExport
6363
void writeGroup( int code, const QgsPoint &p, double z = 0.0, bool skipz = false ) /PyName=writeGroupPoint/;
6464
void writeGroup( QColor color, int exactMatch = 62, int rgbCode = 420, int transparencyCode = 440 );
6565

66+
//! Write handle
6667
int writeHandle( int code = 5, int handle = 0 );
6768

68-
//draw dxf primitives
69+
//! Draw dxf polyline
6970
void writePolyline( const QgsPolyline &line, const QString &layer, const QString &lineStyleName, QColor color, double width = -1 );
7071

72+
//! Draw dxf polygon (HATCH)
7173
void writePolygon( const QgsPolygon &polygon, const QString &layer, const QString &hatchPattern, QColor color );
7274

73-
void writeSolid( const QString &layer, QColor color, const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, const QgsPoint &pt4 );
75+
/** Draw solid
76+
* @deprecated see writePolygon
77+
*/
78+
void writeSolid( const QString &layer, QColor color, const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, const QgsPoint &pt4 ) /Deprecated/;
7479

75-
//write line (as a polyline)
80+
//! write line (as a polyline)
7681
void writeLine( const QgsPoint &pt1, const QgsPoint &pt2, const QString &layer, const QString &lineStyleName, QColor color, double width = -1 );
7782

83+
//! Write point
7884
void writePoint( const QString &layer, QColor color, const QgsPoint &pt );
7985

86+
//! Write filled circle (as hatch)
8087
void writeFilledCircle( const QString &layer, QColor color, const QgsPoint &pt, double radius );
8188

89+
//! Write circle (as polyline)
8290
void writeCircle( const QString &layer, QColor color, const QgsPoint &pt, double radius, const QString &lineStyleName, double width );
8391

92+
//! Write text (TEXT)
8493
void writeText( const QString &layer, const QString &text, const QgsPoint &pt, double size, double angle, QColor color );
8594

95+
//! Write mtext (MTEXT)
8696
void writeMText( const QString &layer, const QString &text, const QgsPoint &pt, double width, double angle, QColor color );
8797

8898
static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits );
8999

100+
//! Return cleaned layer name for use in DXF
90101
static QString dxfLayerName( const QString &name );
91102

92103
};

src/core/dxf/qgsdxfexport.cpp

+13-10
Original file line numberDiff line numberDiff line change
@@ -3514,16 +3514,19 @@ void QgsDxfExport::writeMText( const QString& layer, const QString& text, const
35143514

35153515
void QgsDxfExport::writeSolid( const QString& layer, QColor color, const QgsPoint& pt1, const QgsPoint& pt2, const QgsPoint& pt3, const QgsPoint& pt4 )
35163516
{
3517-
writeGroup( 0, "SOLID" );
3518-
writeHandle();
3519-
writeGroup( 100, "AcDbEntity" );
3520-
writeGroup( 100, "AcDbTrace" );
3521-
writeGroup( 8, layer );
3522-
writeGroup( color );
3523-
writeGroup( 0, pt1 );
3524-
writeGroup( 1, pt2 );
3525-
writeGroup( 2, pt3 );
3526-
writeGroup( 3, pt4 );
3517+
// pt1 pt2
3518+
// pt3 pt4
3519+
int i = 0;
3520+
QgsPolygon p( 1 );
3521+
p[0].resize( pt3 != pt4 ? 5 : 4 );
3522+
p[0][i++] = pt1;
3523+
p[0][i++] = pt2;
3524+
p[0][i++] = pt4;
3525+
if ( p[0].size() == 5 )
3526+
p[0][i++] = pt3;
3527+
p[0][i] = pt1;
3528+
3529+
writePolygon( p, layer, "SOLID", color );
35273530
}
35283531

35293532
void QgsDxfExport::writeVertex( const QgsPoint& pt, const QString& layer )

src/core/dxf/qgsdxfexport.h

+13-4
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,38 @@ class CORE_EXPORT QgsDxfExport
7878

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

81-
//! draw dxf primitives
81+
//! Draw dxf primitives (LWPOLYLINE)
8282
void writePolyline( const QgsPolyline &line, const QString &layer, const QString &lineStyleName, QColor color, double width = -1 );
8383

84+
//! Draw dxf polygon (HATCH)
8485
void writePolygon( const QgsPolygon &polygon, const QString &layer, const QString &hatchPattern, QColor color );
8586

86-
void writeSolid( const QString &layer, QColor color, const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, const QgsPoint &pt4 );
87+
/** Draw solid
88+
* @deprecated see writePolygon
89+
*/
90+
Q_DECL_DEPRECATED void writeSolid( const QString &layer, QColor color, const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, const QgsPoint &pt4 );
8791

88-
//! write line (as a polyline)
92+
//! Write line (as a polyline)
8993
void writeLine( const QgsPoint &pt1, const QgsPoint &pt2, const QString &layer, const QString &lineStyleName, QColor color, double width = -1 );
9094

95+
//! Write point
9196
void writePoint( const QString &layer, QColor color, const QgsPoint &pt );
9297

98+
//! Write filled circle (as hatch)
9399
void writeFilledCircle( const QString &layer, QColor color, const QgsPoint &pt, double radius );
94100

101+
//! Write circle (as polyline)
95102
void writeCircle( const QString &layer, QColor color, const QgsPoint &pt, double radius, const QString &lineStyleName, double width );
96103

104+
//! Write text (TEXT)
97105
void writeText( const QString &layer, const QString &text, const QgsPoint &pt, double size, double angle, QColor color );
98106

107+
//! Write mtext (MTEXT)
99108
void writeMText( const QString &layer, const QString &text, const QgsPoint &pt, double width, double angle, QColor color );
100109

101110
static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits );
102111

103-
//! return cleaned layer name for use in DXF
112+
//! Return cleaned layer name for use in DXF
104113
static QString dxfLayerName( const QString &name );
105114

106115
//! return DXF encoding for Qt encoding

src/core/symbology-ng/qgsellipsesymbollayerv2.cpp

+26-37
Original file line numberDiff line numberDiff line change
@@ -687,55 +687,44 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
687687
}
688688
else if ( symbolName == "rectangle" )
689689
{
690-
QPointF pt1( t.map( QPointF( -halfWidth, -halfHeight ) ) );
691-
QPointF pt2( t.map( QPointF( halfWidth, -halfHeight ) ) );
692-
QPointF pt3( t.map( QPointF( -halfWidth, halfHeight ) ) );
693-
QPointF pt4( t.map( QPointF( halfWidth, halfHeight ) ) );
690+
QgsPolygon p( 1 );
691+
p[0].resize( 5 );
692+
p[0][0] = t.map( QPointF( -halfWidth, -halfHeight ) );
693+
p[0][1] = t.map( QPointF( halfWidth, -halfHeight ) );
694+
p[0][2] = t.map( QPointF( halfWidth, halfHeight ) );
695+
p[0][3] = t.map( QPointF( -halfWidth, halfHeight ) );
696+
p[0][4] = p[0][0];
694697
if ( mBrush.style() != Qt::NoBrush )
695-
e.writeSolid( layerName, fc, pt1, pt2, pt3, pt4 );
696-
QgsPolyline line( 5 );
697-
line[0] = pt1;
698-
line[1] = pt2;
699-
line[2] = pt3;
700-
line[3] = pt4;
701-
line[4] = pt1;
698+
e.writePolygon( p, layerName, "SOLID", fc );
702699
if ( mPen.style() != Qt::NoPen )
703-
e.writePolyline( line, layerName, "CONTINUOUS", oc, outlineWidth );
700+
e.writePolyline( p[0], layerName, "CONTINUOUS", oc, outlineWidth );
704701
return true;
705702
}
706703
else if ( symbolName == "cross" && mPen.style() != Qt::NoPen )
707704
{
708-
QgsPolyline line1( 2 );
709-
QPointF pt1( t.map( QPointF( -halfWidth, 0 ) ) );
710-
QPointF pt2( t.map( QPointF( halfWidth, 0 ) ) );
711-
line1[0] = pt1;
712-
line1[1] = pt2;
713-
e.writePolyline( line1, layerName, "CONTINUOUS", oc, outlineWidth );
714-
QgsPolyline line2( 2 );
715-
QPointF pt3( t.map( QPointF( 0, halfHeight ) ) );
716-
QPointF pt4( t.map( QPointF( 0, -halfHeight ) ) );
717-
line2[0] = pt3;
718-
line2[1] = pt4;
719-
e.writePolyline( line2, layerName, "CONTINUOUS", oc, outlineWidth );
705+
QgsPolyline line( 2 );
706+
line[0] = t.map( QPointF( -halfWidth, 0 ) );
707+
line[1] = t.map( QPointF( halfWidth, 0 ) );
708+
e.writePolyline( line, layerName, "CONTINUOUS", oc, outlineWidth );
709+
710+
line[0] = t.map( QPointF( 0, halfHeight ) );
711+
line[1] = t.map( QPointF( 0, -halfHeight ) );
712+
e.writePolyline( line, layerName, "CONTINUOUS", oc, outlineWidth );
713+
720714
return true;
721715
}
722716
else if ( symbolName == "triangle" )
723717
{
724-
QPointF pt1( t.map( QPointF( -halfWidth, -halfHeight ) ) );
725-
QPointF pt2( t.map( QPointF( halfWidth, -halfHeight ) ) );
726-
QPointF pt3( t.map( QPointF( 0, halfHeight ) ) );
727-
QPointF pt4( t.map( QPointF( 0, halfHeight ) ) );
718+
QgsPolygon p( 1 );
719+
p[0].resize( 4 );
720+
p[0][0] = QPointF( t.map( QPointF( -halfWidth, -halfHeight ) ) );
721+
p[0][1] = QPointF( t.map( QPointF( halfWidth, -halfHeight ) ) );
722+
p[0][2] = QPointF( t.map( QPointF( 0, halfHeight ) ) );
723+
p[0][3] = p[0][0];
728724
if ( mBrush.style() != Qt::NoBrush )
729-
e.writeSolid( layerName, fc, pt1, pt2, pt3, pt4 );
725+
e.writePolygon( p, layerName, "SOLID", fc );
730726
if ( mPen.style() != Qt::NoPen )
731-
{
732-
QgsPolyline line( 4 );
733-
line[0] = pt1;
734-
line[1] = pt2;
735-
line[2] = pt3;
736-
line[3] = pt4;
737-
e.writePolyline( line, layerName, "CONTINUOUS", oc, outlineWidth );
738-
}
727+
e.writePolyline( p[0], layerName, "CONTINUOUS", oc, outlineWidth );
739728
return true;
740729
}
741730

src/core/symbology-ng/qgsmarkersymbollayerv2.cpp

+47-54
Original file line numberDiff line numberDiff line change
@@ -909,57 +909,48 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
909909
}
910910
else if ( mName == "square" || mName == "rectangle" )
911911
{
912-
// pt1 pt2
913-
// pt3 pt4
914-
QPointF pt1 = t.map( QPointF( -halfSize, -halfSize ) );
915-
QPointF pt2 = t.map( QPointF( halfSize, -halfSize ) );
916-
QPointF pt3 = t.map( QPointF( -halfSize, halfSize ) );
917-
QPointF pt4 = t.map( QPointF( halfSize, halfSize ) );
912+
QgsPolygon p( 1 );
913+
p[0].resize( 5 );
914+
p[0][0] = t.map( QPointF( -halfSize, -halfSize ) );
915+
p[0][1] = t.map( QPointF( -halfSize, halfSize ) );
916+
p[0][2] = t.map( QPointF( halfSize, halfSize ) );
917+
p[0][3] = t.map( QPointF( halfSize, -halfSize ) );
918+
p[0][4] = p[0][0];
918919

919920
if ( mBrush.style() != Qt::NoBrush )
920-
e.writeSolid( layerName, bc, pt1, pt2, pt3, pt4 );
921-
921+
e.writePolygon( p, layerName, "SOLID", bc );
922922
if ( mPen.style() != Qt::NoPen )
923-
{
924-
e.writeLine( pt1, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
925-
e.writeLine( pt2, pt4, layerName, "CONTINUOUS", pc, outlineWidth );
926-
e.writeLine( pt4, pt3, layerName, "CONTINUOUS", pc, outlineWidth );
927-
e.writeLine( pt3, pt1, layerName, "CONTINUOUS", pc, outlineWidth );
928-
}
923+
e.writePolyline( p[0], layerName, "CONTINUOUS", pc, outlineWidth );
929924
}
930925
else if ( mName == "diamond" )
931926
{
932-
QPointF pt1 = t.map( QPointF( -halfSize, 0 ) );
933-
QPointF pt2 = t.map( QPointF( 0, -halfSize ) );
934-
QPointF pt3 = t.map( QPointF( 0, halfSize ) );
935-
QPointF pt4 = t.map( QPointF( halfSize, 0 ) );
927+
QgsPolygon p( 1 );
928+
p[0].resize( 5 );
929+
p[0][0] = t.map( QPointF( -halfSize, 0 ) );
930+
p[0][1] = t.map( QPointF( 0, halfSize ) );
931+
p[0][3] = t.map( QPointF( halfSize, 0 ) );
932+
p[0][1] = t.map( QPointF( 0, -halfSize ) );
933+
p[0][4] = p[0][0];
936934

937935
if ( mBrush.style() != Qt::NoBrush )
938-
e.writeSolid( layerName, bc, pt1, pt2, pt3, pt4 );
939-
936+
e.writePolygon( p, layerName, "SOLID", bc );
940937
if ( mPen.style() != Qt::NoPen )
941-
{
942-
e.writeLine( pt1, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
943-
e.writeLine( pt2, pt3, layerName, "CONTINUOUS", pc, outlineWidth );
944-
e.writeLine( pt3, pt4, layerName, "CONTINUOUS", pc, outlineWidth );
945-
e.writeLine( pt4, pt1, layerName, "CONTINUOUS", pc, outlineWidth );
946-
}
938+
e.writePolyline( p[0], layerName, "CONTINUOUS", pc, outlineWidth );
947939
}
948940
else if ( mName == "triangle" )
949941
{
950-
QPointF pt1 = t.map( QPointF( -halfSize, -halfSize ) );
951-
QPointF pt2 = t.map( QPointF( halfSize, -halfSize ) );
952-
QPointF pt3 = t.map( QPointF( 0, halfSize ) );
942+
QgsPolygon p( 1 );
943+
p[0].resize( 4 );
944+
p[0][0] = t.map( QPointF( -halfSize, -halfSize ) );
945+
p[0][1] = t.map( QPointF( halfSize, -halfSize ) );
946+
p[0][1] = t.map( QPointF( 0, halfSize ) );
947+
p[0][2] = p[0][0];
953948

954949
if ( mBrush.style() != Qt::NoBrush )
955-
e.writeSolid( layerName, bc, pt1, pt2, pt3, pt3 );
950+
e.writePolygon( p, layerName, "SOLID", bc );
956951

957952
if ( mPen.style() != Qt::NoPen )
958-
{
959-
e.writeLine( pt1, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
960-
e.writeLine( pt2, pt3, layerName, "CONTINUOUS", pc, outlineWidth );
961-
e.writeLine( pt3, pt1, layerName, "CONTINUOUS", pc, outlineWidth );
962-
}
953+
e.writePolyline( p[0], layerName, "CONTINUOUS", pc, outlineWidth );
963954
}
964955
#if 0
965956
else if ( mName == "equilateral_triangle" )
@@ -977,51 +968,53 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
977968
}
978969
else if ( mName == "cross" )
979970
{
980-
QPointF pt1 = t.map( QPointF( -halfSize, 0 ) );
981-
QPointF pt2 = t.map( QPointF( halfSize, 0 ) );
982-
QPointF pt3 = t.map( QPointF( 0, -halfSize ) );
983-
QPointF pt4 = t.map( QPointF( 0, halfSize ) );
984-
985971
if ( mPen.style() != Qt::NoPen )
986972
{
973+
QPointF pt1 = t.map( QPointF( -halfSize, 0 ) );
974+
QPointF pt2 = t.map( QPointF( halfSize, 0 ) );
975+
QPointF pt3 = t.map( QPointF( 0, -halfSize ) );
976+
QPointF pt4 = t.map( QPointF( 0, halfSize ) );
977+
987978
e.writeLine( pt1, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
988979
e.writeLine( pt3, pt4, layerName, "CONTINUOUS", pc, outlineWidth );
989980
}
990981
}
991982
else if ( mName == "x" || mName == "cross2" )
992983
{
993-
QPointF pt1 = t.map( QPointF( -halfSize, -halfSize ) );
994-
QPointF pt2 = t.map( QPointF( halfSize, halfSize ) );
995-
QPointF pt3 = t.map( QPointF( -halfSize, halfSize ) );
996-
QPointF pt4 = t.map( QPointF( halfSize, -halfSize ) );
997-
998984
if ( mPen.style() != Qt::NoPen )
999985
{
986+
QPointF pt1 = t.map( QPointF( -halfSize, -halfSize ) );
987+
QPointF pt2 = t.map( QPointF( halfSize, halfSize ) );
988+
QPointF pt3 = t.map( QPointF( -halfSize, halfSize ) );
989+
QPointF pt4 = t.map( QPointF( halfSize, -halfSize ) );
990+
1000991
e.writeLine( pt1, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
1001992
e.writeLine( pt3, pt4, layerName, "CONTINUOUS", pc, outlineWidth );
1002993
}
1003994
}
1004995
else if ( mName == "arrowhead" )
1005996
{
1006-
QPointF pt1 = t.map( QPointF( -halfSize, halfSize ) );
1007-
QPointF pt2 = t.map( QPointF( 0, 0 ) );
1008-
QPointF pt3 = t.map( QPointF( -halfSize, -halfSize ) );
1009-
1010997
if ( mPen.style() != Qt::NoPen )
1011998
{
999+
QPointF pt1 = t.map( QPointF( -halfSize, halfSize ) );
1000+
QPointF pt2 = t.map( QPointF( 0, 0 ) );
1001+
QPointF pt3 = t.map( QPointF( -halfSize, -halfSize ) );
1002+
10121003
e.writeLine( pt1, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
10131004
e.writeLine( pt3, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
10141005
}
10151006
}
10161007
else if ( mName == "filled_arrowhead" )
10171008
{
1018-
QPointF pt1 = t.map( QPointF( -halfSize, halfSize ) );
1019-
QPointF pt2 = t.map( QPointF( 0, 0 ) );
1020-
QPointF pt3 = t.map( QPointF( -halfSize, -halfSize ) );
1021-
10221009
if ( mBrush.style() != Qt::NoBrush )
10231010
{
1024-
e.writeSolid( layerName, bc, pt1, pt2, pt3, pt3 );
1011+
QgsPolygon p( 1 );
1012+
p[0].resize( 4 );
1013+
p[0][0] = t.map( QPointF( -halfSize, halfSize ) );
1014+
p[0][1] = t.map( QPointF( 0, 0 ) );
1015+
p[0][2] = t.map( QPointF( -halfSize, -halfSize ) );
1016+
p[0][3] = p[0][0];
1017+
e.writePolygon( p, layerName, "SOLID", bc );
10251018
}
10261019
}
10271020
else

0 commit comments

Comments
 (0)