QGIS API Documentation  2.99.0-Master (314842d)
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 "qgsgeometry.h"
23 #include "qgssymbol.h" // for OutputUnit enum
24 #include "qgsmapsettings.h"
25 
26 #include <QColor>
27 #include <QList>
28 #include <QTextStream>
29 
30 class QgsMapLayer;
31 class QgsPoint;
32 class QgsSymbolLayer;
33 class QIODevice;
35 
36 namespace pal
37 {
38  class LabelPosition;
39 };
40 
44 class CORE_EXPORT QgsDxfExport
45 {
46  public:
48  {
49  NoSymbology = 0, //export only data
50  FeatureSymbology, //Keeps the number of features and export symbology per feature (using the first symbol level)
51  SymbolLayerSymbology //Exports one feature per symbol layer (considering symbol levels)
52  };
53 
54  QgsDxfExport();
55  QgsDxfExport( const QgsDxfExport &dxfExport );
56  QgsDxfExport &operator=( const QgsDxfExport &dxfExport );
57 
62  void setMapSettings( const QgsMapSettings &settings );
63 
69  void addLayers( const QList< QPair<QgsVectorLayer *, int > > &layers );
70 
77  int writeToFile( QIODevice *d, const QString &codec ); //maybe add progress dialog? other parameters (e.g. scale, dpi)?
78 
83  void setSymbologyScaleDenominator( double d ) { mSymbologyScaleDenominator = d; }
84 
90  double symbologyScaleDenominator() const { return mSymbologyScaleDenominator; }
91 
96  QgsUnitTypes::DistanceUnit mapUnits() const;
97 
103  void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
104 
110  QgsCoordinateReferenceSystem destinationCrs() const;
111 
116  void setSymbologyExport( SymbologyExport e ) { mSymbologyExport = e; }
117 
123  SymbologyExport symbologyExport() const { return mSymbologyExport; }
124 
129  void setExtent( const QgsRectangle &r ) { mExtent = r; }
130 
136  QgsRectangle extent() const { return mExtent; }
137 
144  void setLayerTitleAsName( bool layerTitleAsName ) { mLayerTitleAsName = layerTitleAsName; }
145 
151  bool layerTitleAsName() { return mLayerTitleAsName; }
152 
157  static int closestColorMatch( QRgb color );
158 
165  QString layerName( const QString &id, const QgsFeature &f ) const;
166 
173  QString layerName( QgsVectorLayer *vl ) const;
174 
181  void writeGroup( int code, int i );
182 
189  void writeGroup( int code, double d );
190 
196  void writeGroup( int code, const QString &s );
197 
205  void writeGroup( int code, const QgsPointV2 &p );
206 
215  void writeGroup( const QColor &color, int exactMatch = 62, int rgbCode = 420, int transparencyCode = 440 );
216 
221  void writeGroupCode( int code );
222 
227  void writeInt( int i );
228 
233  void writeDouble( double d );
234 
239  void writeString( const QString &s );
240 
247  int writeHandle( int code = 5, int handle = 0 );
248 
259  void writePolyline( const QgsPointSequence &line, const QString &layer, const QString &lineStyleName, const QColor &color, double width = -1 );
260 
270  void writePolygon( const QgsRingSequence &polygon, const QString &layer, const QString &hatchPattern, const QColor &color );
271 
274  void writeLine( const QgsPointV2 &pt1, const QgsPointV2 &pt2, const QString &layer, const QString &lineStyleName, const QColor &color, double width = -1 );
275 
279  void writePoint( const QString &layer, const QColor &color, const QgsPointV2 &pt );
280 
284  void writeFilledCircle( const QString &layer, const QColor &color, const QgsPointV2 &pt, double radius );
285 
289  void writeCircle( const QString &layer, const QColor &color, const QgsPointV2 &pt, double radius, const QString &lineStyleName, double width );
290 
294  void writeText( const QString &layer, const QString &text, const QgsPointV2 &pt, double size, double angle, const QColor &color );
295 
299  void writeMText( const QString &layer, const QString &text, const QgsPointV2 &pt, double width, double angle, const QColor &color );
300 
302  static double mapUnitScaleFactor( double scaleDenominator, QgsUnitTypes::RenderUnit symbolUnits, QgsUnitTypes::DistanceUnit mapUnits );
303 
305  static QString dxfLayerName( const QString &name );
306 
308  static QString dxfEncoding( const QString &name );
309 
311  static QStringList encodings();
312 
320  void drawLabel( const QString &layerId, QgsRenderContext &context, pal::LabelPosition *label, const QgsPalLayerSettings &settings );
321 
327  void registerDxfLayer( const QString &layerId, QgsFeatureId fid, const QString &layer );
328 
329  private:
331  QgsRectangle mExtent;
333  double mSymbologyScaleDenominator;
334  SymbologyExport mSymbologyExport;
335  QgsUnitTypes::DistanceUnit mMapUnits;
336  bool mLayerTitleAsName;
337 
338  QTextStream mTextStream;
339 
340  static int sDxfColors[][3];
341  static const char *DXF_ENCODINGS[][2];
342 
343  int mSymbolLayerCounter; //internal counter
344  int mNextHandleId;
345  int mBlockCounter;
346 
347  QHash< const QgsSymbolLayer *, QString > mLineStyles; //symbol layer name types
348  QHash< const QgsSymbolLayer *, QString > mPointSymbolBlocks; //reference to point symbol blocks
349 
350  //AC1009
351  void writeHeader( const QString &codepage );
352  void writeTables();
353  void writeBlocks();
354  void writeEntities();
355  void writeEntitiesSymbolLevels( QgsVectorLayer *layer );
356  void writeEndFile();
357 
358  void startSection();
359  void endSection();
360 
361  void writePoint( const QgsPointV2 &pt, const QString &layer, const QColor &color, QgsSymbolRenderContext &ctx, const QgsSymbolLayer *symbolLayer, const QgsSymbol *symbol, double angle );
362  void writeDefaultLinetypes();
363  void writeSymbolLayerLinetype( const QgsSymbolLayer *symbolLayer );
364  void writeLinetype( const QString &styleName, const QVector<qreal> &pattern, QgsUnitTypes::RenderUnit u );
365 
366  void addFeature( QgsSymbolRenderContext &ctx, const QgsCoordinateTransform &ct, const QString &layer, const QgsSymbolLayer *symbolLayer, const QgsSymbol *symbol );
367 
368  //returns dxf palette index from symbol layer color
369  static QColor colorFromSymbolLayer( const QgsSymbolLayer *symbolLayer, QgsSymbolRenderContext &ctx );
370  QString lineStyleFromSymbolLayer( const QgsSymbolLayer *symbolLayer );
371 
372  //functions for dxf palette
373  static int color_distance( QRgb p1, int index );
374  static QRgb createRgbEntry( qreal r, qreal g, qreal b );
375 
376  //helper functions for symbology export
377  QgsRenderContext renderContext() const;
378 
379  QList< QPair< QgsSymbolLayer *, QgsSymbol * > > symbolLayers( QgsRenderContext &context );
380  static int nLineTypes( const QList< QPair< QgsSymbolLayer *, QgsSymbol *> > &symbolLayers );
381  static bool hasDataDefinedProperties( const QgsSymbolLayer *sl, const QgsSymbol *symbol );
382  double dashSize() const;
383  double dotSize() const;
384  double dashSeparatorSize() const;
385  double sizeToMapUnits( double s ) const;
386  static QString lineNameFromPenStyle( Qt::PenStyle style );
387  bool layerIsScaleBasedVisible( const QgsMapLayer *layer ) const;
388 
389  QHash<QString, int> mBlockHandles;
390  QString mBlockHandle;
391 
393  QMap< QString, QMap<QgsFeatureId, QString> > mDxfLayerNames;
395  QgsMapSettings mMapSettings;
396  QHash<QString, int> mLayerNameAttribute;
397  double mFactor;
398 };
399 
400 #endif // QGSDXFEXPORT_H
static unsigned index
A rectangle specified with double values.
Definition: qgsrectangle.h:36
Base class for all map layer types.
Definition: qgsmaplayer.h:52
void setSymbologyScaleDenominator(double d)
Set reference scale for output.
Definition: qgsdxfexport.h:83
SymbologyExport symbologyExport() const
Get symbology export mode.
Definition: qgsdxfexport.h:123
void setSymbologyExport(SymbologyExport e)
Set symbology export mode.
Definition: qgsdxfexport.h:116
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:136
double symbologyScaleDenominator() const
Retrieve reference scale for output.
Definition: qgsdxfexport.h:90
The QgsMapSettings class contains configuration for rendering of the map.
Point geometry type, with support for z-dimension and m-values.
Definition: qgspointv2.h:36
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:136
void setLayerTitleAsName(bool layerTitleAsName)
Enable use of title (where set) instead of layer name, when attribute index of corresponding layer in...
Definition: qgsdxfexport.h:144
void setExtent(const QgsRectangle &r)
Set extent of area to export.
Definition: qgsdxfexport.h:129
bool layerTitleAsName()
Retrieve whether layer title (where set) instead of name shall be use.
Definition: qgsdxfexport.h:151
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:33
QList< QgsPointV2 > QgsPointSequence
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