Rev 280 | Blame | Compare with Previous | Last modification | View Log | RSS feed
//
// C++ Interface: SRender
//
// Description: This defines the class for SRender.
//
//
// Author: Andreas Theofilu <andreas@theosys.at>, (C) 2009
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifndef _RENDER_H
#define _RENDER_H
#include "config.h"
// Everything here is only available, if Mapnik is available!
#if defined HAVE_MAPNIK
#include <mapnik/map.hpp>
#include <mapnik/datasource_cache.hpp>
#include <mapnik/font_engine_freetype.hpp>
#include <mapnik/agg_renderer.hpp>
#include <mapnik/filter_factory.hpp>
#include <mapnik/color_factory.hpp>
#include <mapnik/image_util.hpp>
#include <mapnik/config_error.hpp>
#include <mapnik/load_map.hpp>
#include <mapnik/save_map.hpp>
#include <mapnik/version.hpp>
/* conversions */
#define DEGREES 180.0
#define SEMICIRCLES 0x80000000
#define SEMI2DEG(a) (double)(a) * DEGREES / SEMICIRCLES
#define DEG2SEMI(a) rint((double)(a) * SEMICIRCLES / DEGREES)
#define DEG2RAD(a) (a) * M_PI / DEGREES
#define RAD2DEG(a) (a) * DEGREES / M_PI
typedef enum {
type_png = 150,
type_gif = 151,
type_jpg = 152,
type_xpm = 153,
type_tif = 154,
type_bmp = 155
}TYPES;
typedef struct LINESYMBOLIZER
{
unsigned stroke; // Color
double stroke_width;
QString stroke_linejoin;
QString stroke_linecap;
double stroke_dasharray[10];
int stroke_anz; // number of entries in dasharray
double stroke_opacity;
LINESYMBOLIZER *next;
}LINESYMBOLIZER;
typedef struct POLYGONSYMBOLIZER
{
unsigned fill; // Color
double fill_opacity;
POLYGONSYMBOLIZER *next;
}POLYGONSYMBOLIZER;
typedef struct TEXTSYMBOLIZER
{
QString name;
QString face_name;
QString placement;
QString alignment;
double size;
unsigned fill; // Color
double halo_radius;
double wrap_width;
double dx;
double dy;
double mindistance; // min distance between labels
double maxdistance; // not used!
TEXTSYMBOLIZER *next;
}TEXTSYMBOLIZER;
typedef struct POINTSYMBOLIZER
{
QString file;
TYPES type; // enum TYPES
double width;
double height;
bool allow_overlap;
POINTSYMBOLIZER *next;
}POINTSYMBOLIZER;
typedef struct POLYGONPATTERNSYMBOLIZER
{
QString file;
TYPES type; // enum TYPES
double width;
double height;
bool allow_overlap;
POLYGONPATTERNSYMBOLIZER *next;
}POLYGONPATTERNSYMBOLIZER;
typedef struct SHIELDSYMBOLIZER
{
QString name;
QString face_name;
double size;
unsigned fill; // Color
QString placement;
QString file;
TYPES type; // enum TYPES
double width;
double height;
double dx;
double dy;
double mindistance; // min distance to next shield symbol
double maxdistance; // not used!
SHIELDSYMBOLIZER *next;
}SHIELDSYMBOLIZER;
typedef struct LINEPATTERNSYMBOLIZER
{
QString file;
TYPES type; // enum TYPES
double width;
double height;
LINEPATTERNSYMBOLIZER *next;
}LINEPATTERNSYMBOLIZER;
typedef struct RULE
{
QString name;
QString title;
double maxscale;
double minscale;
QString filter;
bool elsefilter;
LINESYMBOLIZER *LineSymbolizer;
POLYGONSYMBOLIZER *PolygonSymbolizer;
TEXTSYMBOLIZER *TextSymbolizer;
POINTSYMBOLIZER *PointSymbolizer;
POLYGONPATTERNSYMBOLIZER *PolygonPatternSymbolizer;
SHIELDSYMBOLIZER *ShieldSymbolizer;
LINEPATTERNSYMBOLIZER *LinePatternSymbolizer;
// mapnik::rule_type rl; // the rule to be added to a style
mapnik::rule rl; // the rule to be added to a style
RULE *next; // Pointer to next rule
}RULE;
typedef struct STYLE
{
QString name;
RULE *rule; // Pointer to first rule node of the chain
STYLE *next; // Pointer to next style
}STYLE;
typedef struct
{
QString type;
QString file;
QString parser;
QString url;
QString bbox;
QString host;
QString user;
QString dbname;
QString table;
bool estimate_extent;
double ext_lx;
double ext_ly;
double ext_rx;
double ext_ry;
}DATASOURCE;
typedef struct LAYER
{
QString name; // The unique name
QString title; // The title of the layer (optional)
QString abstract; // Some short description (optional)
bool status; // Is it active?
bool clear_label; // Clear label cache?
QString srs; // Projection
double minzoom;
double maxzoom;
bool queryable;
QStringList Styles; // The names of the Styles
DATASOURCE Datasource;
LAYER *next; // Pointer to next layer
}LAYER;
typedef struct
{
unsigned bgcolor; // Color
int buf_size;
QString srs;
}MAP;
typedef enum {
empty = 0,
stroke_stroke = 100,
stroke_width = 101,
stroke_linejoin = 102,
stroke_linecap = 103,
stroke_opacity = 104,
stroke_dasharray = 105,
fill = 106,
fill_opacity = 107,
type = 108,
file = 109,
host = 110,
user = 111,
dbname = 112,
table = 113,
estimate_extent = 114,
extent = 115,
parser__ = 116,
url = 117,
bbox = 118
}NAMES;
typedef enum {
in_root = 0,
in_map = 100,
in_style = 101,
in_rule = 102,
in_linesymbolizer = 103,
in_pointsymbolizer = 104,
in_polygonsymbolizer = 105,
in_textsymbolizer = 106,
in_polygonpatternsymbolizer = 107,
in_layer = 108,
in_datasource = 109,
in_symbolizer = 110,
in_shieldsymbolizer = 111,
in_linepatternsymbolizer = 112,
in_elsefilter = 113
}CONTAINER;
typedef struct
{
int id;
CONTAINER con;
QString name;
}TOKEN;
using namespace mapnik;
class SRender : public QXmlDefaultHandler
{
public:
enum map_type
{
MAP_SHAPE,
MAP_GIS,
MAP_OSM,
map_type_MAX
};
public:
SRender();
~SRender();
void setDrawArea(int, int);
QPixmap pixmap() { return pxmap; };
void setShapePath(const QString &str) { if (str.isNull()) return; shapePath = str; };
void setXmlPath(const QString &path) { if (path.isNull()) return; XmlPath = path; };
bool getMap(double lx, double ly, double rx, double ry);
inline void setMapType(map_type mt) { __map_type = mt; }
inline map_type getMapType() { return __map_type; }
// Functions to parse the XML file
bool startDocument ();
bool startElement (const QString&, const QString&, const QString& , const QXmlAttributes&);
bool endElement (const QString&, const QString&, const QString&);
bool characters (const QString&);
protected:
void setMaxExtent(double lx, double ly, double rx, double ry);
QString findIcon(QString ic);
private:
QString getKey (int pos);
TYPES getType(QString ty);
char *getTypeText(TYPES type);
bool getBool(QString b);
unsigned colorToUInt(QString col);
color setColor(unsigned);
STYLE *findStyle(QString name);
RULE *getLastRule(RULE *first);
POINTSYMBOLIZER *getLastPointSymbolizer(POINTSYMBOLIZER *first);
LINESYMBOLIZER *getLastLineSymbolizer(LINESYMBOLIZER *first);
POLYGONSYMBOLIZER *getLastPolygonSymbolizer(POLYGONSYMBOLIZER *first);
TEXTSYMBOLIZER *getLastTextSymbolizer(TEXTSYMBOLIZER *first);
POLYGONPATTERNSYMBOLIZER *getLastPolygonPatternSymbolizer(POLYGONPATTERNSYMBOLIZER *first);
SHIELDSYMBOLIZER *getLastShieldSymbolizer(SHIELDSYMBOLIZER *first);
LINEPATTERNSYMBOLIZER *getLastLinePatternSymbolizer(LINEPATTERNSYMBOLIZER *first);
STYLE *allocStyle();
RULE *allocRule();
LAYER *allocLayer();
POINTSYMBOLIZER *allocPointSymbolizer();
LINESYMBOLIZER *allocLineSymbolizer();
POLYGONSYMBOLIZER *allocPolygonSymbolizer();
TEXTSYMBOLIZER *allocTextSymbolizer();
POLYGONPATTERNSYMBOLIZER *allocPolygonPatternSymbolizer();
SHIELDSYMBOLIZER *allocShieldSymbolizer();
LINEPATTERNSYMBOLIZER *allocLinePatternSymbolizer();
private:
QPixmap pxmap;
QString shapePath;
QString pluginPath;
QString fontPath;
QString XmlPath;
bool geographic;
map_type __map_type;
int _width, _height;
CONTAINER Container;
bool ControlSet;
int Field;
int XmlLine; // Line number of the current position in XML file
double _lx, _ly, _rx, _ry;
TYPES Types;
NAMES Names;
MAP MapPars;
Map m;
LAYER *Lay, *firstLayer, *lastLayer;
STYLE *Style, *firstStyle, *lastStyle;
RULE *Rule;
LINESYMBOLIZER *LineSymbolizer;
POLYGONSYMBOLIZER *PolygonSymbolizer;
TEXTSYMBOLIZER *TextSymbolizer;
POINTSYMBOLIZER *PointSymbolizer;
POLYGONPATTERNSYMBOLIZER *PolygonPatternSymbolizer;
SHIELDSYMBOLIZER *ShieldSymbolizer;
LINEPATTERNSYMBOLIZER *LinePatternSymbolizer;
};
#endif // HAVE_MAPNIK
#endif // _RENDER_H