Subversion Repositories public

Rev

Rev 274 | Rev 276 | 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>
275 andreas 16
#include <mapnik/load_map.hpp>
17
#include <mapnik/save_map.hpp>
274 andreas 18
#include <mapnik/datasource_cache.hpp>
19
#include <mapnik/font_engine_freetype.hpp>
20
#include <mapnik/agg_renderer.hpp>
21
#include <mapnik/filter_factory.hpp>
22
#include <mapnik/color_factory.hpp>
23
#include <mapnik/image_util.hpp>
24
#include <mapnik/config_error.hpp>
25
#include <mapnik/color.hpp>
26
#include <mapnik/layer.hpp>
275 andreas 27
#include <mapnik/rule.hpp>
273 andreas 28
 
274 andreas 29
/* conversions */
30
 
31
#define DEGREES      180.0
32
#define SEMICIRCLES  0x80000000
33
 
34
#define SEMI2DEG(a)  (double)(a) * DEGREES / SEMICIRCLES
35
#define DEG2SEMI(a)  rint((double)(a) * SEMICIRCLES / DEGREES)
36
 
37
#define DEG2RAD(a)   (a) * M_PI / DEGREES
38
#define RAD2DEG(a)   (a) * DEGREES / M_PI
39
 
40
typedef enum {
41
	type_png	= 150,
42
	type_gif	= 151,
43
	type_jpg	= 152,
44
	type_xpm	= 153,
45
	type_tif	= 154,
46
	type_bmp	= 155
47
}TYPES;
48
 
273 andreas 49
typedef struct LINESYMBOLIZER
50
{
274 andreas 51
	unsigned  stroke;		// Color
273 andreas 52
	double    stroke_width;
274 andreas 53
	QString   stroke_linejoin;
54
	QString   stroke_linecap;
273 andreas 55
	double    stroke_dasharray[10];
274 andreas 56
	int       stroke_anz;		// number of entries in dasharray
273 andreas 57
	double    stroke_opacity;
58
	LINESYMBOLIZER *next;
59
}LINESYMBOLIZER;
60
 
61
typedef struct POLYGONSYMBOLIZER
62
{
274 andreas 63
	unsigned  fill;			// Color
273 andreas 64
	double    fill_opacity;
65
	POLYGONSYMBOLIZER *next;
66
}POLYGONSYMBOLIZER;
67
 
