Subversion Repositories public

Rev

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