QGIS API Documentation  2.99.0-Master (d55fa22)
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 "qgis_core.h"
22 #include "qgis_sip.h"
23 #include "qgis.h"
24 #include "qgsgeometry.h"
25 #include "qgssymbol.h" // for OutputUnit enum
26 #include "qgsmapsettings.h"
27 
28 #include <QColor>
29 #include <QList>
30 #include <QTextStream>
31 
32 class QgsMapLayer;
33 class QgsPoint;
34 class QgsSymbolLayer;
35 class QIODevice;
37 
38 namespace pal
39 {
40  class LabelPosition;
41 }
42 
46 class CORE_EXPORT QgsDxfExport
47 {
48  public:
50  {
51  NoSymbology = 0, //export only data
52  FeatureSymbology, //Keeps the number of features and export symbology per feature (using the first symbol level)
53  SymbolLayerSymbology //Exports one feature per symbol layer (considering symbol levels)
54  };
55 
56  QgsDxfExport();
57  QgsDxfExport( const QgsDxfExport &dxfExport );
58  QgsDxfExport &operator=( const QgsDxfExport &dxfExport );
59 
64  void setMapSettings( const QgsMapSettings &settings );
65 
71  void addLayers( const QList< QPair<QgsVectorLayer *, int > > &layers );
72 
79  int writeToFile( QIODevice *d, const QString &codec ); //maybe add progress dialog? other parameters (e.g. scale, dpi)?
80 
85  void setSymbologyScaleDenominator( double d ) { mSymbologyScaleDenominator = d; }
86 
92  double symbologyScaleDenominator() const { return mSymbologyScaleDenominator; }
93 
98  QgsUnitTypes::DistanceUnit mapUnits() const;
99 
105  void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
106 
112  QgsCoordinateReferenceSystem destinationCrs() const;
113 
118  void setSymbologyExport( SymbologyExport e ) { mSymbologyExport = e; }
119 
125  SymbologyExport symbologyExport() const { return mSymbologyExport; }
126 
131  void setExtent( const QgsRectangle &r ) { mExtent = r; }
132 
138  QgsRectangle extent() const { return mExtent; }
139 
146  void setLayerTitleAsName( bool layerTitleAsName ) { mLayerTitleAsName = layerTitleAsName; }
147 
153  bool layerTitleAsName() { return mLayerTitleAsName; }
154 
159  static int closestColorMatch( QRgb color );
160 
167  QString layerName( const QString &id, const QgsFeature &f ) const;
168 
175  QString layerName( QgsVectorLayer *vl ) const;
176 
183  void writeGroup( int code, int i ) SIP_PYNAME( writeGroupInt );
184 
191  void writeGroup( int code, double d ) SIP_PYNAME( writeGroupDouble );
192 
198  void writeGroup( int code, const QString &s );
199 
207  void writeGroup( int code, const QgsPointV2 &p ) SIP_PYNAME( writeGroupPointV2 );
208 
217  void writeGroup( const QColor &color, int exactMatch = 62, int rgbCode = 420, int transparencyCode = 440 );
218 
223  void writeGroupCode( int code );
224 
229  void writeInt( int i );
230 
235  void writeDouble( double d );
236 
241  void writeString( const QString &s );
242 
249  int writeHandle( int code = 5, int handle = 0 );
250 
261  void writePolyline( const QgsPointSequence &line, const QString &layer, const QString &lineStyleName, const QColor &color, double width = -1 ) SIP_SKIP;
262 
272  void writePolygon( const QgsRingSequence &polygon, const QString &layer, const QString &hatchPattern, const QColor &color ) SIP_SKIP;
273 
276  void writeLine( const QgsPointV2 &pt1, const QgsPointV2 &pt2, const QString &layer, const QString &lineStyleName, const QColor &color, double width = -1 );
277 
281  void writePoint( const QString &layer, const QColor &color, const QgsPointV2 &pt ) SIP_PYNAME( writePointV2 );
282 
286  void writeFilledCircle( const QString &layer, const QColor &color, const QgsPointV2 &pt, double radius ) SIP_PYNAME( writeFillCircleV2 );
287 
291  void writeCircle( const QString &layer, const QColor &color, const QgsPointV2 &pt, double radius, const QString &lineStyleName, double width ) SIP_PYNAME( writeCircleV2 );
292 
296  void writeText( const QString &layer, const QString &text, const QgsPointV2 &pt, double size, double angle, const QColor &color ) SIP_PYNAME( writeTextV2 );
297 
301  void writeMText( const QString &layer, const QString &text, const QgsPointV2 &pt, double width, double angle, const QColor &color );
302 
304  static double mapUnitScaleFactor( double scaleDenominator, QgsUnitTypes::RenderUnit symbolUnits, QgsUnitTypes::DistanceUnit mapUnits );
305 
307  static QString dxfLayerName( const QString &name );
308 
310  static QString dxfEncoding( const QString &name );
311 
313  static QStringList encodings();
314 
322  void drawLabel( const QString &layerId, QgsRenderContext &context, pal::LabelPosition *label, const QgsPalLayerSettings &settings ) SIP_SKIP;
323 
329  void registerDxfLayer( const QString &layerId, QgsFeatureId fid, const QString &layer );
330 
331  private:
333  QgsRectangle mExtent;
335  double mSymbologyScaleDenominator;
336  SymbologyExport mSymbologyExport;
337  QgsUnitTypes::DistanceUnit mMapUnits;
338  bool mLayerTitleAsName;
339 
340  QTextStream mTextStream;
341 
342  static int sDxfColors[][3];
343  static const char *DXF_ENCODINGS[][2];
344 
345  int mSymbolLayerCounter; //internal counter
346  int mNextHandleId;
347  int mBlockCounter;
348 
349  QHash< const QgsSymbolLayer *, QString > mLineStyles; //symbol layer name types
350  QHash< const QgsSymbolLayer *, QString > mPointSymbolBlocks; //reference to point symbol blocks
351 
352  //AC1009
353  void writeHeader( const QString &codepage );
354  void writeTables();
355  void writeBlocks();
356  void writeEntities();
357  void writeEntitiesSymbolLevels( QgsVectorLayer *layer );
358  void writeEndFile();
359 
360  void startSection();
361  void endSection();
362 
363  void writePoint( const QgsPointV2 &pt, const QString &layer, const QColor &color, QgsSymbolRenderContext &ctx, const QgsSymbolLayer *symbolLayer, const QgsSymbol *symbol, double angle );
364  void writeDefaultLinetypes();
365  void writeSymbolLayerLinetype( const QgsSymbolLayer *symbolLayer );
366  void writeLinetype( const QString &styleName, const QVector<qreal> &pattern, QgsUnitTypes::RenderUnit u );
367 
368  void addFeature( QgsSymbolRenderContext &ctx, const QgsCoordinateTransform &ct, const QString &layer, const QgsSymbolLayer *symbolLayer, const QgsSymbol *symbol );
369 
370  //returns dxf palette index from symbol layer color
371  static QColor colorFromSymbolLayer( const QgsSymbolLayer *symbolLayer, QgsSymbolRenderContext &ctx );
372  QString lineStyleFromSymbolLayer( const QgsSymbolLayer *symbolLayer );
373 
374  //functions for dxf palette
375  static int color_distance( QRgb p1, int index );
376  static QRgb createRgbEntry( qreal r, qreal g, qreal b );
377 
378  //helper functions for symbology export
379  QgsRenderContext renderContext() const;
380 
381  QList< QPair< QgsSymbolLayer *, QgsSymbol * > > symbolLayers( QgsRenderContext &context );
382  static int nLineTypes( const QList< QPair< QgsSymbolLayer *, QgsSymbol *> > &symbolLayers );
383  static bool hasDataDefinedProperties( const QgsSymbolLayer *sl, const QgsSymbol *symbol );
384  double dashSize() const;
385  double dotSize() const;
386  double dashSeparatorSize() const;
387  double sizeToMapUnits( double s ) const;
388  static QString lineNameFromPenStyle( Qt::PenStyle style );
389  bool layerIsScaleBasedVisible( const QgsMapLayer *layer ) const;
390 
391  QHash<QString, int> mBlockHandles;
392  QString mBlockHandle;
393 
395  QMap< QString, QMap<QgsFeatureId, QString> > mDxfLayerNames;
397  QgsMapSettings mMapSettings;
398  QHash<QString, int> mLayerNameAttribute;
399  double mFactor;
400 };
401 
402 #endif // QGSDXFEXPORT_H
A rectangle specified with double values.
Definition: qgsrectangle.h:38
Base class for all map layer types.
Definition: qgsmaplayer.h:54
void setSymbologyScaleDenominator(double d)
Set reference scale for output.
Definition: qgsdxfexport.h:85
QList< QgsPointV2 > QgsPointSequence
SymbologyExport symbologyExport() const
Get symbology export mode.
Definition: qgsdxfexport.h:125
void setSymbologyExport(SymbologyExport e)
Set symbology export mode.
Definition: qgsdxfexport.h:118
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:61
double symbologyScaleDenominator() const
Retrieve reference scale for output.
Definition: qgsdxfexport.h:92
The QgsMapSettings class contains configuration for rendering of the map.
#define SIP_SKIP
Definition: qgis_sip.h:87
Point geometry type, with support for z-dimension and m-values.
Definition: qgspointv2.h:37
A class to represent a point.
Definition: qgspoint.h:37
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:42
Contains information about the context of a rendering operation.
QgsRectangle extent() const
Get extent of area to export.
Definition: qgsdxfexport.h:138
void setLayerTitleAsName(bool layerTitleAsName)
Enable use of title (where set) instead of layer name, when attribute index of corresponding layer in...
Definition: qgsdxfexport.h:146
void setExtent(const QgsRectangle &r)
Set extent of area to export.
Definition: qgsdxfexport.h:131
bool layerTitleAsName()
Retrieve whether layer title (where set) instead of name shall be use.
Definition: qgsdxfexport.h:153
This class represents a coordinate reference system (CRS).
QList< QgsPointSequence > QgsRingSequence
Class for doing transforms between two map coordinate systems.
LabelPosition is a candidate feature label position.
Definition: labelposition.h:52
qint64 QgsFeatureId
Definition: qgsfeature.h:37
Represents a vector layer which manages a vector based data sets.
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)
Definition: MathUtils.cc:857
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:95
#define SIP_PYNAME(name)
Definition: qgis_sip.h:62