Subversion Repositories public

Rev

Rev 278 | Go to most recent revision | 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;
275 andreas 150
	mapnik::rule_type rl;		// the rule to be added to a style
273 andreas 151
	RULE *next;		// Pointer to next rule
152
}RULE;
153
 
154
typedef struct STYLE
155
{
156
	QString  name;
157
	RULE     *rule;		// Pointer to first rule node of the chain
158
	STYLE    *next;		// Pointer to next style
159
}STYLE;
160
 
161
typedef struct
162
{
163
	QString   type;
164
	QString   file;
276 andreas 165
	QString   parser;
166
	QString   url;
167
	QString   bbox;
273 andreas 168
	QString   host;
169
	QString   user;
170
	QString   dbname;
171
	QString   table;
274 andreas 172
	bool      estimate_extent;
273 andreas 173
	double    ext_lx;
174
	double    ext_ly;
175
	double    ext_rx;
176
	double    ext_ry;
177
}DATASOURCE;
178
 
179
typedef struct LAYER
180
{
274 andreas 181
	QString    name;	// The unique name
276 andreas 182
	QString    title;	// The title of the layer (optional)
183
	QString    abstract;	// Some short description (optional)
274 andreas 184
	bool       status;	// Is it active?
276 andreas 185
	bool	   clear_label; // Clear label cache?
273 andreas 186
	QString    srs;		// Projection
275 andreas 187
	double     minzoom;
188
	double     maxzoom;
276 andreas 189
	bool       queryable;
274 andreas 190
	QStringList Styles;	// The names of the Styles
273 andreas 191
	DATASOURCE Datasource;
192
	LAYER      *next;	// Pointer to next layer
193
}LAYER;
194
 
195
typedef struct
196
{
274 andreas 197
	unsigned   bgcolor;	// Color
198
	int        buf_size;
273 andreas 199
	QString    srs;
200
}MAP;
201
 
202
typedef enum {
274 andreas 203
	empty		 = 0,
204
	stroke_stroke	 = 100,
273 andreas 205
	stroke_width	 = 101,
206
	stroke_linejoin  = 102,
207
	stroke_linecap   = 103,
208
	stroke_opacity   = 104,
274 andreas 209
	stroke_dasharray = 105,
210
	fill		 = 106,
211
	fill_opacity	 = 107,
212
	type		 = 108,
213
	file		 = 109,
214
	host		 = 110,
215
	user		 = 111,
216
	dbname		 = 112,
217
	table		 = 113,
218
	estimate_extent  = 114,
276 andreas 219
	extent		 = 115,
220
	parser__	 = 116,
221
	url		 = 117,
222
	bbox		 = 118
273 andreas 223
}NAMES;
224
 
225
typedef enum {
274 andreas 226
	in_root			= 0,
273 andreas 227
	in_map			= 100,
228
	in_style		= 101,
229
	in_rule			= 102,
230
	in_linesymbolizer	= 103,
231
	in_pointsymbolizer	= 104,
232
	in_polygonsymbolizer	= 105,
233
	in_textsymbolizer	= 106,
234
	in_polygonpatternsymbolizer = 107,
235
	in_layer		= 108,
274 andreas 236
	in_datasource		= 109,
237
	in_symbolizer		= 110,
238
	in_shieldsymbolizer	= 111,
276 andreas 239
	in_linepatternsymbolizer = 112,
240
	in_elsefilter		= 113
273 andreas 241
}CONTAINER;
242
 
274 andreas 243
typedef struct
244
{
245
	int id;
246
	CONTAINER con;
247
	QString name;
248
}TOKEN;
273 andreas 249
 
274 andreas 250
using namespace mapnik;
251
 
