64 int QgsDxfExport::sDxfColors[][3] =
324 const char *QgsDxfExport::DXF_ENCODINGS[][2] =
327 {
"8859_1",
"ISO-8859-1" },
328 {
"8859_2",
"ISO-8859-2" },
329 {
"8859_3",
"ISO-8859-3" },
330 {
"8859_4",
"ISO-8859-4" },
331 {
"8859_5",
"ISO-8859-5" },
332 {
"8859_6",
"ISO-8859-6" },
333 {
"8859_7",
"ISO-8859-7" },
334 {
"8859_8",
"ISO-8859-8" },
335 {
"8859_9",
"ISO-8859-9" },
337 {
"DOS850",
"CP850" },
348 {
"MACINTOSH",
"MacRoman" },
350 {
"KSC5601",
"ksc5601.1987-0" },
352 {
"DOS866",
"CP866" },
353 {
"ANSI_1250",
"CP1250" },
354 {
"ANSI_1251",
"CP1251" },
355 {
"ANSI_1252",
"CP1252" },
356 {
"GB2312",
"GB2312" },
357 {
"ANSI_1253",
"CP1253" },
358 {
"ANSI_1254",
"CP1254" },
359 {
"ANSI_1255",
"CP1255" },
360 {
"ANSI_1256",
"CP1256" },
361 {
"ANSI_1257",
"CP1257" },
362 {
"ANSI_874",
"CP874" },
363 {
"ANSI_932",
"Shift_JIS" },
364 {
"ANSI_936",
"CP936" },
365 {
"ANSI_949",
"CP949" },
366 {
"ANSI_950",
"CP950" },
369 {
"ANSI_1258",
"CP1258" },
379 mMapSettings = dxfExport.mMapSettings;
380 mLayerNameAttribute = dxfExport.mLayerNameAttribute;
381 mSymbologyScale = dxfExport.mSymbologyScale;
382 mSymbologyExport = dxfExport.mSymbologyExport;
383 mMapUnits = dxfExport.mMapUnits;
384 mLayerTitleAsName = dxfExport.mLayerTitleAsName;
385 mSymbolLayerCounter = 0;
389 mFactor = dxfExport.mFactor;
390 mForce2d = dxfExport.mForce2d;
396 mMapSettings = settings;
411 QList<QgsMapLayer *> layerList;
413 mLayerNameAttribute.clear();
415 QList< DxfLayer >::const_iterator layerIt = layers.constBegin();
416 for ( ; layerIt != layers.constEnd(); ++layerIt )
418 layerList << layerIt->layer();
419 if ( layerIt->layerOutputAttributeIndex() >= 0 )
420 mLayerNameAttribute.insert( layerIt->layer()->id(), layerIt->layerOutputAttributeIndex() );
448 if ( !mForce2d && p.
is3D() && std::isfinite( p.
z() ) )
455 int minDist = std::numeric_limits<int>::max();
457 for (
int i = 1; i < static_cast< int >(
sizeof( sDxfColors ) /
sizeof( *sDxfColors ) ) && minDist > 0; ++i )
459 int dist = color_distance( color.rgba(), i );
460 if ( dist >= minDist )
467 if ( minDist == 0 && minDistAt != 7 )
471 if ( color.alpha() == 255 )
475 int c = ( color.red() & 0xff ) * 0x10000 + ( color.green() & 0xff ) * 0x100 + ( color.blue() & 0xff );
477 if ( transparencyCode != -1 && color.alpha() < 255 )
478 writeGroup( transparencyCode, 0x2000000 | color.alpha() );
483 mTextStream << QStringLiteral(
"%1\n" ).arg( code, 3, 10, QChar(
' ' ) );
488 mTextStream << QStringLiteral(
"%1\n" ).arg( i, 6, 10, QChar(
' ' ) );
494 if ( !s.contains(
'.' ) )
495 s += QLatin1String(
".0" );
496 mTextStream << s <<
'\n';
501 mTextStream << s <<
'\n';
511 if ( !d->isOpen() && !d->open( QIODevice::WriteOnly | QIODevice::Truncate ) )
516 mTextStream.setDevice( d );
517 mTextStream.setCodec( encoding.toLocal8Bit() );
524 const QList< QgsMapLayer * > layers = mMapSettings.
layers();
539 mExtent = layerExtent;
570 void QgsDxfExport::writeHeader(
const QString &codepage )
572 writeGroup( 999, QStringLiteral(
"DXF created from QGIS" ) );
578 writeGroup( 9, QStringLiteral(
"$ACADVER" ) );
590 writeGroup( 9, QStringLiteral(
"$LTSCALE" ) );
602 writeGroup( 9, QStringLiteral(
"$PSLTSCALE" ) );
605 writeGroup( 9, QStringLiteral(
"$HANDSEED" ) );
608 writeGroup( 9, QStringLiteral(
"$DWGCODEPAGE" ) );
617 handle = mNextHandleId++;
619 Q_ASSERT_X( handle <
DXF_HANDMAX,
"QgsDxfExport::writeHandle(int, int)",
"DXF handle too large" );
621 writeGroup( code, QStringLiteral(
"%1" ).arg( handle, 0, 16 ) );
625 void QgsDxfExport::writeTables()
632 QList< QPair< QgsSymbolLayer *, QgsSymbol * > > slList;
635 slList = symbolLayers( context );
643 writeGroup( 100, QStringLiteral(
"AcDbSymbolTable" ) );
646 writeDefaultLinetypes();
649 QList< QPair< QgsSymbolLayer *, QgsSymbol *> >::const_iterator slIt = slList.constBegin();
650 for ( ; slIt != slList.constEnd(); ++slIt )
652 writeSymbolLayerLinetype( slIt->first );
659 writeGroup( 2, QStringLiteral(
"BLOCK_RECORD" ) );
662 writeGroup( 100, QStringLiteral(
"AcDbSymbolTable" ) );
665 const QStringList blockStrings = QStringList() << QStringLiteral(
"*Model_Space" ) << QStringLiteral(
"*Paper_Space" ) << QStringLiteral(
"*Paper_Space0" );
666 for (
const QString &block : blockStrings )
668 writeGroup( 0, QStringLiteral(
"BLOCK_RECORD" ) );
670 writeGroup( 100, QStringLiteral(
"AcDbSymbolTableRecord" ) );
671 writeGroup( 100, QStringLiteral(
"AcDbBlockTableRecord" ) );
676 slIt = slList.constBegin();
677 for ( ; slIt != slList.constEnd(); ++slIt )
683 if ( hasDataDefinedProperties( ml, slIt->second ) )
686 QString name = QStringLiteral(
"symbolLayer%1" ).arg( i++ );
687 writeGroup( 0, QStringLiteral(
"BLOCK_RECORD" ) );
689 writeGroup( 100, QStringLiteral(
"AcDbSymbolTableRecord" ) );
690 writeGroup( 100, QStringLiteral(
"AcDbBlockTableRecord" ) );
700 writeGroup( 100, QStringLiteral(
"AcDbSymbolTable" ) );
704 writeGroup( 100, QStringLiteral(
"AcDbSymbolTableRecord" ) );
705 writeGroup( 100, QStringLiteral(
"AcDbRegAppTableRecord" ) );
714 writeGroup( 100, QStringLiteral(
"AcDbSymbolTable" ) );
722 writeGroup( 100, QStringLiteral(
"AcDbSymbolTable" ) );
730 writeGroup( 100, QStringLiteral(
"AcDbSymbolTable" ) );
734 writeGroup( 100, QStringLiteral(
"AcDbSymbolTableRecord" ) );
735 writeGroup( 100, QStringLiteral(
"AcDbViewportTableRecord" ) );
774 writeGroup( 2, QStringLiteral(
"DIMSTYLE" ) );
776 writeGroup( 100, QStringLiteral(
"AcDbSymbolTable" ) );
777 writeGroup( 100, QStringLiteral(
"AcDbDimStyleTable" ) );
781 QSet<QString> layerNames;
782 const QList< QgsMapLayer * > layers = mMapSettings.
layers();
785 if ( !layerIsScaleBasedVisible( ml ) )
792 int attrIdx = mLayerNameAttribute.value( vl->
id(), -1 );
799 const QSet<QVariant> values = vl->
uniqueValues( attrIdx );
800 for (
const QVariant &v : values )
812 writeGroup( 100, QStringLiteral(
"AcDbSymbolTable" ) );
817 writeGroup( 100, QStringLiteral(
"AcDbSymbolTableRecord" ) );
818 writeGroup( 100, QStringLiteral(
"AcDbLayerTableRecord" ) );
822 writeGroup( 6, QStringLiteral(
"CONTINUOUS" ) );
825 for (
const QString &
layerName : qgis::as_const( layerNames ) )
829 writeGroup( 100, QStringLiteral(
"AcDbSymbolTableRecord" ) );
830 writeGroup( 100, QStringLiteral(
"AcDbLayerTableRecord" ) );
834 writeGroup( 6, QStringLiteral(
"CONTINUOUS" ) );
843 writeGroup( 100, QStringLiteral(
"AcDbSymbolTable" ) );
849 writeGroup( 100, QStringLiteral(
"AcDbSymbolTableRecord" ) );
850 writeGroup( 100, QStringLiteral(
"AcDbTextStyleTableRecord" ) );
851 writeGroup( 2, QStringLiteral(
"STANDARD" ) );
858 writeGroup( 3, QStringLiteral(
"romans.shx" ) );
866 void QgsDxfExport::writeBlocks()
871 const QStringList blockStrings = QStringList() << QStringLiteral(
"*Model_Space" ) << QStringLiteral(
"*Paper_Space" ) << QStringLiteral(
"*Paper_Space0" );
872 for (
const QString &block : blockStrings )
876 writeGroup( 330, QStringLiteral(
"%1" ).arg( mBlockHandles[ block ], 0, 16 ) );
877 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
879 writeGroup( 100, QStringLiteral(
"AcDbBlockBegin" ) );
887 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
889 writeGroup( 100, QStringLiteral(
"AcDbBlockEnd" ) );
895 QList< QPair< QgsSymbolLayer *, QgsSymbol * > > slList;
898 slList = symbolLayers( ct );
901 QList< QPair< QgsSymbolLayer *, QgsSymbol * > >::const_iterator slIt = slList.constBegin();
902 for ( ; slIt != slList.constEnd(); ++slIt )
913 if ( hasDataDefinedProperties( ml, slIt->second ) )
919 QString block( QStringLiteral(
"symbolLayer%1" ).arg( mBlockCounter++ ) );
920 mBlockHandle = QStringLiteral(
"%1" ).arg( mBlockHandles[ block ], 0, 16 );
925 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
927 writeGroup( 100, QStringLiteral(
"AcDbBlockBegin" ) );
940 ml->
writeDxf( *
this,
mapUnitScaleFactor( mSymbologyScale, ml->
sizeUnit(), mMapUnits, ctx.renderContext().mapToPixel().mapUnitsPerPixel() ), QStringLiteral(
"0" ), ctx );
944 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
946 writeGroup( 100, QStringLiteral(
"AcDbBlockEnd" ) );
948 mPointSymbolBlocks.insert( ml, block );
955 void QgsDxfExport::writeEntities()
958 writeGroup( 2, QStringLiteral(
"ENTITIES" ) );
960 mBlockHandle = QStringLiteral(
"%1" ).arg( mBlockHandles[ QStringLiteral(
"*Model_Space" )], 0, 16 );
962 QImage image( 10, 10, QImage::Format_ARGB32_Premultiplied );
963 image.setDotsPerMeterX( 96 / 25.4 * 1000 );
964 image.setDotsPerMeterY( 96 / 25.4 * 1000 );
965 QPainter painter( &image );
974 mExtent.
height() * mFactor, 0 ) );
984 const QList< QgsMapLayer *> layers = mMapSettings.
layers();
988 if ( !vl || !layerIsScaleBasedVisible( vl ) )
996 QgsDebugMsg( QStringLiteral(
"%1: apply override style" ).arg( vl->
id() ) );
1001 QgsDebugMsg( QStringLiteral(
"%1: no override style" ).arg( vl->
id() ) );
1018 std::unique_ptr< QgsFeatureRenderer > renderer( vl->
renderer()->
clone() );
1019 renderer->startRender( ctx, vl->
fields() );
1021 QSet<QString> attributes = renderer->usedAttributes( ctx );
1022 int attrIdx = mLayerNameAttribute.value( vl->
id(), -1 );
1026 attributes << layerAttr;
1032 if (
const QgsRuleBasedLabeling *rbl = dynamic_cast<const QgsRuleBasedLabeling *>( labeling ) )
1038 if ( !rblp->
prepare( ctx, attributes ) )
1044 else if ( labeling )
1050 if ( !lp->
prepare( ctx, attributes ) )
1059 renderer->usingSymbolLevels() )
1061 writeEntitiesSymbolLevels( vl );
1062 renderer->stopRender( ctx );
1082 if ( !renderer->willRenderFeature( fet, ctx ) )
1087 addFeature( sctx, ct, lName,
nullptr,
nullptr );
1091 QgsSymbolList symbolList = renderer->symbolsForFeature( fet, ctx );
1092 bool hasSymbology = symbolList.size() > 0;
1096 QgsSymbolList::iterator symbolIt = symbolList.begin();
1097 for ( ; symbolIt != symbolList.end(); ++symbolIt )
1099 int nSymbolLayers = ( *symbolIt )->symbolLayerCount();
1100 for (
int i = 0; i < nSymbolLayers; ++i )
1108 bool isGeometryGenerator = ( sl->
layerType() == QLatin1String(
"GeometryGenerator" ) );
1109 if ( isGeometryGenerator )
1111 addGeometryGeneratorSymbolLayer( sctx, ct, lName, sl,
true );
1115 addFeature( sctx, ct, lName, sl, *symbolIt );
1120 else if ( hasSymbology )
1131 addGeometryGeneratorSymbolLayer( sctx, ct, lName, s->
symbolLayer( 0 ), false );
1135 addFeature( sctx, ct, lName, s->
symbolLayer( 0 ), s );
1150 renderer->stopRender( ctx );
1158 void QgsDxfExport::writeEntitiesSymbolLevels(
QgsVectorLayer *layer )
1170 std::unique_ptr< QgsFeatureRenderer > renderer( layer->
renderer()->
clone() );
1171 QHash< QgsSymbol *, QList<QgsFeature> > features;
1176 renderer->startRender( ctx, layer->
fields() );
1195 featureSymbol = renderer->symbolForFeature( fet, ctx );
1196 if ( !featureSymbol )
1201 QHash< QgsSymbol *, QList<QgsFeature> >::iterator it = features.find( featureSymbol );
1202 if ( it == features.end() )
1204 it = features.insert( featureSymbol, QList<QgsFeature>() );
1206 it.value().append( fet );
1212 for (
int i = 0; i < symbols.count(); i++ )
1218 if ( level < 0 || level >= 1000 )
1221 while ( level >= levels.count() )
1223 levels[level].append( item );
1230 for (
int l = 0; l < levels.count(); l++ )
1233 for (
int i = 0; i < level.count(); i++ )
1236 QHash< QgsSymbol *, QList<QgsFeature> >::iterator levelIt = features.find( item.
symbol() );
1237 if ( levelIt == features.end() )
1239 QgsDebugMsg( QStringLiteral(
"No feature found for symbol on %1 %2.%3" ).arg( layer->
id() ).arg( l ).arg( i ) );
1243 int llayer = item.
layer();
1244 QList<QgsFeature> &featureList = levelIt.value();
1245 QList<QgsFeature>::iterator featureIt = featureList.begin();
1246 for ( ; featureIt != featureList.end(); ++featureIt )
1249 addFeature( sctx, ct, layer->
name(), levelIt.key()->symbolLayer( llayer ), levelIt.key() );
1253 renderer->stopRender( ctx );
1256 void QgsDxfExport::writeEndFile()
1283 ACAD_MLEADERSTYLE\n\ 1291 ACAD_PLOTSETTINGS\n\ 1295 ACAD_PLOTSTYLENAME\n\ 1403 ACDBDICTIONARYWDFLT\n\ 1423 AcDbDictionaryWithDefault\n\ 1619 1.000000000000000E+20\n\ 1621 1.000000000000000E+20\n\ 1623 1.000000000000000E+20\n\ 1625 -1.000000000000000E+20\n\ 1627 -1.000000000000000E+20\n\ 1629 -1.000000000000000E+20\n\ 1891 163.1318914119703\n\ 2059 AcDbSavedByObjectVersion\n\ 2149 AcDbSavedByObjectVersion\n\ 2239 AcDbSavedByObjectVersion\n\ 2329 AcDbSavedByObjectVersion\n\ 2419 AcDbSavedByObjectVersion\n\ 2511 AcDbSavedByObjectVersion\n\ 2601 AcDbSavedByObjectVersion\n\ 2691 AcDbSavedByObjectVersion\n\ 2781 AcDbSavedByObjectVersion\n\ 2871 AcDbSavedByObjectVersion\n\ 2961 AcDbSavedByObjectVersion\n\ 3051 AcDbSavedByObjectVersion\n\ 3141 AcDbSavedByObjectVersion\n\ 3231 AcDbSavedByObjectVersion\n\ 3323 AcDbSavedByObjectVersion\n\ 3413 AcDbSavedByObjectVersion\n\ 3423 void QgsDxfExport::startSection()
3425 writeGroup( 0, QStringLiteral(
"SECTION" ) );
3428 void QgsDxfExport::endSection()
3441 msl->
sizeUnit(), mMapUnits ) / 2.0;
3453 QHash< const QgsSymbolLayer *, QString >::const_iterator blockIt = mPointSymbolBlocks.constFind( symbolLayer );
3454 if ( !symbolLayer || blockIt == mPointSymbolBlocks.constEnd() )
3458 if ( msl && symbol )
3472 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3473 writeGroup( 100, QStringLiteral(
"AcDbBlockReference" ) );
3483 int n = line.size();
3486 QgsDebugMsg( QStringLiteral(
"writePolyline: empty line layer=%1 lineStyleName=%2" ).arg( layer, lineStyleName ) );
3492 QgsDebugMsg( QStringLiteral(
"writePolyline: line too short layer=%1 lineStyleName=%2" ).arg( layer, lineStyleName ) );
3496 if ( mForce2d || !line.at( 0 ).is3D() )
3498 bool polygon = line[0] == line[ line.size() - 1 ];
3502 writeGroup( 0, QStringLiteral(
"LWPOLYLINE" ) );
3505 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3506 writeGroup( 100, QStringLiteral(
"AcDbPolyline" ) );
3514 for (
int i = 0; i < n; i++ )
3519 writeGroup( 0, QStringLiteral(
"POLYLINE" ) );
3522 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3526 writeGroup( 100, QStringLiteral(
"AcDb3dPolyline" ) );
3530 for (
int i = 0; i < n; i++ )
3535 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3538 writeGroup( 100, QStringLiteral(
"AcDbVertex" ) );
3539 writeGroup( 100, QStringLiteral(
"AcDb3dPolylineVertex" ) );
3547 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3553 void QgsDxfExport::appendCurve(
const QgsCurve &
c, QVector<QgsPoint> &points, QVector<double> &bulges )
3558 appendLineString( *dynamic_cast<const QgsLineString *>( &c ), points, bulges );
3562 appendCircularString( *dynamic_cast<const QgsCircularString *>( &c ), points, bulges );
3566 appendCompoundCurve( *dynamic_cast<const QgsCompoundCurve *>( &c ), points, bulges );
3575 void QgsDxfExport::appendLineString(
const QgsLineString &ls, QVector<QgsPoint> &points, QVector<double> &bulges )
3577 for (
int i = 0; i < ls.
numPoints(); i++ )
3580 if ( !points.isEmpty() && points.last() == p )
3588 void QgsDxfExport::appendCircularString(
const QgsCircularString &cs, QVector<QgsPoint> &points, QVector<double> &bulges )
3590 for (
int i = 0; i < cs.
numPoints() - 2; i += 2 )
3596 if ( points.isEmpty() || points.last() != p1 )
3598 else if ( !bulges.isEmpty() )
3599 bulges.removeLast();
3601 double a = ( M_PI - ( p1 - p2 ).
angle() + ( p3 - p2 ).
angle() ) / 2.0;
3602 bulges << sin( a ) / cos( a );
3609 void QgsDxfExport::appendCompoundCurve(
const QgsCompoundCurve &cc, QVector<QgsPoint> &points, QVector<double> &bulges )
3611 for (
int i = 0; i < cc.
nCurves(); i++ )
3615 appendCurve( *c, points, bulges );
3624 QgsDebugMsg( QStringLiteral(
"writePolyline: empty line layer=%1 lineStyleName=%2" ).arg( layer, lineStyleName ) );
3630 QgsDebugMsg( QStringLiteral(
"writePolyline: line too short layer=%1 lineStyleName=%2" ).arg( layer, lineStyleName ) );
3634 QVector<QgsPoint> points;
3635 QVector<double> bulges;
3636 appendCurve( curve, points, bulges );
3638 if ( mForce2d || !curve.
is3D() )
3640 writeGroup( 0, QStringLiteral(
"LWPOLYLINE" ) );
3643 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3644 writeGroup( 100, QStringLiteral(
"AcDbPolyline" ) );
3652 for (
int i = 0; i < points.size(); i++ )
3655 if ( bulges[i] != 0.0 )
3661 writeGroup( 0, QStringLiteral(
"POLYLINE" ) );
3664 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3668 writeGroup( 100, QStringLiteral(
"AcDb3dPolyline" ) );
3672 for (
int i = 0; i < points.size(); i++ )
3677 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3680 writeGroup( 100, QStringLiteral(
"AcDbVertex" ) );
3681 writeGroup( 100, QStringLiteral(
"AcDb3dPolylineVertex" ) );
3683 if ( bulges[i] != 0.0 )
3691 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3702 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3705 writeGroup( 100, QStringLiteral(
"AcDbHatch" ) );
3711 writeGroup( 70, hatchPattern == QLatin1String(
"SOLID" ) );
3715 for (
int i = 0; i < polygon.size(); ++i )
3722 for (
int j = 0; j < polygon[i].size(); ++j )
3741 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3744 writeGroup( 100, QStringLiteral(
"AcDbHatch" ) );
3750 writeGroup( 70, hatchPattern == QLatin1String(
"SOLID" ) );
3753 QVector<QVector<QgsPoint>> points;
3754 QVector<QVector<double>> bulges;
3756 points << QVector<QgsPoint>();
3757 bulges << QVector<double>();
3758 appendCurve( *polygon.
exteriorRing(), points.last(), bulges.last() );
3762 points << QVector<QgsPoint>();
3763 bulges << QVector<double>();
3764 appendCurve( *polygon.
interiorRing( i ), points.last(), bulges.last() );
3767 bool hasBulges =
false;
3768 for (
int i = 0; i < points.size() && !hasBulges; ++i )
3769 for (
int j = 0; j < points[i].size() && !hasBulges; ++j )
3770 hasBulges = bulges[i][j] != 0.0;
3774 for (
int i = 0; i < points.size(); ++i )
3781 for (
int j = 0; j < points[i].size(); ++j )
3806 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3807 writeGroup( 100, QStringLiteral(
"AcDbPoint" ) );
3818 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3821 writeGroup( 100, QStringLiteral(
"AcDbHatch" ) );
3852 writeGroup( 0, QStringLiteral(
"LWPOLYLINE" ) );
3856 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3857 writeGroup( 100, QStringLiteral(
"AcDbPolyline" ) );
3876 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3877 writeGroup( 100, QStringLiteral(
"AcDbText" ) );
3884 writeGroup( 7, QStringLiteral(
"STANDARD" ) );
3885 writeGroup( 100, QStringLiteral(
"AcDbText" ) );
3890 if ( !mTextStream.codec()->canEncode( text ) )
3893 QgsDebugMsg( QStringLiteral(
"could not encode:%1" ).arg( text ) );
3899 writeGroup( 100, QStringLiteral(
"AcDbEntity" ) );
3900 writeGroup( 100, QStringLiteral(
"AcDbMText" ) );
3907 while ( t.length() > 250 )
3923 writeGroup( 7, QStringLiteral(
"STANDARD" ) );
3945 if ( mSymbologyExport !=
NoSymbology && symbolLayer )
3947 penColor = colorFromSymbolLayer( symbolLayer, ctx );
3951 Qt::PenStyle penStyle( Qt::SolidLine );
3952 Qt::BrushStyle brushStyle( Qt::NoBrush );
3954 double offset = 0.0;
3956 if ( mSymbologyExport !=
NoSymbology && symbolLayer )
3958 width = symbolLayer->
dxfWidth( *
this, ctx );
3959 offset = symbolLayer->
dxfOffset( *
this, ctx );
3960 angle = symbolLayer->
dxfAngle( ctx );
3968 QString lineStyleName = QStringLiteral(
"CONTINUOUS" );
3971 lineStyleName = lineStyleFromSymbolLayer( symbolLayer );
3977 writePoint( geom.constGet()->coordinateSequence().at( 0 ).at( 0 ).at( 0 ), layer, penColor, ctx, symbolLayer, symbol,
angle );
3984 for (
int i = 0; i < cs.size(); i++ )
3986 writePoint( cs.at( i ).at( 0 ).at( 0 ), layer, penColor, ctx, symbolLayer, symbol,
angle );
3991 if ( penStyle != Qt::NoPen )
3994 std::unique_ptr< QgsAbstractGeometry > tempGeom;
4005 tempGeom.reset( geos.
offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 ) );
4007 sourceGeom = tempGeom.get();
4009 sourceGeom = geom.constGet();
4014 writePolyline( *curve, layer, lineStyleName, penColor, width );
4025 tempGeom.reset( geos.
offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 ) );
4027 sourceGeom = tempGeom.get();
4029 sourceGeom = geom.constGet();
4039 writePolyline( *curve, layer, lineStyleName, penColor, width );
4051 tempGeom.reset( geos.
buffer( offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 ) );
4053 sourceGeom = tempGeom.get();
4055 sourceGeom = geom.constGet();
4059 Q_ASSERT( polygon );
4074 tempGeom.reset( geos.
buffer( offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 ) );
4076 sourceGeom = tempGeom.get();
4078 sourceGeom = geom.constGet();
4087 Q_ASSERT( polygon );
4103 if ( brushStyle != Qt::NoBrush )
4106 std::unique_ptr< QgsAbstractGeometry > tempGeom;
4114 Q_ASSERT( polygon );
4115 writePolygon( *polygon, layer, QStringLiteral(
"SOLID" ), brushColor );
4128 Q_ASSERT( polygon );
4129 writePolygon( *polygon, layer, QStringLiteral(
"SOLID" ), brushColor );
4146 return symbolLayer->
dxfColor( ctx );
4149 QString QgsDxfExport::lineStyleFromSymbolLayer(
const QgsSymbolLayer *symbolLayer )
4151 QString lineStyleName = QStringLiteral(
"CONTINUOUS" );
4154 return lineStyleName;
4157 QHash< const QgsSymbolLayer *, QString >::const_iterator lineTypeIt = mLineStyles.constFind( symbolLayer );
4158 if ( lineTypeIt != mLineStyles.constEnd() )
4160 lineStyleName = lineTypeIt.value();
4161 return lineStyleName;
4165 return lineNameFromPenStyle( symbolLayer->
dxfPenStyle() );
4172 int current_distance = std::numeric_limits<int>::max();
4173 for (
int i = 1; i < static_cast< int >(
sizeof( sDxfColors ) /
sizeof( *sDxfColors ) ); ++i )
4175 int dist = color_distance( pixel, i );
4176 if ( dist < current_distance )
4178 current_distance = dist;
4187 int QgsDxfExport::color_distance( QRgb p1,
int index )
4189 if ( index > 255 || index < 0 )
4194 double redDiff = qRed( p1 ) - sDxfColors[index][0];
4195 double greenDiff = qGreen( p1 ) - sDxfColors[index][1];
4196 double blueDiff = qBlue( p1 ) - sDxfColors[index][2];
4198 QgsDebugMsg( QStringLiteral(
"color_distance( r:%1 g:%2 b:%3 <=> i:%4 r:%5 g:%6 b:%7 ) => %8" )
4199 .arg( qRed( p1 ) ).arg( qGreen( p1 ) ).arg( qBlue( p1 ) )
4201 .arg( mDxfColors[index][0] )
4202 .arg( mDxfColors[index][1] )
4203 .arg( mDxfColors[index][2] )
4204 .arg( redDiff * redDiff + greenDiff * greenDiff + blueDiff * blueDiff ) );
4206 return redDiff * redDiff + greenDiff * greenDiff + blueDiff * blueDiff;
4209 QRgb QgsDxfExport::createRgbEntry( qreal r, qreal g, qreal b )
4211 return QColor::fromRgbF( r, g, b ).rgb();
4233 return mapUnitsPerPixel;
4247 double minSizeMU = std::numeric_limits<double>::lowest();
4250 minSizeMU = scale.
minSizeMM * pixelToMMFactor * mapUnitsPerPixel;
4254 minSizeMU = std::max( minSizeMU, value );
4256 value = std::max( value, minSizeMU );
4258 double maxSizeMU = std::numeric_limits<double>::max();
4261 maxSizeMU = scale.
maxSizeMM * pixelToMMFactor * mapUnitsPerPixel;
4265 maxSizeMU = std::min( maxSizeMU, value );
4267 value = std::min( value, maxSizeMU );
4270 QList< QPair< QgsSymbolLayer *, QgsSymbol * > > QgsDxfExport::symbolLayers(
QgsRenderContext &context )
4272 QList< QPair< QgsSymbolLayer *, QgsSymbol * > > symbolLayers;
4274 const QList< QgsMapLayer * > layers = mMapSettings.
layers();
4292 QgsSymbolList::iterator symbolIt = symbols.begin();
4293 for ( ; symbolIt != symbols.end(); ++symbolIt )
4295 int maxSymbolLayers = ( *symbolIt )->symbolLayerCount();
4298 maxSymbolLayers = 1;
4300 for (
int i = 0; i < maxSymbolLayers; ++i )
4302 symbolLayers.append( qMakePair( ( *symbolIt )->symbolLayer( i ), *symbolIt ) );
4307 return symbolLayers;
4310 void QgsDxfExport::writeDefaultLinetypes()
4313 const QStringList blockStrings = QStringList() << QStringLiteral(
"ByLayer" ) << QStringLiteral(
"ByBlock" ) << QStringLiteral(
"CONTINUOUS" );
4314 for (
const QString <ype : blockStrings )
4318 writeGroup( 100, QStringLiteral(
"AcDbSymbolTableRecord" ) );
4319 writeGroup( 100, QStringLiteral(
"AcDbLinetypeTableRecord" ) );
4322 writeGroup( 3, QStringLiteral(
"Defaultstyle" ) );
4328 double das = dashSize();
4329 double dss = dashSeparatorSize();
4330 double dos = dotSize();
4332 QVector<qreal> dashVector( 2 );
4333 dashVector[0] = das;
4334 dashVector[1] = dss;
4337 QVector<qreal> dotVector( 2 );
4342 QVector<qreal> dashDotVector( 4 );
4343 dashDotVector[0] = das;
4344 dashDotVector[1] = dss;
4345 dashDotVector[2] = dos;
4346 dashDotVector[3] = dss;
4349 QVector<qreal> dashDotDotVector( 6 );
4350 dashDotDotVector[0] = das;
4351 dashDotDotVector[1] = dss;
4352 dashDotDotVector[2] = dos;
4353 dashDotDotVector[3] = dss;
4354 dashDotDotVector[4] = dos;
4355 dashDotDotVector[5] = dss;
4359 void QgsDxfExport::writeSymbolLayerLinetype(
const QgsSymbolLayer *symbolLayer )
4368 if ( !customLinestyle.isEmpty() )
4370 QString name = QStringLiteral(
"symbolLayer%1" ).arg( mSymbolLayerCounter++ );
4371 writeLinetype( name, customLinestyle, unit );
4372 mLineStyles.insert( symbolLayer, name );
4376 int QgsDxfExport::nLineTypes(
const QList< QPair< QgsSymbolLayer *, QgsSymbol * > > &symbolLayers )
4379 QList< QPair< QgsSymbolLayer *, QgsSymbol *> >::const_iterator slIt = symbolLayers.constBegin();
4380 for ( ; slIt != symbolLayers.constEnd(); ++slIt )
4394 void QgsDxfExport::writeLinetype(
const QString &styleName,
const QVector<qreal> &pattern,
QgsUnitTypes::RenderUnit u )
4397 QVector<qreal>::const_iterator dashIt = pattern.constBegin();
4398 for ( ; dashIt != pattern.constEnd(); ++dashIt )
4406 writeGroup( 100, QStringLiteral(
"AcDbSymbolTableRecord" ) );
4407 writeGroup( 100, QStringLiteral(
"AcDbLinetypeTableRecord" ) );
4415 dashIt = pattern.constBegin();
4417 for ( ; dashIt != pattern.constEnd(); ++dashIt )
4420 double segmentLength = ( isGap ? -*dashIt : *dashIt );
4446 geomExpr.
prepare( &expressionContext );
4454 symbolExpressionContextScope->
setFeature( f );
4459 for (
int i = 0; i < nSymbolLayers; ++i )
4461 addFeature( ctx, ct, layer, symbol->
symbolLayer( i ), symbol );
4470 if ( !sl || !symbol )
4483 double QgsDxfExport::dashSize()
const 4485 double size = mSymbologyScale * 0.002;
4486 return sizeToMapUnits( size );
4489 double QgsDxfExport::dotSize()
const 4491 double size = mSymbologyScale * 0.0006;
4492 return sizeToMapUnits( size );
4495 double QgsDxfExport::dashSeparatorSize()
const 4497 double size = mSymbologyScale * 0.0006;
4498 return sizeToMapUnits( size );
4501 double QgsDxfExport::sizeToMapUnits(
double s )
const 4507 QString QgsDxfExport::lineNameFromPenStyle( Qt::PenStyle style )
4512 return QStringLiteral(
"DASH" );
4514 return QStringLiteral(
"DOT" );
4515 case Qt::DashDotLine:
4516 return QStringLiteral(
"DASHDOT" );
4517 case Qt::DashDotDotLine:
4518 return QStringLiteral(
"DASHDOTDOT" );
4521 return QStringLiteral(
"CONTINUOUS" );
4527 if ( name.isEmpty() )
4528 return QStringLiteral(
"0" );
4536 layerName.replace(
'<',
'_' );
4537 layerName.replace(
'>',
'_' );
4538 layerName.replace(
'/',
'_' );
4539 layerName.replace(
'\\',
'_' );
4540 layerName.replace(
'\"',
'_' );
4541 layerName.replace(
':',
'_' );
4542 layerName.replace(
';',
'_' );
4543 layerName.replace(
'?',
'_' );
4544 layerName.replace(
'*',
'_' );
4545 layerName.replace(
'|',
'_' );
4546 layerName.replace(
'=',
'_' );
4547 layerName.replace(
'\'',
'_' );
4550 layerName.replace( QLatin1String(
"\r\n" ), QLatin1String(
"_" ) );
4551 layerName.replace(
'\r',
'_' );
4552 layerName.replace(
'\n',
'_' );
4554 return layerName.trimmed();
4557 bool QgsDxfExport::layerIsScaleBasedVisible(
const QgsMapLayer *layer )
const 4570 const QList< QgsMapLayer * > layers = mMapSettings.
layers();
4574 if ( vl && vl->
id() == id )
4576 int attrIdx = mLayerNameAttribute.value( vl->
id(), -1 );
4581 return QStringLiteral(
"0" );
4586 const QList< QByteArray > codecs = QTextCodec::availableCodecs();
4587 for (
const QByteArray &codec : codecs )
4589 if ( name != codec )
4593 for ( i = 0; i < static_cast< int >(
sizeof( DXF_ENCODINGS ) /
sizeof( *DXF_ENCODINGS ) ) && name != DXF_ENCODINGS[i][1]; ++i )
4596 if ( i == static_cast< int >(
sizeof( DXF_ENCODINGS ) /
sizeof( *DXF_ENCODINGS ) ) )
4599 return DXF_ENCODINGS[i][0];
4608 const QList< QByteArray > codecs = QTextCodec::availableCodecs();
4609 for (
const QByteArray &codec : codecs )
4612 for ( i = 0; i < static_cast< int >(
sizeof( DXF_ENCODINGS ) /
sizeof( *DXF_ENCODINGS ) ) && strcmp( codec.data(), DXF_ENCODINGS[i][1] ) != 0; ++i )
4615 if ( i < static_cast< int >(
sizeof( DXF_ENCODINGS ) /
sizeof( *DXF_ENCODINGS ) ) )
4616 encodings << codec.data();
4624 return mLayerTitleAsName && !vl->
title().isEmpty() ? vl->
title() : vl->
name();
4642 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues = lf->
dataDefinedValues();
4647 QgsDebugMsgLevel( QStringLiteral(
"PAL font definedFont: %1, Style: %2" ).arg( dFont.toString(), dFont.styleName() ), 4 );
4677 QgsPalLabeling::dataDefinedTextStyle( tmpLyr, ddValues );
4680 QgsPalLabeling::dataDefinedTextBuffer( tmpLyr, ddValues );
4683 QgsPalLabeling::dataDefinedTextFormatting( tmpLyr, ddValues );
4689 QString dxfLayer = mDxfLayerNames[layerId][fid];
4691 QString wrapchr = tmpLyr.
wrapChar.isEmpty() ? QStringLiteral(
"\n" ) : tmpLyr.
wrapChar;
4696 bool prependSymb =
false;
4714 prependSymb =
false;
4722 symb = symb + wrapchr;
4726 prependSymb =
false;
4727 symb = wrapchr + symb;
4732 txt.prepend( symb );
4746 txt = txt.replace( wrapchr, QLatin1String(
"\\P" ) );
4747 txt.replace(
" ",
"\\~" );
4751 txt.prepend(
"\\L" ).append(
"\\l" );
4756 txt.prepend(
"\\O" ).append(
"\\o" );
4761 txt.prepend(
"\\K" ).append(
"\\k" );
4764 txt.prepend( QStringLiteral(
"\\f%1|i%2|b%3;\\H%4;" )
4766 .arg( tmpLyr.
format().
font().italic() ? 1 : 0 )
4767 .arg( tmpLyr.
format().
font().bold() ? 1 : 0 )
4768 .arg( label->
getHeight() / ( 1 + txt.count( QStringLiteral(
"\\P" ) ) ) * 0.75 ) );
4776 if ( !mDxfLayerNames.contains( layerId ) )
4777 mDxfLayerNames[ layerId ] = QMap<QgsFeatureId, QString>();
4779 mDxfLayerNames[layerId][fid] =
layerName;
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
QgsSymbol * subSymbol() override
Returns the symbol's sub symbol, if present.
Class for parsing and evaluation of expressions (formerly called "search strings").
QgsDxfExport()=default
Constructor for QgsDxfExport.
virtual QVector< qreal > dxfCustomDashPattern(QgsUnitTypes::RenderUnit &unit) const
Gets dash pattern.
Wrapper for iterator of features from vector data provider or vector layer.
QString labelText() const
Text of the label.
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
sets destination coordinate reference system
A rectangle specified with double values.
Base class for all map layer types.
void setExtent(const QgsRectangle &rect, bool magnified=true)
Set coordinates of the rectangle which should be rendered.
double minSizeMM
The minimum size in millimeters, or 0.0 if unset.
QString leftDirectionSymbol
String to use for left direction arrows.
void writeLine(const QgsPoint &pt1, const QgsPoint &pt2, const QString &layer, const QString &lineStyleName, const QColor &color, double width=-1)
Write line (as a polyline)
void clipValueToMapUnitScale(double &value, const QgsMapUnitScale &scale, double pixelToMMFactor) const
Clips value to scale minimum/maximum.
void addProvider(QgsAbstractLabelProvider *provider)
Add provider of label features. Takes ownership of the provider.
int numPoints() const override
Returns the number of points in the curve.
QgsFeatureId featureId() const
Returns the unique ID of the feature.
void removeProvider(QgsAbstractLabelProvider *provider)
Remove provider if the provider's initialization failed. Provider instance is deleted.
Abstract base class for all rendered symbols.
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
QgsLabelFeature * feature()
Returns the parent feature.
virtual double dxfOffset(const QgsDxfExport &e, QgsSymbolRenderContext &context) const
Gets offset.
Restore overridden layer style on destruction.
void writeGroup(int code, int i)
Write a tuple of group code and integer value.
void writePolyline(const QgsPointSequence &line, const QString &layer, const QString &lineStyleName, const QColor &color, double width=-1)
Draw dxf primitives (LWPOLYLINE)
QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
Place direction symbols on below label.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
bool exists(int i) const
Returns if a field index is valid.
QVector< QgsRingSequence > QgsCoordinateSequence
QString geometryExpression() const
Gets the expression to generate this geometry.
Export text as TEXT elements. If not set, text will be exported as MTEXT elements.
double getY(int i=0) const
Returns the down-left y coordinate.
void startRender(QgsSymbolRenderContext &context) override
A simple line symbol layer, which renders lines using a line in a variety of styles (e...
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Implements a derived label provider for rule based labels internally used for DXF export...
const QgsCurve * interiorRing(int i) const
Retrieves an interior ring from the curve polygon.
void setRendererScale(double scale)
Sets the renderer map scale.
void setFont(const QFont &font)
Sets the font used for rendering text.
const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > & dataDefinedValues() const
Gets data-defined values.
QgsAbstractGeometry * buffer(double distance, int segments, QString *errorMsg=nullptr) const override
void setOutputDpi(double dpi)
Sets DPI used for conversion between real world units (e.g. mm) and pixels.
void registerDxfLayer(const QString &layerId, QgsFeatureId fid, const QString &layer)
Register name of layer for feature.
static int closestColorMatch(QRgb color)
Gets DXF palette index of nearest entry for given color.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QColor color() const
Returns the color that text will be rendered in.
Class that adds extra information to QgsLabelFeature for text labels.
Curve polygon geometry type.
static QStringList encodings()
Returns list of available DXF encodings.
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
bool addDirectionSymbol
If true, '<' or '>' (or custom strings set via leftDirectionSymbol and rightDirectionSymbol) will be ...
void setMapSettings(const QgsMapSettings &mapSettings)
Associate map settings instance.
void registerDxfFeature(QgsFeature &feature, QgsRenderContext &context, const QString &dxfLayerName)
Registration method that keeps track of DXF layer names of individual features.
QgsDxfExport::Flags flags() const
Returns the export flags.
A geometry is the spatial representation of a feature.
bool drawLabels
Whether to draw labels for this layer.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
QgsUnitTypes::DistanceUnit mapUnits
MultiLineAlign multilineAlign
Horizontal alignment of multi-line labels.
QgsUnitTypes::DistanceUnit mapUnits() const
Retrieve map units.
virtual double dxfWidth(const QgsDxfExport &e, QgsSymbolRenderContext &context) const
Gets line width.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
FeaturePart * getFeaturePart()
Returns the feature corresponding to this labelposition.
QList< QgsMapLayer * > layers() const
Gets list of layers for map rendering The layers are stored in the reverse order of how they are rend...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
const QgsCoordinateReferenceSystem & crs
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setExtent(const QgsRectangle &extent)
When rendering a map layer, calling this method sets the "clipping" extent for the layer (in the laye...
Rotation of symbol may be changed during rendering and symbol should not be cached.
QgsPoint pointN(int i) const
Returns the point at index i within the circular string.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
bool reverseDirectionSymbol
True if direction symbols should be reversed.
double maxScale
The maximum scale, or 0.0 if unset.
void setFlags(QgsDxfExport::Flags flags)
Sets the export flags.
void writeInt(int i)
Write an integer value.
bool minSizeMMEnabled
Whether the minimum size in mm should be respected.
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
void writePolygon(const QgsRingSequence &polygon, const QString &layer, const QString &hatchPattern, const QColor &color)
Draw dxf filled polygon (HATCH)
int numPoints() const override
Returns the number of points in the curve.
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
QList< QgsSymbolLevel > QgsSymbolLevelOrder
The QgsMapSettings class contains configuration for rendering of the map.
virtual bool hasDataDefinedProperties() const
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties...
void setMapSettings(const QgsMapSettings &settings)
Set map settings and assign layer name attributes.
void writeString(const QString &s)
Write a string value.
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Returns the coordinate transform from layer's CRS to destination CRS.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
void reinit(QgsVectorLayer *layer)
Reinitialize the subproviders with QgsDxfLabelProviders.
int writeToFile(QIODevice *d, const QString &codec)
Export to a dxf file in the given encoding.
QString wktTypeStr() const
Returns the WKT type string of the geometry.
Perform transforms between map coordinates and device coordinates.
int numInteriorRings() const
Returns the number of interior rings contained with the curve polygon.
void writePoint(const QString &layer, const QColor &color, const QgsPoint &pt)
Write point.
int renderingPass() const
Specifies the rendering pass in which this symbol layer should be rendered.
Type
The WKB type describes the number of dimensions a geometry has.
QList< QgsSymbol * > QgsSymbolList
void setOutputSize(QSize size)
Sets the size of the resulting map image.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
bool prepare(const QgsRenderContext &context, QSet< QString > &attributeNames) override
Prepare for registration of features.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
virtual bool prepare(const QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
Set destination CRS.
virtual QgsPalLayerSettings settings(const QString &providerId=QString()) const =0
Gets associated label settings.
#define QgsDebugMsgLevel(str, level)
bool isEmpty() const
Returns true if the rectangle is empty.
double size() const
Returns the symbol size.
void writeGroupCode(int code)
Write a group code.
double width() const
Returns the width of the rectangle.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void registerDxfFeature(const QgsFeature &feature, QgsRenderContext &context, const QString &dxfLayerName)
Registration method that keeps track of DXF layer names of individual features.
virtual Qt::BrushStyle dxfBrushStyle() const
Gets brush/fill style.
static double mapUnitScaleFactor(double scale, QgsUnitTypes::RenderUnit symbolUnits, QgsUnitTypes::DistanceUnit mapUnits, double mapUnitsPerPixel=1.0)
Returns scale factor for conversion to map units.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
Quadrant getQuadrant() const
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
void writeFilledCircle(const QString &layer, const QColor &color, const QgsPoint &pt, double radius)
Write filled circle (as hatch)
QgsSymbolRenderContext * symbolRenderContext()
Returns the symbol render context.
QgsFeatureRenderer * renderer()
Returns renderer.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Abstract base class for curved geometry type.
const QgsAbstractVectorLayerLabeling * labeling() const
Access to const labeling configuration.
bool useCustomDashPattern() const
Returns true if the line uses a custom dash pattern.
Single scope for storing variables and functions for use within a QgsExpressionContext.
Abstract base class for all geometries.
double mapUnitsPerPixel() const
Returns current map units per pixel.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the scope.
Does vector analysis using the geos library and handles import, export, exception handling*...
void writeText(const QString &layer, const QString &text, const QgsPoint &pt, double size, double angle, const QColor &color)
Write text (TEXT)
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
QgsSymbolLayer * symbolLayer(int layer)
Returns a specific symbol layer contained in the symbol.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination CRS, or an invalid CRS if no reprojection will be done.
Point geometry type, with support for z-dimension and m-values.
const QgsMapToPixel & mapToPixel() const
static QString dxfEncoding(const QString &name)
Returns DXF encoding for Qt encoding.
QgsRectangle extent() const FINAL
Returns the extent of the layer.
const QgsTextFormat & format() const
Returns the label text formatting settings, e.g., font settings, buffer settings, etc...
QString layerName(const QString &id, const QgsFeature &f) const
Gets layer name for feature.
virtual QColor dxfBrushColor(QgsSymbolRenderContext &context) const
Gets brush/fill color.
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
int numGeometries() const
Returns the number of geometries within the collection.
Contains geos related utilities and functions.
Place direction symbols on above label.
virtual bool isClosed() const
Returns true if the curve is closed.
void drawLabel(const QString &layerId, QgsRenderContext &context, pal::LabelPosition *label, const QgsPalLayerSettings &settings)
Output the label.
QgsCoordinateSequence coordinateSequence() const override
Retrieves the sequence of geometries, rings and nodes.
Rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
int nCurves() const
Returns the number of curves in the geometry.
QgsExpressionContext & expressionContext()
Gets the expression context.
DistanceUnit
Units of distance.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
QVector< QgsPoint > QgsPointSequence
void setFeature(const QgsFeature *f)
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle...
QString wrapChar
Wrapping character string.
virtual Qt::PenStyle dxfPenStyle() const
Gets pen style.
static QString dxfLayerName(const QString &name)
Returns cleaned layer name for use in DXF.
QVector< QgsPointSequence > QgsRingSequence
QgsAbstractGeometry * offsetCurve(double distance, int segments, int joinStyle, double miterLimit, QString *errorMsg=nullptr) const override
QString rightDirectionSymbol
String to use for right direction arrows.
The QgsLabelingEngine class provides map labeling functionality.
void run(QgsRenderContext &context)
compute the labeling with given map settings and providers
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon'...
Contains information about the context of a rendering operation.
Abstract base class for marker symbol layers.
void writeCircle(const QString &layer, const QColor &color, const QgsPoint &pt, double radius, const QString &lineStyleName, double width)
Write circle (as polyline)
QFont definedFont()
Font to be used for rendering.
QMap< QString, QString > layerStyleOverrides() const
Gets map of map layer style overrides (key: layer ID, value: style name) where a different style shou...
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
double maxSizeMM
The maximum size in millimeters, or 0.0 if unset.
QList< QgsSymbolLevelItem > QgsSymbolLevel
double getAlpha() const
Returns the angle to rotate text (in rad).
QSet< QVariant > uniqueValues(int fieldIndex, int limit=-1) const FINAL
Calculates a list of unique values contained within an attribute in the layer.
Struct for storing maximum and minimum scales for measurements in map units.
virtual double dxfAngle(QgsSymbolRenderContext &context) const
Gets angle.
virtual QgsSymbolList symbols(QgsRenderContext &context) const
Returns list of symbols used by the renderer.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the symbol's size.
double getX(int i=0) const
Returns the down-left x coordinate.
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
QgsPointXY layerToMapCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from layer's CRS to output CRS
virtual QColor dxfColor(QgsSymbolRenderContext &context) const
Gets color.
RenderHints renderHints() const
Returns the rendering hint flags for the symbol.
Line string geometry type, with support for z-dimension and m-values.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
static QgsProject * instance()
Returns the QgsProject singleton instance.
const QgsFeature * feature() const
Returns the current feature being rendered.
This class represents a coordinate reference system (CRS).
void writeDouble(double d)
Write a floating point value.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context's map to pixel transform, which transforms between map coordinates and device coordi...
const QgsCurve * curveAt(int i) const
Returns the curve at the specified index.
Abstract base class - its implementations define different approaches to the labeling of a vector lay...
QgsPoint pointN(int i) const
Returns the specified point from inside the line string.
LabelPosition is a candidate feature label position.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
void setLayers(const QList< QgsMapLayer *> &layers)
Set list of layers for map rendering.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
Compound curve geometry type.
Circular string geometry type.
void appendScopes(const QList< QgsExpressionContextScope *> &scopes)
Appends a list of scopes to the end of the context.
void stopRender(QgsSymbolRenderContext &context) override
QgsPointXY center() const
Returns the center point of the rectangle.
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
bool nextFeature(QgsFeature &f)
Implements a derived label provider internally used for DXF export.
#define DXF_HANDPLOTSTYLE
virtual bool writeDxf(QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, QgsSymbolRenderContext &context, QPointF shift=QPointF(0.0, 0.0)) const
write as DXF
void setOverrideStyle(const QString &style)
Temporarily apply a different style to the layer.
Container for all settings relating to text rendering.
Geometry is not required. It may still be returned if e.g. required for a filter condition.
const QgsCurve * exteriorRing() const
Returns the curve polygon's exterior ring.
int writeHandle(int code=5, int handle=0)
Write a tuple of group code and a handle.
static Q_INVOKABLE double fromUnitToUnitFactor(QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
QgsPointXY mapToLayerCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from output CRS to layer's CRS
Represents a vector layer which manages a vector based data sets.
double minScale
The minimum scale, or 0.0 if unset.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
static Type flatType(Type type)
Returns the flat type for a WKB type.
virtual bool hasCurvedSegments() const
Returns true if the geometry contains curved segments.
bool maxSizeMMEnabled
Whether the maximum size in mm should be respected.
virtual int numPoints() const =0
Returns the number of points in the curve.
QFont font() const
Returns the font used for rendering text.
void writeMText(const QString &layer, const QString &text, const QgsPoint &pt, double width, double angle, const QColor &color)
Write mtext (MTEXT)
void addLayers(const QList< QgsDxfExport::DxfLayer > &layers)
Add layers to export.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
QgsDxfExport & operator=(const QgsDxfExport &dxfExport)
RenderUnit
Rendering size units.
double height() const
Returns the height of the rectangle.
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
virtual QString layerType() const =0
Returns a string that represents this layer type.
DirectionSymbols placeDirectionSymbol
Placement option for direction symbols.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Exports one feature per symbol layer (considering symbol levels)
QgsExpressionContextScope * expressionContextScope()
This scope is always available when a symbol of this type is being rendered.