Subversion Repositories public

Rev

Rev 273 | Rev 275 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 273 Rev 274
Line 1... Line 1...
1
//
1
//
2
// C++ Interface: render
2
// C++ Interface: SRender
3
//
3
//
4
// Description: This defines the class for render.
4
// Description: This defines the class for SRender.
5
//
5
//
6
//
6
//
7
// Author: Andreas Theofilu <andreas@theosys.at>, (C) 2009
7
// Author: Andreas Theofilu <andreas@theosys.at>, (C) 2009
8
//
8
//
9
// Copyright: See COPYING file that comes with this distribution
9
// Copyright: See COPYING file that comes with this distribution
10
//
10
//
11
//
11
//
12
#ifndef _RENDER_H
12
#ifndef _RENDER_H
13
#define _RENDER_H
13
#define _RENDER_H
14
 
14
 
15
#include <QLabel>
15
#include <mapnik/map.hpp>
-
 
16
#include <mapnik/datasource_cache.hpp>
-
 
17
#include <mapnik/font_engine_freetype.hpp>
-
 
18
#include <mapnik/agg_renderer.hpp>
-
 
19
#include <mapnik/filter_factory.hpp>
-
 
20
#include <mapnik/color_factory.hpp>
16
#include <QString>
21
#include <mapnik/image_util.hpp>
17
#include <QPainter>
22
#include <mapnik/config_error.hpp>
18
#include <QXmlReader>
23
#include <mapnik/color.hpp>
19
#include <KStandardDirs>
24
#include <mapnik/layer.hpp>
-
 
25
 
-
 
26
/* conversions */
-
 
27
 
-
 
28
#define DEGREES      180.0
-
 
29
#define SEMICIRCLES  0x80000000
-
 
30
 
-
 
31
#define SEMI2DEG(a)  (double)(a) * DEGREES / SEMICIRCLES
-
 
32
#define DEG2SEMI(a)  rint((double)(a) * SEMICIRCLES / DEGREES)
-
 
33
 
-
 
34
#define DEG2RAD(a)   (a) * M_PI / DEGREES
-
 
35
#define RAD2DEG(a)   (a) * DEGREES / M_PI
-
 
36
 
-
 
37
typedef enum {
-
 
38
	type_png	= 150,
-
 
39
	type_gif	= 151,
-
 
40
	type_jpg	= 152,
-
 
41
	type_xpm	= 153,
-
 
42
	type_tif	= 154,
-
 
43
	type_bmp	= 155
-
 
44
}TYPES;
20
 
45
 
21
typedef struct LINESYMBOLIZER
46
typedef struct LINESYMBOLIZER
22
{
47
{
23
	Color     stroke;
48
	unsigned  stroke;		// Color
24
	double    stroke_width;
49
	double    stroke_width;
25
	short int stroke_linejoin;
50
	QString   stroke_linejoin;
26
	short int stroke_linecap;
51
	QString   stroke_linecap;
27
	double    stroke_dasharray[10];
52
	double    stroke_dasharray[10];
-
 
53
	int       stroke_anz;		// number of entries in dasharray
28
	double    stroke_opacity;
54
	double    stroke_opacity;
29
	LINESYMBOLIZER *next;
55
	LINESYMBOLIZER *next;
30
}LINESYMBOLIZER;
56
}LINESYMBOLIZER;
31
 
57
 
32
typedef struct POLYGONSYMBOLIZER
58
typedef struct POLYGONSYMBOLIZER
33
{
59
{
34
	Color     fill;
60
	unsigned  fill;			// Color
35
	double    fill_opacity;
61
	double    fill_opacity;
36
	POLYGONSYMBOLIZER *next;
62
	POLYGONSYMBOLIZER *next;
37
}POLYGONSYMBOLIZER;
63
}POLYGONSYMBOLIZER;
38
 
64
 
39
typedef struct TEXTSYMBOLIZER
65
typedef struct TEXTSYMBOLIZER
40
{
66
{
41
	QString   name;
67
	QString   name;
42
	QString   face_name;
68
	QString   face_name;
43
	double    size;
69
	double    size;
44
	Color     fill;
70
	unsigned  fill;			// Color
45
	double    halo_radius;
71
	double    halo_radius;
46
	double    wrap_width;
72
	double    wrap_width;
47
	double    dy;
73
	double    dy;
48
	double    mindistance;
74
	double    mindistance;
49
	double    maxdistance;
75
	double    maxdistance;
Line 51... Line 77...
51
}TEXTSYMBOLIZER;
77
}TEXTSYMBOLIZER;
52
 
