Skip to content

Commit

Permalink
DXF export improvements:
Browse files Browse the repository at this point in the history
* 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 26, 2014
1 parent e47642b commit 67e0778
Show file tree
Hide file tree
Showing 34 changed files with 3,751 additions and 1,240 deletions.
60 changes: 60 additions & 0 deletions python/core/conversions.sip
Expand Up @@ -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>
Expand Down
26 changes: 18 additions & 8 deletions python/core/dxf/qgsdxfexport.sip
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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 );

Expand Down
2 changes: 1 addition & 1 deletion python/core/layertree/qgslayertreemodel.sip
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsmaprenderer.sip
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions python/core/qgspallabeling.sip
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
3 changes: 1 addition & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -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() )
Expand Down

1 comment on commit 67e0778

@3nids
Copy link
Member

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

Choose a reason for hiding this comment

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

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.