Subversion Repositories public

Compare Revisions

Ignore whitespace Rev 273 → Rev 274

/sportwatcher/trunk/src/shapewidget.cpp
0,0 → 1,93
//
// C++ Implementation:
//
// Description:
//
//
// Author: Andreas Theofilu <andreas@theosys.at>, (C) 2009
//
// Copyright: See COPYING file that comes with this distribution
//
//
 
#include "config.h"
#include "shapewidget.h"
#include <KConfig>
#include <KUrlRequester>
#include <KLineEdit>
#include <QDir>
 
shapeWidget::shapeWidget (QWidget* parent, Qt::WFlags fl)
: QDialog (parent, fl), Ui::shapeWidgetBase()
{
QString basePath;
QDir dir = QDir::home();
QString path = dir.absolutePath();
 
setupUi (this);
// Make sure we are useing only existing files on the local system.
edShapeFileSet->setMode(KFile::ExistingOnly | KFile::LocalOnly);
edPluginPath->setMode(KFile::ExistingOnly | KFile::LocalOnly);
edFontPath->setMode(KFile::ExistingOnly | KFile::LocalOnly);
edXmlFile->setMode(KFile::ExistingOnly | KFile::LocalOnly);
 
// Get some already saved information from the config file
KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
KConfigGroup ic (&cfg, "SportWatcher");
KConfigGroup sh (&cfg, "ShapeFile");
basePath = ic.readEntry("Data", path + "/.sportwatcher");
edShapeFileSet->setUrl(ic.readEntry("MAP", basePath + "/shapefiles"));
// Read the shape specific informations
#ifdef MAPNIK_PLUGINS
edPluginPath->setUrl(QString(MAPNIK_PLUGINS));
edPluginPath->setEnabled(false);
#else
// Test some default path
if (dir.exists(QString("/usr/lib/mapnik/input")))
edPluginPath->setUrl(sh.readEntry("PluginPath", QString("/usr/lib/mapnik/input")));
else if (dir.exists(QString("/usr/local/lib/mapnik/input")))
edPluginPath->setUrl(sh.readEntry("PluginPath", QString("/usr/local/lib/mapnik/input")));
else if (dir.exists(QString("/usr/lib/mapnik/0.6/input")))
edPluginPath->setUrl(sh.readEntry("PluginPath", QString("/usr/lib/mapnik/0.6/input")));
else
edPluginPath->setUrl(sh.readEntry("PluginPath", QString("")));
#endif
#ifdef MAPNIK_FONTS
edFontPath->setUrl(QString(MAPNIK_FONTS));
edFontPath->setEnabled(false);
#else
// Test some default path
if (dir.exists(QString("/usr/lib/mapnik/fonts")))
edFontPath->setUrl(sh.readEntry("FontPath", QString("/usr/lib/mapnik/fonts")));
else if (dir.exists(QString("/usr/local/lib/mapnik/fonts")))
edFontPath->setUrl(sh.readEntry("FontPath", QString("/usr/local/lib/mapnik/fonts")));
else if (dir.exists(QString("/usr/share/mapnik/fonts")))
edFontPath->setUrl(sh.readEntry("FontPath", QString("/usr/share/mapnik/fonts")));
else if (dir.exists(QString("/usr/share/fonts/truetype/ttf-dejavu")))
edFontPath->setUrl(sh.readEntry("FontPath", QString("/usr/share/fonts/truetype/ttf-dejavu")));
else
edFontPath->setUrl(sh.readEntry("FontPath", QString("")));
#endif
edXmlFile->setUrl(sh.readEntry("XmlFile", basePath + "/shapefiles/osm.xml"));
}
 
shapeWidget::~shapeWidget()
{
}
 
/*$SPECIALIZATION$*/
void shapeWidget::accept()
{
KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
KConfigGroup ic (&cfg, "SportWatcher");
KConfigGroup sh (&cfg, "ShapeFile");
ic.writeEntry("MAP", edShapeFileSet->lineEdit()->text());
sh.writeEntry("PluginPath", edPluginPath->lineEdit()->text());
sh.writeEntry("FontPath", edFontPath->lineEdit()->text());
sh.writeEntry("XmlFile", edXmlFile->lineEdit()->text());
cfg.sync();
done(QDialog::Accepted);
}
 
#include "shapewidget.moc"
 
/sportwatcher/trunk/src/render.cpp
1,5 → 1,5
//
// C++ Implementation: render
// C++ Implementation: SRender
//
// Description: Renders a map from some shape files. This class assumes,
// that the shape files are in open street map format!
12,17 → 12,21
//
 
#define BOOST_SPIRIT_THREADSAFE
#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 <QLabel>
#include <QString>
#include <QXmlReader>
#include <QDir>
#include <QColor>
#include <KStandardDirs>
#include <KConfig>
#include <KLocale>
#include <KMessageBox>
#include <KGlobalSettings>
#include <KConfigGroup>
 
#include "config.h"
#include "render.h"
#include <iostream>
 
#define CON_MAP 100
#define CON_STYLE 101
34,6 → 38,8
#define CON_POLYGONPATTERNSYMBOLIZER 107
#define CON_LAYER 108
#define CON_DATASOURCE 109
#define CON_SHIELDSYMBOLIZER 110
#define CON_LINEPATTERNSYMBOLIZER 111
 
#define FLD_FILTER 200
#define FLD_CSSPARAMETER 201
61,7 → 67,7
#define ATT_SRS 316
 
#define FIRST_CON 100
#define LAST_CON 109
#define LAST_CON 111
 
#define FIRST_FLD 200
#define LAST_FLD 205
69,50 → 75,59
#define FIRST_ATT 300
#define LAST_ATT 316
 
