QGIS API Documentation  2.99.0-Master (90ae728)
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  void setMapUnits( QgsUnitTypes::DistanceUnit u ) { mMapUnits = u; }
97 
103  QgsUnitTypes::DistanceUnit mapUnits() const { return mMapUnits; }
104 
110  void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
111 
117  QgsCoordinateReferenceSystem destinationCrs() const;
118 
123  void setSymbologyExport( SymbologyExport e ) { mSymbologyExport = e; }
124 
130  SymbologyExport symbologyExport() const { return mSymbologyExport; }
131 
136  void setExtent( const QgsRectangle &r ) { mExtent = r; }
137 
143  QgsRectangle extent() const { return mExtent; }
144 
151  void setLayerTitleAsName( bool layerTitleAsName ) { mLayerTitleAsName = layerTitleAsName; }
152 
158  bool layerTitleAsName() { return mLayerTitleAsName; }
159 
164  static int closestColorMatch( QRgb color );
165 
172  QString layerName( const QString &id, const QgsFeature &f ) const;
173 
180  QString layerName( QgsVectorLayer *vl ) const;
181 
188  void writeGroup( int code, int i );
189 
196  void writeGroup( int code, double d );
197 
203  void writeGroup( int code, const QString &s );
204 
212  void writeGroup( int code, const QgsPointV2 &p );
213 
222  void writeGroup( const QColor& color, int exactMatch = 62, int rgbCode = 420, int transparencyCode = 440 );
223 
228  void writeGroupCode( int code );
229 
234  void writeInt( int i );
235 
240  void writeDouble( double d );
241 
246  void writeString( const QString &s );
247 
254  int writeHandle( int code = 5, int handle = 0 );
255 
266  void writePolyline( const QgsPointSequence &line, const QString &layer, const QString &lineStyleName, const QColor& color, double width = -1 );
267 
277  void writePolygon( const QgsRingSequence &polygon, const QString &layer, const QString &hatchPattern, const QColor& color );
278 
281  void writeLine( const QgsPointV2 &pt1, const QgsPointV2 &pt2, const QString &layer, const QString &lineStyleName, const QColor& color, double width = -1 );
282 
286  void writePoint( const QString &layer, const QColor& color, const QgsPointV2 &pt );
287 
291  void writeFilledCircle( const QString &layer, const QColor& color, const QgsPointV2 &pt, double radius );
292 
296  void writeCircle( const QString &layer, const QColor& color, const QgsPointV2 &pt, double radius, const QString &lineStyleName, double width );
297 
301  void writeText( const QString &layer, const QString &text, const QgsPointV2 &pt, double size, double angle, const QColor& color );
302 
306  void writeMText( const QString &layer, const QString &text, const QgsPointV2 &pt, double width, double angle, const QColor& color );
307 
309  static double mapUnitScaleFactor( double scaleDenominator, QgsUnitTypes::RenderUnit symbolUnits, QgsUnitTypes::DistanceUnit mapUnits );
310 
312  static QString dxfLayerName( const QString &name );
313 
315  static QString dxfEncoding( const QString &name );
316 
318  static QStringList encodings();
319 
327  void drawLabel( const QString &layerId, QgsRenderContext& context, pal::LabelPosition* label, const QgsPalLayerSettings &settings );
328 
334  void registerDxfLayer( const QString &layerId, QgsFeatureId fid, const QString &layer );
335 
336  private:
338  QgsRectangle mExtent;
340  double mSymbologyScaleDenominator;
341  SymbologyExport mSymbologyExport;
342  QgsUnitTypes::DistanceUnit mMapUnits;
343  bool mLayerTitleAsName;
344 
345  QTextStream mTextStream;
346 
347  static int sDxfColors[][3];
348  static const char *DXF_ENCODINGS[][2];
349 
350  int mSymbolLayerCounter; //internal counter
351  int mNextHandleId;
352  int mBlockCounter;
353 
354  QHash< const QgsSymbolLayer*, QString > mLineStyles; //symbol layer name types
355  QHash< const QgsSymbolLayer*, QString > mPointSymbolBlocks; //reference to point symbol blocks
356 
357  //AC1009
358  void writeHeader( const QString& codepage );
359  void writeTables();
360  void writeBlocks();
361  void writeEntities();
362  void writeEntitiesSymbolLevels( QgsVectorLayer *layer );
363  void writeEndFile();
364 
365  void startSection();
366  void endSection();
367 
368  void writePoint( const QgsPointV2 &pt, const QString &layer, const QColor& color, QgsSymbolRenderContext &ctx, const QgsSymbolLayer *symbolLayer, const QgsSymbol *symbol, double angle );
369  void writeDefaultLinetypes();
370  void writeSymbolLayerLinetype( const QgsSymbolLayer *symbolLayer );
371  void writeLinetype( const QString &styleName, const QVector<qreal> &pattern, QgsUnitTypes::RenderUnit u );
372 
373  void addFeature( QgsSymbolRenderContext &ctx, const QgsCoordinateTransform& ct, const QString &layer, const QgsSymbolLayer *symbolLayer, const QgsSymbol *symbol );
374 
375  //returns dxf palette index from symbol layer color
376  static QColor colorFromSymbolLayer( const QgsSymbolLayer *symbolLayer, QgsSymbolRenderContext &ctx );
377  QString lineStyleFromSymbolLayer( const QgsSymbolLayer *symbolLayer );
378 
379  //functions for dxf palette
380  static int color_distance( QRgb p1, int index );
381  static QRgb createRgbEntry( qreal r, qreal g, qreal b );
382 
383  //helper functions for symbology export
384  QgsRenderContext renderContext() const;
385 
386  QList< QPair< QgsSymbolLayer *, QgsSymbol * > > symbolLayers( QgsRenderContext& context );
387  static int nLineTypes( const QList< QPair< QgsSymbolLayer*, QgsSymbol*> > &symbolLayers );
388  static bool hasDataDefinedProperties( const QgsSymbolLayer *sl, const QgsSymbol *symbol );
389  double dashSize() const;
390  double dotSize() const;
391  double dashSeparatorSize() const;
392  double sizeToMapUnits( double s ) const;
393  static QString lineNameFromPenStyle( Qt::PenStyle style );
394  bool layerIsScaleBasedVisible( const QgsMapLayer *layer ) const;
395 
396  QHash<QString, int> mBlockHandles;
397  QString mBlockHandle;
398 
400  QMap< QString, QMap<QgsFeatureId, QString> > mDxfLayerNames;
402  QgsMapSettings mMapSettings;
403  QHash<QString, int> mLayerNameAttribute;
404  double mFactor;
405 };
406 
407 #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:130
void setSymbologyExport(SymbologyExport e)
Set symbology export mode.
Definition: qgsdxfexport.h:123
QgsUnitTypes::DistanceUnit mapUnits() const
Retrieve map units.
Definition: qgsdxfexport.h:103
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.
void setMapUnits(QgsUnitTypes::DistanceUnit u)
Set map units.
Definition: qgsdxfexport.h:96
Point geometry type, with support for z-dimension and m-values.
Definition: qgspointv2.h:36
A class to represent a point.
Definition: qgspoint.h:143
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:43
Contains information about the context of a rendering operation.
QgsRectangle extent() const
Get extent of area to export.
Definition: qgsdxfexport.h:143
void setLayerTitleAsName(bool layerTitleAsName)
Enable use of title (where set) instead of layer name, when attribute index of corresponding layer in...
Definition: qgsdxfexport.h:151
void setExtent(const QgsRectangle &r)
Set extent of area to export.
Definition: qgsdxfexport.h:136
bool layerTitleAsName()
Retrieve whether layer title (where set) instead of name shall be use.
Definition: qgsdxfexport.h:158
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:92