Skip to content

Commit

Permalink
dxf export:
Browse files Browse the repository at this point in the history
* empty field name resets to layer name (fixes #17060)
* allow forcing to 2d to support polyline width (fixes #17049)
  • Loading branch information
jef-n committed Aug 29, 2017
1 parent b978c4d commit 12e69d0
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 35 deletions.
15 changes: 15 additions & 0 deletions python/core/dxf/qgsdxfexport.sip
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ class QgsDxfExport
:rtype: bool
%End

void setForce2d( bool force2d );
%Docstring
Force 2d output (eg. to support linewidth in polylines)
\param force2d flag
.. seealso:: force2d
%End

bool force2d();
%Docstring
Retrieve whether the output should be forced to 2d
:return: flag
.. seealso:: setForce2d
:rtype: bool
%End

static int closestColorMatch( QRgb color );
%Docstring
Get DXF palette index of nearest entry for given 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 @@ -5528,6 +5528,7 @@ void QgisApp::dxfExport()
dxfExport.setSymbologyExport( d.symbologyMode() );
dxfExport.setLayerTitleAsName( d.layerTitleAsName() );
dxfExport.setDestinationCrs( d.crs() );
dxfExport.setForce2d( d.force2d() );
if ( mapCanvas() )
{
//extent
Expand Down
7 changes: 6 additions & 1 deletion src/app/qgsdxfexportdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ QWidget *FieldSelectorDelegate::createEditor( QWidget *parent, const QStyleOptio
if ( !vl )
return nullptr;


QgsFieldComboBox *w = new QgsFieldComboBox( parent );
w->setLayer( vl );
w->setAllowEmptyFieldName( true );
return w;
}

Expand Down Expand Up @@ -607,6 +607,11 @@ bool QgsDxfExportDialog::layerTitleAsName() const
return mLayerTitleAsName->isChecked();
}

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

void QgsDxfExportDialog::saveSettings()
{
QgsSettings 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 @@ -88,6 +88,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;
QgsCoordinateReferenceSystem crs() const;
Expand Down
51 changes: 26 additions & 25 deletions src/core/dxf/qgsdxfexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ QgsDxfExport::QgsDxfExport()
, mNextHandleId( DXF_HANDSEED )
, mBlockCounter( 0 )
, mFactor( 1 )
, mForce2d( false )
{
}

Expand Down Expand Up @@ -443,7 +444,7 @@ void QgsDxfExport::writeGroup( int code, const QgsPoint &p )
{
writeGroup( code + 10, p.x() );
writeGroup( code + 20, p.y() );
if ( p.is3D() && std::isfinite( p.z() ) )
if ( !mForce2d && p.is3D() && std::isfinite( p.z() ) )
writeGroup( code + 30, p.z() );
}

Expand Down Expand Up @@ -735,28 +736,28 @@ void QgsDxfExport::writeTables()
writeGroup( 5, QgsPoint( 1.0, 1.0 ) ); // grid spacing
writeGroup( 6, QgsPoint( QgsWkbTypes::PointZ, 0.0, 0.0, 1.0 ) ); // view direction from target point
writeGroup( 7, QgsPoint( mExtent.center() ) ); // view target point
writeGroup( 40, mExtent.height() ); // view height
writeGroup( 41, mExtent.width() / mExtent.height() ); // view aspect ratio
writeGroup( 42, 50.0 ); // lens length
writeGroup( 43, 0.0 ); // front clipping plane
writeGroup( 44, 0.0 ); // back clipping plane
writeGroup( 50, 0.0 ); // snap rotation
writeGroup( 51, 0.0 ); // view twist angle
writeGroup( 71, 0 ); // view mode (0 = deactivates)
writeGroup( 72, 100 ); // circle zoom percent
writeGroup( 73, 1 ); // fast zoom setting
writeGroup( 74, 1 ); // UCSICON setting
writeGroup( 75, 0 ); // snapping off
writeGroup( 76, 0 ); // grid off
writeGroup( 77, 0 ); // snap style
writeGroup( 78, 0 ); // snap isopair
writeGroup( 281, 0 ); // render mode (0 = 2D optimized)
writeGroup( 65, 1 ); // value of UCSVP for this viewport
writeGroup( 40, mExtent.height() ); // view height
writeGroup( 41, mExtent.width() / mExtent.height() ); // view aspect ratio
writeGroup( 42, 50.0 ); // lens length
writeGroup( 43, 0.0 ); // front clipping plane
writeGroup( 44, 0.0 ); // back clipping plane
writeGroup( 50, 0.0 ); // snap rotation
writeGroup( 51, 0.0 ); // view twist angle
writeGroup( 71, 0 ); // view mode (0 = deactivates)
writeGroup( 72, 100 ); // circle zoom percent
writeGroup( 73, 1 ); // fast zoom setting
writeGroup( 74, 1 ); // UCSICON setting
writeGroup( 75, 0 ); // snapping off
writeGroup( 76, 0 ); // grid off
writeGroup( 77, 0 ); // snap style
writeGroup( 78, 0 ); // snap isopair
writeGroup( 281, 0 ); // render mode (0 = 2D optimized)
writeGroup( 65, 1 ); // value of UCSVP for this viewport
writeGroup( 100, QgsPoint( QgsWkbTypes::PointZ ) ); // UCS origin
writeGroup( 101, QgsPoint( QgsWkbTypes::PointZ, 1.0 ) ); // UCS x axis
writeGroup( 102, QgsPoint( QgsWkbTypes::PointZ, 0.0, 1.0 ) ); // UCS y axis
writeGroup( 79, 0 ); // Orthographic type of UCS (0 = UCS is not orthographic)
writeGroup( 146, 0.0 ); // Elevation
writeGroup( 79, 0 ); // Orthographic type of UCS (0 = UCS is not orthographic)
writeGroup( 146, 0.0 ); // Elevation

writeGroup( 70, 0 );
writeGroup( 0, QStringLiteral( "ENDTAB" ) );
Expand Down Expand Up @@ -3457,7 +3458,7 @@ void QgsDxfExport::writePolyline( const QgsPointSequence &line, const QString &l
return;
}

if ( !line.at( 0 ).is3D() )
if ( mForce2d || !line.at( 0 ).is3D() )
{
writeGroup( 0, QStringLiteral( "LWPOLYLINE" ) );
writeHandle();
Expand Down Expand Up @@ -3760,7 +3761,7 @@ void QgsDxfExport::addFeature( QgsSymbolRenderContext &ctx, const QgsCoordinateT
QgsGeos geos( tempGeom );
if ( tempGeom != geom.get() )
delete tempGeom;
tempGeom = geos.offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 ); //#spellok //#spellok
tempGeom = geos.offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 ); //#spellok
if ( !tempGeom )
tempGeom = geom.get();
}
Expand All @@ -3781,7 +3782,7 @@ void QgsDxfExport::addFeature( QgsSymbolRenderContext &ctx, const QgsCoordinateT
QgsGeos geos( tempGeom );
if ( tempGeom != geom.get() )
delete tempGeom;
tempGeom = geos.offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 ); //#spellok //#spellok
tempGeom = geos.offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 ); //#spellok
if ( !tempGeom )
tempGeom = geom.get();
}
Expand All @@ -3807,7 +3808,7 @@ void QgsDxfExport::addFeature( QgsSymbolRenderContext &ctx, const QgsCoordinateT
QgsGeos geos( tempGeom );
if ( tempGeom != geom.get() )
delete tempGeom;
tempGeom = geos.buffer( offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 ); //#spellok //#spellok
tempGeom = geos.buffer( offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 ); //#spellok
if ( !tempGeom )
tempGeom = geom.get();
}
Expand All @@ -3828,7 +3829,7 @@ void QgsDxfExport::addFeature( QgsSymbolRenderContext &ctx, const QgsCoordinateT
QgsGeos geos( tempGeom );
if ( tempGeom != geom.get() )
delete tempGeom;
tempGeom = geos.buffer( offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 ); //#spellok //#spellok
tempGeom = geos.buffer( offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 ); //#spellok
if ( !tempGeom )
tempGeom = geom.get();
}
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 @@ -155,6 +155,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 @@ -403,6 +417,7 @@ class CORE_EXPORT QgsDxfExport
QgsMapSettings mMapSettings;
QHash<QString, int> mLayerNameAttribute;
double mFactor;
bool mForce2d;
};

#endif // QGSDXFEXPORT_H
27 changes: 18 additions & 9 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 @@ -125,7 +125,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 @@ -173,6 +173,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 @@ -197,15 +204,17 @@
<tabstop>mFileLineEdit</tabstop>
<tabstop>mFileSelectionButton</tabstop>
<tabstop>mSymbologyModeComboBox</tabstop>
<tabstop>mScaleWidget</tabstop>
<tabstop>mEncoding</tabstop>
<tabstop>mScaleWidget</tabstop>
<tabstop>mVisibilityPresets</tabstop>
<tabstop>mCrsSelector</tabstop>
<tabstop>mTreeView</tabstop>
<tabstop>mSelectAllButton</tabstop>
<tabstop>mDeselectAllButton</tabstop>
<tabstop>mLayerTitleAsName</tabstop>
<tabstop>mMapExtentCheckBox</tabstop>
<tabstop>mForce2d</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
Expand Down

1 comment on commit 12e69d0

@3nids
Copy link
Member

@3nids 3nids commented on 12e69d0 Sep 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jef-n thanks a lot for the fix.
Do you consider this as a feature? or is there another reason not to backport?

Please sign in to comment.