Skip to content

Commit

Permalink
Dxf export: modify layer name to be a valid dxf layer name
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Dec 11, 2013
1 parent b1b7904 commit 8405ddb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
38 changes: 35 additions & 3 deletions src/core/dxf/qgsdxfexport.cpp
Expand Up @@ -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" );
Expand Down Expand Up @@ -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
{
Expand All @@ -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 );
Expand Down Expand Up @@ -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 )
Expand Down
1 change: 1 addition & 0 deletions src/core/dxf/qgsdxfexport.h
Expand Up @@ -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.