KEYS keys[] = {
using std::cout;
using std::cerr;
using std::clog;
using std::endl;
 
TOKEN token[] = {
// Containers
{ CON_MAP QString("Map") },
{ CON_STYLE QString("Style") },
{ CON_RULE QString("Rule") },
{ CON_LINESYMBOLIZER QString("LineSymbolizer") },
{ CON_POINTSYMBOLIZER QString("PointSymbolizer") },
{ CON_POLYGONSYMBOLIZER QString("PolygonSymbolizer") },
{ CON_TEXTSYMBOLIZER QString("TextSymbolizer") },
{ CON_POLYGONPATTERNSYMBOLIZER QString("PolygonPatternSymbolizer") },
{ CON_LAYER QString("Layer") },
{ CON_DATASOURCE QString("Datasource") },
{ CON_MAP, in_map, QString("Map") },
{ CON_STYLE, in_style, QString("Style") },
{ CON_RULE, in_rule, QString("Rule") },
{ CON_LINESYMBOLIZER, in_linesymbolizer, QString("LineSymbolizer") },
{ CON_POINTSYMBOLIZER, in_pointsymbolizer, QString("PointSymbolizer") },
{ CON_POLYGONSYMBOLIZER, in_polygonsymbolizer, QString("PolygonSymbolizer") },
{ CON_TEXTSYMBOLIZER, in_textsymbolizer, QString("TextSymbolizer") },
{ CON_POLYGONPATTERNSYMBOLIZER, in_polygonpatternsymbolizer, QString("PolygonPatternSymbolizer") },
{ CON_LAYER, in_layer, QString("Layer") },
{ CON_DATASOURCE, in_datasource, QString("Datasource") },
{ CON_SHIELDSYMBOLIZER, in_shieldsymbolizer, QString("ShieldSymbolizer") },
// Fields
{ FLD_FILTER QString("Filter") },
{ FLD_CSSPARAMETER QString("CSSParameter") },
{ FLD_MINSCALE QString("MinScaleDenominator") },
{ FLD_MAXSCALE QString("MaxScaleDenominator") },
{ FLD_STYLENAME QString("StyleName") },
{ FLD_PARAMETER QString("Parameter") },
{ FLD_FILTER, in_rule, QString("Filter") },
{ FLD_CSSPARAMETER, in_symbolizer, QString("CSSParameter") },
{ FLD_MINSCALE, in_rule, QString("MinScaleDenominator") },
{ FLD_MAXSCALE, in_rule, QString("MaxScaleDenominator") },
{ FLD_STYLENAME, in_style, QString("StyleName") },
{ FLD_PARAMETER, in_datasource, QString("Parameter") },
// Attributes
{ ATT_FILL QString("fill") },
{ ATT_NAME QString("name") },
{ ATT_FILE QString("file") },
{ ATT_TYPE QString("type") },
{ ATT_WIDTH QString("width") },
{ ATT_HEIGHT QString("height") },
{ ATT_SIZE QString("size") },
{ ATT_FACENAME QString("face_name") },
{ ATT_DY QString("dy") },
{ ATT_HALORADIUS QString("halo_radius") },
{ ATT_WRAPWIDTH QString("wrap_width") },
{ ATT_MINDISTANCE QString("min_distance") },
{ ATT_MAXDISTANCE QString("max_distance") },
{ ATT_PLACEMAENT QString("placement") },
{ ATT_ALLOWOVERLAP QString("allow_overlap") },
{ ATT_STATUS QString("status") },
{ ATT_SRS QString("srs") },
{ 0 QString::null }
{ ATT_FILL, in_symbolizer, QString("fill") },
{ ATT_NAME, in_symbolizer, QString("name") },
{ ATT_FILE, in_symbolizer, QString("file") },
{ ATT_TYPE, in_symbolizer, QString("type") },
{ ATT_WIDTH, in_symbolizer, QString("width") },
{ ATT_HEIGHT, in_symbolizer, QString("height") },
{ ATT_SIZE, in_symbolizer, QString("size") },
{ ATT_FACENAME, in_symbolizer, QString("face_name") },
{ ATT_DY, in_symbolizer, QString("dy") },
{ ATT_HALORADIUS, in_symbolizer, QString("halo_radius") },
{ ATT_WRAPWIDTH, in_symbolizer, QString("wrap_width") },
{ ATT_MINDISTANCE, in_symbolizer, QString("min_distance") },
{ ATT_MAXDISTANCE, in_symbolizer, QString("max_distance") },
{ ATT_PLACEMENT, in_symbolizer, QString("placement") },
{ ATT_ALLOWOVERLAP, in_symbolizer, QString("allow_overlap") },
{ ATT_STATUS, in_layer, QString("status") },
{ ATT_SRS, in_layer, QString("srs") },
{ 0, in_root, QString::null }
};
 
render::render()
SRender::SRender()
{
Layer = 0;
Style = 0;
label = 0;
shapePath = QString::null;
XmlPath = QString::null;
Lay = firstLayer = lastLayer = 0;
Style = firstStyle = lastStyle = 0;
Rule = 0;
LineSymbolizer = 0;
PolygonSymbolizer = 0;
121,12 → 136,57
PolygonPatternSymbolizer = 0;
ShieldSymbolizer = 0;
LinePatternSymbolizer = 0;
// This is true, when a XML file was parsed successfully
ControlSet = false;
 
// Read settings from config file
KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
KConfigGroup ic (&cfg, "SportWatcher");
KConfigGroup sh (&cfg, "ShapeFile");
QString basePath = ic.readEntry("Data", QDir::home().absolutePath() + "/.sportwatcher");
shapePath = ic.readEntry("MAP", basePath + "/shapefiles");
// Read the shape specific informations
#ifdef MAPNIK_PLUGINS
pluginPath = QString(MAPNIK_PLUGINS);
#else
// Test some default path
if (dir.exists(QString("/usr/lib/mapnik/input")))
pluginPath = sh.readEntry("PluginPath", QString("/usr/lib/mapnik/input"));
else if (dir.exists(QString("/usr/local/lib/mapnik/input")))
pluginPath = sh.readEntry("PluginPath", QString("/usr/local/lib/mapnik/input"));
else if (dir.exists(QString("/usr/lib/mapnik/0.6/input")))
pluginPath = sh.readEntry("PluginPath", QString("/usr/lib/mapnik/0.6/input"));
else
pluginPath = sh.readEntry("PluginPath", QString(""));
#endif
#ifdef MAPNIK_FONTS
fontPath = QString(MAPNIK_FONTS);
#else
// Test some default path
if (dir.exists(QString("/usr/lib/mapnik/fonts")))
fontPath = sh.readEntry("FontPath", QString("/usr/lib/mapnik/fonts"));
else if (dir.exists(QString("/usr/local/lib/mapnik/fonts")))
fontPath = sh.readEntry("FontPath", QString("/usr/local/lib/mapnik/fonts"));
else if (dir.exists(QString("/usr/share/mapnik/fonts")))
fontPath = sh.readEntry("FontPath", QString("/usr/share/mapnik/fonts"));
else if (dir.exists(QString("/usr/share/fonts/truetype/ttf-dejavu")))
fontPath = sh.readEntry("FontPath", QString("/usr/share/fonts/truetype/ttf-dejavu"));
else
fontPath = sh.readEntry("FontPath", QString(""));
#endif
XmlPath = sh.readEntry("XmlFile", basePath + "/shapefiles/osm.xml");
}
 
bool render::startDocument()
SRender::~SRender()
{
indent = 0;
startDocument(); // Clean everything
ControlSet = false;
}
 
bool SRender::startDocument()
{
m.remove_all(); // delete styles and layers from map
 
if (firstStyle) // free if allocated
{
Style = firstStyle;
133,10 → 193,11
 
while (Style)
{
STYLE *sakt = Style->next;
 
if (Style->rule)
{
RULE *rule = Style->rule;
STYLE *sakt = Style->next;
 
while (rule)
{
146,7 → 207,7
TEXTSYMBOLIZER *TextSymbolizer = rule->TextSymbolizer;
POINTSYMBOLIZER *PointSymbolizer = rule->PointSymbolizer;
POLYGONPATTERNSYMBOLIZER *PolygonPatternSymbolizer = rule->PolygonPatternSymbolizer;
SHIELDSYMBOLIZER *ShieldSymbolizer = rule->ShielSymbolizer;
SHIELDSYMBOLIZER *ShieldSymbolizer = rule->ShieldSymbolizer;
LINEPATTERNSYMBOLIZER *LinePatternSymbolizer = rule->LinePatternSymbolizer;
 
while (LineSymbolizer)
209,6 → 270,23
}
 
Style = firstStyle = lastStyle = 0;
 
if (firstLayer)
{
Lay = firstLayer;
 
while (Lay)
{
LAYER *akt;
 
akt = Lay->next;
delete Lay;
Lay = akt;
}
}
 
Lay = firstLayer = lastLayer = 0;
Container = in_root;
return true;
}
 
215,24 → 293,33
/*
* This is called every time a new start element was parsed.
*/
bool render::startElement( const QString&, const QString&,
bool SRender::startElement( const QString&, const QString&,
const QString& qName,
const QXmlAttributes& att)
{
int i = FIRST_CON;
int index;
QString hv0;
 
indent++;
 
while (i < LAST_CON)
while (i <= LAST_CON)
{
if (qName.toLower() == getKey(i).toLower())
{
Container = token[i].con;
 
switch (i)
{
case CON_MAP:
Container = in_map;
 
if (ControlSet) // Must be false here!
{
KMessageBox::error(0, i18n("Error parsing %1: There is another MAP! Only one map information is allowed!").arg(XmlPath));
return false;
}
 
if ((index = att.index(QString("bgcolor"))) != -1)
MapPars.bgcolor = color_factory::from_string(att.value(index).toAscii().data());
MapPars.bgcolor = colorToUInt(att.value(index));
 
if ((index = att.index(QString("buffer_size"))) != -1)
MapPars.buf_size = att.value(index).toInt();
239,19 → 326,20
 
if ((index = att.index(QString("srs"))) != -1)
MapPars.srs = att.value(index);
cout << "<Map bgcolor=" << MapPars.bgcolor << " buffer_size=" << MapPars.buf_size << " srs=" << MapPars.srs.toAscii().data() << ">" << endl;
break;
 
case CON_STYLE:
Container = in_style;
 
if (!lastStyle)
{
Style = new STYLE;
fistStyle = lastStyle = Style;
memset (Style, 0, sizeof (STYLE));
Style = allocStyle();
firstStyle = lastStyle = Style;
}
else
{
Style = new STYLE;
memset (Style, 0, sizeof (STYLE));
Style = allocStyle();
lastStyle->next = Style;
lastStyle = Style;
}
260,12 → 348,15
Style->name = att.value(index);
else
{
KMessageBox::error(0, i18n("Error parsing %1: Open STYLE wihout a name!").arg(XmlPath));
KMessageBox::error(0, i18n("Error parsing %1: Open STYLE without a name!").arg(XmlPath));
return false;
}
cout << " <Style name=" << Style->name.toAscii().data() << ">" << endl;
break;
 
case CON_RULE:
Container = in_rule;
 
if (!Style)
{
KMessageBox::error(0, i18n("Error parsing %1: Open RULE outside of a STYLE!").arg(XmlPath));
276,19 → 367,50
 
if (!Rule)
{
Rule = new RULE;
memset (Rule, 0, sizeof(RULE));
Rule = allocRule();
Style->rule = Rule;
}
else
{
Rule->next = new RULE;
Rule->next = allocRule();
Rule = Rule->next;
memset (Rule, 0, sizeof(RULE));
}
cout << " <Rule>" << endl;
break;
 
case CON_LAYER:
Container = in_layer;
 
if (!firstLayer)
{
Lay = allocLayer();
firstLayer = lastLayer = Lay;
}
else
{
Lay = allocLayer();
lastLayer->next = Lay;
lastLayer = Lay;
}
 
if ((index = att.index(QString("name"))) != -1)
Lay->name = att.value(index);
 
if ((index = att.index(QString("status"))) != -1)
Lay->status = getBool(att.value(index));
 
if ((index = att.index(QString("srs"))) != -1)
Lay->srs = att.value(index);
cout << " <Layer name=" << Lay->name.toAscii().data() << " status=" << Lay->status << " srs=" << Lay->srs.toAscii().data() << ">" << endl;
break;
 
case CON_DATASOURCE:
Container = in_datasource;
break;
 
case CON_POINTSYMBOLIZER:
Container = in_pointsymbolizer;
 
if (!Rule)
{
KMessageBox::error(0, i18n("Error parsing %1: Open POINTSYMBOLIZER outside of a RULE!").arg(XmlPath));
299,15 → 421,13
 
if (!PointSymbolizer)
{
PointSymbolizer = new POINTSYMBOLIZER;
memset (PointSymbolizer, 0, sizeof(POINTSYMBOLIZER));
PointSymbolizer = allocPointSymbolizer();
Rule->PointSymbolizer = PointSymbolizer;
}
else
{
PointSymbolizer->next = new POINTSYMBOLIZER;
PointSymbolizer->next = allocPointSymbolizer();
PointSymbolizer = PointSymbolizer->next;
memset (PointSymbolizer, 0, sizeof(POINTSYMBOLIZER));
}
 
if ((index = att.index(QString("file"))) != -1)
314,30 → 434,15
PointSymbolizer->file = att.value(index);
 
if ((index = att.index(QString("type"))) != -1)
{
QString ty = att.value(index);
PointSymbolizer->type = getType(att.value(index));
 
if (ty.toLower() == QString("png"))
PointSymbolizer->type = type_png;
else if (ty.toLower() == QString("gif"))
PointSymbolizer->type = type_gif;
else if (ty.toLower() == QString("jpg"))
PointSymbolizer->type = type_jpg;
else if (ty.toLower() == QString("xpm"))
PointSymbolizer->type = type_xpm;
else if (ty.toLower() == QString("bmp"))
PointSymbolizer->type = type_xmp;
else if (ty.toLower() == QString("tif") || ty.toLower() == QString("tiff"))
PointSymbolizer->type = type_tif;
}
 
if ((index = add.index(QString("width"))) != -1)
if ((index = att.index(QString("width"))) != -1)
PointSymbolizer->width = att.value(index).toDouble();
 
if ((index = add.index(QString("height"))) != -1)
if ((index = att.index(QString("height"))) != -1)
PointSymbolizer->height = att.value(index).toDouble();
 
if ((index = add.index(QString("allow_overlap"))) != -1)
if ((index = att.index(QString("allow_overlap"))) != -1)
{
if (att.value(index).toLower() == QString("true"))
PointSymbolizer->allow_overlap = true;
344,11 → 449,14
else
PointSymbolizer->allow_overlap = false;
}
cout << " <Pointsymbolizer file=" << PointSymbolizer->file.toAscii().data() << " ... >" << endl;
break;
 
break;
 
case CON_LINESYMBOLIZER:
Container = in_linesymbolizer;
 
if (!Rule)
{
KMessageBox::error(0, i18n("Error parsing %1: Open LINESYMBOLIZER outside of a RULE!").arg(XmlPath));
359,19 → 467,20
 
if (!LineSymbolizer)
{
LineSymbolizer = new LINESYMBOLIZER;
memset (LineSymbolizer, 0, sizeof(LINESYMBOLIZER));
LineSymbolizer = allocLineSymbolizer();
Rule->LineSymbolizer = LineSymbolizer;
}
else
{
LineSymbolizer->next = new LINESYMBOLIZER;
LineSymbolizer->next = allocLineSymbolizer();
LineSymbolizer = LineSymbolizer->next;
memset (LineSymbolizer, 0, sizeof(LINESYMBOLIZER));
}
cout << " <Linesymbolizer>" << endl;
break;
 
case CON_POLYGONSYMBOLIZER:
Container = in_polygonsymbolizer;
 
if (!Rule)
{
KMessageBox::error(0, i18n("Error parsing %1: Open POLYGONSYMBOLIZER outside of a RULE!").arg(XmlPath));
382,19 → 491,20
 
if (!PolygonSymbolizer)
{
PolygonSymbolizer = new POLYGONSYMBOLIZER;
memset (PolygonSymbolizer, 0, sizeof(POLYGONSYMBOLIZER));
PolygonSymbolizer = allocPolygonSymbolizer();
Rule->PolygonSymbolizer = PolygonSymbolizer;
}
else
{
PolygonSymbolizer->next = new POLYGONSYMBOLIZER;
PolygonSymbolizer->next = allocPolygonSymbolizer();
PolygonSymbolizer = PolygonSymbolizer->next;
memset (PolygonSymbolizer, 0, sizeof(POLYGONSYMBOLIZER));
}
cout << " <Polygonsymbolizer>" << endl;
break;
 
case CON_TEXTSYMBOLIZER:
Container = in_textsymbolizer;
 
if (!Rule)
{
KMessageBox::error(0, i18n("Error parsing %1: Open TEXTSYMBOLIZER outside of a RULE!").arg(XmlPath));
405,15 → 515,13
 
if (!TextSymbolizer)
{
TextSymbolizer = new TEXTSYMBOLIZER;
memset (TextSymbolizer, 0, sizeof(TEXTSYMBOLIZER));
TextSymbolizer = allocTextSymbolizer();
Rule->TextSymbolizer = TextSymbolizer;
}
else
{
TextSymbolizer->next = new TEXTSYMBOLIZER;
TextSymbolizer->next = allocTextSymbolizer();
TextSymbolizer = TextSymbolizer->next;
memset (TextSymbolizer, 0, sizeof(TEXTSYMBOLIZER));
}
 
if ((index = att.index(QString("name"))) != -1)
426,16 → 534,534
TextSymbolizer->size = att.value(index).toDouble();
 
if ((index = att.index(QString("fill"))) != -1)
TextSymbolizer->fill =
TextSymbolizer->fill = colorToUInt(att.value(index));
 
if ((index = att.index(QString("halo_radius"))) != -1)
TextSymbolizer->halo_radius = att.value(index).toDouble();
 
if ((index = att.index(QString("wrap_width"))) != -1)
TextSymbolizer->wrap_width = att.value(index).toDouble();
 
if ((index = att.index(QString("dy"))) != -1)
TextSymbolizer->dy = att.value(index).toDouble();
 
if ((index = att.index(QString("max_distance"))) != -1)
TextSymbolizer->maxdistance = att.value(index).toDouble();
 
if ((index = att.index(QString("min_distance"))) != -1)
TextSymbolizer->mindistance = att.value(index).toDouble();
cout << " <Textsymbolizer name=" << TextSymbolizer->name.toAscii().data() << " ... >" << endl;
break;
 
case CON_POLYGONPATTERNSYMBOLIZER:
Container = in_polygonpatternsymbolizer;
 
if (!Rule)
{
KMessageBox::error(0, i18n("Error parsing %1: Open POLYGONPATTERNSYMBOLIZER outside of a RULE!").arg(XmlPath));
return false;
}
 
PolygonPatternSymbolizer = getLastPolygonPatternSymbolizer(Rule->PolygonPatternSymbolizer);
 
if (!PolygonPatternSymbolizer)
{
PolygonPatternSymbolizer = allocPolygonPatternSymbolizer();
Rule->PolygonPatternSymbolizer = PolygonPatternSymbolizer;
}
else
{
PolygonPatternSymbolizer->next = allocPolygonPatternSymbolizer();
PolygonPatternSymbolizer = PolygonPatternSymbolizer->next;
}
 
if ((index = att.index(QString("file"))) != -1)
PolygonPatternSymbolizer->file = att.value(index);
 
if ((index = att.index(QString("type"))) != -1)
PolygonPatternSymbolizer->type = getType(att.value(index));
 
if ((index = att.index(QString("width"))) != -1)
PolygonPatternSymbolizer->width = att.value(index).toDouble();
 
if ((index = att.index(QString("height"))) != -1)
PolygonPatternSymbolizer->height = att.value(index).toDouble();
 
if ((index = att.index(QString("allow_overlap"))) != -1)
PolygonPatternSymbolizer->allow_overlap = getBool(att.value(index));
cout << " <Polygonpatternsymbolizer file=" << PolygonPatternSymbolizer->file.toAscii().data() << " ... >" << endl;
break;
 
case CON_SHIELDSYMBOLIZER:
Container = in_shieldsymbolizer;
 
if (!Rule)
{
KMessageBox::error(0, i18n("Error parsing %1: Open SHIELDSYMBOLIZER outside of a RULE!").arg(XmlPath));
return false;
}
 
ShieldSymbolizer = getLastShieldSymbolizer(Rule->ShieldSymbolizer);
 
if (!ShieldSymbolizer)
{
ShieldSymbolizer = allocShieldSymbolizer();
Rule->ShieldSymbolizer = ShieldSymbolizer;
}
else
{
ShieldSymbolizer->next = allocShieldSymbolizer();
ShieldSymbolizer = ShieldSymbolizer->next;
}
 
if ((index = att.index(QString("name"))) != -1)
ShieldSymbolizer->name = att.value(index);
 
if ((index = att.index(QString("face_name"))) != -1)
ShieldSymbolizer->face_name = att.value(index);
 
if ((index = att.index(QString("fill"))) != -1)
ShieldSymbolizer->fill = colorToUInt(att.value(index));
 
if ((index = att.index(QString("placement"))) != -1)
ShieldSymbolizer->placement = att.value(index);
 
if ((index = att.index(QString("file"))) != -1)
ShieldSymbolizer->file = att.value(index);
 
if ((index = att.index(QString("type"))) != -1)
ShieldSymbolizer->type = getType(att.value(index));
 
if ((index = att.index(QString("size"))) != -1)
ShieldSymbolizer->size = att.value(index).toDouble();
 
if ((index = att.index(QString("width"))) != -1)
ShieldSymbolizer->width = att.value(index).toDouble();
 
if ((index = att.index(QString("height"))) != -1)
ShieldSymbolizer->height = att.value(index).toDouble();
 
if ((index = att.index(QString("min_distance"))) != -1)
ShieldSymbolizer->mindistance = att.value(index).toDouble();
 
if ((index = att.index(QString("max_distance"))) != -1)
ShieldSymbolizer->maxdistance = att.value(index).toDouble();
cout << " <Shieldsymbolizer name=" << ShieldSymbolizer->name.toAscii().data() << " ... >" << endl;
break;
 
case CON_LINEPATTERNSYMBOLIZER:
Container = in_linepatternsymbolizer;
 
if (!Rule)
{
KMessageBox::error(0, i18n("Error parsing %1: Open LINEPATTERNSYMBOLIZER outside of a RULE!").arg(XmlPath));
return false;
}
 
LinePatternSymbolizer = getLastLinePatternSymbolizer(Rule->LinePatternSymbolizer);
 
if (!LinePatternSymbolizer)
{
LinePatternSymbolizer = allocLinePatternSymbolizer();
Rule->LinePatternSymbolizer = LinePatternSymbolizer;
}
else
{
LinePatternSymbolizer->next = allocLinePatternSymbolizer();
LinePatternSymbolizer = LinePatternSymbolizer->next;
}
 
if ((index = att.index(QString("file"))) != -1)
LinePatternSymbolizer->file = att.value(index);
 
if ((index = att.index(QString("type"))) != -1)
LinePatternSymbolizer->type = getType(att.value(index));
 
if ((index = att.index(QString("width"))) != -1)
LinePatternSymbolizer->width = att.value(index).toDouble();
 
if ((index = att.index(QString("height"))) != -1)
LinePatternSymbolizer->height = att.value(index).toDouble();
cout << " <Linepatternsymbolizer file=" << LinePatternSymbolizer->file.toAscii().data() << " ... >" << endl;
break;
}
}
 
i++;
}
 
i = FIRST_FLD;
 
while (i <= LAST_FLD)
{
if (qName.toLower() == getKey(i).toLower())
{
Field = i;
 
switch(Container)
{
case in_linesymbolizer:
Names = empty;
 
if (i == FLD_CSSPARAMETER)
{
if ((index = att.index(QString("name"))) != -1)
{
if (att.value(index).toLower() == QString("stroke"))
Names = stroke_stroke;
else if (att.value(index).toLower() == QString("stroke-width"))
Names = stroke_width;
else if (att.value(index).toLower() == QString("stroke-opacity"))
Names = stroke_opacity;
else if (att.value(index).toLower() == QString("stroke-linejoin"))
Names = stroke_linejoin;
else if (att.value(index).toLower() == QString("stroke-linecap"))
Names = stroke_linecap;
else if (att.value(index).toLower() == QString("stroke-dasharray"))
Names = stroke_dasharray;
}
else
{
KMessageBox::error(0, i18n("Error parsing %1: Required attribute NAME is missing in CSSPARAMETER inside LINESYMBOLIZER!").arg(XmlPath));
return false;
}
}
break;
 
case in_polygonsymbolizer:
Names = empty;
 
if (i == FLD_CSSPARAMETER)
{
if ((index = att.index(QString("name"))) != -1)
{
if (att.value(index).toLower() == QString("fill"))
Names = fill;
else if (att.value(index).toLower() == QString("fill-opacity"))
Names = fill_opacity;
}
else
{
KMessageBox::error(0, i18n("Error parsing %1: Required attribute NAME is missing in CSSPARAMETER inside POLYGONSYMBOLIZER!").arg(XmlPath));
return false;
}
}
break;
 
case in_datasource:
Names = empty;
 
if (i == FLD_PARAMETER)
{
if ((index = att.index(QString("name"))) != -1)
{
if (att.value(index).toLower() == QString("type"))
Names = type;
else if (att.value(index).toLower() == QString("file"))
Names = file;
else if (att.value(index).toLower() == QString("host"))
Names = host;
else if (att.value(index).toLower() == QString("user"))
Names = user;
else if (att.value(index).toLower() == QString("dbname"))
Names = dbname;
else if (att.value(index).toLower() == QString("table"))
Names = table;
else if (att.value(index).toLower() == QString("estimate_extent"))
Names = estimate_extent;
else if (att.value(index).toLower() == QString("extent"))
Names = extent;
}
else
{
KMessageBox::error(0, i18n("Error parsing %1: Required attribute NAME is missing in PARAMETER inside DATASOURCE!").arg(XmlPath));
return false;
}
}
break;
 
case in_root:
Names = empty;
break;
case in_map:
Names = empty;
break;
case in_style:
Names = empty;
break;
case in_rule:
Names = empty;
break;
case in_pointsymbolizer:
Names = empty;
break;
case in_textsymbolizer:
Names = empty;
break;
case in_polygonpatternsymbolizer:
Names = empty;
break;
case in_layer:
Names = empty;
break;
case in_symbolizer:
Names = empty;
break;
case in_shieldsymbolizer:
Names = empty;
break;
case in_linepatternsymbolizer:
Names = empty;
break;
}
}
 
i++;
}
 
return true;
}
 
/*
* This is called every time an element is closed.
*/
bool render::endElement( const QString&, const QString&, const QString& qName)
bool SRender::endElement( const QString&, const QString&, const QString& qName)
{
if (qName.toLower() == QString("datasource"))
Container = in_layer;
else if (qName.toLower() == QString("layer"))
{
parameters p;
Container = in_map;
 
if (Lay->Datasource.type.toLower() == QString("shape"))
{
p["type"] = "shape";
p["file"] = Lay->Datasource.file.toAscii().constData();
}
else if (Lay->Datasource.type.toLower() == QString("postgis"))
{
p["type"] = "postgis";
p["host"] = Lay->Datasource.host.toAscii().constData();
p["user"] = Lay->Datasource.user.toAscii().constData();
p["dbname"] = Lay->Datasource.dbname.toAscii().constData();
p["table"] = Lay->Datasource.table.toAscii().constData();
p["estimate_extent"] = (Lay->Datasource.estimate_extent) ? "true" : "false";
p["extent"] = QString("%1,%2,%3,%4").arg(Lay->Datasource.ext_lx).arg(Lay->Datasource.ext_ly).arg(Lay->Datasource.ext_rx).arg(Lay->Datasource.ext_ry).toAscii().data();
}
else
{
cerr << "Warning: Layer with no source! Ingnoring!" << endl;
return true;
}
 
Layer lyr(Lay->name.toAscii().data());
lyr.set_datasource(datasource_cache::instance()->create(p));
lyr.setActive(Lay->status);
 
if (!Lay->srs.isEmpty())
lyr.set_srs(Lay->srs.toAscii().constData());
 
// Add the styles
for (int i = 0; i < Lay->Styles.size(); i++)
lyr.add_style(Lay->Styles.at(i).toAscii().constData());
 
m.addLayer(lyr);
}
else if (qName.toLower() == QString("map"))
{
color col;
 
Container = in_root;
col.set_bgr(MapPars.bgcolor);
m.set_background(col);
m.set_buffer_size(MapPars.buf_size);
ControlSet = true;
}
else if (qName.toLower() == QString("pointsymbol") ||
qName.toLower() == QString("linesymbol") ||
qName.toLower() == QString("polygonsymbol") ||
qName.toLower() == QString("textsymbol") ||
qName.toLower() == QString("polygonpatternsymbol") ||
qName.toLower() == QString("shieldsymbol") ||
qName.toLower() == QString("linepatternsymbol") ||
qName.toLower() == QString("filter") ||
qName.toLower() == QString("maxscaledenominator") ||
qName.toLower() == QString("minscaledenominator"))
Container = in_rule;
else if (qName.toLower() == QString("rule"))
Container = in_style;
else if (qName.toLower() == QString("style"))
{
Container = in_map;
feature_type_style style;
 
if (Style->rule)
{
rule_type rule;
Rule = Style->rule;
 
while (Rule)
{
if (Rule->minscale >= 0.0)
rule.set_min_scale(Rule->minscale);
 
if (Rule->maxscale >= 0.0)
rule.set_max_scale(Rule->maxscale);
 
if (!Rule->filter.isEmpty())
rule.set_filter(create_filter(Rule->filter.toAscii().data()));
 
LineSymbolizer = Rule->LineSymbolizer;
 
while (LineSymbolizer)
{
stroke st;
color col;
col.set_bgr(LineSymbolizer->stroke);
 
st.set_color (col);
st.set_width (LineSymbolizer->stroke_width);
 
if (!LineSymbolizer->stroke_linejoin.isEmpty())
{
if (LineSymbolizer->stroke_linejoin.toLower() == QString("miter"))
st.set_line_join (mapnik::MITER_JOIN);
else if (LineSymbolizer->stroke_linejoin.toLower() == QString("miter_revert") ||
LineSymbolizer->stroke_linejoin.toLower() == QString("miter-revert"))
st.set_line_join (mapnik::MITER_REVERT_JOIN);
else if (LineSymbolizer->stroke_linejoin.toLower() == QString("round"))
st.set_line_join (mapnik::ROUND_JOIN);
else if (LineSymbolizer->stroke_linejoin.toLower() == QString("bevel"))
st.set_line_join (mapnik::BEVEL_JOIN);
else
{
cerr << "Error parsing " << XmlPath.toAscii().data() << ": Unknown >>line_join<< \"" << LineSymbolizer->stroke_linejoin.toAscii().data() << "\" --> ignoring!" << endl;
LineSymbolizer = LineSymbolizer->next;
continue;
}
}
 
if (!LineSymbolizer->stroke_linecap.isEmpty())
{
if (LineSymbolizer->stroke_linecap.toLower() == QString("butt"))
st.set_line_cap (mapnik::BUTT_CAP);
else if (LineSymbolizer->stroke_linecap.toLower() == QString("square"))
st.set_line_cap (mapnik::SQUARE_CAP);
else if (LineSymbolizer->stroke_linecap.toLower() == QString("round"))
st.set_line_cap (mapnik::ROUND_CAP);
else
{
cerr << "Error parsing " << XmlPath.toAscii().data() << ": Unknown >>line_cap<< \"" << LineSymbolizer->stroke_linecap.toAscii().data() << "\" --> ignoring!" << endl;
LineSymbolizer = LineSymbolizer->next;
continue;
}
}
 
st.add_dash(LineSymbolizer->stroke_dasharray[0], LineSymbolizer->stroke_dasharray[1]);
st.set_opacity(LineSymbolizer->stroke_opacity);
rule.append(line_symbolizer(st));
LineSymbolizer = LineSymbolizer->next;
}
 
PointSymbolizer = Rule->PointSymbolizer;
 
while (PointSymbolizer)
{
if (PointSymbolizer->file.length() == 0 || PointSymbolizer->width == 0 || PointSymbolizer->height == 0)
{
cerr << "Warning parsing " << XmlPath.toAscii().data() << ": Ignoring empty POINTSYMBOLIZER!" << endl;
break;
}
 
point_symbolizer ps(PointSymbolizer->file.toAscii().data(), getTypeText(PointSymbolizer->type), PointSymbolizer->width, PointSymbolizer->height);
ps.set_allow_overlap (PointSymbolizer->allow_overlap);
rule.append(ps);
PointSymbolizer = PointSymbolizer->next;
}
 
PolygonSymbolizer = Rule->PolygonSymbolizer;
 
while (PolygonSymbolizer)
{
color col;
col.set_bgr(PolygonSymbolizer->fill);
 
polygon_symbolizer ps(col);
ps.set_opacity(PolygonSymbolizer->fill_opacity);
rule.append(ps);
PolygonSymbolizer = PolygonSymbolizer->next;
}
 
TextSymbolizer = Rule->TextSymbolizer;
 
while (TextSymbolizer)
{
color col;
col.set_bgr(TextSymbolizer->fill);
 
text_symbolizer ts(TextSymbolizer->name.toAscii().data(), TextSymbolizer->face_name.toAscii().data(), TextSymbolizer->size, col);
ts.set_halo_radius((unsigned int)TextSymbolizer->halo_radius);
ts.set_wrap_width((unsigned int)TextSymbolizer->wrap_width);
ts.set_max_char_angle_delta(TextSymbolizer->dy);
ts.set_displacement(TextSymbolizer->mindistance, TextSymbolizer->maxdistance);
rule.append(ts);
TextSymbolizer = TextSymbolizer->next;
}
 
PolygonPatternSymbolizer = Rule->PolygonPatternSymbolizer;
 
while (PolygonPatternSymbolizer)
{
// FIXME: The file name must be variable and KDE like!!
rule.append(polygon_pattern_symbolizer(PolygonPatternSymbolizer->file.toAscii().data(),
getTypeText(PolygonPatternSymbolizer->type),
PolygonPatternSymbolizer->width,
PolygonPatternSymbolizer->height));
PolygonPatternSymbolizer = PolygonPatternSymbolizer->next;
}
 
ShieldSymbolizer = Rule->ShieldSymbolizer;
 
while (ShieldSymbolizer)
{
color col;
col.set_bgr(ShieldSymbolizer->fill);
// FIXME: The file name must be variable and KDE like!!
shield_symbolizer ss(ShieldSymbolizer->name.toAscii().data(),
ShieldSymbolizer->face_name.toAscii().data(),
ShieldSymbolizer->size, col,
ShieldSymbolizer->file.toAscii().data(),
getTypeText(ShieldSymbolizer->type),
ShieldSymbolizer->width, ShieldSymbolizer->height);
ss.set_label_placement((ShieldSymbolizer->placement.toLower() == QString("point")) ? mapnik::POINT_PLACEMENT : mapnik::LINE_PLACEMENT);
ss.set_displacement(ShieldSymbolizer->mindistance, ShieldSymbolizer->maxdistance);
rule.append(ss);
ShieldSymbolizer = ShieldSymbolizer->next;
}
 
LinePatternSymbolizer = Rule->LinePatternSymbolizer;
 
while (LinePatternSymbolizer)
{
// FIXME: The file name must be variable and KDE like!!
rule.append(line_pattern_symbolizer(LinePatternSymbolizer->file.toAscii().data(),
getTypeText(LinePatternSymbolizer->type),
LinePatternSymbolizer->width,
LinePatternSymbolizer->height));
LinePatternSymbolizer = LinePatternSymbolizer->next;
}
 
style.add_rule(rule);
Rule = Rule->next;
}
}
 
// Add style to map
m.insert_style(Style->name.toAscii().data(), style);
}
 
return true;
}
 
/*
442,18 → 1068,109
* The reader calls this function when it has parsed a chunk of character data
* - either normal character data or character data inside a CDATA section.
*/
bool render::characters (const QString& ch)
bool SRender::characters (const QString& ch)
{
if (ch.length() == 0 || ch.at(0) == QChar('\n'))
return true;
 
if (Container == in_rule && Rule)
{
if (Field == FLD_FILTER)
Rule->filter = ch;
else if (Field == FLD_MAXSCALE)
Rule->maxscale = ch.toDouble();
else if (Field == FLD_MINSCALE)
Rule->minscale = ch.toDouble();
}
else if (Container == in_linesymbolizer && LineSymbolizer)
{
if (Field == FLD_CSSPARAMETER)
{
if (Names == stroke_stroke)
LineSymbolizer->stroke = colorToUInt(ch);
else if (Names == stroke_width)
LineSymbolizer->stroke_width = ch.toDouble();
else if (Names == stroke_linejoin)
LineSymbolizer->stroke_linejoin = ch;
else if (Names == stroke_linecap)
LineSymbolizer->stroke_linecap = ch;
else if (Names == stroke_opacity)
LineSymbolizer->stroke_opacity = ch.toDouble();
else if (Names == stroke_dasharray)
{
int pos;
QString arr = ch;
QStringList list;
 
list = arr.split(",", QString::SkipEmptyParts);
 
for (pos = 0; pos < list.size() && pos < 10; pos++)
{
LineSymbolizer->stroke_dasharray[pos] = list.at(pos).toDouble();
pos++;
}
 
LineSymbolizer->stroke_anz = pos;
}
}
}
else if (Container == in_polygonsymbolizer && PolygonSymbolizer)
{
if (Field == FLD_CSSPARAMETER)
{
if (Names == fill)
PolygonSymbolizer->fill = colorToUInt(ch);
else if (Names == fill_opacity)
PolygonSymbolizer->fill_opacity = ch.toDouble();
}
}
else if (Container == in_layer && Lay)
{
if (Field == FLD_STYLENAME)
Lay->Styles << ch;
}
else if (Container == in_datasource && Lay)
{
if (Field == FLD_PARAMETER)
{
if (Names == type)
Lay->Datasource.type = ch;
else if (Names == file)
Lay->Datasource.file = ch;
else if (Names == host)
Lay->Datasource.host = ch;
else if (Names == user)
Lay->Datasource.user = ch;
else if (Names == dbname)
Lay->Datasource.dbname = ch;
else if (Names == table)
Lay->Datasource.table = ch;
else if (Names == estimate_extent)
Lay->Datasource.estimate_extent = getBool(ch);
else if (Names == extent)
{
QString arr = ch;
QStringList list;
list = arr.split(",");
Lay->Datasource.ext_lx = list.at(0).toDouble();
Lay->Datasource.ext_ly = list.at(1).toDouble();
Lay->Datasource.ext_rx = list.at(2).toDouble();
Lay->Datasource.ext_ry = list.at(3).toDouble();
}
}
}
 
return true;
}
 
QString render::getKey (int pos)
QString SRender::getKey (int pos)
{
int i = 0;
 
while (keys[i].id > 0)
while (token[i].id > 0)
{
if (keys[i].id == pos)
return keys[i].name;
if (token[i].id == pos)
return token[i].name;
 
i++;
}
461,219 → 1178,208
return QString::null;
}
 
bool render::getMap (double lx, double ly, double rx double ry)
TYPES SRender::getType(QString ty)
{
int width, height;
if (ty.toLower() == QString("png"))
return type_png;
else if (ty.toLower() == QString("gif"))
return type_gif;
else if (ty.toLower() == QString("jpg"))
return type_jpg;
else if (ty.toLower() == QString("xpm"))
return type_xpm;
else if (ty.toLower() == QString("bmp"))
return type_bmp;
else if (ty.toLower() == QString("tif") || ty.toLower() == QString("tiff"))
return type_tif;
 
datasource_cache::instance()->register_datasources(MAPNIK_PLUGIN_PATH + "/");
freetype_engine::register_font(MAPNIK_FONTS + "/DejaVuSans.ttf");
return type_png;
}
 
width = label.width();
height = label.height();
char *grTypes[] = { (char *)"png", (char *)"gif", (char *)"jpg", (char*)"xpm",
(char *)"bmp", (char *)"tif" };
 
Map m(width, height, "+proj=merc +datum=WGS84 +k=1.0 +units=m +over +no_defs");
m.set_background(color_factory::from_string("white"));
char *SRender::getTypeText(TYPES type)
{
switch (type)
{
case type_png: return grTypes[0]; break;
case type_gif: return grTypes[1]; break;
case type_jpg: return grTypes[2]; break;
case type_xpm: return grTypes[3]; break;
case type_bmp: return grTypes[4]; break;
case type_tif: return grTypes[5]; break;
}
 
// create styles
// world1
feature_type_style world1_style;
addRule(&world1_style, 0, 6000000.0, 250000000000.0, Color(0xf2, 0xef, 0xe9), Color(0xb5, 0xd0, 0xd0), 0.5, 0, 0, 0);
return 0;
}
 
// world
feature_type_style world_style;
addRule(&world_style, 0, 600000.0, 6000000.0, Color(0xf2, 0xef, 0xe9), 0, 0.0, 0, 0, 0);
bool SRender::getBool(QString b)
{
if (b.toLower() == QString("true") ||
b.toLower() == QString("on") ||
b.toLower() == QString("1") ||
b.toLower() == QString("yes") ||
b.toLower() == QString("t") ||
b.toLower() == QString("y"))
return true;
 
// coast_poly
feature_type_style coast_poly_style;
addRule(&coas_poly_style, 0, -1.0, 600000.0, Color(0xf2, 0xef, 0xe9), 0, 0.0, 0, 0, 0);
return false;
}
 
// builtup
feature_type_style builtup_style;
addRule(&builtup_style, 0, 500000.0, 2500000.0, Color(0x0d, 0x0d, 0x0d), 0, 0.0, 0, 0, 0);
bool SRender::getMap (double lx, double ly, double rx, double ry)
{
int width, height, pid;
QXmlSimpleReader reader;
QString hv0;
QFile file(XmlPath);
 
// places
feature_type_style places_style;
text_symbolizer places_ts = addTextSymbolizer("place_name", "DejaVu Sans Book", 10, Color(0x04, 0x04, 0x04), 1, 0.0);
places_style.append(places_ts);
addRule(&places_style, 0, 10000000.0, 50000000.0, 0, 0, 0.0, 0, 0, 0);
hv0 = pluginPath + "/";
datasource_cache::instance()->register_datasources(hv0.toAscii().data());
hv0 = fontPath + "/DejaVuSans.ttf";
freetype_engine::register_font(hv0.toAscii().data());
 
// stations
feature_type_style stations_style;
addRulePoint(&stations_style, "[railway]='station'", 25000.0, 250000.0, 0, 0, 0.0, QString("station_small.png"), 5, 5);
addRulePoint(&stations_style, "[railway]='station'", -1.0, 25000.0, 0, 0, 0.0, QString("station.png", 9, 9);
addRulePoint(&stations_style, "[railway]='halt' or [railway]='tram_stop'", -1.0, 100000.0, 0, 0, 0.0, QString("halt.png"), 3, 3);
width = label->width();
height = label->height();
 
text_symbolizer stations_ts = addTextSymbolizer("name", "DejaVu Sans Bold", 8, Color(0, 0, 0), 1, 0, -8.0);
stations_style.append(stations_ts);
addRulePoint(&stations_style, "[railway]='halt'", 25000.0, 50000.0, 0, 0, 0.0, 0, 0, 0, 0);
m.setWidth(width);
m.setHeight(height);
 
text_symbolizer stations_ts1 = addTextSymbolizer("name", "DejaVu Sans Bold", 10, Color(0, 0, 0), 1, 0, -14.0);
stations_style.append(stations_ts1);
addRule(&stations_style, "[railway] ='halt'", -1.0, 25000.0, 0, 0, 0.0, 0, 0, 0);
if (!ControlSet) // Initialize the map?
{
QXmlInputSource source (&file);
reader.setContentHandler (this);
reader.parse (source);
}
 
text_symbolizer stations_ts2 = addTextSymbolizer("name", "DejaVu Sans Bold", 9, Color(0, 0, 0), 1, 0, -8.0);
stations_style.append(stations_ts2);
addRule(&stations_style, "[railway]='station'", 25000.0, 50000.0, 0, 0, 0.0, 0, 0, 0);
// First we use Mapnik to create the map
cout << lx << ", " << ly << ", " << rx << ", " << ry << endl;
//cout << DEG2RAD(lx) << ", " << DEG2RAD(ly) << ", " << DEG2RAD(rx) << ", " << DEG2RAD(ry) << endl;
m.zoomToBox(Envelope<double>(lx, ly, rx, ry));
Image32 buf(m.getWidth(), m.getHeight());
agg_renderer<Image32> ren(m, buf);
ren.apply();
// Create a unique file name
pid = getpid();
hv0.sprintf("/var/tmp/SportWatcher_%d", pid);
save_to_file<ImageData32>(buf.data(), hv0.toAscii().data(), "png");
 
text_symbolizer stations_ts3 = addTextSymbolizer("name", "DejaVu Sans Bold", 12, Color(0, 0, 0), 1, 0, -14.0);
stations_style.append(stations_ts3);
addRule(&stations_style, "[railway]='station'", -1.0, 25000.0, 0, 0, 0.0, 0, 0, 0);
addRulePoint(&stations_style, "[railway]='level_crossing'", 10000.0, 50000.0, 0, 0, 0.0, QString("level_crossing.png"), 7, 7);
// Now we move the image into a QPixmap
QPixmap pm;
pm.load(hv0);
unlink(hv0.toAscii().data()); // delete the temporary file
label->setPixmap(pm);
return true;
}
 
// leisure
feature_type_style leisure_style;
RULE *SRender::getLastRule(RULE *first)
{
RULE *akt = first;
 
addRule(&leisure_style, "[man_made] = 'pier'", -1.0, 100000.0, Color(0xed, 0xed, 0xed), color_factory::from_string("grey"), 0.3, 0, 0, 0);
addRule(&leisure_style, "[highway] = 'residential'", -1.0, 50000.0, Color(255, 255, 255), Color(0x09, 0x09, 0x09), 1.0, 0, 0, 0);
addRule(&leisure_style, "[highway] = 'pedestrian'", -1.0, 50000.0, Color(0xed, 0xed, 0xed), color_factory::from_string("grey"), 0.5, 0, 0, 0);
addRule(&leisure_style, "[leisure] = 'playground'", -1.0, 100000.0, Color(0xcc, 0xff, 0xff), Color(0x06, 0x06, 0x06), 0.3, 0, 0, 0);
addRule(&leisure_style, "[tourism] = 'attraction'", -1.0, 100000.0, Color(0xf2, 0xca, 0xea), 0, -1.0, 0, 0, 0);
addRule(&leisure_style, "[landuse] = 'quarry'", -1.0, 500000.0, 0, color_factory::from_string("grey"), 0.5, QString("quarry2.png"), 30, 30);
addRule(&leisure_style, "[leisure] = 'nature_reserve' or [landuse] = 'vineyard'", 100000.0, 1000000.0, Color(0xab, 0xdf, 0x96), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[landuse] = 'vineyard'", 20000.0, 100000.0, 0, 0, 0.0, QString("vineyard.png"), 19, 21);
addRule(&leisure_style, "[landuse] = 'vineyard'", -1.0, 100000.0, 0, 0, 0.0, QString("vineyard.png"), 29, 29);
addRule(&leisure_style, "[leisure] = 'nature_reserve'", 50000.0, 100000.0, 0, 0, 0.0, QString("nature_reserve.png"), 21, 24);
addRule(&leisure_style, "[leisure] = 'nature_reserve'", -1.0, 50000.0, 0, 0, 0.0, QString("nature_reserve2.png"), 42, 48);
addRule(&leisure_style, "[landuse] = 'cemetery'", 20000.0, 1000000.0, Color(0xaa, 0xcb, 0xaf), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[landuse] = 'residential'", 1000.0, 1000000.0, Color(0x0d, 0x0d, 0x0d), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[military] = 'barracks'", 1000.0, 1000000.0, Color(0xff, 0x8f, 0x8f), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[military] = 'danger_area'", 500000.0, 2000000.0, color_factory::from_string("pink"), 0, 0.0, 0, 0, 0); // FIXME: fill-opacity 0.3 is missing!
addRule(&leisure_style, "[military] = 'danger_area'", 1000.0, 500000.0, 0, 0, 0.0, QString("danger.png"), 30, 30);
addRule(&leisure_style, "[landuse] = 'cemetery'", -1.0, 50000.0, 0, 0, 0.0, QString("grave_yard.png"), 16, 16);
addRule(&leisure_style, "[landuse] = 'meadow'", -1.0, 1000000.0, Color(0xcf, 0xec, 0xa8), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[leisure] = 'park'", -1.0, 1000000.0, Color(0xb6, 0xfd, 0xb6), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[tourism] = 'zoo'", -1.0, 1000000.0, 0, 0, 0.0, QString("zoo.png"), 21, 24);
addRule(&leisure_style, "[leisure] = 'common'", -1.0, 1000000.0, Color(0xcf, 0xec, 0xa8), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[leisure] = 'garden'", -1.0, 1000000.0, Color(0xcf, 0xec, 0xa8), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[leisure] = 'golf_course'", -1.0, 1000000.0, Color(0xb5, 0xe3, 0xb5), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[landuse] = 'allotments'", -1.0, 1000000.0, Color(0xc8, 0xb0, 0x84), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[landuse] = 'forest'", 50000.0, 2000000.0, Color(0x8d, 0xc5, 0x6c), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[landuse] = 'forest'", -1.0, 50000.0, 0, 0, 0.0, QString("forest.png"), 21, 24);
addRule(&leisure_style, "[landuse] = 'farm'", -1.0, 2000000.0, Color(0xea, 0xd8, 0xbd), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[landuse] = 'recreation_ground'", -1.0, 1000000.0, Color(0xcf, 0xec, 0xa8), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[landuse] = 'village_green'", -1.0, 500000.0, Color(0xcf, 0xec, 0xa8), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[landuse] = 'retail'", -1.0, 1000000.0, Color(0xf1, 0xda, 0xda), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[landuse] = 'retail'", -1.0, 25000.0, 0, color_factory::from_string("red"), 0.3, 0, 0, 0);
addRule(&leisure_style, "[landuse] = 'industrial'", -1.0, 1000000.0, Color(0xff, 0xae, 0xb9), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[power] = 'station'", 200000.0, 1000000.0, Color(0x0b, 0x0b, 0x0b), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[power] = 'station'", -1.0, 200000.0, Color(0x0b, 0x0b, 0x0b), Color(0x05, 0x05, 0x05), 0.4, 0, 0, 0);
addRule(&leisure_style, "[power] = 'sub_station'", -1.0, 100000.0, Color(0x0b, 0x0b, 0x0b), Color(0x05, 0x05, 0x05), 0.4, 0, 0, 0);
addRule(&leisure_style, "[landuse] = 'commercial'", -1.0, 1000000.0, Color(0xef, 0xc8, 0xc8), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[landuse] = 'brownfield' or [landuse]='landfill'", -1, 1000000.0, Color(0x9d, 0x9d, 0x6c), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[natural] = 'wood' or [landuse] = 'wood'", -1.0, 1000000.0, Color(0xae, 0xd1, 0xa0), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[natural] = 'heath'", -1.0, 1000000.0, Color(0xff, 0xff, 0xc0), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[landuse] = 'basin'", -1.0, 5000000.0, Color(0xb5, 0xd0, 0xd0), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[amenity] = 'university' or [amenity] = 'college' or [amenity] = 'school' or [amenity]='hospital'", -1.0, 1000000.0, Color(0xf0, 0xf0, 0xd8), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[amenity] = 'university' or [amenity] = 'college' or [amenity] = 'school' or [amenity]='hospital'", -1.0, 250000.0, 0, color_factory::from_string("brown"), 0.3, 0, 0, 0);
addRule(&leisure_style, "[amenity] = 'parking'", -1.0, 1000000.0, Color(0xf7, 0xef, 0xb7), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[amenity] = 'parking'", -1.0, 25000.0, 0, Color(0xee, 0xee, 0xd1), 0.3, 0, 0, 0);
addRule(&leisure_style, "[railway] = 'station' or [building] = 'station'", -1.0, 1000000.0, Color(0xff, 0xf6, 0x8f), 0, 0.0, 0, 0, 0); // FIXME: fill-opacity = 0.5 is missing!
addRule(&leisure_style, "[building] = 'supermarket'", -1.0, 1000000.0, color_factory::from_string("pink"), 0, 0.0, 0, 0, 0); // FIXME: fill-opacity = 0.5 is missing!
addRule(&leisure_style, "[building] <> 'station' and [building] <> 'supermarket' and [building] <> ''", -1.0, 1000000.0, Color(0xcc, 0x99, 0x99), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[amenity] = 'place_of_worship'", 20000.0, 1000000.0, Color(0x07, 0x07, 0x07), 0, 0.0, 0, 0, 0); // FIXME: fill-opacity = 0.5 is missing!
addRule(&leisure_style, "[amenity] = 'place_of_worship'", -1.0, 20000.0, Color(0x07, 0x07, 0x07), Color(0x01, 0x01, 0x01), 0.3, 0, 0, 0);
addRule(&leisure_style, "[leisure] = 'sports_centre' or [leisure]='stadium' or [leisure]='track'", -1.0, 1000000.0, Color(0x33, 0xcc, 0x99), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[leisure] = 'pitch'", -1.0, 1000000.0, Color(0x8a, 0xd3, 0xaf), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[aeroway] = 'terminal'", -1.0, 200000.0, Color(0xcc, 0x99, 0xff), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[aeroway] = 'terminal'", -1.0, 50000.0, 0, Color(0x33, 0x00, 0x66), 0.2, 0, 0, 0);
addRule(&leisure_style, "[aeroway] = 'apron'", -1.0, 200000.0, Color(0xf0, 0xe0, 0xff), 0, 0.0, 0, 0, 0);
addRule(&leisure_style, "[natural] = 'beach'", -1.0, 100000.0, 0, 0, 0.0, QString("beach.png"), 10, 10);
while (akt)
{
if (!akt->next)
return akt;
 
akt = akt->next;
}
 
return 0;
}
 
void render::addRule (feature_type_style &fts, char *filter, double minscale, double maxscale, Color &polcol, Color &symcol, double symwidth, QString &pattern, int pw, int ph)
POINTSYMBOLIZER *SRender::getLastPointSymbolizer(POINTSYMBOLIZER *first)
{
rule_type rule;
POINTSYMBOLIZER *akt = first;
 
if (minscale >= 0.0)
rule.set_min_scale(minscale);
while (akt)
{
if (!akt->next)
return akt;
 
if (maxscale >= 0.0)
rule.set_max_scale(maxscale);
akt = akt->next;
}
 
if (pattern && pw > 0 && ph > 0)
return 0;
}
 
LINESYMBOLIZER *SRender::getLastLineSymbolizer(LINESYMBOLIZER *first)
{
LINESYMBOLIZER *akt = first;
 
while (akt)
{
QString ptf = KStandardDirs::findRessource("icon", pattern);
if (!akt->next)
return akt;
 
rule.append(polygon_pattern_symbolizer(ptf.toAscii().data(), "png", pw, ph));
akt = akt->next;
}
 
if (filter)
rule.set_filter(create_filter(filter));
return 0;
}
 
if (polcol)
rule.append(polygon_symbolizer(polcol));
POLYGONSYMBOLIZER *SRender::getLastPolygonSymbolizer(POLYGONSYMBOLIZER *first)
{
POLYGONSYMBOLIZER *akt = first;
 
if (symcol)
while (akt)
{
stroke stk (symcol);
if (!akt->next)
return akt;
 
if (symwidth >= 0.0)
stk.set_width(0.3);
 
rule.append(line_symbolizer(stk));
akt = akt->next;
}
 
fts.add_rule(rule);
return 0;
}
 
void render::addRulePoint (feature_type_style &fts, char *filter, double minscale, double maxscale, Color &polcol, Color &symcol, double symwidth, QString &pattern, int pw, int ph)
TEXTSYMBOLIZER *SRender::getLastTextSymbolizer(TEXTSYMBOLIZER *first)
{
rule_type rule;
TEXTSYMBOLIZER *akt = first;
 
if (minscale >= 0.0)
rule.set_min_scale(minscale);
 
if (maxscale >= 0.0)
rule.set_max_scale(maxscale);
 
if (pattern && pw > 0 && ph > 0)
while (akt)
{
QString ptf = KStandardDirs::findRessource("icon", pattern);
if (!akt->next)
return akt;
 
rule.append(point_symbolizer(ptf.toAscii().data(), "png", pw, ph));
akt = akt->next;
}
 
if (filter)
rule.set_filter(create_filter(filter));
return 0;
}
 
if (polcol)
rule.append(polygon_symbolizer(polcol));
POLYGONPATTERNSYMBOLIZER *SRender::getLastPolygonPatternSymbolizer(POLYGONPATTERNSYMBOLIZER *first)
{
POLYGONPATTERNSYMBOLIZER *akt = first;
 
if (symcol)
while (akt)
{
stroke stk (symcol);
if (!akt->next)
return akt;
 
if (symwidth >= 0.0)
stk.set_width(0.3);
 
rule.append(line_symbolizer(stk));
akt = akt->next;
}
 
fts.add_rule(rule);
return 0;
}
 
text_symbolizer &render::addTextSymbolizer (char *name, char *font, int size, Color &col, int radius, int wrap, double dy)
SHIELDSYMBOLIZER *SRender::getLastShieldSymbolizer(SHIELDSYMBOLIZER *first)
{
text_symbolizer ts(name, font, size, Color(0, 0, 0));
SHIELDSYMBOLIZER *akt = first;
 
if (vol && radius > 0)
while (akt)
{
ts.set_halo_fill(halo);
ts.set_halo_radius(radius);
if (!akt->next)
return akt;
 
akt = akt->next;
}
 
if (dy < 0.0)
ts.set_max_char_angle_delta(dy);
 
if (wrap >= 0)
ts.set_wrap_width(wrap);
 
return &ts;
return 0;
}
 
RULE *render::getLastRule(RULE *first)
LINEPATTERNSYMBOLIZER *SRender::getLastLinePatternSymbolizer(LINEPATTERNSYMBOLIZER *first)
{
RULE *akt = first;
LINEPATTERNSYMBOLIZER *akt = first;
 
while (akt)
{
686,13 → 1392,13
return 0;
}
 
POINTSYMBOLIZER *render::getLastPointSymbolizer(POINTSYMBOLIZER *first)
STYLE *SRender::findStyle(QString name)
{
POINTSYMBOLIZER *akt = first;
STYLE *akt = firstStyle;
 
while (akt)
{
if (!akt->next)
if (akt->name.toLower() == name.toLower())
return akt;
 
akt = akt->next;
700,3 → 1406,160
 
return 0;
}
 
unsigned SRender::colorToUInt(QString col)
{
QColor qc(col);
 
return (qc.red() * 65536) + (qc.green() * 256) + qc.blue();
}
 
STYLE *SRender::allocStyle()
{
STYLE *St = new STYLE;
 
St->name.clear();
St->rule = 0;
St->next = 0;
return St;
}
 
RULE *SRender::allocRule()
{
RULE *Ru = new RULE;
 
Ru->maxscale = 0;
Ru->minscale = 0;
Ru->filter.clear();
Ru->LineSymbolizer = 0;
Ru->PolygonSymbolizer = 0;
Ru->TextSymbolizer = 0;
Ru->PointSymbolizer = 0;
Ru->PolygonPatternSymbolizer = 0;
Ru->ShieldSymbolizer = 0;
Ru->LinePatternSymbolizer = 0;
Ru->next = 0;
return Ru;
}
 
LAYER *SRender::allocLayer()
{
LAYER *La = new LAYER;
 
La->name.clear(); // The unique name
La->status = false; // Is it active?
La->srs.clear(); // Projection
La->Datasource.type.clear();
La->Datasource.file.clear();
La->Datasource.host.clear();
La->Datasource.user.clear();
La->Datasource.dbname.clear();
La->Datasource.table.clear();
La->Datasource.estimate_extent = false;
La->Datasource.ext_lx = 0.0;
La->Datasource.ext_ly = 0.0;
La->Datasource.ext_rx = 0.0;
La->Datasource.ext_ry = 0.0;
La->next = 0;
return La;
}
 
LINEPATTERNSYMBOLIZER *SRender::allocLinePatternSymbolizer()
{
LINEPATTERNSYMBOLIZER *lps = new LINEPATTERNSYMBOLIZER;
 
lps->file.clear();
lps->type = type_png; // enum TYPES
lps->width = 0.0;
lps->height = 0.0;
lps->next = 0;
return lps;
}
 
SHIELDSYMBOLIZER *SRender::allocShieldSymbolizer()
{
SHIELDSYMBOLIZER *ss = new SHIELDSYMBOLIZER;
 
ss->name.clear();
ss->face_name.clear();
ss->size = 0.0;
ss->fill = 0; // Color
ss->placement.clear();
ss->file.clear();
ss->type = type_png; // enum TYPES
ss->width = 0.0;
ss->height = 0.0;
ss->mindistance = 0.0;
ss->maxdistance = 0.0;
ss->next = 0;
return ss;
}
 
POLYGONPATTERNSYMBOLIZER *SRender::allocPolygonPatternSymbolizer()
{
POLYGONPATTERNSYMBOLIZER *pps = new POLYGONPATTERNSYMBOLIZER;
 
pps->file.clear();
pps->type = type_png; // enum TYPES
pps->width = 0.0;
pps->height = 0.0;
pps->allow_overlap = false;
pps->next = 0;
return pps;
}
 
POINTSYMBOLIZER *SRender::allocPointSymbolizer()
{
POINTSYMBOLIZER *ps = new POINTSYMBOLIZER;
 
ps->file.clear();
ps->type = type_png; // enum TYPES
ps->width = 0.0;
ps->height = 0.0;
ps->allow_overlap = false;
ps->next = 0;
return ps;
}
 
TEXTSYMBOLIZER *SRender::allocTextSymbolizer()
{
TEXTSYMBOLIZER *ts = new TEXTSYMBOLIZER;
 
ts->name.clear();
ts->face_name.clear();
ts->size = 0;
ts->fill = 0; // Color
ts->halo_radius = 0;
ts->wrap_width = 0;
ts->dy = 0.0;
ts->mindistance = 0.0;
ts->maxdistance = 0.0;
ts->next = 0;
return ts;
}
 
POLYGONSYMBOLIZER *SRender::allocPolygonSymbolizer()
{
POLYGONSYMBOLIZER *ps = new POLYGONSYMBOLIZER;
 
memset (ps, 0, sizeof(POLYGONSYMBOLIZER));
return ps;
}
 
LINESYMBOLIZER *SRender::allocLineSymbolizer()
{
LINESYMBOLIZER *ls = new LINESYMBOLIZER;
 
ls->stroke = 0; // Color
ls->stroke_width = 0.0;
ls->stroke_linejoin.clear();
ls->stroke_linecap.clear();
 
for (int i = 0; i < 10; i++)
ls->stroke_dasharray[i] = 0.0;
 
ls->stroke_anz = 0; // number of entries in dasharray
ls->stroke_opacity = 0.0;
ls->next = 0;
return ls;
}
/sportwatcher/trunk/src/CMakeLists.txt
7,7 → 7,9
main.cpp
managefile.cpp
progresswidget.cpp
render.cpp
settingswidget.cpp
shapewidget.cpp
sportwatcher.cpp
sportwatcherwidget.cpp
transform.cpp
17,9 → 19,12
coordinateswidgetbase.ui
progresswidgetbase.ui
settingswidgetbase.ui
shapewidgetbase.ui
sportwatcherwidgetbase.ui
wmswidgetbase.ui)
 
add_definitions(-fexceptions)
 
kde4_add_ui_files(sportwatcher_SRCS ${sportwatcher_UI})
kde4_add_app_icon(sportwatcher_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/../src/hi*-app-sportwatcher.png")
kde4_add_executable(sportwatcher ${sportwatcher_SRCS})
/sportwatcher/trunk/src/shapewidget.h
0,0 → 1,34
//
// C++ Interface:
//
// Description:
//
//
// Author: Andreas Theofilu <andreas@theosys.at>, (C) 2009
//
// Copyright: See COPYING file that comes with this distribution
//
//
 
#ifndef SHAPEWIDGET_H
#define SHAPEWIDGET_H
 
#include <QDialog>
#include "ui_shapewidgetbase.h"
 
class shapeWidget : public QDialog, private Ui::shapeWidgetBase
{
Q_OBJECT
 
public:
shapeWidget (QWidget* parent = 0, Qt::WFlags fl = 0);
~shapeWidget();
/*$PUBLIC_FUNCTIONS$*/
 
public slots:
/*$PUBLIC_SLOTS$*/
virtual void accept();
};
 
#endif
 
/sportwatcher/trunk/src/render.h
1,7 → 1,7
//
// C++ Interface: render
// C++ Interface: SRender
//
// Description: This defines the class for render.
// Description: This defines the class for SRender.
//
//
// Author: Andreas Theofilu <andreas@theosys.at>, (C) 2009
12,19 → 12,45
#ifndef _RENDER_H
#define _RENDER_H
 
#include <QLabel>
#include <QString>
#include <QPainter>
#include <QXmlReader>
#include <KStandardDirs>
#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/color.hpp>
#include <mapnik/layer.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
{
Color stroke;
unsigned stroke; // Color
double stroke_width;
short int stroke_linejoin;
short int stroke_linecap;
QString stroke_linejoin;
QString stroke_linecap;
double stroke_dasharray[10];
int stroke_anz; // number of entries in dasharray
double stroke_opacity;
LINESYMBOLIZER *next;
}LINESYMBOLIZER;
31,7 → 57,7
 
typedef struct POLYGONSYMBOLIZER
{
Color fill;
unsigned fill; // Color
double fill_opacity;
POLYGONSYMBOLIZER *next;
}POLYGONSYMBOLIZER;
41,7 → 67,7
QString name;
QString face_name;
double size;
Color fill;
unsigned fill; // Color
double halo_radius;
double wrap_width;
double dy;
53,7 → 79,7
typedef struct POINTSYMBOLIZER
{
QString file;
int type; // enum TYPES
TYPES type; // enum TYPES
double width;
double height;
bool allow_overlap;
63,7 → 89,7
typedef struct POLYGONPATTERNSYMBOLIZER
{
QString file;
int type; // enum TYPES
TYPES type; // enum TYPES
double width;
double height;
bool allow_overlap;
75,10 → 101,10
QString name;
QString face_name;
double size;
Color fill;
unsigned fill; // Color
QString placement;
QString file;
int type;
TYPES type; // enum TYPES
double width;
double height;
double mindistance;
89,7 → 115,7
typedef struct LINEPATTERNSYMBOLIZER
{
QString file;
int type;
TYPES type; // enum TYPES
double width;
double height;
LINEPATTERNSYMBOLIZER *next;
125,7 → 151,7
QString user;
QString dbname;
QString table;
bool estimate_extend;
bool estimate_extent;
double ext_lx;
double ext_ly;
double ext_rx;
134,10 → 160,10
 
typedef struct LAYER
{
QString name;
bool status;
QString name; // The unique name
bool status; // Is it active?
QString srs; // Projection
STYLE *Style; // Pointer to first style
QStringList Styles; // The names of the Styles
DATASOURCE Datasource;
LAYER *next; // Pointer to next layer
}LAYER;
144,30 → 170,33
 
typedef struct
{
Color bgcolor;
int buffer_size;
unsigned bgcolor; // Color
int buf_size;
QString srs;
}MAP;
 
typedef enum {
stroke = 100,
empty = 0,
stroke_stroke = 100,
stroke_width = 101,
stroke_linejoin = 102,
stroke_linecap = 103,
stroke_opacity = 104,
stroke_dasharray = 105
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
}NAMES;
 
typedef enum {
type_png = 150,
type_gif = 151,
type_jpg = 152,
type_xpm = 153,
type_tif = 154,
type_bmp = 155
}TYPES;
 
typedef enum {
in_root = 0,
in_map = 100,
in_style = 101,
in_rule = 102,
177,45 → 206,79
in_textsymbolizer = 106,
in_polygonpatternsymbolizer = 107,
in_layer = 108,
in_datasource = 109
in_datasource = 109,
in_symbolizer = 110,
in_shieldsymbolizer = 111,
in_linepatternsymbolizer = 112
}CONTAINER;
 
extern KEYS keys[]; // defined at >import.h<
typedef struct
{
int id;
CONTAINER con;
QString name;
}TOKEN;
 
class render
using namespace mapnik;
 
class SRender : public QXmlDefaultHandler
{
public:
render();
SRender();
~SRender();
 
bool setDrawArea(QLabel *lb) { if (!lb) return false; label = *lb; return true; };
bool setShapePath(QString *str) { if (!str) return false; shapePath = *str; return true; };
void setDrawArea(const QLabel &lb) { label = (QLabel *)&lb; };
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);
 
// 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 addRule (feature_type_style &fts, char *filter, double minscale, double maxscale, Color &polcol, Color &symcol, double symwidth, QString &pattern, int pw, int ph);
void addRulePoint (feature_type_style &fts, char *filter, double minscale, double maxscale, Color &polcol, Color &symcol, double symwidth, QString &pattern, int pw, int ph);
void addTextSymbolizer (char *name, char *font, int size, Color &col, int radius, int wrap, double dy);
 
private:
QString getKey (int pos);
TYPES getType(QString ty);
char *getTypeText(TYPES type);
bool getBool(QString b);
unsigned colorToUInt(QString col);
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:
QLabel label;
QLabel *label;
QString shapePath;
QString pluginPath;
QString fontPath;
QString XmlPath;
int indent;
CONTAINER Container;
bool ControlSet;
int Field;
TYPES Types;
NAMES Names;
MAP MapPars;
LAYER *Layer;
Map m;
LAYER *Lay, *firstLayer, *lastLayer;
STYLE *Style, *firstStyle, *lastStyle;
RULE *Rule;
LINESYMBOLIZER *LineSymbolizer;
/sportwatcher/trunk/src/sportwatcherwidget.cpp
24,6 → 24,7
#include "progresswidget.h"
#include "wmsbase.h"
#include "coordinateswidget.h"
#include "shapewidget.h"
#include <string.h>
 
#include <iostream>
58,6 → 59,7
#include "garmin.h"
#include "transform.h"
#include "import.h"
#include "render.h"
 
//#define DEBUG 1
 
1740,21 → 1742,31
delete idlg;
return;
}
if (MapType != MPT_WMS)
 
if (MapType == MPT_WMS)
{
wmsbase *dlg = new wmsbase(this);
dlg->exec();
delete dlg;
}
 
if (MapType == MPT_SHP)
{
shapeWidget *dlg = new shapeWidget(this);
dlg->exec();
delete dlg;
}
 
if (MapType != MPT_WMS && MapType != MPT_SHP)
{
KMessageBox::detailedSorry(this,
i18n("You have not choosen a WMS tag file!"),
i18n("This dialog is especialy to set WMS specific parameters. ") +
i18n("You have not choosen a WMS tag file or shape file directory!"),
i18n("This dialog is especialy to set map specific parameters. ") +
i18n("Therefore this dialog is temporary disabled. It will be ") +
i18n("available again, as soon as you choose \"WMS server\" as ") +
i18n("your map type."));
i18n("available again, as soon as you choose \"WMS server\" or ") +
i18n("Shape file as your map type."));
return;
}
 
wmsbase *dlg = new wmsbase(this);
dlg->exec();
delete dlg;
#else
KMessageBox::detailedSorry(this,
i18n("This function was disabled at compile time because of missing GDAL v1.5.x!"),
2742,84 → 2754,13
}
else
{
OGRDataSource *poDS = 0;
OGRLayer *poLy;
OGRFeature *poFeat;
OGRFeatureDefn *poFDefn;
OGRFieldDefn *poFieldDefn;
OGRGeometry *poGeometry;
OGRPoint *poPoint;
int nLayers, iField;
QString sfn;
SRender rd;
 
OGRRegisterAll ();
// read all shape files and put them together
for (a = 0; (uint)a < shpd.count(); a++)
{
sfn = MAP + shpd[a];
poDS = OGRSFDriverRegistrar::Open(sfn.toAscii().data(), false);
 
if (!poDS)
{
cerr << "Error opening the file " << sfn.toAscii().data() << "!" << endl;
break;
}
 
nLayers = poDS->GetLayerCount ();
 
// Read all layers of a shape file
for (int j = 0; j< nLayers; j++)
{
if ((poLy = poDS->GetLayer (j)) == NULL)
{
cerr << "Error getting layer " << j << "!" << endl;
continue;
}
 
poLy->SetSpatialFilterRect (geoRect.llon, geoRect.llat, geoRect.rlon, geoRect.rlat);
 
// Read all features of a layer and get the fields
// of the features
poLy->ResetReading();
 
while ((poFeat = poLy->GetNextFeature()) != NULL)
{
if ((poFDefn = poLy->GetLayerDefn()) == NULL)
{
cerr << "Error getting a layer defination!" << endl;
continue;
}
 
poGeometry = poFeat->GetGeometryRef();
 
if (poGeometry != NULL && wkbFlatten (poGeometry->getGeometryType()) == wkbPoint)
{
poPoint = (OGRPoint *) poGeometry;
cout << "pointX: " << poPoint->getX() << ", pointY: " << poPoint->getY() << endl;
}
 
for (iField = 0; iField < poFDefn->GetFieldCount(); iField++)
{
poFieldDefn = poFDefn->GetFieldDefn (iField);
 
if (poFieldDefn->GetType() == OFTInteger)
cout << "Layer: " << j << " int: " << poFeat->GetFieldAsInteger (iField) << endl;
else if (poFieldDefn->GetType() == OFTReal)
cout << "Layer: " << j << " float: " << poFeat->GetFieldAsDouble (iField) << endl;
else if (poFieldDefn->GetType() == OFTString)
cout << "Layer: " << j << " string: " << poFeat->GetFieldAsString (iField) << endl;
else
cout << "Layer: " << j << " Unkn.: " << poFeat->GetFieldAsString (iField) << endl;
}
 
cout << "----------------------------" << endl;
}
 
OGRFeature::DestroyFeature (poFeat);
}
 
OGRDataSource::DestroyDataSource(poDS);
}
paint.end();
rd.setDrawArea(*ui_sportwatcherWidgetBase.imgMap);
rd.getMap(posLXY.lat, posLXY.lon, posRXY.lat, posRXY.lon);
pmMap = *ui_sportwatcherWidgetBase.imgMap->pixmap();
paint.begin(&pmMap);
}
}
else
3729,7 → 3670,7
int i, secs, cuType;
int lineHeight, margin_left, margin_right, margin_bottom;
int x1, y1, x2, y2; // Coordinates
bool meter, meterHR, meterElev, meterSpeed;
bool meterHR;
double maxHeight, minHeight, maxSpeed, minSpeed;
int maxHr, minHr, rh, rhHR, rhElev, rhSpeed;
POINT *point;
/sportwatcher/trunk/src/shapewidgetbase.ui
0,0 → 1,161
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>shapeWidgetBase</class>
<widget class="QDialog" name="shapeWidgetBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>190</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>600</width>
<height>100</height>
</size>
</property>
<property name="windowTitle">
<string>Shape file settings</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>hi16-app-sportwatcher.png</normaloff>hi16-app-sportwatcher.png</iconset>
</property>
<property name="toolTip">
<string>Allows to set everything needed for a set of shape files</string>
</property>
<property name="locale">
<locale language="English" country="UnitedStates"/>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Path to shape file set</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KUrlRequester" name="edShapeFileSet">
<property name="toolTip">
<string>This Line contains the path to the directory with the shape files, containing the map.</string>
</property>
<property name="whatsThis">
<string>An input line, containing the path to the shape files.</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Path to Mapnik plugin directory</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="KUrlRequester" name="edPluginPath">
<property name="toolTip">
<string>Path to the directory containing the plugins for Mapnik.</string>
</property>
<property name="whatsThis">
<string>An edit line containing the path to the Mapnik plugin directory.</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Path to Mapnik font directory</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="KUrlRequester" name="edFontPath">
<property name="toolTip">
<string>Contains the path to a font directory with true type fonts used to draw the labels of the map.</string>
</property>
<property name="whatsThis">
<string>Input line containing the path to a font directory.</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Name and path to description file</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="KUrlRequester" name="edXmlFile">
<property name="toolTip">
<string>Contains the file name of a file, describing the contents of the shape file.</string>
</property>
<property name="whatsThis">
<string>Input line containing the name of a file describing the contents of shape files.</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KUrlRequester</class>
<extends>QFrame</extends>
<header>kurlrequester.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>shapeWidgetBase</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>shapeWidgetBase</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>