Skip to content
Permalink
Browse files

DXF export improvements:

* tree view and attribute selection for layer assigment in dialog
* support fill polygons/HATCH
* represent texts as MTEXT instead of TEXT (including font, slant and weight)
* support for RGB colors when there's no exact color match
* use AutoCAD 2000 DXF (R15) instead of R12
* remove R18 test methods

Funded-By: City of Uster
Funded-By: Ville de Morges
Funded-By: SIGE
  • Loading branch information
jef-n committed Sep 8, 2014
1 parent e47642b commit 67e077853e46b0c30e0ed9f467566358a671d7dc
Showing with 3,751 additions and 1,240 deletions.
  1. +60 −0 python/core/conversions.sip
  2. +18 −8 python/core/dxf/qgsdxfexport.sip
  3. +1 −1 python/core/layertree/qgslayertreemodel.sip
  4. +1 −1 python/core/qgsmaprenderer.sip
  5. +2 −2 python/core/qgspallabeling.sip
  6. +1 −2 src/app/qgisapp.cpp
  7. +262 −9 src/app/qgsdxfexportdialog.cpp
  8. +57 −4 src/app/qgsdxfexportdialog.h
  9. +4 −3 src/app/qgsprojectlayergroupdialog.cpp
  10. +3,096 −908 src/core/dxf/qgsdxfexport.cpp
  11. +31 −19 src/core/dxf/qgsdxfexport.h
  12. +3 −3 src/core/dxf/qgsdxfpaintengine.cpp
  13. +1 −1 src/core/dxf/qgsdxfpaintengine.h
  14. +16 −30 src/core/dxf/qgsdxfpallabeling.cpp
  15. +1 −1 src/core/dxf/qgsdxfpallabeling.h
  16. +1 −1 src/core/layertree/qgslayertreegroup.cpp
  17. +1 −1 src/core/layertree/qgslayertreegroup.h
  18. +26 −13 src/core/layertree/qgslayertreemodel.cpp
  19. +1 −1 src/core/layertree/qgslayertreemodel.h
  20. +6 −1 src/core/qgsconnectionpool.h
  21. +1 −1 src/core/qgsmaprenderer.h
  22. +5 −0 src/core/qgspalgeometry.h
  23. +5 −150 src/core/qgspallabeling.cpp
  24. +2 −2 src/core/qgspallabeling.h
  25. +6 −9 src/core/symbology-ng/qgsellipsesymbollayerv2.cpp
  26. +37 −22 src/core/symbology-ng/qgsfillsymbollayerv2.cpp
  27. +2 −0 src/core/symbology-ng/qgsfillsymbollayerv2.h
  28. +12 −20 src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
  29. +11 −0 src/core/symbology-ng/qgssymbollayerv2.cpp
  30. +2 −0 src/core/symbology-ng/qgssymbollayerv2.h
  31. +1 −1 src/gui/qgsmaplayerproxymodel.h
  32. +11 −0 src/providers/postgres/qgspostgresconnpool.cpp
  33. +6 −0 src/providers/postgres/qgspostgresconnpool.h
  34. +61 −26 src/ui/qgsdxfexportdialogbase.ui
@@ -1355,6 +1355,66 @@ template<double, TYPE2>
%End
};

