Showing with 106 additions and 6 deletions.
  1. +7 −0 src/app/qgisapp.cpp
  2. +22 −0 src/app/qgsdxfexportdialog.cpp
  3. +18 −0 src/app/qgsdxfexportdialog.h
  4. +46 −6 src/core/dxf/qgsdxfexport.cpp
  5. +6 −0 src/core/dxf/qgsdxfexport.h
  6. +7 −0 src/ui/qgsdxfexportdialogbase.ui
7 changes: 7 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3846,7 +3846,14 @@ void QgisApp::dxfExport()
{
dxfExport.setMapUnits( r->mapUnits() );
}

//extent
if ( d.exportMapExtent() )
{
dxfExport.setExtent( mapCanvas()->extent() );
}
}

QFile dxfFile( d.saveFile() );
if ( dxfExport.writeToFile( &dxfFile ) == 0 )
{
Expand Down
22 changes: 22 additions & 0 deletions src/app/qgsdxfexportdialog.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/***************************************************************************
qgsdxfexportdialog.cpp
----------------------
begin : September 2013
copyright : (C) 2013 by Marco Hugentobler
email : marco at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsdxfexportdialog.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
Expand Down Expand Up @@ -123,6 +140,11 @@ void QgsDxfExportDialog::setOkEnabled()
btn->setEnabled( fi.absoluteDir().exists() );
}

bool QgsDxfExportDialog::exportMapExtent() const
{
return mMapExtentCheckBox->isChecked();
}

void QgsDxfExportDialog::saveSettings()
{
QSettings s;
Expand Down
18 changes: 18 additions & 0 deletions src/app/qgsdxfexportdialog.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/***************************************************************************
qgsdxfexportdialog.h
--------------------
begin : September 2013
copyright : (C) 2013 by Marco Hugentobler
email : marco at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSDXFEXPORTDIALOG_H
#define QGSDXFEXPORTDIALOG_H

Expand All @@ -15,6 +32,7 @@ class QgsDxfExportDialog: public QDialog, private Ui::QgsDxfExportDialogBase
double symbologyScale() const;
QgsDxfExport::SymbologyExport symbologyMode() const;
QString saveFile() const;
bool exportMapExtent() const;

public slots:
/** change the selection of layers in the list */
Expand Down
52 changes: 46 additions & 6 deletions src/core/dxf/qgsdxfexport.cpp
Original file line number Diff line number Diff line change
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 @@ -565,15 +565,19 @@ void QgsDxfExport::writeEntities()
renderer->stopRender( ctx );
}


QgsFeatureIterator featureIt = vl->getFeatures( QgsFeatureRequest().setSubsetOfAttributes(
renderer->usedAttributes(), dp->fields() ) );
QgsFeatureRequest freq = QgsFeatureRequest().setSubsetOfAttributes(
renderer->usedAttributes(), dp->fields() );
if ( !mExtent.isEmpty() )
{
freq.setFilterRect( mExtent );
}
QgsFeatureIterator featureIt = vl->getFeatures( freq );
QgsFeature fet;
while ( featureIt.nextFeature( fet ) )
{
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 @@ -593,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 @@ -625,6 +629,10 @@ void QgsDxfExport::writeEntitiesSymbolLevels( QgsVectorLayer* layer )
req.setFlags( QgsFeatureRequest::NoGeometry );
}
req.setSubsetOfAttributes( QStringList( renderer->usedAttributes() ), layer->pendingFields() );
if ( !mExtent.isEmpty() )
{
req.setFilterRect( mExtent );
}
QgsFeatureIterator fit = layer->getFeatures( req );

//fetch features
Expand Down Expand Up @@ -1323,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
6 changes: 6 additions & 0 deletions src/core/dxf/qgsdxfexport.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class CORE_EXPORT QgsDxfExport
void setSymbologyExport( SymbologyExport e ) { mSymbologyExport = e; }
SymbologyExport symbologyExport() const { return mSymbologyExport; }

void setExtent( const QgsRectangle& r ) { mExtent = r; }
QgsRectangle extent() const { return mExtent; }

//get closest entry in dxf palette
static int closestColorMatch( QRgb pixel );

Expand Down Expand Up @@ -83,6 +86,8 @@ class CORE_EXPORT QgsDxfExport
private:

QList< QgsMapLayer* > mLayers;
/**Extent for export, only intersecting features are exported. If the extent is an empty rectangle, all features are exported*/
QgsRectangle mExtent;
/**Scale for symbology export (used if symbols units are mm)*/
double mSymbologyScaleDenominator;
SymbologyExport mSymbologyExport;
Expand Down Expand Up @@ -155,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
7 changes: 7 additions & 0 deletions src/ui/qgsdxfexportdialogbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@
</item>
</layout>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="mMapExtentCheckBox">
<property name="text">
<string>Export features intersecting the current map extent</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
Expand Down