Skip to content

Commit 67e0778

Browse files
committed
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
1 parent e47642b commit 67e0778

34 files changed

+3751
-1240
lines changed

python/core/conversions.sip

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,66 @@ template<double, TYPE2>
13551355
%End
13561356
};
13571357

1358+
%MappedType QList < QPair< QgsVectorLayer *, int > >
1359+
{
1360+
%TypeHeaderCode
1361+
#include <QPair>
1362+
#include <QList>
1363+
%End
1364+
1365+
%ConvertFromTypeCode
1366+
//convert map to a python dictionary
1367+
PyObject *d;
1368+
1369+
if ((d = PyList_New( sipCpp->size() )) == NULL)
1370+
return NULL;
1371+
1372+
for ( int i = 0; i<sipCpp->size(); i++ )
1373+
{
1374+
PyObject *p;
1375+
if ((p = PyList_New(2) ) == NULL)
1376+
{
1377+
Py_DECREF(d);
1378+
return NULL;
1379+
}
1380+
1381+
PyObject *t1obj = sipConvertFromNewType(sipCpp->at(i).first, sipType_QgsVectorLayer, sipTransferObj);
1382+
PyObject *t2obj = PyInt_FromLong( (long) sipCpp->at(i).second );
1383+
PyList_SetItem( p, 0, t1obj );
1384+
PyList_SetItem( p, 1, t2obj );
1385+
1386+
PyList_SetItem( d, i, p );
1387+
}
1388+
1389+
return d;
1390+
%End
1391+
%ConvertToTypeCode
1392+
#if PY_VERSION_HEX >= 0x02050000
1393+
Py_ssize_t i = 0;
1394+
#else
1395+
int i = 0;
1396+
#endif
1397+
QList < QPair< QgsVectorLayer *, int > > *qm = new QList< QPair< QgsVectorLayer *, int > >;
1398+
1399+
for ( i = 0; i < PyList_GET_SIZE(sipPy); i++ )
1400+
{
1401+
int state;
1402+
1403+
PyObject *sipPair = PyList_GetItem( sipPy, i );
1404+
PyObject *sipLayer = PyList_GetItem( sipPair, 0 );
1405+
PyObject *sipIdx = PyList_GetItem( sipPair, 1 );
1406+
1407+
QgsVectorLayer *t1 = reinterpret_cast<QgsVectorLayer *>(sipConvertToType(sipLayer, sipType_QgsVectorLayer, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
1408+
int idx = PyLong_AsLongLong(sipIdx);
1409+
qm->append( qMakePair<QgsVectorLayer *, int>( t1, idx ) );
1410+
sipReleaseType(t1, sipType_QgsVectorLayer, state);
1411+
}
1412+
1413+
*sipCppPtr = qm;
1414+
1415+
return sipGetState(sipTransferObj);
1416+
%End
1417+
};
13581418

13591419

13601420
template <TYPE>

python/core/dxf/qgsdxfexport.sip

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class QgsDxfExport
3131
QgsDxfExport();
3232
~QgsDxfExport();
3333

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

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

52+
QString layerName( const QString &id, const QgsFeature &f ) const;
53+
5254
//! @note available in python bindings as writeGroupInt
5355
void writeGroup( int code, int i ) /PyName=writeGroupInt/;
5456
//! @note available in python bindings as writeGroupDouble
@@ -58,21 +60,29 @@ class QgsDxfExport
5860
void writeInt( int i );
5961
void writeDouble( double d );
6062
void writeString( const QString& s );
63+
void writeGroup( int code, const QgsPoint &p, double z = 0.0, bool skipz = false ) /PyName=writeGroupPoint/;
64+
void writeGroup( QColor color, int exactMatch = 62, int rgb = 420 );
65+
66+
int writeHandle( int code = 5, int handle = 0 );
6167

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

66-
void writeSolid( const QString& layer, int color, const QgsPoint& pt1, const QgsPoint& pt2, const QgsPoint& pt3, const QgsPoint& pt4 );
72+
void writePolygon( const QgsPolygon &polygon, const QString &layer, const QString &hatchPattern, QColor color );
73+
74+
void writeSolid( const QString& layer, QColor color, const QgsPoint& pt1, const QgsPoint& pt2, const QgsPoint& pt3, const QgsPoint& pt4 );
6775

6876
//write line (as a polyline)
69-
void writeLine( const QgsPoint& pt1, const QgsPoint& pt2, const QString& layer, const QString& lineStyleName, int color, double width = -1 );
77+
void writeLine( const QgsPoint& pt1, const QgsPoint& pt2, const QString& layer, const QString& lineStyleName, QColor color, double width = -1 );
78+
79+
void writePoint( const QString& layer, QColor color, const QgsPoint& pt );
7080

71-
void writePoint( const QString& layer, int color, const QgsPoint& pt );
81+
void writeCircle( const QString& layer, QColor color, const QgsPoint& pt, double radius );
7282

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

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

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

python/core/layertree/qgslayertreemodel.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class QgsLayerTreeModel : QAbstractItemModel
9595
QList<QgsLayerTreeModelLegendNode*> layerLegendNodes( QgsLayerTreeLayer* nodeLayer );
9696

9797
//! Return pointer to the root node of the layer tree. Always a non-null pointer.
98-
QgsLayerTreeGroup* rootGroup();
98+
QgsLayerTreeGroup* rootGroup() const;
9999
//! Reset the model and use a new root group node
100100
//! @note added in 2.6
101101
void setRootGroup( QgsLayerTreeGroup* newRootGroup );

python/core/qgsmaprenderer.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class QgsLabelingEngineInterface
5757
//! adds a diagram layer to the labeling engine
5858
virtual int addDiagramLayer( QgsVectorLayer* layer, const QgsDiagramLayerSettings* s );
5959
//! called for every feature
60-
virtual void registerFeature( const QString& layerID, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ) = 0;
60+
virtual void registerFeature( const QString& layerID, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext(), QString dxfLayer = QString::null ) = 0;
6161
//! called for every diagram feature
6262
virtual void registerDiagramFeature( const QString& layerID, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() );
6363
//! called when the map is drawn and labels should be placed

python/core/qgspallabeling.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ class QgsPalLayerSettings
449449
void calculateLabelSize( const QFontMetricsF* fm, QString text, double& labelX, double& labelY, QgsFeature* f = 0 );
450450

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

454454
void readFromLayer( QgsVectorLayer* layer );
455455
void writeToLayer( QgsVectorLayer* layer );
@@ -696,7 +696,7 @@ class QgsPalLabeling : QgsLabelingEngineInterface
696696
//! adds a diagram layer to the labeling engine
697697
virtual int addDiagramLayer( QgsVectorLayer* layer, const QgsDiagramLayerSettings *s );
698698
//! hook called when drawing for every feature in a layer
699-
virtual void registerFeature( const QString& layerID, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() );
699+
virtual void registerFeature( const QString& layerID, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext(), QString dxfLayer = QString::null );
700700
virtual void registerDiagramFeature( const QString& layerID, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() );
701701
//! called when the map is drawn and labels should be placed
702702
virtual void drawLabeling( QgsRenderContext& context );

src/app/qgisapp.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4013,8 +4013,7 @@ void QgisApp::dxfExport()
40134013
if ( d.exec() == QDialog::Accepted )
40144014
{
40154015
QgsDxfExport dxfExport;
4016-
QList<QgsMapLayer*> layerList = d.layers();
4017-
dxfExport.addLayers( layerList );
4016+
dxfExport.addLayers( d.layers() );
40184017
dxfExport.setSymbologyScaleDenominator( d.symbologyScale() );
40194018
dxfExport.setSymbologyExport( d.symbologyMode() );
40204019
if ( mapCanvas() )

0 commit comments

Comments
 (0)