QGIS API Documentation  2.17.0-Master (0497e4a)
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 "qgsmapsettings.h"
24 
25 #include <QColor>
26 #include <QList>
27 #include <QTextStream>
28 
29 class QgsMapLayer;
30 class QgsPoint;
31 class QgsSymbolLayerV2;
32 class QIODevice;
34 
35 namespace pal
36 {
37  class LabelPosition;
38 };
39 
43 class CORE_EXPORT QgsDxfExport
44 {
45  public:
47  {
48  NoSymbology = 0, //export only data
49  FeatureSymbology, //Keeps the number of features and export symbology per feature (using the first symbol level)
50  SymbolLayerSymbology //Exports one feature per symbol layer (considering symbol levels)
51  };
52 
53  QgsDxfExport();
54  QgsDxfExport( const QgsDxfExport &dxfExport );
55  ~QgsDxfExport();
56  QgsDxfExport &operator=( const QgsDxfExport &dxfExport );
57 
63  void addLayers( const QList< QPair<QgsVectorLayer *, int > > &layers );
64 
71  int writeToFile( QIODevice *d, const QString& codec ); //maybe add progress dialog? other parameters (e.g. scale, dpi)?
72 
77  void setSymbologyScaleDenominator( double d ) { mSymbologyScaleDenominator = d; }
78 
84  double symbologyScaleDenominator() const { return mSymbologyScaleDenominator; }
85 
90  void setMapUnits( QGis::UnitType u ) { mMapUnits = u; }
91 
97  QGis::UnitType mapUnits() const { return mMapUnits; }
98 
102  void setDestinationCrs( long crs );
103 
107  long destinationCrs();
108 
113  void setSymbologyExport( SymbologyExport e ) { mSymbologyExport = e; }
114 
120  SymbologyExport symbologyExport() const { return mSymbologyExport; }
121 
126  void setExtent( const QgsRectangle &r ) { mExtent = r; }
127 
133  QgsRectangle extent() const { return mExtent; }
134 
141  void setLayerTitleAsName( bool layerTitleAsName ) { mLayerTitleAsName = layerTitleAsName; }
142 
148  bool layerTitleAsName() { return mLayerTitleAsName; }
149 
154  static int closestColorMatch( QRgb color );
155 
162  QString layerName( const QString &id, const QgsFeature &f ) const;
163 
170  QString layerName( QgsVectorLayer *vl ) const;
171 
178  void writeGroup( int code, int i );
179 
186  void writeGroup( int code, double d );
187 
193  void writeGroup( int code, const QString &s );
194 
204  Q_DECL_DEPRECATED void writeGroup( int code, const QgsPoint &p, double z = 0.0, bool skipz = false );
205 
213  void writeGroup( int code, const QgsPointV2 &p );
214 
223  void writeGroup( const QColor& color, int exactMatch = 62, int rgbCode = 420, int transparencyCode = 440 );
224 
229  void writeGroupCode( int code );
230 
235  void writeInt( int i );
236 
241  void writeDouble( double d );
242 
247  void writeString( const QString &s );
248 
255  int writeHandle( int code = 5, int handle = 0 );
256 
266  Q_DECL_DEPRECATED void writePolyline( const QgsPolyline &line, const QString &layer, const QString &lineStyleName, const QColor& color, double width = -1 );
267 
278  void writePolyline( const QgsPointSequenceV2 &line, const QString &layer, const QString &lineStyleName, const QColor& color, double width = -1 );
279 
288  Q_DECL_DEPRECATED void writePolygon( const QgsPolygon &polygon, const QString &layer, const QString &hatchPattern, const QColor& color );
289 
299  void writePolygon( const QgsRingSequenceV2 &polygon, const QString &layer, const QString &hatchPattern, const QColor& color );
300 
311  Q_DECL_DEPRECATED void writeSolid( const QString &layer, const QColor& color, const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, const QgsPoint &pt4 );
312 
315  Q_DECL_DEPRECATED void writeLine( const QgsPoint &pt1, const QgsPoint &pt2, const QString &layer, const QString &lineStyleName, const QColor& color, double width = -1 );
316 
319  void writeLine( const QgsPointV2 &pt1, const QgsPointV2 &pt2, const QString &layer, const QString &lineStyleName, const QColor& color, double width = -1 );
320 
323  Q_DECL_DEPRECATED void writePoint( const QString &layer, const QColor& color, const QgsPoint &pt );
324 
328  void writePoint( const QString &layer, const QColor& color, const QgsPointV2 &pt );
329 
332  Q_DECL_DEPRECATED void writeFilledCircle( const QString &layer, const QColor& color, const QgsPoint &pt, double radius );
333 
337  void writeFilledCircle( const QString &layer, const QColor& color, const QgsPointV2 &pt, double radius );
338 
341  Q_DECL_DEPRECATED void writeCircle( const QString &layer, const QColor& color, const QgsPoint &pt, double radius, const QString &lineStyleName, double width );
342 
346  void writeCircle( const QString &layer, const QColor& color, const QgsPointV2 &pt, double radius, const QString &lineStyleName, double width );
347 
350  Q_DECL_DEPRECATED void writeText( const QString &layer, const QString &text, const QgsPoint &pt, double size, double angle, const QColor& color );
351 
355  void writeText( const QString &layer, const QString &text, const QgsPointV2 &pt, double size, double angle, const QColor& color );
356 
359  Q_DECL_DEPRECATED void writeMText( const QString &layer, const QString &text, const QgsPoint &pt, double width, double angle, const QColor& color );
360 
364  void writeMText( const QString &layer, const QString &text, const QgsPointV2 &pt, double width, double angle, const QColor& color );
365 
366  static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits );
367 
369  static QString dxfLayerName( const QString &name );
370 
372  static QString dxfEncoding( const QString &name );
373 
375  static QStringList encodings();
376 
384  void drawLabel( QString layerId, QgsRenderContext& context, pal::LabelPosition* label, const QgsPalLayerSettings &settings );
385 
391  void registerDxfLayer( QString layerId, QgsFeatureId fid, QString layer );
392 
393  private:
395 
397  QgsRectangle mExtent;
399  double mSymbologyScaleDenominator;
400  SymbologyExport mSymbologyExport;
401  QGis::UnitType mMapUnits;
402  bool mLayerTitleAsName;
403 
404  QTextStream mTextStream;
405 
406  static int mDxfColors[][3];
407  static const char *mDxfEncodings[][2];
408 
409  int mSymbolLayerCounter; //internal counter
410  int mNextHandleId;
411  int mBlockCounter;
412 
413  QHash< const QgsSymbolLayerV2*, QString > mLineStyles; //symbol layer name types
414  QHash< const QgsSymbolLayerV2*, QString > mPointSymbolBlocks; //reference to point symbol blocks
415 
416  //AC1009
417  void writeHeader( const QString& codepage );
418  void writeTables();
419  void writeBlocks();
420  void writeEntities();
421  void writeEntitiesSymbolLevels( QgsVectorLayer *layer );
422  void writeEndFile();
423 
424  void startSection();
425  void endSection();
426 
427  void writePoint( const QgsPointV2 &pt, const QString &layer, const QColor& color, QgsSymbolV2RenderContext &ctx, const QgsSymbolLayerV2 *symbolLayer, const QgsSymbolV2 *symbol, double angle );
428  void writeDefaultLinetypes();
429  void writeSymbolLayerLinetype( const QgsSymbolLayerV2 *symbolLayer );
430  void writeLinetype( const QString &styleName, const QVector<qreal> &pattern, QgsSymbolV2::OutputUnit u );
431 
432  void addFeature( QgsSymbolV2RenderContext &ctx, const QgsCoordinateTransform *ct, const QString &layer, const QgsSymbolLayerV2 *symbolLayer, const QgsSymbolV2 *symbol );
433 
434  //returns dxf palette index from symbol layer color
435  static QColor colorFromSymbolLayer( const QgsSymbolLayerV2 *symbolLayer, QgsSymbolV2RenderContext &ctx );
436  QString lineStyleFromSymbolLayer( const QgsSymbolLayerV2 *symbolLayer );
437 
438  //functions for dxf palette
439  static int color_distance( QRgb p1, int index );
440  static QRgb createRgbEntry( qreal r, qreal g, qreal b );
441 
442  //helper functions for symbology export
443  QgsRenderContext renderContext() const;
444 
446  static int nLineTypes( const QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2*> > &symbolLayers );
447  static bool hasDataDefinedProperties( const QgsSymbolLayerV2 *sl, const QgsSymbolV2 *symbol );
448  double dashSize() const;
449  double dotSize() const;
450  double dashSeparatorSize() const;
451  double sizeToMapUnits( double s ) const;
452  static QString lineNameFromPenStyle( Qt::PenStyle style );
453  bool layerIsScaleBasedVisible( const QgsMapLayer *layer ) const;
454 
455  QHash<QString, int> mBlockHandles;
456  QString mBlockHandle;
457 
460  long mCrs;
461  QgsMapSettings mMapSettings;
462  double mFactor;
463 };
464 
465 #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:77
OutputUnit
The unit of the output.
Definition: qgssymbolv2.h:65
SymbologyExport symbologyExport() const
Get symbology export mode.
Definition: qgsdxfexport.h:120
void setSymbologyExport(SymbologyExport e)
Set symbology export mode.
Definition: qgsdxfexport.h:113
QGis::UnitType mapUnits() const
Retrieve map units.
Definition: qgsdxfexport.h:97
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
double symbologyScaleDenominator() const
Retrieve reference scale for output.
Definition: qgsdxfexport.h:84
The QgsMapSettings class contains configuration for rendering of the map.
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)
Contains information about the context of a rendering operation.
QgsRectangle extent() const
Get extent of area to export.
Definition: qgsdxfexport.h:133
void setLayerTitleAsName(bool layerTitleAsName)
Enable use of title (where set) instead of layer name, when attribute index of corresponding layer in...
Definition: qgsdxfexport.h:141
void setExtent(const QgsRectangle &r)
Set extent of area to export.
Definition: qgsdxfexport.h:126
void setMapUnits(QGis::UnitType u)
Set map units.
Definition: qgsdxfexport.h:90
bool layerTitleAsName()
Retrieve wether layer title (where set) instead of name shall be use.
Definition: qgsdxfexport.h:148
Class for doing transforms between two map coordinate systems.
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.