Subversion Repositories public

Rev

Rev 273 | Rev 275 | 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>
23
#include <mapnik/color.hpp>
24
#include <mapnik/layer.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;
69
	double    size;
274 andreas 70
	unsigned  fill;			// Color
273 andreas 71
	double    halo_radius;
72
	double    wrap_width;
73
	double    dy;
74
	double    mindistance;
75
	double    maxdistance;
76
	TEXTSYMBOLIZER *next;
77
}TEXTSYMBOLIZER;
78
 
79
typedef struct POINTSYMBOLIZER
80
{
81
	QString   file;
274 andreas 82
	TYPES     type;		// enum TYPES
273 andreas 83
	double    width;
84
	double    height;
85
	bool      allow_overlap;
86
	POINTSYMBOLIZER *next;
87
}POINTSYMBOLIZER;
88
 
89
typedef struct POLYGONPATTERNSYMBOLIZER
90
{
91
	QString   file;
274 andreas 92
	TYPES     type;		// enum TYPES
273 andreas 93
	double    width;
94
	double    height;
95
	bool      allow_overlap;
96
	POLYGONPATTERNSYMBOLIZER *next;
97
}POLYGONPATTERNSYMBOLIZER;
98
 
99
typedef struct SHIELDSYMBOLIZER
100
{
101
	QString   name;
102
	QString   face_name;
103
	double    size;
274 andreas 104
	unsigned  fill;		// Color
273 andreas 105
	QString   placement;
106
	QString   file;
274 andreas 107
	TYPES     type;		// enum TYPES
273 andreas 108
	double    width;
109
	double    height;
110
	double    mindistance;
111
	double    maxdistance;
112
	SHIELDSYMBOLIZER *next;
113
}SHIELDSYMBOLIZER;
114
 
115
typedef struct LINEPATTERNSYMBOLIZER
116
{
117
	QString   file;
274 andreas 118
	TYPES     type;		// enum TYPES
273 andreas 119
	double    width;
120
	double    height;
121
	LINEPATTERNSYMBOLIZER *next;
122
}LINEPATTERNSYMBOLIZER;
123
 
124
typedef struct RULE
125
{
126
	double    maxscale;
127
	double    minscale;
128
	QString   filter;
129
	LINESYMBOLIZER		 *LineSymbolizer;
130
	POLYGONSYMBOLIZER	 *PolygonSymbolizer;
131
	TEXTSYMBOLIZER		 *TextSymbolizer;
132
	POINTSYMBOLIZER		 *PointSymbolizer;
133
	POLYGONPATTERNSYMBOLIZER *PolygonPatternSymbolizer;
134
	SHIELDSYMBOLIZER	 *ShieldSymbolizer;
135
	LINEPATTERNSYMBOLIZER    *LinePatternSymbolizer;
136
	RULE *next;		// Pointer to next rule
137
}RULE;
138
 
139
typedef struct STYLE
140
{
141
	QString  name;
142
	RULE     *rule;		// Pointer to first rule node of the chain
143
	STYLE    *next;		// Pointer to next style
144
}STYLE;
145
 
146
typedef struct
147
{
148
	QString   type;
149
	QString   file;
150
	QString   host;
151
	QString   user;
152
	QString   dbname;
153
	QString   table;
274 andreas 154
	bool      estimate_extent;
273 andreas 155
	double    ext_lx;
156
	double    ext_ly;
157
	double    ext_rx;
158
	double    ext_ry;
159
}DATASOURCE;
160
 
161
typedef struct LAYER
162
{
274 andreas 163
	QString    name;	// The unique name
164
	bool       status;	// Is it active?
273 andreas 165
	QString    srs;		// Projection
274 andreas 166
	QStringList Styles;	// The names of the Styles
273 andreas 167
	DATASOURCE Datasource;
168
	LAYER      *next;	// Pointer to next layer
169
}LAYER;
170
 
171
typedef struct
172
{
274 andreas 173
	unsigned   bgcolor;	// Color
174
	int        buf_size;
273 andreas 175
	QString    srs;
176
}MAP;
177
 
178
typedef enum {
274 andreas 179
	empty		 = 0,
180
	stroke_stroke	 = 100,
273 andreas 181
	stroke_width	 = 101,
182
	stroke_linejoin  = 102,
183
	stroke_linecap   = 103,
184
	stroke_opacity   = 104,
274 andreas 185
	stroke_dasharray = 105,
186
	fill		 = 106,
187
	fill_opacity	 = 107,
188
	type		 = 108,
189
	file		 = 109,
190
	host		 = 110,
191
	user		 = 111,
192
	dbname		 = 112,
193
	table		 = 113,
194
	estimate_extent  = 114,
195
	extent		 = 115
273 andreas 196
}NAMES;
197
 