68
typedef struct TEXTSYMBOLIZER
69
{
70
	QString   name;
71
	QString   face_name;
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
{
132
	double    maxscale;
133
	double    minscale;
134
	QString   filter;
135
	LINESYMBOLIZER		 *LineSymbolizer;
136
	POLYGONSYMBOLIZER	 *PolygonSymbolizer;
137
	TEXTSYMBOLIZER		 *TextSymbolizer;
138
	POINTSYMBOLIZER		 *PointSymbolizer;
139
	POLYGONPATTERNSYMBOLIZER *PolygonPatternSymbolizer;
140
	SHIELDSYMBOLIZER	 *ShieldSymbolizer;
141
	LINEPATTERNSYMBOLIZER    *LinePatternSymbolizer;
275 andreas 142
	mapnik::rule_type rl;		// the rule to be added to a style
273 andreas 143
	RULE *next;		// Pointer to next rule
144
}RULE;
145
 
146
typedef struct STYLE
147
{
148
	QString  name;
149
	RULE     *rule;		// Pointer to first rule node of the chain
150
	STYLE    *next;		// Pointer to next style
151
}STYLE;
152
 
153
typedef struct
154
{
155
	QString   type;
156
	QString   file;
157
	QString   host;
158
	QString   user;
159
	QString   dbname;
160
	QString   table;
274 andreas 161
	bool      estimate_extent;
273 andreas 162
	double    ext_lx;
163
	double    ext_ly;
164
	double    ext_rx;
165
	double    ext_ry;
166
}DATASOURCE;
167
 
168
typedef struct LAYER
169
{
274 andreas 170
	QString    name;	// The unique name
171
	bool       status;	// Is it active?
273 andreas 172
	QString    srs;		// Projection
275 andreas 173
	double     minzoom;
174
	double     maxzoom;
274 andreas 175
	QStringList Styles;	// The names of the Styles
273 andreas 176
	DATASOURCE Datasource;
177
	LAYER      *next;	// Pointer to next layer
178
}LAYER;
179
 
180
typedef struct
181
{
274 andreas 182
	unsigned   bgcolor;	// Color
183
	int        buf_size;
273 andreas 184
	QString    srs;
185
}MAP;
186
 
187
typedef enum {
274 andreas 188
	empty		 = 0,
189
	stroke_stroke	 = 100,
273 andreas 190
	stroke_width	 = 101,
191
	stroke_linejoin  = 102,
192
	stroke_linecap   = 103,
193
	stroke_opacity   = 104,
274 andreas 194
	stroke_dasharray = 105,
195
	fill		 = 106,
196
	fill_opacity	 = 107,
197
	type		 = 108,
198
	file		 = 109,
199
	host		 = 110,
200
	user		 = 111,
201
	dbname		 = 112,
202
	table		 = 113,
203
	estimate_extent  = 114,
204
	extent		 = 115
273 andreas 205
}NAMES;
206
 
207
typedef enum {
274 andreas 208
	in_root			= 0,
273 andreas 209
	in_map			= 100,
210
	in_style		= 101,
211
	in_rule			= 102,
212
	in_linesymbolizer	= 103,
213
	in_pointsymbolizer	= 104,
214
	in_polygonsymbolizer	= 105,
215
	in_textsymbolizer	= 106,
216
	in_polygonpatternsymbolizer = 107,
217
	in_layer		= 108,
274 andreas 218
	in_datasource		= 109,
219
	in_symbolizer		= 110,
220
	in_shieldsymbolizer	= 111,
221
	in_linepatternsymbolizer = 112
273 andreas 222
}CONTAINER;
223
 
274 andreas 224
typedef struct
225
{
226
	int id;
227
	CONTAINER con;
228
	QString name;
229
}TOKEN;
273 andreas 230
 
274 andreas 231
using namespace mapnik;
232
 
233
class SRender : public QXmlDefaultHandler
273 andreas 234
{
235
	public:
274 andreas 236
	   SRender();
237
	   ~SRender();
273 andreas 238
 
274 andreas 239
	   void setDrawArea(const QLabel &lb) { label = (QLabel *)&lb; };
240
	   void setShapePath(const QString &str) { if (str.isNull()) return; shapePath = str; };
241
	   void setXmlPath(const QString &path) { if (path.isNull()) return; XmlPath = path; };
273 andreas 242
	   bool getMap(double lx, double ly, double rx, double ry);
275 andreas 243
	   QString getOutBuf () { return OutBuf; };
273 andreas 244
 
274 andreas 245
	   // Functions to parse the XML file
273 andreas 246
	   bool startDocument ();
247
	   bool startElement (const QString&, const QString&, const QString& , const QXmlAttributes&);
248
	   bool endElement (const QString&, const QString&, const QString&);
249
	   bool characters (const QString&);
250
 
275 andreas 251
	protected:
252
	   void setMaxExtent(double lx, double ly, double rx, double ry);
253
	   QString findIcon(QString ic);
254
 
273 andreas 255
	private:
256
	   QString getKey (int pos);
274 andreas 257
	   TYPES getType(QString ty);
258
	   char *getTypeText(TYPES type);
259
	   bool getBool(QString b);
260
	   unsigned colorToUInt(QString col);
261
	   STYLE *findStyle(QString name);
273 andreas 262
	   RULE *getLastRule(RULE *first);
263
	   POINTSYMBOLIZER *getLastPointSymbolizer(POINTSYMBOLIZER *first);
274 andreas 264
	   LINESYMBOLIZER *getLastLineSymbolizer(LINESYMBOLIZER *first);
265
	   POLYGONSYMBOLIZER *getLastPolygonSymbolizer(POLYGONSYMBOLIZER *first);
266
	   TEXTSYMBOLIZER *getLastTextSymbolizer(TEXTSYMBOLIZER *first);
267
	   POLYGONPATTERNSYMBOLIZER *getLastPolygonPatternSymbolizer(POLYGONPATTERNSYMBOLIZER *first);
268
	   SHIELDSYMBOLIZER *getLastShieldSymbolizer(SHIELDSYMBOLIZER *first);
269
	   LINEPATTERNSYMBOLIZER *getLastLinePatternSymbolizer(LINEPATTERNSYMBOLIZER *first);
273 andreas 270
 
274 andreas 271
	   STYLE *allocStyle();
272
	   RULE *allocRule();
273
	   LAYER *allocLayer();
274
	   POINTSYMBOLIZER *allocPointSymbolizer();
275
	   LINESYMBOLIZER *allocLineSymbolizer();
276
	   POLYGONSYMBOLIZER *allocPolygonSymbolizer();
277
	   TEXTSYMBOLIZER *allocTextSymbolizer();
278
	   POLYGONPATTERNSYMBOLIZER *allocPolygonPatternSymbolizer();
279
	   SHIELDSYMBOLIZER *allocShieldSymbolizer();
280
	   LINEPATTERNSYMBOLIZER *allocLinePatternSymbolizer();
281
 
273 andreas 282
	private:
274 andreas 283
	   QLabel *label;
273 andreas 284
	   QString shapePath;
274 andreas 285
	   QString pluginPath;
286
	   QString fontPath;
273 andreas 287
	   QString XmlPath;
275 andreas 288
	   QString OutBuf;
273 andreas 289
	   CONTAINER Container;
274 andreas 290
	   bool ControlSet;
291
	   int Field;
275 andreas 292
	   int XmlLine;	// Line number of the current position in XML file
293
	   double _lx, _ly, _rx, _ry;
273 andreas 294
	   TYPES Types;
295
	   NAMES Names;
296
	   MAP MapPars;
274 andreas 297
	   Map m;
298
	   LAYER *Lay, *firstLayer, *lastLayer;
273 andreas 299
	   STYLE *Style, *firstStyle, *lastStyle;
300
	   RULE *Rule;
301
	   LINESYMBOLIZER		*LineSymbolizer;
302
	   POLYGONSYMBOLIZER	 	*PolygonSymbolizer;
303
	   TEXTSYMBOLIZER		*TextSymbolizer;
304
	   POINTSYMBOLIZER		*PointSymbolizer;
305
	   POLYGONPATTERNSYMBOLIZER 	*PolygonPatternSymbolizer;
306
	   SHIELDSYMBOLIZER	 	*ShieldSymbolizer;
307
	   LINEPATTERNSYMBOLIZER    	*LinePatternSymbolizer;
308
};
309
 
310
#endif // _RENDER_H