QGIS API Documentation  2.5.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( QList< QgsMapLayer* >& layers ) { mLayers = layers; }
48  int writeToFile( QIODevice* d ); //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 
66  void writeGroup( int code, int i );
68  void writeGroup( int code, double d );
69  void writeGroup( int code, const QString& s );
70  void writeGroupCode( int code );
71  void writeInt( int i );
72  void writeDouble( double d );
73  void writeString( const QString& s );
74 
75  //draw dxf primitives
76  void writePolyline( const QgsPolyline& line, const QString& layer, const QString& lineStyleName, int color,
77  double width = -1, bool polygon = false );
78 
79  void writeSolid( const QString& layer, int color, const QgsPoint& pt1, const QgsPoint& pt2, const QgsPoint& pt3, const QgsPoint& pt4 );
80 
81  //write line (as a polyline)
82  void writeLine( const QgsPoint& pt1, const QgsPoint& pt2, const QString& layer, const QString& lineStyleName, int color, double width = -1 );
83 
84  void writePoint( const QString& layer, int color, const QgsPoint& pt );
85 
86  void writeCircle( const QString& layer, int color, const QgsPoint& pt, double radius );
87 
88  void writeText( const QString& layer, const QString& text, const QgsPoint& pt, double size, double angle, int color );
89 
90  static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits );
91 
92  static QString dxfLayerName( const QString& name );
93 
94 
95  private:
96 
97  QList< QgsMapLayer* > mLayers;
99  QgsRectangle mExtent;
101  double mSymbologyScaleDenominator;
102  SymbologyExport mSymbologyExport;
103  QGis::UnitType mMapUnits;
104 
105  QTextStream mTextStream;
106 
107  static double mDxfColors[][3];
108 
109  int mSymbolLayerCounter; //internal counter
110  int mNextHandleId;
111  int mBlockCounter;
112 
113  QHash< const QgsSymbolLayerV2*, QString > mLineStyles; //symbol layer name types
114  QHash< const QgsSymbolLayerV2*, QString > mPointSymbolBlocks; //reference to point symbol blocks
115 
116  //AC1009
117  void writeHeader();
118  void writeTables();
119  void writeBlocks();
120  void writeEntities();
121  void writeEntitiesSymbolLevels( QgsVectorLayer* layer );
122  void writeEndFile();
123 
124  void startSection();
125  void endSection();
126 
127  void writePoint( const QgsPoint& pt, const QString& layer, int color, const QgsFeature* f, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol );
128  void writeVertex( const QgsPoint& pt, const QString& layer );
129  void writeDefaultLinestyles();
130  void writeSymbolLayerLinestyle( const QgsSymbolLayerV2* symbolLayer );
131  void writeLinestyle( const QString& styleName, const QVector<qreal>& pattern, QgsSymbolV2::OutputUnit u );
132 
133  //AC1018
134  void writeHeaderAC1018( QTextStream& stream );
135  void writeTablesAC1018( QTextStream& stream );
136  void writeEntitiesAC1018( QTextStream& stream );
137  void writeEntitiesSymbolLevelsAC1018( QTextStream& stream, QgsVectorLayer* layer );
138  void writeSymbolLayerLinestyleAC1018( QTextStream& stream, const QgsSymbolLayerV2* symbolLayer );
139  void writeLinestyleAC1018( QTextStream& stream, const QString& styleName, const QVector<qreal>& pattern, QgsSymbolV2::OutputUnit u );
140  void writeVertexAC1018( QTextStream& stream, const QgsPoint& pt );
141  void writePolylineAC1018( QTextStream& stream, const QgsPolyline& line, const QString& layer, const QString& lineStyleName, int color,
142  double width = -1, bool polygon = false );
143 
144 
145  QgsRectangle dxfExtent() const;
146 
147  void addFeature( const QgsSymbolV2RenderContext& ctx, const QString& layer, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol );
148 
149  //returns dxf palette index from symbol layer color
150  static int colorFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2RenderContext& ctx );
151  QString lineStyleFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer );
152 
153  //functions for dxf palette
154  static int color_distance( QRgb p1, int index );
155  static QRgb createRgbEntry( qreal r, qreal g, qreal b );
156 
157  //helper functions for symbology export
158  QgsRenderContext renderContext() const;
159 
160  QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2* > > symbolLayers();
161  static int nLineTypes( const QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2*> >& symbolLayers );
162  static bool hasDataDefinedProperties( const QgsSymbolLayerV2* sl, const QgsSymbolV2* symbol );
163  double dashSize() const;
164  double dotSize() const;
165  double dashSeparatorSize() const;
166  double sizeToMapUnits( double s ) const;
167  static QString lineNameFromPenStyle( Qt::PenStyle style );
168  bool layerIsScaleBasedVisible( const QgsMapLayer* layer ) const;
169 };
170 
171 #endif // QGSDXFEXPORT_H
static unsigned index
Definition: mersenne-twister.cpp:36
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:48
void setSymbologyScaleDenominator(double d)
Definition: qgsdxfexport.h:50
OutputUnit
Definition: qgssymbolv2.h:47
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
Definition: qgssymbollayerv2.h:45
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
QgsRectangle extent() const
Definition: qgsdxfexport.h:60
SymbologyExport
Definition: qgsdxfexport.h:35
Definition: qgssymbolv2.h:43
Definition: qgsdxfexport.h:38
A class to represent a point geometry.
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
void addLayers(QList< QgsMapLayer * > &layers)
Definition: qgsdxfexport.h:47
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:39
void setExtent(const QgsRectangle &r)
Definition: qgsdxfexport.h:59
void setMapUnits(QGis::UnitType u)
Definition: qgsdxfexport.h:53
Definition: qgssymbolv2.h:165
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:470
double size
Definition: qgssvgcache.cpp:77
Definition: qgsdxfexport.h:32