Subversion Repositories public

Rev

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