78
 
53
typedef struct POINTSYMBOLIZER
79
typedef struct POINTSYMBOLIZER
54
{
80
{
55
	QString   file;
81
	QString   file;
56
	int       type;		// enum TYPES
82
	TYPES     type;		// enum TYPES
57
	double    width;
83
	double    width;
58
	double    height;
84
	double    height;
59
	bool      allow_overlap;
85
	bool      allow_overlap;
60
	POINTSYMBOLIZER *next;
86
	POINTSYMBOLIZER *next;
61
}POINTSYMBOLIZER;
87
}POINTSYMBOLIZER;
62
 
88
 
63
typedef struct POLYGONPATTERNSYMBOLIZER
89
typedef struct POLYGONPATTERNSYMBOLIZER
64
{
90
{
65
	QString   file;
91
	QString   file;
66
	int       type;		// enum TYPES
92
	TYPES     type;		// enum TYPES
67
	double    width;
93
	double    width;
68
	double    height;
94
	double    height;
69
	bool      allow_overlap;
95
	bool      allow_overlap;
70
	POLYGONPATTERNSYMBOLIZER *next;
96
	POLYGONPATTERNSYMBOLIZER *next;
71
}POLYGONPATTERNSYMBOLIZER;
97
}POLYGONPATTERNSYMBOLIZER;
Line 73... Line 99...
73
typedef struct SHIELDSYMBOLIZER
99
typedef struct SHIELDSYMBOLIZER
74
{
100
{
75
	QString   name;
101
	QString   name;
76
	QString   face_name;
102
	QString   face_name;
77
	double    size;
103
	double    size;
78
	Color     fill;
104
	unsigned  fill;		// Color
79
	QString   placement;
105
	QString   placement;
80
	QString   file;
106
	QString   file;
81
	int       type;
107
	TYPES     type;		// enum TYPES
82
	double    width;
108
	double    width;
83
	double    height;
109
	double    height;
84
	double    mindistance;
110
	double    mindistance;
85
	double    maxdistance;
111
	double    maxdistance;
86
	SHIELDSYMBOLIZER *next;
112
	SHIELDSYMBOLIZER *next;
87
}SHIELDSYMBOLIZER;
113
}SHIELDSYMBOLIZER;
88
 
114
 
89
typedef struct LINEPATTERNSYMBOLIZER
115
typedef struct LINEPATTERNSYMBOLIZER
90
{
116
{
91
	QString   file;
117
	QString   file;
92
	int       type;
118
	TYPES     type;		// enum TYPES
93
	double    width;
119
	double    width;
94
	double    height;
120
	double    height;
95
	LINEPATTERNSYMBOLIZER *next;
121
	LINEPATTERNSYMBOLIZER *next;
96
}LINEPATTERNSYMBOLIZER;
122
}LINEPATTERNSYMBOLIZER;
97
 
123
 
Line 123... Line 149...
123
	QString   file;
149
	QString   file;
124
	QString   host;
150
	QString   host;
125
	QString   user;
151
	QString   user;
126
	QString   dbname;
152
	QString   dbname;
127
	QString   table;
153
	QString   table;
128
	bool      estimate_extend;
154
	bool      estimate_extent;
129
	double    ext_lx;
155
	double    ext_lx;
130
	double    ext_ly;
156
	double    ext_ly;
131
	double    ext_rx;
157
	double    ext_rx;
132
	double    ext_ry;
158
	double    ext_ry;
133
}DATASOURCE;
159
}DATASOURCE;
134
 
160
 
135
typedef struct LAYER
161
typedef struct LAYER
136
{
162
{
137
	QString    name;
163
	QString    name;	// The unique name
138
	bool       status;
164
	bool       status;	// Is it active?
139
	QString    srs;		// Projection
165
	QString    srs;		// Projection
140
	STYLE      *Style;	// Pointer to first style
166
	QStringList Styles;	// The names of the Styles
141
	DATASOURCE Datasource;
167
	DATASOURCE Datasource;
142
	LAYER      *next;	// Pointer to next layer
168
	LAYER      *next;	// Pointer to next layer
143
}LAYER;
169
}LAYER;
144
 
170
 
