Skip to content

Commit

Permalink
dxf export: allow forcing to 2d to support polyline width (fixes #17049)
Browse files Browse the repository at this point in the history
(backported from commit 12e69d0)
  • Loading branch information
jef-n committed Sep 4, 2017
1 parent c550e82 commit 238a119
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 12 deletions.
14 changes: 14 additions & 0 deletions python/core/dxf/qgsdxfexport.sip
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,20 @@ class QgsDxfExport
*/
bool layerTitleAsName();

/**
* Force 2d output (eg. to support linewidth in polylines)
* \param force2d flag
* \see force2d
*/
void setForce2d( bool force2d );

/**
* Retrieve whether the output should be forced to 2d
* \returns flag
* \see setForce2d
*/
bool force2d();

/**
* Get DXF palette index of nearest entry for given color
* @param color
Expand Down
1 change: 1 addition & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5116,6 +5116,7 @@ void QgisApp::dxfExport()
dxfExport.setSymbologyExport( d.symbologyMode() );
dxfExport.setLayerTitleAsName( d.layerTitleAsName() );
dxfExport.setDestinationCrs( d.crs() );
dxfExport.setForce2d( d.force2d() );
if ( mapCanvas() )
{
dxfExport.setMapUnits( mapCanvas()->mapUnits() );
Expand Down
6 changes: 5 additions & 1 deletion src/app/qgsdxfexportdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ QWidget *FieldSelectorDelegate::createEditor( QWidget *parent, const QStyleOptio
if ( !vl )
return nullptr;


QgsFieldComboBox *w = new QgsFieldComboBox( parent );
w->setLayer( vl );
return w;
Expand Down Expand Up @@ -603,6 +602,11 @@ bool QgsDxfExportDialog::layerTitleAsName() const
return mLayerTitleAsName->isChecked();
}

bool QgsDxfExportDialog::force2d() const
{
return mForce2d->isChecked();
}

void QgsDxfExportDialog::saveSettings()
{
QSettings s;
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsdxfexportdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class QgsDxfExportDialog : public QDialog, private Ui::QgsDxfExportDialogBase
QString saveFile() const;
bool exportMapExtent() const;
bool layerTitleAsName() const;
bool force2d() const;
QString mapTheme() const;
QString encoding() const;
long crs() const;
Expand Down
7 changes: 4 additions & 3 deletions src/core/dxf/qgsdxfexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ QgsDxfExport::QgsDxfExport()
, mNextHandleId( DXF_HANDSEED )
, mBlockCounter( 0 )
, mCrs( -1 )
, mForce2d( false )
{
}

Expand Down Expand Up @@ -444,15 +445,15 @@ void QgsDxfExport::writeGroup( int code, const QgsPoint &p, double z, bool skipz
{
writeGroup( code + 10, p.x() );
writeGroup( code + 20, p.y() );
if ( !skipz )
if ( !mForce2d && !skipz )
writeGroup( code + 30, z );
}

void QgsDxfExport::writeGroup( int code, const QgsPointV2 &p )
{
writeGroup( code + 10, p.x() );
writeGroup( code + 20, p.y() );
if ( p.is3D() && qIsFinite( p.z() ) )
if ( !mForce2d && p.is3D() && qIsFinite( p.z() ) )
writeGroup( code + 30, p.z() );
}

Expand Down Expand Up @@ -3472,7 +3473,7 @@ void QgsDxfExport::writePolyline( const QgsPointSequenceV2 &line, const QString&
return;
}

if ( !line.at( 0 ).is3D() )
if ( mForce2d || !line.at( 0 ).is3D() )
{
writeGroup( 0, "LWPOLYLINE" );
writeHandle();
Expand Down
15 changes: 15 additions & 0 deletions src/core/dxf/qgsdxfexport.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ class CORE_EXPORT QgsDxfExport
*/
bool layerTitleAsName() { return mLayerTitleAsName; }

/**
* Force 2d output (eg. to support linewidth in polylines)
* \param force2d flag
* \see force2d
*/
void setForce2d( bool force2d ) { mForce2d = force2d; }

/**
* Retrieve whether the output should be forced to 2d
* \returns flag
* \see setForce2d
*/
bool force2d() { return mForce2d; }

/**
* Get DXF palette index of nearest entry for given color
* @param color
Expand Down Expand Up @@ -465,6 +479,7 @@ class CORE_EXPORT QgsDxfExport
QgsMapSettings mMapSettings;
QHash<QString, int> mLayerNameAttribute;
double mFactor;
bool mForce2d;
};

#endif // QGSDXFEXPORT_H
25 changes: 17 additions & 8 deletions src/ui/qgsdxfexportdialogbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
<string>DXF export</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="0">
<widget class="QLabel" name="mSymbologyScaleLabel">
<property name="text">
<string>Symbology scale</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QToolButton" name="mFileSelectionButton">
<property name="text">
Expand Down Expand Up @@ -54,13 +61,6 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mSymbologyScaleLabel">
<property name="text">
<string>Symbology scale</string>
</property>
</widget>
</item>
<item row="7" column="0" colspan="3">
<widget class="QgsLayerTreeView" name="mTreeView">
<property name="selectionMode">
Expand Down Expand Up @@ -122,7 +122,7 @@
</property>
</widget>
</item>
<item row="12" column="0" colspan="3">
<item row="13" column="0" colspan="3">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand Down Expand Up @@ -170,6 +170,13 @@
</property>
</widget>
</item>
<item row="12" column="0" colspan="3">
<widget class="QCheckBox" name="mForce2d">
<property name="text">
<string>Force 2d output (eg. to support polyline width)</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
Expand All @@ -195,12 +202,14 @@
<tabstop>mFileSelectionButton</tabstop>
<tabstop>mSymbologyModeComboBox</tabstop>
<tabstop>mEncoding</tabstop>
<tabstop>mScaleWidget</tabstop>
<tabstop>mVisibilityPresets</tabstop>
<tabstop>mTreeView</tabstop>
<tabstop>mSelectAllButton</tabstop>
<tabstop>mUnSelectAllButton</tabstop>
<tabstop>mLayerTitleAsName</tabstop>
<tabstop>mMapExtentCheckBox</tabstop>
<tabstop>mForce2d</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
Expand Down

0 comments on commit 238a119

Please sign in to comment.