QGIS API Documentation  2.13.0-Master
qgsdxfexport.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdxfexport.h
3  --------------
4  begin : September 2013
5  copyright : (C) 2013 by Marco Hugentobler
6  email : marco at sourcepole dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSDXFEXPORT_H
19 #define QGSDXFEXPORT_H
20 
21 #include "qgsgeometry.h"
22 #include "qgssymbolv2.h"
23 #include <QColor>
24 #include <QList>
25 #include <QTextStream>
26 
27 class QgsMapLayer;
28 class QgsPoint;
29 class QgsSymbolLayerV2;
30 class QIODevice;
31 
32 class CORE_EXPORT QgsDxfExport
33 {
34  public:
36  {
37  NoSymbology = 0, //export only data
38  FeatureSymbology, //Keeps the number of features and export symbology per feature (using the first symbol level)
39  SymbolLayerSymbology //Exports one feature per symbol layer (considering symbol levels)
40  };
41 
42  QgsDxfExport();
43  QgsDxfExport( const QgsDxfExport &dxfExport );
44  ~QgsDxfExport();
45  QgsDxfExport &operator=( const QgsDxfExport &dxfExport );
46 
52  void addLayers( const QList< QPair<QgsVectorLayer *, int > > &layers );
53 
60  int writeToFile( QIODevice *d, const QString& codec ); //maybe add progress dialog? other parameters (e.g. scale, dpi)?
61 
66  void setSymbologyScaleDenominator( double d ) { mSymbologyScaleDenominator = d; }
67 
73  double symbologyScaleDenominator() const { return mSymbologyScaleDenominator; }
74 
79  void setMapUnits( QGis::UnitType u ) { mMapUnits = u; }
80 
86  QGis::UnitType mapUnits() const { return mMapUnits; }
87 
92  void setSymbologyExport( SymbologyExport e ) { mSymbologyExport = e; }
93 
99  SymbologyExport symbologyExport() const { return mSymbologyExport; }
100 
105  void setExtent( const QgsRectangle &r ) { mExtent = r; }
106 
112  QgsRectangle extent() const { return mExtent; }
113 
120  void setLayerTitleAsName( bool layerTitleAsName ) { mLayerTitleAsName = layerTitleAsName; }
121 
127  bool layerTitleAsName() { return mLayerTitleAsName; }
128 
133  static int closestColorMatch( QRgb color );
134 
141  QString layerName( const QString &id, const QgsFeature &f ) const;
142 
149  QString layerName( QgsVectorLayer *vl ) const;
150 
157  void writeGroup( int code, int i );
158 
165  void writeGroup( int code, double d );
166 
172  void writeGroup( int code, const QString &s );
173 
182  void writeGroup( int code, const QgsPoint &p, double z = 0.0, bool skipz = false );
183 
192  void writeGroup( const QColor& color, int exactMatch = 62, int rgbCode = 420, int transparencyCode = 440 );
193 
198  void writeGroupCode( int code );
199 
204  void writeInt( int i );
205 
210  void writeDouble( double d );
211 
216  void writeString( const QString &s );
217 
224  int writeHandle( int code = 5, int handle = 0 );
225 
234  void writePolyline( const QgsPolyline &line, const QString &layer, const QString &lineStyleName, const QColor& color, double width = -1 );
235 
243  void writePolygon( const QgsPolygon &polygon, const QString &layer, const QString &hatchPattern, const QColor& color );
244 
255  Q_DECL_DEPRECATED void writeSolid( const QString &layer, const QColor& color, const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, const QgsPoint &pt4 );
256 
258  void writeLine( const QgsPoint &pt1, const QgsPoint &pt2, const QString &layer, const QString &lineStyleName, const QColor& color, double width = -1 );
259 
261  void writePoint( const QString &layer, const QColor& color, const QgsPoint &pt );
262 
264  void writeFilledCircle( const QString &layer, const QColor& color, const QgsPoint &pt, double radius );
265 
267  void writeCircle( const QString &layer, const QColor& color, const QgsPoint &pt, double radius, const QString &lineStyleName, double width );
268 
270  void writeText( const QString &layer, const QString &text, const QgsPoint &pt, double size, double angle, const QColor& color );
271 
273  void writeMText( const QString &layer, const QString &text, const QgsPoint &pt, double width, double angle, const QColor& color );
274 
275  static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits );
276 
278  static QString dxfLayerName( const QString &name );
279 
281  static QString dxfEncoding( const QString &name );
282 
284  static QStringList encodings();
285 
286  private:
288 
290  QgsRectangle mExtent;
292  double mSymbologyScaleDenominator;
293  SymbologyExport mSymbologyExport;
294  QGis::UnitType mMapUnits;
295  bool mLayerTitleAsName;
296 
297  QTextStream mTextStream;
298 
299  static int mDxfColors[][3];
300  static const char *mDxfEncodings[][2];
301 
302  int mSymbolLayerCounter; //internal counter
303  int mNextHandleId;
304  int mBlockCounter;
305 
306  QHash< const QgsSymbolLayerV2*, QString > mLineStyles; //symbol layer name types
307  QHash< const QgsSymbolLayerV2*, QString > mPointSymbolBlocks; //reference to point symbol blocks
308 
309  //AC1009
310  void writeHeader( const QString& codepage );
311  void writeTables();
312  void writeBlocks();
313  void writeEntities();
314  void writeEntitiesSymbolLevels( QgsVectorLayer *layer );
315  void writeEndFile();
316 
317  void startSection();
318  void endSection();
319 
320  void writePoint( const QgsPoint &pt, const QString &layer, const QColor& color, const QgsFeature *f, const QgsSymbolLayerV2 *symbolLayer, const QgsSymbolV2 *symbol );
321  void writeVertex( const QgsPoint &pt, const QString &layer );
322  void writeDefaultLinetypes();
323  void writeSymbolLayerLinetype( const QgsSymbolLayerV2 *symbolLayer );
324  void writeLinetype( const QString &styleName, const QVector<qreal> &pattern, QgsSymbolV2::OutputUnit u );
325 
326  QgsRectangle dxfExtent() const;
327 
328  void addFeature( QgsSymbolV2RenderContext &ctx, const QString &layer, const QgsSymbolLayerV2 *symbolLayer, const QgsSymbolV2 *symbol );
329 
330  //returns dxf palette index from symbol layer color
331  static QColor colorFromSymbolLayer( const QgsSymbolLayerV2 *symbolLayer, QgsSymbolV2RenderContext &ctx );
332  QString lineStyleFromSymbolLayer( const QgsSymbolLayerV2 *symbolLayer );
333 
334  //functions for dxf palette
335  static int color_distance( QRgb p1, int index );
336  static QRgb createRgbEntry( qreal r, qreal g, qreal b );
337 
338  //helper functions for symbology export
339  QgsRenderContext renderContext() const;
340 
342  static int nLineTypes( const QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2*> > &symbolLayers );
343  static bool hasDataDefinedProperties( const QgsSymbolLayerV2 *sl, const QgsSymbolV2 *symbol );
344  double dashSize() const;
345  double dotSize() const;
346  double dashSeparatorSize() const;
347  double sizeToMapUnits( double s ) const;
348  static QString lineNameFromPenStyle( Qt::PenStyle style );
349  bool layerIsScaleBasedVisible( const QgsMapLayer *layer ) const;
350 
351  QHash<QString, int> mBlockHandles;
352  QString mBlockHandle;
353 };
354 
355 #endif // QGSDXFEXPORT_H
static unsigned index
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:49
void setSymbologyScaleDenominator(double d)
Set reference scale for output.
Definition: qgsdxfexport.h:66
OutputUnit
The unit of the output.
Definition: qgssymbolv2.h:59
SymbologyExport symbologyExport() const
Get symbology export mode.
Definition: qgsdxfexport.h:99
QGis::UnitType mapUnits() const
Retrieve map units.
Definition: qgsdxfexport.h:86
void setSymbologyExport(SymbologyExport e)
Set symbology export mode.
Definition: qgsdxfexport.h:92
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
QgsRectangle extent() const
Get extent of area to export.
Definition: qgsdxfexport.h:112
A class to represent a point.
Definition: qgspoint.h:65
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
double symbologyScaleDenominator() const
Retrieve reference scale for output.
Definition: qgsdxfexport.h:73
Contains information about the context of a rendering operation.
void setLayerTitleAsName(bool layerTitleAsName)
Enable use of title (where set) instead of layer name, when attribute index of corresponding layer in...
Definition: qgsdxfexport.h:120
void setExtent(const QgsRectangle &r)
Set extent of area to export.
Definition: qgsdxfexport.h:105
void setMapUnits(QGis::UnitType u)
Set map units.
Definition: qgsdxfexport.h:79
bool layerTitleAsName()
Retrieve wether layer title (where set) instead of name shall be use.
Definition: qgsdxfexport.h:127
UnitType
Map units that qgis supports.
Definition: qgis.h:155
Represents a vector layer which manages a vector based data sets.