252
class SRender : public QXmlDefaultHandler
273 andreas 253
{
254
	public:
276 andreas 255
	   enum map_type
256
	   {
257
	      MAP_SHAPE,
258
	      MAP_GIS,
259
	      MAP_OSM,
260
	      map_type_MAX
261
	   };
262
 
263
	public:
274 andreas 264
	   SRender();
265
	   ~SRender();
273 andreas 266
 
280 andreas 267
	   void setDrawArea(int, int);
268
	   QPixmap pixmap() { return pxmap; };
274 andreas 269
	   void setShapePath(const QString &str) { if (str.isNull()) return; shapePath = str; };
270
	   void setXmlPath(const QString &path) { if (path.isNull()) return; XmlPath = path; };
273 andreas 271
	   bool getMap(double lx, double ly, double rx, double ry);
276 andreas 272
	   inline void setMapType(map_type mt) { __map_type = mt; }
273
	   inline map_type getMapType() { return __map_type; }
273 andreas 274
 
274 andreas 275
	   // Functions to parse the XML file
273 andreas 276
	   bool startDocument ();
277
	   bool startElement (const QString&, const QString&, const QString& , const QXmlAttributes&);
278
	   bool endElement (const QString&, const QString&, const QString&);
279
	   bool characters (const QString&);
280
 
275 andreas 281
	protected:
282
	   void setMaxExtent(double lx, double ly, double rx, double ry);
283
	   QString findIcon(QString ic);
284
 
273 andreas 285
	private:
286
	   QString getKey (int pos);
274 andreas 287
	   TYPES getType(QString ty);
288
	   char *getTypeText(TYPES type);
289
	   bool getBool(QString b);
290
	   unsigned colorToUInt(QString col);
278 andreas 291
	   color setColor(unsigned);
274 andreas 292
	   STYLE *findStyle(QString name);
273 andreas 293
	   RULE *getLastRule(RULE *first);
294
	   POINTSYMBOLIZER *getLastPointSymbolizer(POINTSYMBOLIZER *first);
274 andreas 295
	   LINESYMBOLIZER *getLastLineSymbolizer(LINESYMBOLIZER *first);
296
	   POLYGONSYMBOLIZER *getLastPolygonSymbolizer(POLYGONSYMBOLIZER *first);
297
	   TEXTSYMBOLIZER *getLastTextSymbolizer(TEXTSYMBOLIZER *first);
298
	   POLYGONPATTERNSYMBOLIZER *getLastPolygonPatternSymbolizer(POLYGONPATTERNSYMBOLIZER *first);
299
	   SHIELDSYMBOLIZER *getLastShieldSymbolizer(SHIELDSYMBOLIZER *first);
300
	   LINEPATTERNSYMBOLIZER *getLastLinePatternSymbolizer(LINEPATTERNSYMBOLIZER *first);
273 andreas 301
 
274 andreas 302
	   STYLE *allocStyle();
303
	   RULE *allocRule();
304
	   LAYER *allocLayer();
305
	   POINTSYMBOLIZER *allocPointSymbolizer();
306
	   LINESYMBOLIZER *allocLineSymbolizer();
307
	   POLYGONSYMBOLIZER *allocPolygonSymbolizer();
308
	   TEXTSYMBOLIZER *allocTextSymbolizer();
309
	   POLYGONPATTERNSYMBOLIZER *allocPolygonPatternSymbolizer();
310
	   SHIELDSYMBOLIZER *allocShieldSymbolizer();
311
	   LINEPATTERNSYMBOLIZER *allocLinePatternSymbolizer();
312
 
273 andreas 313
	private:
280 andreas 314
	   QPixmap pxmap;
273 andreas 315
	   QString shapePath;
274 andreas 316
	   QString pluginPath;
317
	   QString fontPath;
273 andreas 318
	   QString XmlPath;
278 andreas 319
	   bool geographic;
276 andreas 320
	   map_type __map_type;
280 andreas 321
	   int _width, _height;
273 andreas 322
	   CONTAINER Container;
274 andreas 323
	   bool ControlSet;
324
	   int Field;
275 andreas 325
	   int XmlLine;	// Line number of the current position in XML file
326
	   double _lx, _ly, _rx, _ry;
273 andreas 327
	   TYPES Types;
328
	   NAMES Names;
329
	   MAP MapPars;
274 andreas 330
	   Map m;
331
	   LAYER *Lay, *firstLayer, *lastLayer;
273 andreas 332
	   STYLE *Style, *firstStyle, *lastStyle;
333
	   RULE *Rule;
334
	   LINESYMBOLIZER		*LineSymbolizer;
335
	   POLYGONSYMBOLIZER	 	*PolygonSymbolizer;
336
	   TEXTSYMBOLIZER		*TextSymbolizer;
337
	   POINTSYMBOLIZER		*PointSymbolizer;
338
	   POLYGONPATTERNSYMBOLIZER 	*PolygonPatternSymbolizer;
339
	   SHIELDSYMBOLIZER	 	*ShieldSymbolizer;
340
	   LINEPATTERNSYMBOLIZER    	*LinePatternSymbolizer;
341
};
342
 
280 andreas 343
#endif // HAVE_MAPNIK
273 andreas 344
#endif // _RENDER_H