Subversion Repositories public

Rev

Rev 280 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
273 andreas 1
//
274 andreas 2
// C++ Interface: SRender
273 andreas 3
//
274 andreas 4
// Description: This defines the class for SRender.
273 andreas 5
//
6
//
7
// Author: Andreas Theofilu <andreas@theosys.at>, (C) 2009
8
//
9
// Copyright: See COPYING file that comes with this distribution
10
//
11
//
12
#ifndef _RENDER_H
13
#define _RENDER_H
14
 
280 andreas 15
#include "config.h"
16
 
17
// Everything here is only available, if Mapnik is available!
18
#if defined HAVE_MAPNIK
19
 
274 andreas 20
#include <mapnik/map.hpp>
21
#include <mapnik/datasource_cache.hpp>
22
#include <mapnik/font_engine_freetype.hpp>
23
#include <mapnik/agg_renderer.hpp>
24
#include <mapnik/filter_factory.hpp>
25
#include <mapnik/color_factory.hpp>
26
#include <mapnik/image_util.hpp>
27
#include <mapnik/config_error.hpp>
276 andreas 28
#include <mapnik/load_map.hpp>
29
#include <mapnik/save_map.hpp>
278 andreas 30
#include <mapnik/version.hpp>
273 andreas 31
 
274 andreas 32
/* conversions */
33
 
34
#define DEGREES      180.0
35
#define SEMICIRCLES  0x80000000
36
 
37
#define SEMI2DEG(a)  (double)(a) * DEGREES / SEMICIRCLES
38
#define DEG2SEMI(a)  rint((double)(a) * SEMICIRCLES / DEGREES)
39
 
40
#define DEG2RAD(a)   (a) * M_PI / DEGREES
41
#define RAD2DEG(a)   (a) * DEGREES / M_PI
42
 
43
typedef enum {
44
	type_png	= 150,
45
	type_gif	= 151,
46
	type_jpg	= 152,
47
	type_xpm	= 153,
48
	type_tif	= 154,
49
	type_bmp	= 155
50
}TYPES;
51
 
273 andreas 52
typedef struct LINESYMBOLIZER
53
{
274 andreas 54
	unsigned  stroke;		// Color
273 andreas 55
	double    stroke_width;
274 andreas 56
	QString   stroke_linejoin;
57
	QString   stroke_linecap;
273 andreas 58
	double    stroke_dasharray[10];
274 andreas 59
	int       stroke_anz;		// number of entries in dasharray
273 andreas 60
	double    stroke_opacity;
61
	LINESYMBOLIZER *next;
62
}LINESYMBOLIZER;
63
 
64
typedef struct POLYGONSYMBOLIZER
65
{
274 andreas 66
	unsigned  fill;			// Color
273 andreas 67
	double    fill_opacity;
68
	POLYGONSYMBOLIZER *next;
69
}POLYGONSYMBOLIZER;
70
 
71
typedef struct TEXTSYMBOLIZER
72
{
73
	QString   name;
74
	QString   face_name;
276 andreas 75
	QString   placement;
76
	QString   alignment;
273 andreas 77
	double    size;
274 andreas 78
	unsigned  fill;			// Color
273 andreas 79
	double    halo_radius;
80
	double    wrap_width;
275 andreas 81
	double    dx;
273 andreas 82
	double    dy;
275 andreas 83
	double    mindistance;		// min distance between labels
84
	double    maxdistance;		// not used!
273 andreas 85
	TEXTSYMBOLIZER *next;
86
}TEXTSYMBOLIZER;
87
 
88
typedef struct POINTSYMBOLIZER
89
{
90
	QString   file;
274 andreas 91
	TYPES     type;		// enum TYPES
273 andreas 92
	double    width;
93
	double    height;
94
	bool      allow_overlap;
95
	POINTSYMBOLIZER *next;
96
}POINTSYMBOLIZER;
97
 
98
typedef struct POLYGONPATTERNSYMBOLIZER
99
{
100
	QString   file;
274 andreas 101
	TYPES     type;		// enum TYPES
273 andreas 102
	double    width;
103
	double    height;
104
	bool      allow_overlap;
105
	POLYGONPATTERNSYMBOLIZER *next;
106
}POLYGONPATTERNSYMBOLIZER;
107
 
108
typedef struct SHIELDSYMBOLIZER
109
{
110
	QString   name;
111
	QString   face_name;
112
	double    size;
274 andreas 113
	unsigned  fill;		// Color
273 andreas 114
	QString   placement;
115
	QString   file;
274 andreas 116
	TYPES     type;		// enum TYPES
273 andreas 117
	double    width;
118
	double    height;
275 andreas 119
	double    dx;
120
	double    dy;
121
	double    mindistance;	// min distance to next shield symbol
122
	double    maxdistance;	// not used!
273 andreas 123
	SHIELDSYMBOLIZER *next;
124
}SHIELDSYMBOLIZER;
125
 
