Skip to content

Commit

Permalink
Merge pull request #33162 from m-kuhn/dxf_dash_beautify
Browse files Browse the repository at this point in the history
DXF export preserve dashed line style
  • Loading branch information
m-kuhn committed Dec 5, 2019
2 parents 7df4ec7 + ba87ae6 commit c01f804
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 5 deletions.
11 changes: 11 additions & 0 deletions python/core/auto_additions/qgsdxfexport.py
Expand Up @@ -24,3 +24,14 @@
QgsDxfExport.HAlign.Undefined.__doc__ = "Undefined"
QgsDxfExport.HAlign.__doc__ = 'Horizontal alignments.\n\n' + '* ``HLeft``: ' + QgsDxfExport.HAlign.HLeft.__doc__ + '\n' + '* ``HCenter``: ' + QgsDxfExport.HAlign.HCenter.__doc__ + '\n' + '* ``HRight``: ' + QgsDxfExport.HAlign.HRight.__doc__ + '\n' + '* ``HAligned``: ' + QgsDxfExport.HAlign.HAligned.__doc__ + '\n' + '* ``HMiddle``: ' + QgsDxfExport.HAlign.HMiddle.__doc__ + '\n' + '* ``HFit``: ' + QgsDxfExport.HAlign.HFit.__doc__ + '\n' + '* ``Undefined``: ' + QgsDxfExport.HAlign.Undefined.__doc__
# --
# monkey patching scoped based enum
QgsDxfExport.DxfPolylineFlag.Closed.__doc__ = "This is a closed polyline (or a polygon mesh closed in the M direction)"
QgsDxfExport.DxfPolylineFlag.Curve.__doc__ = "Curve-fit vertices have been added"
QgsDxfExport.DxfPolylineFlag.Spline.__doc__ = ""
QgsDxfExport.DxfPolylineFlag.Is3DPolyline.__doc__ = "This is a 3D polyline"
QgsDxfExport.DxfPolylineFlag.Is3DPolygonMesh.__doc__ = "This is a 3D polygon mesh"
QgsDxfExport.DxfPolylineFlag.PolygonMesh.__doc__ = "The polygon mesh is closed in the N direction"
QgsDxfExport.DxfPolylineFlag.PolyfaceMesh.__doc__ = "The polyline is a polyface mesh"
QgsDxfExport.DxfPolylineFlag.ContinuousPattern.__doc__ = "The linetype pattern is generated continuously around the vertices of this polyline"
QgsDxfExport.DxfPolylineFlag.__doc__ = 'Flags for polylines\n\n.. versionadded:: 3.12\n\n' + '* ``Closed``: ' + QgsDxfExport.DxfPolylineFlag.Closed.__doc__ + '\n' + '* ``Curve``: ' + QgsDxfExport.DxfPolylineFlag.Curve.__doc__ + '\n' + '* ``Spline``: ' + QgsDxfExport.DxfPolylineFlag.Spline.__doc__ + '\n' + '* ``Is3DPolyline``: ' + QgsDxfExport.DxfPolylineFlag.Is3DPolyline.__doc__ + '\n' + '* ``Is3DPolygonMesh``: ' + QgsDxfExport.DxfPolylineFlag.Is3DPolygonMesh.__doc__ + '\n' + '* ``PolygonMesh``: ' + QgsDxfExport.DxfPolylineFlag.PolygonMesh.__doc__ + '\n' + '* ``PolyfaceMesh``: ' + QgsDxfExport.DxfPolylineFlag.PolyfaceMesh.__doc__ + '\n' + '* ``ContinuousPattern``: ' + QgsDxfExport.DxfPolylineFlag.ContinuousPattern.__doc__
# --
16 changes: 16 additions & 0 deletions python/core/auto_generated/dxf/qgsdxfexport.sip.in
Expand Up @@ -13,6 +13,7 @@




class QgsDxfExport
{

Expand Down Expand Up @@ -91,6 +92,21 @@ unique value.
Undefined
};

enum class DxfPolylineFlag
{
Closed,
Curve,
Spline,
Is3DPolyline,
Is3DPolygonMesh,
PolygonMesh,
PolyfaceMesh,
ContinuousPattern,
};

