20
20
#include " qgspoint.h"
21
21
#include " qgsrendererv2.h"
22
22
#include " qgssymbollayerv2.h"
23
+ #include " qgsfillsymbollayerv2.h"
23
24
#include " qgslinesymbollayerv2.h"
24
25
#include " qgsvectorlayer.h"
25
26
#include < QIODevice>
@@ -427,18 +428,10 @@ void QgsDxfExport::writeTables()
427
428
mLineStyles .clear ();
428
429
writeGroup ( 0 , " TABLE" );
429
430
writeGroup ( 2 , " LTYPE" );
430
- writeGroup ( 70 , nLineTypes ( slList ) + 1 );
431
+ writeGroup ( 70 , nLineTypes ( slList ) + 5 );
431
432
432
- // add continuous style as default
433
- writeGroup ( 0 , " LTYPE" );
434
- writeGroup ( 2 , " CONTINUOUS" );
435
- writeGroup ( 70 , 64 );
436
- writeGroup ( 3 , " Defaultstyle" );
437
- writeGroup ( 72 , 65 );
438
- writeGroup ( 73 , 0 );
439
- writeGroup ( 40 , 0.0 );
440
-
441
- // add symbol layer linestyles
433
+ writeDefaultLinestyles ();
434
+ // add custom linestyles
442
435
QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2*> >::const_iterator slIt = slList.constBegin ();
443
436
for ( ; slIt != slList.constEnd (); ++slIt )
444
437
{
@@ -829,15 +822,7 @@ void QgsDxfExport::addFeature( const QgsFeature& fet, const QString& layer, cons
829
822
{
830
823
int c = colorFromSymbolLayer ( symbolLayer );
831
824
double width = widthFromSymbolLayer ( symbolLayer );
832
- QString lineStyleName = " CONTINUOUS" ;
833
- QHash< const QgsSymbolLayerV2*, QString >::const_iterator lineTypeIt = mLineStyles .find ( symbolLayer );
834
- if ( lineTypeIt != mLineStyles .constEnd () )
835
- {
836
- lineStyleName = lineTypeIt.value ();
837
- }
838
-
839
- // todo: write point symbols as blocks
840
-
825
+ QString lineStyleName = lineStyleFromSymbolLayer ( symbolLayer );
841
826
QGis::WkbType geometryType = geom->wkbType ();
842
827
843
828
// single point
@@ -922,7 +907,7 @@ int QgsDxfExport::colorFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer )
922
907
return closestColorMatch ( c.rgba () );
923
908
}
924
909
925
- double QgsDxfExport::widthFromSymbolLayer ( const QgsSymbolLayerV2* symbolLayer )
910
+ double QgsDxfExport::widthFromSymbolLayer ( const QgsSymbolLayerV2* symbolLayer ) const
926
911
{
927
912
// line symbol layer has width and width units
928
913
if ( symbolLayer && symbolLayer->type () == QgsSymbolV2::Line )
@@ -938,6 +923,36 @@ double QgsDxfExport::widthFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer )
938
923
// mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits )
939
924
}
940
925
926
+ QString QgsDxfExport::lineStyleFromSymbolLayer ( const QgsSymbolLayerV2* symbolLayer )
927
+ {
928
+ QString lineStyleName = " CONTINUOUS" ;
929
+ if ( !symbolLayer )
930
+ {
931
+ return lineStyleName;
932
+ }
933
+
934
+ QHash< const QgsSymbolLayerV2*, QString >::const_iterator lineTypeIt = mLineStyles .find ( symbolLayer );
935
+ if ( lineTypeIt != mLineStyles .constEnd () )
936
+ {
937
+ lineStyleName = lineTypeIt.value ();
938
+ }
939
+ else
940
+ {
941
+ // simple line and simple fill have pen style member
942
+ if ( symbolLayer->layerType () == " SimpleLine" )
943
+ {
944
+ const QgsSimpleLineSymbolLayerV2* sl = static_cast < const QgsSimpleLineSymbolLayerV2* >( symbolLayer );
945
+ return lineNameFromPenStyle ( sl->penStyle () );
946
+ }
947
+ else if ( symbolLayer->layerType () == " SimpleFill" )
948
+ {
949
+ const QgsSimpleFillSymbolLayerV2* sf = static_cast < const QgsSimpleFillSymbolLayerV2* >( symbolLayer );
950
+ return lineNameFromPenStyle ( sf->borderStyle () );
951
+ }
952
+ }
953
+ return lineStyleName;
954
+ }
955
+
941
956
int QgsDxfExport::closestColorMatch ( QRgb pixel )
942
957
{
943
958
int idx = 0 ;
@@ -1070,6 +1085,48 @@ QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2* > > QgsDxfExport::symbolLayers()
1070
1085
return symbolLayers;
1071
1086
}
1072
1087
1088
+ void QgsDxfExport::writeDefaultLinestyles ()
1089
+ {
1090
+ double das = dashSize ();
1091
+ double dos = dotSize ();
1092
+ double dss = dashSeparatorSize ();
1093
+
1094
+ // continuous (Qt solid line)
1095
+ writeGroup ( 0 , " LTYPE" );
1096
+ writeGroup ( 2 , " CONTINUOUS" );
1097
+ writeGroup ( 70 , 64 );
1098
+ writeGroup ( 3 , " Defaultstyle" );
1099
+ writeGroup ( 72 , 65 );
1100
+ writeGroup ( 73 , 0 );
1101
+ writeGroup ( 40 , 0.0 );
1102
+
1103
+ QVector<qreal> dashVector ( 2 );
1104
+ dashVector[0 ] = das;
1105
+ dashVector[1 ] = dss;
1106
+ writeLinestyle ( " DASH" , dashVector, QgsSymbolV2::MapUnit );
1107
+
1108
+ QVector<qreal> dotVector ( 2 );
1109
+ dotVector[0 ] = dos;
1110
+ dotVector[1 ] = dss;
1111
+ writeLinestyle ( " DOT" , dotVector, QgsSymbolV2::MapUnit );
1112
+
1113
+ QVector<qreal> dashDotVector ( 4 );
1114
+ dashDotVector[0 ] = das;
1115
+ dashDotVector[1 ] = dss;
1116
+ dashDotVector[2 ] = dos;
1117
+ dashDotVector[3 ] = dss;
1118
+ writeLinestyle ( " DASHDOT" , dashDotVector, QgsSymbolV2::MapUnit );
1119
+
1120
+ QVector<qreal> dashDotDotVector ( 6 );
1121
+ dashDotDotVector[0 ] = das;
1122
+ dashDotDotVector[1 ] = dss;
1123
+ dashDotDotVector[2 ] = dos;
1124
+ dashDotDotVector[3 ] = dss;
1125
+ dashDotDotVector[4 ] = dos;
1126
+ dashDotDotVector[5 ] = dss;
1127
+ writeLinestyle ( " DASHDOTDOT" , dashDotDotVector, QgsSymbolV2::MapUnit );
1128
+ }
1129
+
1073
1130
void QgsDxfExport::writeSymbolLayerLinestyle ( const QgsSymbolLayerV2* symbolLayer )
1074
1131
{
1075
1132
if ( !symbolLayer )
@@ -1155,6 +1212,56 @@ bool QgsDxfExport::hasDataDefinedProperties( const QgsSymbolLayerV2* sl, const Q
1155
1212
return sl->hasDataDefinedProperties ();
1156
1213
}
1157
1214
1215
+ double QgsDxfExport::dashSize () const
1216
+ {
1217
+ double size = mSymbologyScaleDenominator * 0.002 ;
1218
+ return sizeToMapUnits ( size );
1219
+ }
1220
+
1221
+ double QgsDxfExport::dotSize () const
1222
+ {
1223
+ double size = mSymbologyScaleDenominator * 0.0006 ;
1224
+ return sizeToMapUnits ( size );
1225
+ }
1226
+
1227
+ double QgsDxfExport::dashSeparatorSize () const
1228
+ {
1229
+ double size = mSymbologyScaleDenominator * 0.0006 ;
1230
+ return sizeToMapUnits ( size );
1231
+ }
1232
+
1233
+ double QgsDxfExport::sizeToMapUnits ( double s ) const
1234
+ {
1235
+ double size = s;
1236
+ if ( mMapUnits == QGis::Feet )
1237
+ {
1238
+ size /= 0.3048 ;
1239
+ }
1240
+ else if ( mMapUnits == QGis::Degrees )
1241
+ {
1242
+ size /= 111120 ;
1243
+ }
1244
+ return size;
1245
+ }
1246
+
1247
+ QString QgsDxfExport::lineNameFromPenStyle ( Qt::PenStyle style )
1248
+ {
1249
+ switch ( style )
1250
+ {
1251
+ case Qt::DashLine:
1252
+ return " DASH" ;
1253
+ case Qt::DotLine:
1254
+ return " DOT" ;
1255
+ case Qt::DashDotLine:
1256
+ return " DASHDOT" ;
1257
+ case Qt::DashDotDotLine:
1258
+ return " DASHDOTDOT" ;
1259
+ case Qt::SolidLine:
1260
+ default :
1261
+ return " CONTINUOUS" ;
1262
+ }
1263
+ }
1264
+
1158
1265
/* *****************************************************Test with AC_1018 methods***************************************************************/
1159
1266
1160
1267
void QgsDxfExport::writeHeaderAC1018 ( QTextStream& stream )
0 commit comments