126
typedef struct LINEPATTERNSYMBOLIZER
127
{
128
	QString   file;
274 andreas 129
	TYPES     type;		// enum TYPES
273 andreas 130
	double    width;
131
	double    height;
132
	LINEPATTERNSYMBOLIZER *next;
133
}LINEPATTERNSYMBOLIZER;
134
 
135
typedef struct RULE
136
{
276 andreas 137
	QString   name;
138
	QString   title;
273 andreas 139
	double    maxscale;
140
	double    minscale;
141
	QString   filter;
276 andreas 142
	bool      elsefilter;
273 andreas 143
	LINESYMBOLIZER		 *LineSymbolizer;
144
	POLYGONSYMBOLIZER	 *PolygonSymbolizer;
145
	TEXTSYMBOLIZER		 *TextSymbolizer;
146
	POINTSYMBOLIZER		 *PointSymbolizer;
147
	POLYGONPATTERNSYMBOLIZER *PolygonPatternSymbolizer;
148
	SHIELDSYMBOLIZER	 *ShieldSymbolizer;
149
	LINEPATTERNSYMBOLIZER    *LinePatternSymbolizer;
311 andreas 150
//	mapnik::rule_type rl;		// the rule to be added to a style
151
	mapnik::rule rl;		// the rule to be added to a style
273 andreas 152
	RULE *next;		// Pointer to next rule
153
}RULE;
154
 
155
typedef struct STYLE
156
{
157
	QString  name;
158
	RULE     *rule;		// Pointer to first rule node of the chain
159
	STYLE    *next;		// Pointer to next style
160
}STYLE;
161
 
162
typedef struct
163
{
164
	QString   type;
165
	QString   file;
276 andreas 166
	QString   parser;
167
	QString   url;
168
	QString   bbox;
273 andreas 169
	QString   host;
170
	QString   user;
171
	QString   dbname;
172
	QString   table;
274 andreas 173
	bool      estimate_extent;
273 andreas 174
	double    ext_lx;
175
	double    ext_ly;
176
	double    ext_rx;
177
	double    ext_ry;
178
}DATASOURCE;
179
 
180
typedef struct LAYER
181
{
274 andreas 182
	QString    name;	// The unique name
276 andreas 183
	QString    title;	// The title of the layer (optional)
184
	QString    abstract;	// Some short description (optional)
274 andreas 185
	bool       status;	// Is it active?
276 andreas 186
	bool	   clear_label; // Clear label cache?
273 andreas 187
	QString    srs;		// Projection
275 andreas 188
	double     minzoom;
189
	double     maxzoom;
276 andreas 190
	bool       queryable;
274 andreas 191
	QStringList Styles;	// The names of the Styles
273 andreas 192
	DATASOURCE Datasource;
193
	LAYER      *next;	// Pointer to next layer
194
}LAYER;
195
 
196
typedef struct
197
{
274 andreas 198
	unsigned   bgcolor;	// Color
199
	int        buf_size;
273 andreas 200
	QString    srs;
201
}MAP;
202
 
203
typedef enum {
274 andreas 204
	empty		 = 0,
205
	stroke_stroke	 = 100,
273 andreas 206
	stroke_width	 = 101,
207
	stroke_linejoin  = 102,
208
	stroke_linecap   = 103,
209
	stroke_opacity   = 104,
274 andreas 210
	stroke_dasharray = 105,
211
	fill		 = 106,
212
	fill_opacity	 = 107,
213
	type		 = 108,
214
	file		 = 109,
215
	host		 = 110,
216
	user		 = 111,
217
	dbname		 = 112,
218
	table		 = 113,
219
	estimate_extent  = 114,
276 andreas 220
	extent		 = 115,
221
	parser__	 = 116,
222
	url		 = 117,
223
	bbox		 = 118
273 andreas 224
}NAMES;
225
 
226
typedef enum {
274 andreas 227
	in_root			= 0,
273 andreas 228
	in_map			= 100,
229
	in_style		= 101,
230
	in_rule			= 102,
231
	in_linesymbolizer	= 103,
232
	in_pointsymbolizer	= 104,
233
	in_polygonsymbolizer	= 105,
234
	in_textsymbolizer	= 106,
235
	in_polygonpatternsymbolizer = 107,
236
	in_layer		= 108,
274 andreas 237
	in_datasource		= 109,
238
	in_symbolizer		= 110,
239
	in_shieldsymbolizer	= 111,
276 andreas 240
	in_linepatternsymbolizer = 112,
241
	in_elsefilter		= 113
273 andreas 242
}CONTAINER;
243
 
274 andreas 244
typedef struct
245
{
246
	int id;
247
	CONTAINER con;
248
	QString name;
249
}TOKEN;
273 andreas 250
 
274 andreas 251
using namespace mapnik;
252
 
