QGIS API Documentation  2.9.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
84  void writePolygon( const QgsPolygon &polygon, const QString &layer, const QString &hatchPattern, QColor color );
85 
86  void writeSolid( const QString &layer, QColor color, const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, const QgsPoint &pt4 );
87 
89  void writeLine( const QgsPoint &pt1, const QgsPoint &pt2, const QString &layer, const QString &lineStyleName, QColor color, double width = -1 );
90 
91  void writePoint( const QString &layer, QColor color, const QgsPoint &pt );
92 
93  void writeFilledCircle( const QString &layer, QColor color, const QgsPoint &pt, double radius );
94 
95  void writeCircle( const QString &layer, QColor color, const QgsPoint &pt, double radius, const QString &lineStyleName, double width );
96 
97  void writeText( const QString &layer, const QString &text, const QgsPoint &pt, double size, double angle, QColor color );
98 
99  void writeMText( const QString &layer, const QString &text, const QgsPoint &pt, double width, double angle, QColor color );
100 
101  static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits );
102 
104  static QString dxfLayerName( const QString &name );
105 
107  static QString dxfEncoding( const QString &name );
108 
110  static QStringList encodings();
111 
112  private:
113  QList< QPair<QgsVectorLayer*, int> > mLayers;
114 
116  QgsRectangle mExtent;
118  double mSymbologyScaleDenominator;
119  SymbologyExport mSymbologyExport;
120  QGis::UnitType mMapUnits;
121 
122  QTextStream mTextStream;
123 
124  static int mDxfColors[][3];
125  static const char *mDxfEncodings[][2];
126 
127  int mSymbolLayerCounter; //internal counter
128  int mNextHandleId;
129  int mBlockCounter;
130 
131  QHash< const QgsSymbolLayerV2*, QString > mLineStyles; //symbol layer name types
132  QHash< const QgsSymbolLayerV2*, QString > mPointSymbolBlocks; //reference to point symbol blocks
133 
134  //AC1009
135  void writeHeader( QString codepage );
136  void writeTables();
137  void writeBlocks();
138  void writeEntities();
139  void writeEntitiesSymbolLevels( QgsVectorLayer *layer );
140  void writeEndFile();
141 
142  void startSection();
143  void endSection();
144 
145  void writePoint( const QgsPoint &pt, const QString &layer, QColor color, const QgsFeature *f, const QgsSymbolLayerV2 *symbolLayer, const QgsSymbolV2 *symbol );
146  void writeVertex( const QgsPoint &pt, const QString &layer );
147  void writeDefaultLinetypes();
148  void writeSymbolLayerLinetype( const QgsSymbolLayerV2 *symbolLayer );
149  void writeLinetype( const QString &styleName, const QVector<qreal> &pattern, QgsSymbolV2::OutputUnit u );
150 
151  QgsRectangle dxfExtent() const;
152 
153  void addFeature( const QgsSymbolV2RenderContext &ctx, const QString &layer, const QgsSymbolLayerV2 *symbolLayer, const QgsSymbolV2 *symbol );
154 
155  //returns dxf palette index from symbol layer color
156  static QColor colorFromSymbolLayer( const QgsSymbolLayerV2 *symbolLayer, const QgsSymbolV2RenderContext &ctx );
157  QString lineStyleFromSymbolLayer( const QgsSymbolLayerV2 *symbolLayer );
158 
159  //functions for dxf palette
160  static int color_distance( QRgb p1, int index );
161  static QRgb createRgbEntry( qreal r, qreal g, qreal b );
162 
163  //helper functions for symbology export
164  QgsRenderContext renderContext() const;
165 
166  QList< QPair< QgsSymbolLayerV2 *, QgsSymbolV2 * > > symbolLayers();
167  static int nLineTypes( const QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2*> > &symbolLayers );
168  static bool hasDataDefinedProperties( const QgsSymbolLayerV2 *sl, const QgsSymbolV2 *symbol );
169  double dashSize() const;
170  double dotSize() const;
171  double dashSeparatorSize() const;
172  double sizeToMapUnits( double s ) const;
173  static QString lineNameFromPenStyle( Qt::PenStyle style );
174  bool layerIsScaleBasedVisible( const QgsMapLayer *layer ) const;
175 
176  int mModelSpaceBR;
177 };
178 
179 #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
UnitType
Map units that qgis supports.
Definition: qgis.h:229
QVector< QgsPoint > QgsPolyline
polyline is represented as a vector of points
Definition: qgsgeometry.h:33
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:119
QgsRectangle extent() const
Definition: qgsdxfexport.h:60
QVector< QgsPolyline > QgsPolygon
polygon: first item of the list is outer ring, inner rings (if any) start from second item ...
Definition: qgsgeometry.h:39
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
Represents a vector layer which manages a vector based data sets.
double size
Definition: qgssvgcache.cpp:77