From f81b680aa100dac65e6da6ecfe6dacdf68762c8f Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Fri, 29 Nov 2019 17:56:19 +0100 Subject: [PATCH 1/3] DXF export preserve dashed line style We do not (yet) support an option to guarantee stroked parts at corners. So also do not set this flag in the DXF export. --- python/core/auto_additions/qgsdxfexport.py | 11 +++++++++++ .../core/auto_generated/dxf/qgsdxfexport.sip.in | 16 ++++++++++++++++ src/core/dxf/qgsdxfexport.cpp | 12 +++++++++++- src/core/dxf/qgsdxfexport.h | 15 +++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/python/core/auto_additions/qgsdxfexport.py b/python/core/auto_additions/qgsdxfexport.py index dc0cd665d80..7470f99b0af 100644 --- a/python/core/auto_additions/qgsdxfexport.py +++ b/python/core/auto_additions/qgsdxfexport.py @@ -24,3 +24,14 @@ QgsDxfExport.HAlign.HFit.__doc__ = "Fit into point = (5) (if VAlign==0)" 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__ = '\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__ +# -- diff --git a/python/core/auto_generated/dxf/qgsdxfexport.sip.in b/python/core/auto_generated/dxf/qgsdxfexport.sip.in index 3fff4b36eb4..39d14e3832e 100644 --- a/python/core/auto_generated/dxf/qgsdxfexport.sip.in +++ b/python/core/auto_generated/dxf/qgsdxfexport.sip.in @@ -13,6 +13,7 @@ + class QgsDxfExport { @@ -91,6 +92,21 @@ unique value. Undefined }; + enum class DxfPolylineFlag + { + Closed, + Curve, + Spline, + Is3DPolyline, + Is3DPolygonMesh, + PolygonMesh, + PolyfaceMesh, + ContinuousPattern, + }; + + typedef QFlags DxfPolylineFlags; + + QgsDxfExport(); %Docstring Constructor for QgsDxfExport. diff --git a/src/core/dxf/qgsdxfexport.cpp b/src/core/dxf/qgsdxfexport.cpp index 1e2a67bf398..53256f28205 100644 --- a/src/core/dxf/qgsdxfexport.cpp +++ b/src/core/dxf/qgsdxfexport.cpp @@ -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( polylineFlags ) ); writeGroup( 43, width ); for ( int i = 0; i < points.size(); i++ ) diff --git a/src/core/dxf/qgsdxfexport.h b/src/core/dxf/qgsdxfexport.h index f0e53948519..d59302dfa10 100644 --- a/src/core/dxf/qgsdxfexport.h +++ b/src/core/dxf/qgsdxfexport.h @@ -49,6 +49,7 @@ namespace pal // SIP_SKIP class LabelPosition; } + /** * \ingroup core * \class QgsDxfExport @@ -142,6 +143,20 @@ class CORE_EXPORT QgsDxfExport Undefined = 9999 //!< Undefined }; + 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. */ From e87ea5ef85bc6f540f9afb2e0aad05ebc235c597 Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Sun, 1 Dec 2019 10:04:01 +0100 Subject: [PATCH 2/3] Add dox --- python/core/auto_additions/qgsdxfexport.py | 2 +- src/core/dxf/qgsdxfexport.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/python/core/auto_additions/qgsdxfexport.py b/python/core/auto_additions/qgsdxfexport.py index 7470f99b0af..8a3afa86d21 100644 --- a/python/core/auto_additions/qgsdxfexport.py +++ b/python/core/auto_additions/qgsdxfexport.py @@ -33,5 +33,5 @@ QgsDxfExport.DxfPolylineFlag.Is3DPolygonMesh.__doc__ = "This is a 3D polygon mes 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__ = '\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__ +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__ # -- diff --git a/src/core/dxf/qgsdxfexport.h b/src/core/dxf/qgsdxfexport.h index d59302dfa10..3463e7ef26d 100644 --- a/src/core/dxf/qgsdxfexport.h +++ b/src/core/dxf/qgsdxfexport.h @@ -143,6 +143,11 @@ 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) From ba87ae6a3c3007c355749e719edce94f4b2e1278 Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Sun, 1 Dec 2019 10:06:28 +0100 Subject: [PATCH 3/3] Fix tests --- tests/src/core/testqgsdxfexport.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/src/core/testqgsdxfexport.cpp b/tests/src/core/testqgsdxfexport.cpp index 4b3890d5109..8f431a4ca09 100644 --- a/tests/src/core/testqgsdxfexport.cpp +++ b/tests/src/core/testqgsdxfexport.cpp @@ -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() @@ -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" @@ -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" @@ -934,7 +935,7 @@ void TestQgsDxfExport::testDashedLine() " 90\n" " 6\n" " 70\n" - " 0\n" + " 128\n" " 43\n" "0.11\n" " 10\n"