QGIS API Documentation  2.99.0-Master (e077efd)
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 "qgssymbol.h" // for OutputUnit enum
23 #include "qgsmapsettings.h"
24 
25 #include <QColor>
26 #include <QList>
27 #include <QTextStream>
28 
29 class QgsMapLayer;
30 class QgsPoint;
31 class QgsSymbolLayer;
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( QgsUnitTypes::DistanceUnit u ) { mMapUnits = u; }
91 
97  QgsUnitTypes::DistanceUnit mapUnits() const { return mMapUnits; }
98 
104  void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
105 
111  QgsCoordinateReferenceSystem destinationCrs() const;
112 
117  void setSymbologyExport( SymbologyExport e ) { mSymbologyExport = e; }
118 
124  SymbologyExport symbologyExport() const { return mSymbologyExport; }
125 
130  void setExtent( const QgsRectangle &r ) { mExtent = r; }
131 
137  QgsRectangle extent() const { return mExtent; }
138 
145  void setLayerTitleAsName( bool layerTitleAsName ) { mLayerTitleAsName = layerTitleAsName; }
146 
152  bool layerTitleAsName() { return mLayerTitleAsName; }
153 
158  static int closestColorMatch( QRgb color );
159 
166  QString layerName( const QString &id, const QgsFeature &f ) const;
167 
174  QString layerName( QgsVectorLayer *vl ) const;
175 
182  void writeGroup( int code, int i );
183 
190  void writeGroup( int code, double d );
191 
197  void writeGroup( int code, const QString &s );
198 
206  void writeGroup( int code, const QgsPointV2 &p );
207 
216  void writeGroup( const QColor& color, int exactMatch = 62, int rgbCode = 420, int transparencyCode = 440 );
217 
222  void writeGroupCode( int code );
223 
228  void writeInt( int i );
229 
234  void writeDouble( double d );
235 
240  void writeString( const QString &s );
241 
248  int writeHandle( int code = 5, int handle = 0 );
249 
260  void writePolyline( const QgsPointSequence &line, const QString &layer, const QString &lineStyleName, const QColor& color, double width = -1 );
261 
271  void writePolygon( const QgsRingSequence &polygon, const QString &layer, const QString &hatchPattern, const QColor& color );
272 
275  void writeLine( const QgsPointV2 &pt1, const QgsPointV2 &pt2, const QString &layer, const QString &lineStyleName, const QColor& color, double width = -1 );
276 
280  void writePoint( const QString &layer, const QColor& color, const QgsPointV2 &pt );
281 
285  void writeFilledCircle( const QString &layer, const QColor& color, const QgsPointV2 &pt, double radius );
286 
290  void writeCircle( const QString &layer, const QColor& color, const QgsPointV2 &pt, double radius, const QString &lineStyleName, double width );
291 
295  void writeText( const QString &layer, const QString &text, const QgsPointV2 &pt, double size, double angle, const QColor& color );
296 
300  void writeMText( const QString &layer, const QString &text, const QgsPointV2 &pt, double width, double angle, const QColor& color );
301 
303  static double mapUnitScaleFactor( double scaleDenominator, QgsUnitTypes::RenderUnit symbolUnits, QgsUnitTypes::DistanceUnit mapUnits );
304 
306  static QString dxfLayerName( const QString &name );
307 
309  static QString dxfEncoding( const QString &name );
310 
312  static QStringList encodings();
313 
321  void drawLabel( const QString &layerId, QgsRenderContext& context, pal::LabelPosition* label, const QgsPalLayerSettings &settings );
322 
328  void registerDxfLayer( const QString &layerId, QgsFeatureId fid, const QString &layer );
329 
330  private:
331  QList< QPair<QgsVectorLayer*, int> > mLayers;
332 
334  QgsRectangle mExtent;
336  double mSymbologyScaleDenominator;
337  SymbologyExport mSymbologyExport;
338  QgsUnitTypes::DistanceUnit mMapUnits;
339  bool mLayerTitleAsName;
340 
341  QTextStream mTextStream;
342 
343  static int mDxfColors[][3];
344  static const char *mDxfEncodings[][2];
345 
346  int mSymbolLayerCounter; //internal counter
347  int mNextHandleId;
348  int mBlockCounter;
349 
350  QHash< const QgsSymbolLayer*, QString > mLineStyles; //symbol layer name types
351  QHash< const QgsSymbolLayer*, QString > mPointSymbolBlocks; //reference to point symbol blocks
352 
353  //AC1009
354  void writeHeader( const QString& codepage );
355  void writeTables();
356  void writeBlocks();
357  void writeEntities();
358  void writeEntitiesSymbolLevels( QgsVectorLayer *layer );
359  void writeEndFile();
360 
361  void startSection();
362  void endSection();
363 
364  void writePoint( const QgsPointV2 &pt, const QString &layer, const QColor& color, QgsSymbolRenderContext &ctx, const QgsSymbolLayer *symbolLayer, const QgsSymbol *symbol, double angle );
365  void writeDefaultLinetypes();
366  void writeSymbolLayerLinetype( const QgsSymbolLayer *symbolLayer );
367  void writeLinetype( const QString &styleName, const QVector<qreal> &pattern, QgsUnitTypes::RenderUnit u );
368 
369  void addFeature( QgsSymbolRenderContext &ctx, const QgsCoordinateTransform& ct, const QString &layer, const QgsSymbolLayer *symbolLayer, const QgsSymbol *symbol );
370 
371  //returns dxf palette index from symbol layer color
372  static QColor colorFromSymbolLayer( const QgsSymbolLayer *symbolLayer, QgsSymbolRenderContext &ctx );
373  QString lineStyleFromSymbolLayer( const QgsSymbolLayer *symbolLayer );
374 
375  //functions for dxf palette
376  static int color_distance( QRgb p1, int index );
377  static QRgb createRgbEntry( qreal r, qreal g, qreal b );
378 
379  //helper functions for symbology export
380  QgsRenderContext renderContext() const;
381 
382  QList< QPair< QgsSymbolLayer *, QgsSymbol * > > symbolLayers( QgsRenderContext& context );
383  static int nLineTypes( const QList< QPair< QgsSymbolLayer*, QgsSymbol*> > &symbolLayers );
384  static bool hasDataDefinedProperties( const QgsSymbolLayer *sl, const QgsSymbol *symbol );
385  double dashSize() const;
386  double dotSize() const;
387  double dashSeparatorSize() const;
388  double sizeToMapUnits( double s ) const;
389  static QString lineNameFromPenStyle( Qt::PenStyle style );
390  bool layerIsScaleBasedVisible( const QgsMapLayer *layer ) const;
391 
392  QHash<QString, int> mBlockHandles;
393  QString mBlockHandle;
394 
396  QMap< QString, QMap<QgsFeatureId, QString> > mDxfLayerNames;
398  QgsMapSettings mMapSettings;
399  double mFactor;
400 };
401 
402 #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
SymbologyExport symbologyExport() const
Get symbology export mode.
Definition: qgsdxfexport.h:124
void setSymbologyExport(SymbologyExport e)
Set symbology export mode.
Definition: qgsdxfexport.h:117
QgsUnitTypes::DistanceUnit 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:135
double symbologyScaleDenominator() const
Retrieve reference scale for output.
Definition: qgsdxfexport.h:84
The QgsMapSettings class contains configuration for rendering of the map.
void setMapUnits(QgsUnitTypes::DistanceUnit u)
Set map units.
Definition: qgsdxfexport.h:90
Point geometry type, with support for z-dimension and m-values.
Definition: qgspointv2.h:35
A class to represent a point.
Definition: qgspoint.h:111
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:137
void setLayerTitleAsName(bool layerTitleAsName)
Enable use of title (where set) instead of layer name, when attribute index of corresponding layer in...
Definition: qgsdxfexport.h:145
void setExtent(const QgsRectangle &r)
Set extent of area to export.
Definition: qgsdxfexport.h:130
bool layerTitleAsName()
Retrieve wether layer title (where set) instead of name shall be use.
Definition: qgsdxfexport.h:152
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:51
qint64 QgsFeatureId
Definition: qgsfeature.h:32
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:91