QGIS API Documentation  2.17.0-Master (bf77d09)
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 
24 #include <QColor>
25 #include <QList>
26 #include <QTextStream>
27 
28 class QgsMapLayer;
29 class QgsPoint;
30 class QgsSymbolLayerV2;
31 class QIODevice;
33 
34 namespace pal
35 {
36  class LabelPosition;
37 };
38 
42 class CORE_EXPORT QgsDxfExport
43 {
44  public:
46  {
47  NoSymbology = 0, //export only data
48  FeatureSymbology, //Keeps the number of features and export symbology per feature (using the first symbol level)
49  SymbolLayerSymbology //Exports one feature per symbol layer (considering symbol levels)
50  };
51 
52  QgsDxfExport();
53  QgsDxfExport( const QgsDxfExport &dxfExport );
54  ~QgsDxfExport();
55  QgsDxfExport &operator=( const QgsDxfExport &dxfExport );
56 
62  void addLayers( const QList< QPair<QgsVectorLayer *, int > > &layers );
63 
70  int writeToFile( QIODevice *d, const QString& codec ); //maybe add progress dialog? other parameters (e.g. scale, dpi)?
71 
76  void setSymbologyScaleDenominator( double d ) { mSymbologyScaleDenominator = d; }
77 
83  double symbologyScaleDenominator() const { return mSymbologyScaleDenominator; }
84 
89  void setMapUnits( QGis::UnitType u ) { mMapUnits = u; }
90 
96  QGis::UnitType mapUnits() const { return mMapUnits; }
97 
102  void setSymbologyExport( SymbologyExport e ) { mSymbologyExport = e; }
103 
109  SymbologyExport symbologyExport() const { return mSymbologyExport; }
110 
115  void setExtent( const QgsRectangle &r ) { mExtent = r; }
116 
122  QgsRectangle extent() const { return mExtent; }
123 
130  void setLayerTitleAsName( bool layerTitleAsName ) { mLayerTitleAsName = layerTitleAsName; }
131 
137  bool layerTitleAsName() { return mLayerTitleAsName; }
138 
143  static int closestColorMatch( QRgb color );
144 
151  QString layerName( const QString &id, const QgsFeature &f ) const;
152 
159  QString layerName( QgsVectorLayer *vl ) const;
160 
167  void writeGroup( int code, int i );
168 
175  void writeGroup( int code, double d );
176 
182  void writeGroup( int code, const QString &s );
183 
193  Q_DECL_DEPRECATED void writeGroup( int code, const QgsPoint &p, double z = 0.0, bool skipz = false );
194 
202  void writeGroup( int code, const QgsPointV2 &p );
203 
212  void writeGroup( const QColor& color, int exactMatch = 62, int rgbCode = 420, int transparencyCode = 440 );
213 
218  void writeGroupCode( int code );
219 
224  void writeInt( int i );
225 
230  void writeDouble( double d );
231 
236  void writeString( const QString &s );
237 
244  int writeHandle( int code = 5, int handle = 0 );
245 
255  Q_DECL_DEPRECATED void writePolyline( const QgsPolyline &line, const QString &layer, const QString &lineStyleName, const QColor& color, double width = -1 );
256 
267  void writePolyline( const QgsPointSequenceV2 &line, const QString &layer, const QString &lineStyleName, const QColor& color, double width = -1 );
268 
277  Q_DECL_DEPRECATED void writePolygon( const QgsPolygon &polygon, const QString &layer, const QString &hatchPattern, const QColor& color );
278 
288  void writePolygon( const QgsRingSequenceV2 &polygon, const QString &layer, const QString &hatchPattern, const QColor& color );
289 
300  Q_DECL_DEPRECATED void writeSolid( const QString &layer, const QColor& color, const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, const QgsPoint &pt4 );
301 
304  Q_DECL_DEPRECATED void writeLine( const QgsPoint &pt1, const QgsPoint &pt2, const QString &layer, const QString &lineStyleName, const QColor& color, double width = -1 );
305 
308  void writeLine( const QgsPointV2 &pt1, const QgsPointV2 &pt2, const QString &layer, const QString &lineStyleName, const QColor& color, double width = -1 );
309 
312  Q_DECL_DEPRECATED void writePoint( const QString &layer, const QColor& color, const QgsPoint &pt );
313 
317  void writePoint( const QString &layer, const QColor& color, const QgsPointV2 &pt );
318 
321  Q_DECL_DEPRECATED void writeFilledCircle( const QString &layer, const QColor& color, const QgsPoint &pt, double radius );
322 
326  void writeFilledCircle( const QString &layer, const QColor& color, const QgsPointV2 &pt, double radius );
327 
330  Q_DECL_DEPRECATED void writeCircle( const QString &layer, const QColor& color, const QgsPoint &pt, double radius, const QString &lineStyleName, double width );
331 
335  void writeCircle( const QString &layer, const QColor& color, const QgsPointV2 &pt, double radius, const QString &lineStyleName, double width );
336 
339  Q_DECL_DEPRECATED void writeText( const QString &layer, const QString &text, const QgsPoint &pt, double size, double angle, const QColor& color );
340 
344  void writeText( const QString &layer, const QString &text, const QgsPointV2 &pt, double size, double angle, const QColor& color );
345 
348  Q_DECL_DEPRECATED void writeMText( const QString &layer, const QString &text, const QgsPoint &pt, double width, double angle, const QColor& color );
349 
353  void writeMText( const QString &layer, const QString &text, const QgsPointV2 &pt, double width, double angle, const QColor& color );
354 
355  static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits );
356 
358  static QString dxfLayerName( const QString &name );
359 
361  static QString dxfEncoding( const QString &name );
362 
364  static QStringList encodings();
365 
373  void drawLabel( QString layerId, QgsRenderContext& context, pal::LabelPosition* label, const QgsPalLayerSettings &settings );
374 
380  void registerDxfLayer( QString layerId, QgsFeatureId fid, QString layer );
381 
382  private:
384 
386  QgsRectangle mExtent;
388  double mSymbologyScaleDenominator;
389  SymbologyExport mSymbologyExport;
390  QGis::UnitType mMapUnits;
391  bool mLayerTitleAsName;
392 
393  QTextStream mTextStream;
394 
395  static int mDxfColors[][3];
396  static const char *mDxfEncodings[][2];
397 
398  int mSymbolLayerCounter; //internal counter
399  int mNextHandleId;
400  int mBlockCounter;
401 
402  QHash< const QgsSymbolLayerV2*, QString > mLineStyles; //symbol layer name types
403  QHash< const QgsSymbolLayerV2*, QString > mPointSymbolBlocks; //reference to point symbol blocks
404 
405  //AC1009
406  void writeHeader( const QString& codepage );
407  void writeTables();
408  void writeBlocks();
409  void writeEntities();
410  void writeEntitiesSymbolLevels( QgsVectorLayer *layer );
411  void writeEndFile();
412 
413  void startSection();
414  void endSection();
415 
416  void writePoint( const QgsPointV2 &pt, const QString &layer, const QColor& color, QgsSymbolV2RenderContext &ctx, const QgsSymbolLayerV2 *symbolLayer, const QgsSymbolV2 *symbol, double angle );
417  void writeDefaultLinetypes();
418  void writeSymbolLayerLinetype( const QgsSymbolLayerV2 *symbolLayer );
419  void writeLinetype( const QString &styleName, const QVector<qreal> &pattern, QgsSymbolV2::OutputUnit u );
420 
421  QgsRectangle dxfExtent() const;
422 
423  void addFeature( QgsSymbolV2RenderContext &ctx, const QString &layer, const QgsSymbolLayerV2 *symbolLayer, const QgsSymbolV2 *symbol );
424 
425  //returns dxf palette index from symbol layer color
426  static QColor colorFromSymbolLayer( const QgsSymbolLayerV2 *symbolLayer, QgsSymbolV2RenderContext &ctx );
427  QString lineStyleFromSymbolLayer( const QgsSymbolLayerV2 *symbolLayer );
428 
429  //functions for dxf palette
430  static int color_distance( QRgb p1, int index );
431  static QRgb createRgbEntry( qreal r, qreal g, qreal b );
432 
433  //helper functions for symbology export
434  QgsRenderContext renderContext() const;
435 
437  static int nLineTypes( const QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2*> > &symbolLayers );
438  static bool hasDataDefinedProperties( const QgsSymbolLayerV2 *sl, const QgsSymbolV2 *symbol );
439  double dashSize() const;
440  double dotSize() const;
441  double dashSeparatorSize() const;
442  double sizeToMapUnits( double s ) const;
443  static QString lineNameFromPenStyle( Qt::PenStyle style );
444  bool layerIsScaleBasedVisible( const QgsMapLayer *layer ) const;
445 
446  QHash<QString, int> mBlockHandles;
447  QString mBlockHandle;
448 
451 };
452 
453 #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:76
OutputUnit
The unit of the output.
Definition: qgssymbolv2.h:65
SymbologyExport symbologyExport() const
Get symbology export mode.
Definition: qgsdxfexport.h:109
QGis::UnitType mapUnits() const
Retrieve map units.
Definition: qgsdxfexport.h:96
void setSymbologyExport(SymbologyExport e)
Set symbology export mode.
Definition: qgsdxfexport.h:102
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:122
Point geometry type, with support for z-dimension and m-values.
Definition: qgspointv2.h:34
A class to represent a point.
Definition: qgspoint.h:117
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:83
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:130
void setExtent(const QgsRectangle &r)
Set extent of area to export.
Definition: qgsdxfexport.h:115
void setMapUnits(QGis::UnitType u)
Set map units.
Definition: qgsdxfexport.h:89
bool layerTitleAsName()
Retrieve wether layer title (where set) instead of name shall be use.
Definition: qgsdxfexport.h:137
LabelPosition is a candidate feature label position.
Definition: labelposition.h:51
UnitType
Map units that qgis supports.
Definition: qgis.h:159
qint64 QgsFeatureId
Definition: qgsfeature.h:31
Represents a vector layer which manages a vector based data sets.