198
typedef enum {
274 andreas 199
	in_root			= 0,
273 andreas 200
	in_map			= 100,
201
	in_style		= 101,
202
	in_rule			= 102,
203
	in_linesymbolizer	= 103,
204
	in_pointsymbolizer	= 104,
205
	in_polygonsymbolizer	= 105,
206
	in_textsymbolizer	= 106,
207
	in_polygonpatternsymbolizer = 107,
208
	in_layer		= 108,
274 andreas 209
	in_datasource		= 109,
210
	in_symbolizer		= 110,
211
	in_shieldsymbolizer	= 111,
212
	in_linepatternsymbolizer = 112
273 andreas 213
}CONTAINER;
214
 
274 andreas 215
typedef struct
216
{
217
	int id;
218
	CONTAINER con;
219
	QString name;
220
}TOKEN;
273 andreas 221
 
274 andreas 222
using namespace mapnik;
223
 
224
class SRender : public QXmlDefaultHandler
273 andreas 225
{
226
	public:
274 andreas 227
	   SRender();
228
	   ~SRender();
273 andreas 229
 
274 andreas 230
	   void setDrawArea(const QLabel &lb) { label = (QLabel *)&lb; };
231
	   void setShapePath(const QString &str) { if (str.isNull()) return; shapePath = str; };
232
	   void setXmlPath(const QString &path) { if (path.isNull()) return; XmlPath = path; };
273 andreas 233
	   bool getMap(double lx, double ly, double rx, double ry);
234
 
274 andreas 235
	   // Functions to parse the XML file
273 andreas 236
	   bool startDocument ();
237
	   bool startElement (const QString&, const QString&, const QString& , const QXmlAttributes&);
238
	   bool endElement (const QString&, const QString&, const QString&);
239
	   bool characters (const QString&);
240
 
241
	private:
242
	   QString getKey (int pos);
274 andreas 243
	   TYPES getType(QString ty);
244
	   char *getTypeText(TYPES type);
245
	   bool getBool(QString b);
246
	   unsigned colorToUInt(QString col);
247
	   STYLE *findStyle(QString name);
273 andreas 248
	   RULE *getLastRule(RULE *first);
249
	   POINTSYMBOLIZER *getLastPointSymbolizer(POINTSYMBOLIZER *first);
274 andreas 250
	   LINESYMBOLIZER *getLastLineSymbolizer(LINESYMBOLIZER *first);
251
	   POLYGONSYMBOLIZER *getLastPolygonSymbolizer(POLYGONSYMBOLIZER *first);
252
	   TEXTSYMBOLIZER *getLastTextSymbolizer(TEXTSYMBOLIZER *first);
253
	   POLYGONPATTERNSYMBOLIZER *getLastPolygonPatternSymbolizer(POLYGONPATTERNSYMBOLIZER *first);
254
	   SHIELDSYMBOLIZER *getLastShieldSymbolizer(SHIELDSYMBOLIZER *first);
255
	   LINEPATTERNSYMBOLIZER *getLastLinePatternSymbolizer(LINEPATTERNSYMBOLIZER *first);
273 andreas 256
 
274 andreas 257
	   STYLE *allocStyle();
258
	   RULE *allocRule();
259
	   LAYER *allocLayer();
260
	   POINTSYMBOLIZER *allocPointSymbolizer();
261
	   LINESYMBOLIZER *allocLineSymbolizer();
262
	   POLYGONSYMBOLIZER *allocPolygonSymbolizer();
263
	   TEXTSYMBOLIZER *allocTextSymbolizer();
264
	   POLYGONPATTERNSYMBOLIZER *allocPolygonPatternSymbolizer();
265
	   SHIELDSYMBOLIZER *allocShieldSymbolizer();
266
	   LINEPATTERNSYMBOLIZER *allocLinePatternSymbolizer();
267
 
273 andreas 268
	private:
274 andreas 269
	   QLabel *label;
273 andreas 270
	   QString shapePath;
274 andreas 271
	   QString pluginPath;
272
	   QString fontPath;
273 andreas 273
	   QString XmlPath;
274
	   CONTAINER Container;
274 andreas 275
	   bool ControlSet;
276
	   int Field;
273 andreas 277
	   TYPES Types;
278
	   NAMES Names;
279
	   MAP MapPars;
274 andreas 280
	   Map m;
281
	   LAYER *Lay, *firstLayer, *lastLayer;
273 andreas 282
	   STYLE *Style, *firstStyle, *lastStyle;
283
	   RULE *Rule;
284
	   LINESYMBOLIZER		*LineSymbolizer;
285
	   POLYGONSYMBOLIZER	 	*PolygonSymbolizer;
286
	   TEXTSYMBOLIZER		*TextSymbolizer;
287
	   POINTSYMBOLIZER		*PointSymbolizer;
288
	   POLYGONPATTERNSYMBOLIZER 	*PolygonPatternSymbolizer;
289
	   SHIELDSYMBOLIZER	 	*ShieldSymbolizer;
290
	   LINEPATTERNSYMBOLIZER    	*LinePatternSymbolizer;
291
};
292
 
293
#endif // _RENDER_H