145
typedef struct
171
typedef struct
146
{
172
{
147
	Color      bgcolor;
173
	unsigned   bgcolor;	// Color
148
	int        buffer_size;
174
	int        buf_size;
149
	QString    srs;
175
	QString    srs;
150
}MAP;
176
}MAP;
151
 
177
 
152
typedef enum {
178
typedef enum {
-
 
179
	empty		 = 0,
153
	stroke		 = 100,
180
	stroke_stroke	 = 100,
154
	stroke_width	 = 101,
181
	stroke_width	 = 101,
155
	stroke_linejoin  = 102,
182
	stroke_linejoin  = 102,
156
	stroke_linecap   = 103,
183
	stroke_linecap   = 103,
157
	stroke_opacity   = 104,
184
	stroke_opacity   = 104,
158
	stroke_dasharray = 105
185
	stroke_dasharray = 105,
-
 
186
	fill		 = 106,
-
 
187
	fill_opacity	 = 107,
-
 
188
	type		 = 108,
-
 
189
	file		 = 109,
-
 
190
	host		 = 110,
-
 
191
	user		 = 111,
-
 
192
	dbname		 = 112,
-
 
193
	table		 = 113,
-
 
194
	estimate_extent  = 114,
-
 
195
	extent		 = 115
159
}NAMES;
196
}NAMES;
160
 
197
 
161
typedef enum {
198
typedef enum {
162
	type_png	= 150,
-
 
163
	type_gif	= 151,
-
 
164
	type_jpg	= 152,
-
 
165
	type_xpm	= 153,
-
 
166
	type_tif	= 154,
199
	in_root			= 0,
167
	type_bmp	= 155
-
 
168
}TYPES;
-
 
169
 
-
 
170
typedef enum {
-
 
171
	in_map			= 100,
200
	in_map			= 100,
172
	in_style		= 101,
201
	in_style		= 101,
173
	in_rule			= 102,
202
	in_rule			= 102,
174
	in_linesymbolizer	= 103,
203
	in_linesymbolizer	= 103,
175
	in_pointsymbolizer	= 104,
204
	in_pointsymbolizer	= 104,
176
	in_polygonsymbolizer	= 105,
205
	in_polygonsymbolizer	= 105,
177
	in_textsymbolizer	= 106,
206
	in_textsymbolizer	= 106,
178
	in_polygonpatternsymbolizer = 107,
207
	in_polygonpatternsymbolizer = 107,
179
	in_layer		= 108,
208
	in_layer		= 108,
180
	in_datasource		= 109
209
	in_datasource		= 109,
-
 
210
	in_symbolizer		= 110,
-
 
211
	in_shieldsymbolizer	= 111,
-
 
212
	in_linepatternsymbolizer = 112
181
}CONTAINER;
213
}CONTAINER;
182
 
214
 
-
 
215
typedef struct
-
 
216
{
-
 
217
	int id;
-
 
218
	CONTAINER con;
-
 
219
	QString name;
-
 
220
}TOKEN;
-
 
221
 
183
extern KEYS keys[];		// defined at >import.h<
222
using namespace mapnik;
184
 
223
 