%MappedType QList < QPair< QgsVectorLayer *, int > >
{
%TypeHeaderCode
#include <QPair>
#include <QList>
%End

%ConvertFromTypeCode
//convert map to a python dictionary
PyObject *d;

if ((d = PyList_New( sipCpp->size() )) == NULL)
return NULL;

for ( int i = 0; i<sipCpp->size(); i++ )
{
PyObject *p;
if ((p = PyList_New(2) ) == NULL)
{
Py_DECREF(d);
return NULL;
}

PyObject *t1obj = sipConvertFromNewType(sipCpp->at(i).first, sipType_QgsVectorLayer, sipTransferObj);
PyObject *t2obj = PyInt_FromLong( (long) sipCpp->at(i).second );
PyList_SetItem( p, 0, t1obj );
PyList_SetItem( p, 1, t2obj );

PyList_SetItem( d, i, p );
}

return d;
%End
%ConvertToTypeCode
#if PY_VERSION_HEX >= 0x02050000
Py_ssize_t i = 0;
#else
int i = 0;
#endif
QList < QPair< QgsVectorLayer *, int > > *qm = new QList< QPair< QgsVectorLayer *, int > >;

for ( i = 0; i < PyList_GET_SIZE(sipPy); i++ )
{
int state;

PyObject *sipPair = PyList_GetItem( sipPy, i );
PyObject *sipLayer = PyList_GetItem( sipPair, 0 );
PyObject *sipIdx = PyList_GetItem( sipPair, 1 );

QgsVectorLayer *t1 = reinterpret_cast<QgsVectorLayer *>(sipConvertToType(sipLayer, sipType_QgsVectorLayer, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
int idx = PyLong_AsLongLong(sipIdx);
qm->append( qMakePair<QgsVectorLayer *, int>( t1, idx ) );
sipReleaseType(t1, sipType_QgsVectorLayer, state);
}

*sipCppPtr = qm;

return sipGetState(sipTransferObj);
%End
};


template <TYPE>
@@ -31,8 +31,8 @@ class QgsDxfExport
QgsDxfExport();
~QgsDxfExport();

void addLayers( QList< QgsMapLayer* >& layers );
int writeToFile( QIODevice* d );
void addLayers( const QList< QPair<QgsVectorLayer *, int > > &layers );
int writeToFile( QIODevice* d ); //maybe add progress dialog? //other parameters (e.g. scale, dpi)?

void setSymbologyScaleDenominator( double d );
double symbologyScaleDenominator() const;
@@ -49,6 +49,8 @@ class QgsDxfExport
//get closest entry in dxf palette
static int closestColorMatch( QRgb pixel );

QString layerName( const QString &id, const QgsFeature &f ) const;

//! @note available in python bindings as writeGroupInt
void writeGroup( int code, int i ) /PyName=writeGroupInt/;
//! @note available in python bindings as writeGroupDouble
@@ -58,21 +60,29 @@ class QgsDxfExport
void writeInt( int i );
void writeDouble( double d );
void writeString( const QString& s );
void writeGroup( int code, const QgsPoint &p, double z = 0.0, bool skipz = false ) /PyName=writeGroupPoint/;
void writeGroup( QColor color, int exactMatch = 62, int rgb = 420 );

int writeHandle( int code = 5, int handle = 0 );

//draw dxf primitives
void writePolyline( const QgsPolyline& line, const QString& layer, const QString& lineStyleName, int color,
void writePolyline( const QgsPolyline& line, const QString& layer, const QString& lineStyleName, QColor color,
double width = -1, bool polygon = false );

void writeSolid( const QString& layer, int color, const QgsPoint& pt1, const QgsPoint& pt2, const QgsPoint& pt3, const QgsPoint& pt4 );
void writePolygon( const QgsPolygon &polygon, const QString &layer, const QString &hatchPattern, QColor color );

void writeSolid( const QString& layer, QColor color, const QgsPoint& pt1, const QgsPoint& pt2, const QgsPoint& pt3, const QgsPoint& pt4 );

//write line (as a polyline)
void writeLine( const QgsPoint& pt1, const QgsPoint& pt2, const QString& layer, const QString& lineStyleName, int color, double width = -1 );
void writeLine( const QgsPoint& pt1, const QgsPoint& pt2, const QString& layer, const QString& lineStyleName, QColor color, double width = -1 );

void writePoint( const QString& layer, QColor color, const QgsPoint& pt );

void writePoint( const QString& layer, int color, const QgsPoint& pt );
void writeCircle( const QString& layer, QColor color, const QgsPoint& pt, double radius );

void writeCircle( const QString& layer, int color, const QgsPoint& pt, double radius );
void writeText( const QString& layer, const QString& text, const QgsPoint& pt, double size, double angle, QColor color );

void writeText( const QString& layer, const QString& text, const QgsPoint& pt, double size, double angle, int color );
void writeMText( const QString& layer, const QString& text, const QgsPoint& pt, double width, double angle, QColor color );

static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits );

@@ -95,7 +95,7 @@ class QgsLayerTreeModel : QAbstractItemModel
QList<QgsLayerTreeModelLegendNode*> layerLegendNodes( QgsLayerTreeLayer* nodeLayer );

//! Return pointer to the root node of the layer tree. Always a non-null pointer.
QgsLayerTreeGroup* rootGroup();
QgsLayerTreeGroup* rootGroup() const;
//! Reset the model and use a new root group node
//! @note added in 2.6
void setRootGroup( QgsLayerTreeGroup* newRootGroup );
@@ -57,7 +57,7 @@ class QgsLabelingEngineInterface
//! adds a diagram layer to the labeling engine
virtual int addDiagramLayer( QgsVectorLayer* layer, const QgsDiagramLayerSettings* s );
//! called for every feature
virtual void registerFeature( const QString& layerID, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ) = 0;
virtual void registerFeature( const QString& layerID, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext(), QString dxfLayer = QString::null ) = 0;
//! called for every diagram feature
virtual void registerDiagramFeature( const QString& layerID, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() );
//! called when the map is drawn and labels should be placed
@@ -449,7 +449,7 @@ class QgsPalLayerSettings
void calculateLabelSize( const QFontMetricsF* fm, QString text, double& labelX, double& labelY, QgsFeature* f = 0 );

// implementation of register feature hook
void registerFeature( QgsFeature& f, const QgsRenderContext& context );
void registerFeature( QgsFeature& f, const QgsRenderContext& context, QString dxfLayer );

void readFromLayer( QgsVectorLayer* layer );
void writeToLayer( QgsVectorLayer* layer );
@@ -696,7 +696,7 @@ class QgsPalLabeling : QgsLabelingEngineInterface
//! adds a diagram layer to the labeling engine
virtual int addDiagramLayer( QgsVectorLayer* layer, const QgsDiagramLayerSettings *s );
//! hook called when drawing for every feature in a layer
virtual void registerFeature( const QString& layerID, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() );
virtual void registerFeature( const QString& layerID, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext(), QString dxfLayer = QString::null );
virtual void registerDiagramFeature( const QString& layerID, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() );
//! called when the map is drawn and labels should be placed
virtual void drawLabeling( QgsRenderContext& context );
@@ -4013,8 +4013,7 @@ void QgisApp::dxfExport()
if ( d.exec() == QDialog::Accepted )
{
QgsDxfExport dxfExport;
QList<QgsMapLayer*> layerList = d.layers();
dxfExport.addLayers( layerList );
dxfExport.addLayers( d.layers() );
dxfExport.setSymbologyScaleDenominator( d.symbologyScale() );
dxfExport.setSymbologyExport( d.symbologyMode() );
if ( mapCanvas() )

1 comment on commit 67e0778

@3nids

This comment has been minimized.

Copy link
Member

@3nids 3nids commented on 67e0778 Sep 26, 2014

Thanks for the job, Jürgen.

While testing, I could not find the visibility groups in the GUI. Is this the layerattribute combo? in my case, it was disabled.

Please sign in to comment.
You can’t perform that action at this time.