QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 <QColor>
24 #include <QList>
25 #include <QTextStream>
26 
27 class QgsMapLayer;
28 class QgsPoint;
29 class QgsSymbolLayerV2;
30 class QIODevice;
31 
32 class CORE_EXPORT QgsDxfExport
33 {
34  public:
36  {
37  NoSymbology = 0, //export only data
38  FeatureSymbology, //Keeps the number of features and export symbology per feature (using the first symbol level)
39  SymbolLayerSymbology //Exports one feature per symbol layer (considering symbol levels)
40  };
41 
42  QgsDxfExport();
43  QgsDxfExport( const QgsDxfExport &dxfExport );
44  ~QgsDxfExport();
45  QgsDxfExport &operator=( const QgsDxfExport &dxfExport );
46 
47  void addLayers( const QList< QPair<QgsVectorLayer *, int > > &layers );
48  int writeToFile( QIODevice *d, QString codec ); //maybe add progress dialog? other parameters (e.g. scale, dpi)?
49 
50  void setSymbologyScaleDenominator( double d ) { mSymbologyScaleDenominator = d; }
51  double symbologyScaleDenominator() const { return mSymbologyScaleDenominator; }
52 
53  void setMapUnits( QGis::UnitType u ) { mMapUnits = u; }
54  QGis::UnitType mapUnits() const { return mMapUnits; }
55 
56  void setSymbologyExport( SymbologyExport e ) { mSymbologyExport = e; }
57  SymbologyExport symbologyExport() const { return mSymbologyExport; }
58 
59  void setExtent( const QgsRectangle &r ) { mExtent = r; }
60  QgsRectangle extent() const { return mExtent; }
61 
62  //get closest entry in dxf palette
63  static int closestColorMatch( QRgb pixel );
64 
65  QString layerName( const QString &id, const QgsFeature &f ) const;
66 
68  void writeGroup( int code, int i );
70  void writeGroup( int code, double d );
71  void writeGroup( int code, const QString &s );
72  void writeGroupCode( int code );
73  void writeInt( int i );
74  void writeDouble( double d );
75  void writeString( const QString &s );
76  void writeGroup( int code, const QgsPoint &p, double z = 0.0, bool skipz = false );
77  void writeGroup( QColor color, int exactMatch = 62, int rgbCode = 420, int transparencyCode = 440 );
78 
79  int writeHandle( int code = 5, int handle = 0 );
80 
82  void writePolyline( const QgsPolyline &line, const QString &layer, const QString &lineStyleName, QColor color, double width = -1 );
83 
85  void writePolygon( const QgsPolygon &polygon, const QString &layer, const QString &hatchPattern, QColor color );
86 
90  Q_DECL_DEPRECATED void writeSolid( const QString &layer, QColor color, const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, const QgsPoint &pt4 );
91 
93  void writeLine( const QgsPoint &pt1, const QgsPoint &pt2, const QString &layer, const QString &lineStyleName, QColor color, double width = -1 );
94 
96  void writePoint( const QString &layer, QColor color, const QgsPoint &pt );
97 
99  void writeFilledCircle( const QString &layer, QColor color, const QgsPoint &pt, double radius );
100 
102  void writeCircle( const QString &layer, QColor color, const QgsPoint &pt, double radius, const QString &lineStyleName, double width );
103 
105  void writeText( const QString &layer, const QString &text, const QgsPoint &pt, double size, double angle, QColor color );
106 
108  void writeMText( const QString &layer, const QString &text, const QgsPoint &pt, double width, double angle, QColor color );
109 
110  static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits );
111 
113  static QString dxfLayerName( const QString &name );
114 
116  static QString dxfEncoding( const QString &name );
117 
119  static QStringList encodings();
120 
121  private:
123 
125  QgsRectangle mExtent;
127  double mSymbologyScaleDenominator;
128  SymbologyExport mSymbologyExport;
129  QGis::UnitType mMapUnits;
130 
131  QTextStream mTextStream;
132 
133  static int mDxfColors[][3];
134  static const char *mDxfEncodings[][2];
135 
136  int mSymbolLayerCounter; //internal counter
137  int mNextHandleId;
138  int mBlockCounter;
139 
140  QHash< const QgsSymbolLayerV2*, QString > mLineStyles; //symbol layer name types
141  QHash< const QgsSymbolLayerV2*, QString > mPointSymbolBlocks; //reference to point symbol blocks
142 
143  //AC1009
144  void writeHeader( QString codepage );
145  void writeTables();
146  void writeBlocks();
147  void writeEntities();
148  void writeEntitiesSymbolLevels( QgsVectorLayer *layer );
149  void writeEndFile();
150 
151  void startSection();
152  void endSection();
153 
154  void writePoint( const QgsPoint &pt, const QString &layer, QColor color, const QgsFeature *f, const QgsSymbolLayerV2 *symbolLayer, const QgsSymbolV2 *symbol );
155  void writeVertex( const QgsPoint &pt, const QString &layer );
156  void writeDefaultLinetypes();
157  void writeSymbolLayerLinetype( const QgsSymbolLayerV2 *symbolLayer );
158  void writeLinetype( const QString &styleName, const QVector<qreal> &pattern, QgsSymbolV2::OutputUnit u );
159 
160  QgsRectangle dxfExtent() const;
161 
162  void addFeature( const QgsSymbolV2RenderContext &ctx, const QString &layer, const QgsSymbolLayerV2 *symbolLayer, const QgsSymbolV2 *symbol );
163 
164  //returns dxf palette index from symbol layer color
165  static QColor colorFromSymbolLayer( const QgsSymbolLayerV2 *symbolLayer, const QgsSymbolV2RenderContext &ctx );
166  QString lineStyleFromSymbolLayer( const QgsSymbolLayerV2 *symbolLayer );
167 
168  //functions for dxf palette
169  static int color_distance( QRgb p1, int index );
170  static QRgb createRgbEntry( qreal r, qreal g, qreal b );
171 
172  //helper functions for symbology export
173  QgsRenderContext renderContext() const;
174 
176  static int nLineTypes( const QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2*> > &symbolLayers );
177  static bool hasDataDefinedProperties( const QgsSymbolLayerV2 *sl, const QgsSymbolV2 *symbol );
178  double dashSize() const;
179  double dotSize() const;
180  double dashSeparatorSize() const;
181  double sizeToMapUnits( double s ) const;
182  static QString lineNameFromPenStyle( Qt::PenStyle style );
183  bool layerIsScaleBasedVisible( const QgsMapLayer *layer ) const;
184 
185  QHash<QString, int> mBlockHandles;
186  QString mBlockHandle;
187 };
188 
189 #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)
Definition: qgsdxfexport.h:50
SymbologyExport symbologyExport() const
Definition: qgsdxfexport.h:57
QGis::UnitType mapUnits() const
Definition: qgsdxfexport.h:54
void setSymbologyExport(SymbologyExport e)
Definition: qgsdxfexport.h:56
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:162
QgsRectangle extent() const
Definition: qgsdxfexport.h:60
A class to represent a point.
Definition: qgspoint.h:63
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)
double symbologyScaleDenominator() const
Definition: qgsdxfexport.h:51
Contains information about the context of a rendering operation.
void setExtent(const QgsRectangle &r)
Definition: qgsdxfexport.h:59
void setMapUnits(QGis::UnitType u)
Definition: qgsdxfexport.h:53
UnitType
Map units that qgis supports.
Definition: qgis.h:229
Represents a vector layer which manages a vector based data sets.