typedef QFlags<QgsDxfExport::DxfPolylineFlag> DxfPolylineFlags;


QgsDxfExport();
%Docstring
Constructor for QgsDxfExport.
Expand Down
12 changes: 11 additions & 1 deletion src/core/dxf/qgsdxfexport.cpp
Expand Up @@ -1097,7 +1097,17 @@ void QgsDxfExport::writePolyline( const QgsCurve &curve, const QString &layer, c
writeGroup( color );

writeGroup( 90, points.size() );
writeGroup( 70, ( curve.isClosed() ? 1 : 0 ) | ( curve.hasCurvedSegments() ? 2 : 0 ) );
QgsDxfExport::DxfPolylineFlags polylineFlags;
if ( curve.isClosed() )
polylineFlags.setFlag( QgsDxfExport::DxfPolylineFlag::Closed );
if ( curve.hasCurvedSegments() )
polylineFlags.setFlag( QgsDxfExport::DxfPolylineFlag::Curve );

// Might need to conditional once this feature is implemented
// https://github.com/qgis/QGIS/issues/32468
polylineFlags.setFlag( QgsDxfExport::DxfPolylineFlag::ContinuousPattern );

writeGroup( 70, static_cast<int>( polylineFlags ) );
writeGroup( 43, width );

for ( int i = 0; i < points.size(); i++ )
Expand Down
20 changes: 20 additions & 0 deletions src/core/dxf/qgsdxfexport.h
Expand Up @@ -49,6 +49,7 @@ namespace pal // SIP_SKIP
class LabelPosition;
}


/**
* \ingroup core
* \class QgsDxfExport
Expand Down Expand Up @@ -142,6 +143,25 @@ class CORE_EXPORT QgsDxfExport
Undefined = 9999 //!< Undefined
};

/**
* Flags for polylines
*
* \since QGIS 3.12
*/
enum class DxfPolylineFlag : int
{
Closed = 1, //!< This is a closed polyline (or a polygon mesh closed in the M direction)
Curve = 2, //!< Curve-fit vertices have been added
Spline = 4, //! < Spline-fit vertices have been added
Is3DPolyline = 8, //!< This is a 3D polyline
Is3DPolygonMesh = 16, //!< This is a 3D polygon mesh
PolygonMesh = 32, //!< The polygon mesh is closed in the N direction
PolyfaceMesh = 64, //!< The polyline is a polyface mesh
ContinuousPattern = 128, //!< The linetype pattern is generated continuously around the vertices of this polyline
};

Q_DECLARE_FLAGS( DxfPolylineFlags, DxfPolylineFlag )

/**
* Constructor for QgsDxfExport.
*/
Expand Down
9 changes: 5 additions & 4 deletions tests/src/core/testqgsdxfexport.cpp
Expand Up @@ -742,7 +742,8 @@ void TestQgsDxfExport::testCurveExport()
QCOMPARE( d.writeToFile( &dxfFile, QStringLiteral( "CP1252" ) ), QgsDxfExport::ExportResult::Success );
dxfFile.close();

QVERIFY( fileContainsText( file, dxfText ) );
QString debugInfo;
QVERIFY2( fileContainsText( file, dxfText, &debugInfo ), debugInfo.toUtf8().constData() );
}

void TestQgsDxfExport::testCurveExport_data()
Expand Down Expand Up @@ -775,7 +776,7 @@ void TestQgsDxfExport::testCurveExport_data()
" 90\n"
" 2\n"
" 70\n"
" 2\n"
" 130\n"
" 43\n"
"-1.0\n"
" 10\n"
Expand Down Expand Up @@ -815,7 +816,7 @@ void TestQgsDxfExport::testCurveExport_data()
" 90\n"
" 5\n"
" 70\n"
" 3\n"
" 131\n"
" 43\n"
"-1.0\n"
" 10\n"
Expand Down Expand Up @@ -934,7 +935,7 @@ void TestQgsDxfExport::testDashedLine()
" 90\n"
" 6\n"
" 70\n"
" 0\n"
" 128\n"
" 43\n"
"0.11\n"
" 10\n"
Expand Down

0 comments on commit c01f804

Please sign in to comment.