Skip to content
Permalink
Browse files

Dxf export: modify layer name to be a valid dxf layer name

  • Loading branch information
mhugent committed Dec 11, 2013
1 parent b1b7904 commit 8405ddb876a8e6cec3be40de7691bf19c2c2f3fb
Showing with 36 additions and 3 deletions.
  1. +35 −3 src/core/dxf/qgsdxfexport.cpp
  2. +1 −0 src/core/dxf/qgsdxfexport.h
@@ -467,7 +467,7 @@ void QgsDxfExport::writeTables()
{
writeGroup( 0, "LAYER" );
QString layerName = *layerIt ? ( *layerIt )->name() : "";
writeGroup( 2, layerName );
writeGroup( 2, dxfLayerName( layerName ) );
writeGroup( 70, 64 );
writeGroup( 62, 1 );
writeGroup( 6, "CONTINUOUS" );
@@ -577,7 +577,7 @@ void QgsDxfExport::writeEntities()
{
if ( mSymbologyExport == NoSymbology )
{
addFeature( fet, vl->name(), 0, 0 ); //no symbology at all
addFeature( fet, dxfLayerName( vl->name() ), 0, 0 ); //no symbology at all
}
else
{
@@ -597,7 +597,7 @@ void QgsDxfExport::writeEntities()
{
continue;
}
addFeature( fet, vl->name(), s->symbolLayer( 0 ), s );
addFeature( fet, dxfLayerName( vl->name() ), s->symbolLayer( 0 ), s );
}
}
renderer->stopRender( ctx );
@@ -1331,6 +1331,38 @@ QString QgsDxfExport::lineNameFromPenStyle( Qt::PenStyle style )
}
}

QString QgsDxfExport::dxfLayerName( const QString& name )
{
//dxf layers can be max 31 characters long
QString layerName = name.left( 31 );

//allowed characters are 0-9, A-Z, $, -, _
for ( int i = 0; i < layerName.size(); ++i )
{
QChar c = layerName.at( i );
if ( c > 122 )
{
layerName[i] = '_';
continue;
}

if ( c.isNumber() )
{
continue;
}
if ( c == '$' || c == '-' || c == '_' )
{
continue;
}

if ( !c.isLetter() )
{
layerName[i] = '_';
}
}
return layerName;
}

/******************************************************Test with AC_1018 methods***************************************************************/

void QgsDxfExport::writeHeaderAC1018( QTextStream& stream )
@@ -160,6 +160,7 @@ class CORE_EXPORT QgsDxfExport
double dashSeparatorSize() const;
double sizeToMapUnits( double s ) const;
static QString lineNameFromPenStyle( Qt::PenStyle style );
static QString dxfLayerName( const QString& name );
};

#endif // QGSDXFEXPORT_H

0 comments on commit 8405ddb

Please sign in to comment.
You can’t perform that action at this time.