185
class render
224
class SRender : public QXmlDefaultHandler
186
{
225
{
187
	public:
226
	public:
188
	   render();
227
	   SRender();
-
 
228
	   ~SRender();
189
 
229
 
190
	   bool setDrawArea(QLabel *lb) { if (!lb) return false; label = *lb; return true; };
230
	   void setDrawArea(const QLabel &lb) { label = (QLabel *)&lb; };
191
	   bool setShapePath(QString *str) { if (!str) return false; shapePath = *str; return true; };
231
	   void setShapePath(const QString &str) { if (str.isNull()) return; shapePath = str; };
-
 
232
	   void setXmlPath(const QString &path) { if (path.isNull()) return; XmlPath = path; };
192
	   bool getMap(double lx, double ly, double rx, double ry);
233
	   bool getMap(double lx, double ly, double rx, double ry);
193
 
234
 
-
 
235
	   // Functions to parse the XML file
194
	   bool startDocument ();
236
	   bool startDocument ();
195
	   bool startElement (const QString&, const QString&, const QString& , const QXmlAttributes&);
237
	   bool startElement (const QString&, const QString&, const QString& , const QXmlAttributes&);
196
	   bool endElement (const QString&, const QString&, const QString&);
238
	   bool endElement (const QString&, const QString&, const QString&);
197
	   bool characters (const QString&);
239
	   bool characters (const QString&);
198
 
240
 
199
	protected:
-
 
200
	   void addRule (feature_type_style &fts, char *filter, double minscale, double maxscale, Color &polcol, Color &symcol, double symwidth, QString &pattern, int pw, int ph);
-
 
201
	   void addRulePoint (feature_type_style &fts, char *filter, double minscale, double maxscale, Color &polcol, Color &symcol, double symwidth, QString &pattern, int pw, int ph);
-
 
202
	   void addTextSymbolizer (char *name, char *font, int size, Color &col, int radius, int wrap, double dy);
-
 
203
 
-
 
204
	private:
241
	private:
205
	   QString getKey (int pos);
242
	   QString getKey (int pos);
-
 
243
	   TYPES getType(QString ty);
-
 
244
	   char *getTypeText(TYPES type);
-
 
245
	   bool getBool(QString b);
-
 
246
	   unsigned colorToUInt(QString col);
-
 
247
	   STYLE *findStyle(QString name);
206
	   RULE *getLastRule(RULE *first);
248
	   RULE *getLastRule(RULE *first);
207
	   POINTSYMBOLIZER *getLastPointSymbolizer(POINTSYMBOLIZER *first);
249
	   POINTSYMBOLIZER *getLastPointSymbolizer(POINTSYMBOLIZER *first);
-
 
250
	   LINESYMBOLIZER *getLastLineSymbolizer(LINESYMBOLIZER *first);
-
 
251
	   POLYGONSYMBOLIZER *getLastPolygonSymbolizer(POLYGONSYMBOLIZER *first);
-
 
252
	   TEXTSYMBOLIZER *getLastTextSymbolizer(TEXTSYMBOLIZER *first);
-
 
253
	   POLYGONPATTERNSYMBOLIZER *getLastPolygonPatternSymbolizer(POLYGONPATTERNSYMBOLIZER *first);
-
 
254
	   SHIELDSYMBOLIZER *getLastShieldSymbolizer(SHIELDSYMBOLIZER *first);
-
 
255
	   LINEPATTERNSYMBOLIZER *getLastLinePatternSymbolizer(LINEPATTERNSYMBOLIZER *first);
-
 
256
 
-
 
257
	   STYLE *allocStyle();
-
 
258
	   RULE *allocRule();
-
 
259
	   LAYER *allocLayer();
-
 
260
	   POINTSYMBOLIZER *allocPointSymbolizer();
-
 
261
	   LINESYMBOLIZER *allocLineSymbolizer();
-
 
262
	   POLYGONSYMBOLIZER *allocPolygonSymbolizer();
-
 
263
	   TEXTSYMBOLIZER *allocTextSymbolizer();
-
 
264
	   POLYGONPATTERNSYMBOLIZER *allocPolygonPatternSymbolizer();
-
 
265
	   SHIELDSYMBOLIZER *allocShieldSymbolizer();
-
 
266
	   LINEPATTERNSYMBOLIZER *allocLinePatternSymbolizer();
208
 
267
 
209
	private:
268
	private:
210
	   QLabel label;
269
	   QLabel *label;
211
	   QString shapePath;
270
	   QString shapePath;
-
 
271
	   QString pluginPath;
-
 
272
	   QString fontPath;
212
	   QString XmlPath;
273
	   QString XmlPath;
213
	   int indent;
-
 
214
	   CONTAINER Container;
274
	   CONTAINER Container;
-
 
275
	   bool ControlSet;
-
 
276
	   int Field;
215
	   TYPES Types;
277
	   TYPES Types;
216
	   NAMES Names;
278
	   NAMES Names;
217
	   MAP MapPars;
279
	   MAP MapPars;
218
	   LAYER *Layer;
280
	   Map m;
-
 
281
	   LAYER *Lay, *firstLayer, *lastLayer;
219
	   STYLE *Style, *firstStyle, *lastStyle;
282
	   STYLE *Style, *firstStyle, *lastStyle;
220
	   RULE *Rule;
283
	   RULE *Rule;
221
	   LINESYMBOLIZER		*LineSymbolizer;
284
	   LINESYMBOLIZER		*LineSymbolizer;
222
	   POLYGONSYMBOLIZER	 	*PolygonSymbolizer;
285
	   POLYGONSYMBOLIZER	 	*PolygonSymbolizer;
223
	   TEXTSYMBOLIZER		*TextSymbolizer;
286
	   TEXTSYMBOLIZER		*TextSymbolizer;