253
class SRender : public QXmlDefaultHandler
273 andreas 254
{
255
	public:
276 andreas 256
	   enum map_type
257
	   {
258
	      MAP_SHAPE,
259
	      MAP_GIS,
260
	      MAP_OSM,
261
	      map_type_MAX
262
	   };
263
 
264
	public:
274 andreas 265
	   SRender();
266
	   ~SRender();
273 andreas 267
 
280 andreas 268
	   void setDrawArea(int, int);
269
	   QPixmap pixmap() { return pxmap; };
274 andreas 270
	   void setShapePath(const QString &str) { if (str.isNull()) return; shapePath = str; };
271
	   void setXmlPath(const QString &path) { if (path.isNull()) return; XmlPath = path; };
273 andreas 272
	   bool getMap(double lx, double ly, double rx, double ry);
276 andreas 273
	   inline void setMapType(map_type mt) { __map_type = mt; }
274
	   inline map_type getMapType() { return __map_type; }
273 andreas 275
 
274 andreas 276
	   // Functions to parse the XML file
273 andreas 277
	   bool startDocument ();
278
	   bool startElement (const QString&, const QString&, const QString& , const QXmlAttributes&);
279
	   bool endElement (const QString&, const QString&, const QString&);
280
	   bool characters (const QString&);
281
 
275 andreas 282
	protected:
283
	   void setMaxExtent(double lx, double ly, double rx, double ry);
284
	   QString findIcon(QString ic);
285
 
273 andreas 286
	private:
287
	   QString getKey (int pos);
274 andreas 288
	   TYPES getType(QString ty);
289
	   char *getTypeText(TYPES type);
290
	   bool getBool(QString b);
291
	   unsigned colorToUInt(QString col);
278 andreas 292
	   color setColor(unsigned);
274 andreas 293
	   STYLE *findStyle(QString name);
273 andreas 294
	   RULE *getLastRule(RULE *first);
295
	   POINTSYMBOLIZER *getLastPointSymbolizer(POINTSYMBOLIZER *first);
274 andreas 296
	   LINESYMBOLIZER *getLastLineSymbolizer(LINESYMBOLIZER *first);
297
	   POLYGONSYMBOLIZER *getLastPolygonSymbolizer(POLYGONSYMBOLIZER *first);
298
	   TEXTSYMBOLIZER *getLastTextSymbolizer(TEXTSYMBOLIZER *first);
299
	   POLYGONPATTERNSYMBOLIZER *getLastPolygonPatternSymbolizer(POLYGONPATTERNSYMBOLIZER *first);
300
	   SHIELDSYMBOLIZER *getLastShieldSymbolizer(SHIELDSYMBOLIZER *first);
301
	   LINEPATTERNSYMBOLIZER *getLastLinePatternSymbolizer(LINEPATTERNSYMBOLIZER *first);
273 andreas 302
 
274 andreas 303
	   STYLE *allocStyle();
304
	   RULE *allocRule();
305
	   LAYER *allocLayer();
306
	   POINTSYMBOLIZER *allocPointSymbolizer();
307
	   LINESYMBOLIZER *allocLineSymbolizer();
308
	   POLYGONSYMBOLIZER *allocPolygonSymbolizer();
309
	   TEXTSYMBOLIZER *allocTextSymbolizer();
310
	   POLYGONPATTERNSYMBOLIZER *allocPolygonPatternSymbolizer();
311
	   SHIELDSYMBOLIZER *allocShieldSymbolizer();
312
	   LINEPATTERNSYMBOLIZER *allocLinePatternSymbolizer();
313
 
273 andreas 314
	private:
280 andreas 315
	   QPixmap pxmap;
273 andreas 316
	   QString shapePath;
274 andreas 317
	   QString pluginPath;
318
	   QString fontPath;
273 andreas 319
	   QString XmlPath;
278 andreas 320
	   bool geographic;
276 andreas 321
	   map_type __map_type;
280 andreas 322
	   int _width, _height;
273 andreas 323
	   CONTAINER Container;
274 andreas 324
	   bool ControlSet;
325
	   int Field;
275 andreas 326
	   int XmlLine;	// Line number of the current position in XML file
327
	   double _lx, _ly, _rx, _ry;
273 andreas 328
	   TYPES Types;
329
	   NAMES Names;
330
	   MAP MapPars;
274 andreas 331
	   Map m;
332
	   LAYER *Lay, *firstLayer, *lastLayer;
273 andreas 333
	   STYLE *Style, *firstStyle, *lastStyle;
334
	   RULE *Rule;
335
	   LINESYMBOLIZER		*LineSymbolizer;
336
	   POLYGONSYMBOLIZER	 	*PolygonSymbolizer;
337
	   TEXTSYMBOLIZER		*TextSymbolizer;
338
	   POINTSYMBOLIZER		*PointSymbolizer;
339
	   POLYGONPATTERNSYMBOLIZER 	*PolygonPatternSymbolizer;
340
	   SHIELDSYMBOLIZER	 	*ShieldSymbolizer;
341
	   LINEPATTERNSYMBOLIZER    	*LinePatternSymbolizer;
342
};
343
 
280 andreas 344
#endif // HAVE_MAPNIK
311 andreas 345
#endif // _RENDER_H