QGIS API Documentation  2.15.0-Master (5773d0d)
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 
39 class CORE_EXPORT QgsDxfExport
40 {
41  public:
43  {
44  NoSymbology = 0, //export only data
45  FeatureSymbology, //Keeps the number of features and export symbology per feature (using the first symbol level)
46  SymbolLayerSymbology //Exports one feature per symbol layer (considering symbol levels)
47  };
48 
49  QgsDxfExport();
50  QgsDxfExport( const QgsDxfExport &dxfExport );
51  ~QgsDxfExport();
52  QgsDxfExport &operator=( const QgsDxfExport &dxfExport );
53 
59  void addLayers( const QList< QPair<QgsVectorLayer *, int > > &layers );
60 
67  int writeToFile( QIODevice *d, const QString& codec ); //maybe add progress dialog? other parameters (e.g. scale, dpi)?
68 
73  void setSymbologyScaleDenominator( double d ) { mSymbologyScaleDenominator = d; }
74 
80  double symbologyScaleDenominator() const { return mSymbologyScaleDenominator; }
81 
86  void setMapUnits( QGis::UnitType u ) { mMapUnits = u; }
87 
93  QGis::UnitType mapUnits() const { return mMapUnits; }
94 
99  void setSymbologyExport( SymbologyExport e ) { mSymbologyExport = e; }
100 
106  SymbologyExport symbologyExport() const { return mSymbologyExport; }
107 
112  void setExtent( const QgsRectangle &r ) { mExtent = r; }
113 
119  QgsRectangle extent() const { return mExtent; }
120 
127  void setLayerTitleAsName( bool layerTitleAsName ) { mLayerTitleAsName = layerTitleAsName; }
128 
134  bool layerTitleAsName() { return mLayerTitleAsName; }
135 
140  static int closestColorMatch( QRgb color );
141 
148  QString layerName( const QString &id, const QgsFeature &f ) const;
149 
156  QString layerName( QgsVectorLayer *vl ) const;
157 
164  void writeGroup( int code, int i );
165 
172  void writeGroup( int code, double d );
173 
179  void writeGroup( int code, const QString &s );
180 
190  Q_DECL_DEPRECATED void writeGroup( int code, const QgsPoint &p, double z = 0.0, bool skipz = false );
191 
199  void writeGroup( int code, const QgsPointV2 &p );
200 
209  void writeGroup( const QColor& color, int exactMatch = 62, int rgbCode = 420, int transparencyCode = 440 );
210 
215  void writeGroupCode( int code );
216 
221  void writeInt( int i );
222 
227  void writeDouble( double d );
228 
233  void writeString( const QString &s );
234 
241  int writeHandle( int code = 5, int handle = 0 );
242 
252  Q_DECL_DEPRECATED void writePolyline( const QgsPolyline &line, const QString &layer, const QString &lineStyleName, const QColor& color, double width = -1 );
253 
264  void writePolyline( const QgsPointSequenceV2 &line, const QString &layer, const QString &lineStyleName, const QColor& color, double width = -1 );
265 
274  Q_DECL_DEPRECATED void writePolygon( const QgsPolygon &polygon, const QString &layer, const QString &hatchPattern, const QColor& color );
275 
285  void writePolygon( const QgsRingSequenceV2 &polygon, const QString &layer, const QString &hatchPattern, const QColor& color );
286 
297  Q_DECL_DEPRECATED void writeSolid( const QString &layer, const QColor& color, const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, const QgsPoint &pt4 );
298 
301  Q_DECL_DEPRECATED void writeLine( const QgsPoint &pt1, const QgsPoint &pt2, const QString &layer, const QString &lineStyleName, const QColor& color, double width = -1 );
302 
305  void writeLine( const QgsPointV2 &pt1, const QgsPointV2 &pt2, const QString &layer, const QString &lineStyleName, const QColor& color, double width = -1 );
306 
309  Q_DECL_DEPRECATED void writePoint( const QString &layer, const QColor& color, const QgsPoint &pt );
310 
314  void writePoint( const QString &layer, const QColor& color, const QgsPointV2 &pt );
315 
318  Q_DECL_DEPRECATED void writeFilledCircle( const QString &layer, const QColor& color, const QgsPoint &pt, double radius );
319 
323  void writeFilledCircle( const QString &layer, const QColor& color, const QgsPointV2 &pt, double radius );
324 
327  Q_DECL_DEPRECATED void writeCircle( const QString &layer, const QColor& color, const QgsPoint &pt, double radius, const QString &lineStyleName, double width );
328 
332  void writeCircle( const QString &layer, const QColor& color, const QgsPointV2 &pt, double radius, const QString &lineStyleName, double width );
333 
336  Q_DECL_DEPRECATED void writeText( const QString &layer, const QString &text, const QgsPoint &pt, double size, double angle, const QColor& color );
337 
341  void writeText( const QString &layer, const QString &text, const QgsPointV2 &pt, double size, double angle, const QColor& color );
342 
345  Q_DECL_DEPRECATED void writeMText( const QString &layer, const QString &text, const QgsPoint &pt, double width, double angle, const QColor& color );
346 
350  void writeMText( const QString &layer, const QString &text, const QgsPointV2 &pt, double width, double angle, const QColor& color );
351 
352  static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits );
353 
355  static QString dxfLayerName( const QString &name );
356 
358  static QString dxfEncoding( const QString &name );
359 
361  static QStringList encodings();
362 
370  void drawLabel( QString layerId, QgsRenderContext& context, pal::LabelPosition* label, const QgsPalLayerSettings &settings );
371 
377  void registerDxfLayer( QString layerId, QgsFeatureId fid, QString layer );
378 
379  private:
381 
383  QgsRectangle mExtent;
385  double mSymbologyScaleDenominator;
386  SymbologyExport mSymbologyExport;
387  QGis::UnitType mMapUnits;
388  bool mLayerTitleAsName;
389 
390  QTextStream mTextStream;
391 
392  static int mDxfColors[][3];
393  static const char *mDxfEncodings[][2];
394 
395  int mSymbolLayerCounter; //internal counter
396  int mNextHandleId;
397  int mBlockCounter;
398 
399  QHash< const QgsSymbolLayerV2*, QString > mLineStyles; //symbol layer name types
400  QHash< const QgsSymbolLayerV2*, QString > mPointSymbolBlocks; //reference to point symbol blocks
401 
402  //AC1009
403  void writeHeader( const QString& codepage );
404  void writeTables();
405  void writeBlocks();
406  void writeEntities();
407  void writeEntitiesSymbolLevels( QgsVectorLayer *layer );
408  void writeEndFile();
409 
410  void startSection();
411  void endSection();
412 
413  void writePoint( const QgsPointV2 &pt, const QString &layer, const QColor& color, QgsSymbolV2RenderContext &ctx, const QgsSymbolLayerV2 *symbolLayer, const QgsSymbolV2 *symbol, double angle );
414  void writeDefaultLinetypes();
415  void writeSymbolLayerLinetype( const QgsSymbolLayerV2 *symbolLayer );
416  void writeLinetype( const QString &styleName, const QVector<qreal> &pattern, QgsSymbolV2::OutputUnit u );
417 
418  QgsRectangle dxfExtent() const;
419 
420  void addFeature( QgsSymbolV2RenderContext &ctx, const QString &layer, const QgsSymbolLayerV2 *symbolLayer, const QgsSymbolV2 *symbol );
421 
422  //returns dxf palette index from symbol layer color
423  static QColor colorFromSymbolLayer( const QgsSymbolLayerV2 *symbolLayer, QgsSymbolV2RenderContext &ctx );
424  QString lineStyleFromSymbolLayer( const QgsSymbolLayerV2 *symbolLayer );
425 
426  //functions for dxf palette
427  static int color_distance( QRgb p1, int index );
428  static QRgb createRgbEntry( qreal r, qreal g, qreal b );
429 
430  //helper functions for symbology export
431  QgsRenderContext renderContext() const;
432 
434  static int nLineTypes( const QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2*> > &symbolLayers );
435  static bool hasDataDefinedProperties( const QgsSymbolLayerV2 *sl, const QgsSymbolV2 *symbol );
436  double dashSize() const;
437  double dotSize() const;
438  double dashSeparatorSize() const;
439  double sizeToMapUnits( double s ) const;
440  static QString lineNameFromPenStyle( Qt::PenStyle style );
441  bool layerIsScaleBasedVisible( const QgsMapLayer *layer ) const;
442 
443  QHash<QString, int> mBlockHandles;
444  QString mBlockHandle;
445 
448 };
449 
450 #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:73
OutputUnit
The unit of the output.
Definition: qgssymbolv2.h:62
SymbologyExport symbologyExport() const
Get symbology export mode.
Definition: qgsdxfexport.h:106
QGis::UnitType mapUnits() const
Retrieve map units.
Definition: qgsdxfexport.h:93
void setSymbologyExport(SymbologyExport e)
Set symbology export mode.
Definition: qgsdxfexport.h:99
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:119
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:80
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:127
void setExtent(const QgsRectangle &r)
Set extent of area to export.
Definition: qgsdxfexport.h:112
void setMapUnits(QGis::UnitType u)
Set map units.
Definition: qgsdxfexport.h:86
bool layerTitleAsName()
Retrieve wether layer title (where set) instead of name shall be use.
Definition: qgsdxfexport.h:134
LabelPosition is a candidate feature label position.
Definition: labelposition.h:50
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.