Subversion Repositories public

Compare Revisions

Ignore whitespace Rev 277 → Rev 278

/sportwatcher/trunk/src/shapewidget.cpp
71,6 → 71,9
edFontPath->setUrl(sh.readEntry("FontPath", QString("")));
#endif
edXmlFile->setUrl(sh.readEntry("XmlFile", basePath + "/shapefiles/osm.xml"));
bool geo = sh.readEntry("Geographic", false);
rbForward->setChecked(geo);
rbInverse->setChecked(!geo);
}
 
shapeWidget::~shapeWidget()
108,9 → 111,28
sh.writeEntry("PluginPath", edPluginPath->lineEdit()->text());
sh.writeEntry("FontPath", edFontPath->lineEdit()->text());
sh.writeEntry("XmlFile", edXmlFile->lineEdit()->text());
sh.writeEntry("Geographic", rbForward->isChecked());
cfg.sync();
done(QDialog::Accepted);
}
 
void shapeWidget::slotForwarded(bool stat)
{
if (!stat)
{
rbForward->setChecked(true);
rbInverse->setChecked(false);
}
}
 
void shapeWidget::slotInversed(bool stat)
{
if (!stat)
{
rbForward->setChecked(false);
rbInverse->setChecked(true);
}
}
 
#include "shapewidget.moc"
 
/sportwatcher/trunk/src/render.cpp
187,6 → 187,7
fontPath = sh.readEntry("FontPath", QString(""));
#endif
XmlPath = sh.readEntry("XmlFile", basePath + "/shapefiles/osm.xml");
geographic = sh.readEntry("Geographic", false);
}
 
SRender::~SRender()
193,9 → 194,6
{
startDocument(); // Clean everything
ControlSet = false;
 
if (!OutBuf.isEmpty())
unlink (OutBuf.toAscii().data());
}
 
bool SRender::startDocument()
347,11 → 345,8
 
if ((index = att.index(QString("bgcolor"))) != -1)
{
color col;
 
MapPars.bgcolor = colorToUInt(att.value(index));
col.set_bgr(MapPars.bgcolor);
m.set_background(col);
m.set_background(setColor(MapPars.bgcolor));
}
 
if ((index = att.index(QString("buffer_size"))) != -1)
1044,11 → 1039,8
}
 
stroke st;
color col;
col.set_bgr(LineSymbolizer->stroke);
st.set_color (setColor(LineSymbolizer->stroke));
 
st.set_color (col);
 
if (LineSymbolizer->stroke_width != 0.0)
st.set_width (LineSymbolizer->stroke_width);
 
1097,11 → 1089,8
return false;
}
 
color col;
col.set_bgr(PolygonSymbolizer->fill);
polygon_symbolizer ps(setColor(PolygonSymbolizer->fill));
 
polygon_symbolizer ps(col);
 
if (PolygonSymbolizer->fill_opacity > 0.0)
ps.set_opacity(PolygonSymbolizer->fill_opacity);
 
1117,14 → 1106,11
return false;
}
 
color col;
col.set_bgr(TextSymbolizer->fill);
 
if (TextSymbolizer->name.length() <= 0 || TextSymbolizer->face_name.length() <= 0 || TextSymbolizer->size <= 0)
cerr << "Error parsing " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Empty TEXTSYMBOLIZER found --> ignoring!" << endl;
else
{
text_symbolizer ts(TextSymbolizer->name.toAscii().data(), TextSymbolizer->face_name.toAscii().data(), TextSymbolizer->size, col);
text_symbolizer ts(TextSymbolizer->name.toAscii().data(), TextSymbolizer->face_name.toAscii().data(), TextSymbolizer->size, setColor(TextSymbolizer->fill));
 
if (TextSymbolizer->halo_radius != 0.0)
ts.set_halo_radius((unsigned int)TextSymbolizer->halo_radius);
1193,11 → 1179,9
return false;
}
 
color col;
col.set_bgr(ShieldSymbolizer->fill);
shield_symbolizer ss(ShieldSymbolizer->name.toAscii().data(),
ShieldSymbolizer->face_name.toAscii().data(),
ShieldSymbolizer->size, col,
ShieldSymbolizer->size, setColor(ShieldSymbolizer->fill),
findIcon(ShieldSymbolizer->file).toAscii().data(),
getTypeText(ShieldSymbolizer->type),
ShieldSymbolizer->width, ShieldSymbolizer->height);
1497,9 → 1481,9
QXmlSimpleReader reader;
QString hv0;
QFile file(XmlPath);
QDir dir(fontPath);
double plx, ply, prx, pry;
 
OutBuf.clear();
hv0 = pluginPath;
 
if (hv0.right(1) != QString("/"))
1511,15 → 1495,36
if (hv0.right(1) != QString("/"))
hv0 += "/";
 
hv0 += "DejaVuSans.ttf";
freetype_engine::register_font(hv0.toAscii().data());
// Load all fonts in directory
if (!dir.exists())
{
KMessageBox::error(0, i18n("The font directory does not exist! Please select a valid directory with at least one true type font in it!"));
return false;
}
 
QStringList filters;
filters << "*.ttf";
dir.setNameFilters(filters);
dir.setFilter(QDir::Readable | QDir::Files);
QFileInfoList list = dir.entryInfoList();
 
for (int i = 0; i < list.size(); ++i)
{
QString f;
 
QFileInfo fileInfo = list.at(i);
f = hv0 + fileInfo.fileName();
freetype_engine::register_font(f.toAscii().data());
}
 
// hv0 += "DejaVuSans.ttf"; // Default font
// freetype_engine::register_font(hv0.toAscii().data());
 
width = label->width();
height = label->height();
 
m.setWidth(width);
m.setHeight(height);
// load_map(m, XmlPath.toAscii().data());
 
try
{
1530,8 → 1535,6
reader.parse (source);
}
 
save_map(m, "/home/andreas/.sportwatcher/spw.xml");
// save_map(m, "/home/andreas/.sportwatcher/spw1.xml");
plx = lx;
ply = ly;
prx = rx;
1538,43 → 1541,22
pry = ry;
projection pj(m.srs());
 
if (pj.is_geographic())
if (!geographic && pj.is_geographic())
{
pj.inverse(plx, ply);
pj.inverse(prx, pry);
cout << "Geographic! Inverse projection." << endl;
}
else
 
if (geographic && pj.is_geographic())
{
// pj.forward(plx, ply);
// pj.forward(prx, pry);
cout << "NOT geographic!" << endl;
pj.forward(plx, ply);
pj.forward(prx, pry);
}
 
for (unsigned i = 0; i < m.layerCount(); i++)
{
bool vis = m.getLayer(i).isVisible(m.scale_denominator());
// bool vis = m.getLayer(i).isVisible(m.scale());
cout << "Layer " << i << ": " << m.getLayer(i).name();
cout << ", Visible: " << vis;
cout << ", Active: " << m.getLayer(i).isActive();
Envelope <double>e(m.getLayer(i).envelope());
cout << ", Extent: " << e.minx() << ", " << e.miny() << ", " << e.maxx() << ", " << e.maxy() << endl;
}
 
// First we use Mapnik to create the map
m.zoomToBox(Envelope<double>(plx, ply, prx, pry));
 
Envelope <double>e(m.getCurrentExtent());
cout << std::setprecision(16) << "Parameter envelope: " << lx << ", " << ly << ", " << rx << ", " << ry << endl;
cout << std::setprecision(16) << "Converted envelope: " << plx << ", " << ply << ", " << prx << ", " << pry << endl;
cout << std::setprecision(16) << "Current extent: " << e.minx() << ", " << e.miny() << ", " << e.maxx() << ", " << e.maxy() << endl;
Envelope <double>x(m.get_buffered_extent());
cout << std::setprecision(16) << "Current buf.extent: " << x.minx() << ", " << x.miny() << ", " << x.maxx() << ", " << x.maxy() << endl;
cout << "SRS: " << m.srs() << endl;
cout << std::setprecision(16) << "Scale: " << m.scale() << ", scale denominator: " << m.scale_denominator() << endl;
cout << "width=" << m.getWidth() << ", height=" << m.getHeight() << endl;
 
// Here we render the map to an image buffer
Image32 buf(m.getWidth(), m.getHeight());
agg_renderer<Image32> ren(m, buf);
ren.apply();
1582,10 → 1564,6
// Put the image into a Qt object
QImage image((uchar*)buf.raw_data(), m.getWidth(), m.getHeight(), QImage::Format_ARGB32);
label->setPixmap(QPixmap::fromImage(image.rgbSwapped()));
// Create a unique file name
// pid = getpid();
// OutBuf.sprintf("/var/tmp/SportWatcher_%d.png", pid);
// save_to_file<ImageData32>(buf.data(), OutBuf.toAscii().data(), "png");
}
 
catch (const mapnik::config_error &ex)
1653,6 → 1631,23
return ptf;
}
 
color SRender::setColor(unsigned col)
{
color c;
#if MAPNIK_VERSION == 600
c.set_bgr(col);
#else
int r, g, b;
b = col / 65536;
g = (col - (b * 65536)) / 256;
r = col - ((b* 65536) + (g * 256));
c.set_red(r);
c.set_green(g);
c.set_blue(b);
#endif
return c;
}
 
RULE *SRender::getLastRule(RULE *first)
{
RULE *akt = first;
/sportwatcher/trunk/src/shapewidget.h
38,6 → 38,8
public slots:
/*$PUBLIC_SLOTS$*/
virtual void accept();
virtual void slotForwarded(bool);
virtual void slotInversed(bool);
 
private:
maptype __maptype;
/sportwatcher/trunk/src/render.h
22,6 → 22,7
#include <mapnik/config_error.hpp>
#include <mapnik/load_map.hpp>
#include <mapnik/save_map.hpp>
#include <mapnik/version.hpp>
 
/* conversions */
 
262,7 → 263,6
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);
QString getOutBuf () { return OutBuf; };
inline void setMapType(map_type mt) { __map_type = mt; }
inline map_type getMapType() { return __map_type; }
 
282,6 → 282,7
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);
309,7 → 310,7
QString pluginPath;
QString fontPath;
QString XmlPath;
QString OutBuf;
bool geographic;
map_type __map_type;
CONTAINER Container;
bool ControlSet;
/sportwatcher/trunk/src/shapewidgetbase.ui
7,7 → 7,7
<x>0</x>
<y>0</y>
<width>600</width>
<height>190</height>
<height>214</height>
</rect>
</property>
<property name="sizePolicy">
43,7 → 43,7
</property>
</widget>
</item>
<item row="0" column="1">
<item row="0" column="1" colspan="3">
<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>
60,7 → 60,7
</property>
</widget>
</item>
<item row="1" column="1">
<item row="1" column="1" colspan="3">
<widget class="KUrlRequester" name="edPluginPath">
<property name="toolTip">
<string>Path to the directory containing the plugins for Mapnik.</string>
77,7 → 77,7
</property>
</widget>
</item>
<item row="2" column="1">
<item row="2" column="1" colspan="3">
<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>
94,7 → 94,7
</property>
</widget>
</item>
<item row="3" column="1">
<item row="3" column="1" colspan="3">
<widget class="KUrlRequester" name="edXmlFile">
<property name="toolTip">
<string>Contains the file name of a file, describing the contents of the shape file.</string>
104,7 → 104,40
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>If map file is projected:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QRadioButton" name="rbForward">
<property name="toolTip">
<string>Forward if mapfile is projected.</string>
</property>
<property name="whatsThis">
<string>Makes a forward projection if the mapfile is projected.</string>
</property>
<property name="text">
<string>Forwarded</string>
</property>
</widget>
</item>
<item row="4" column="3">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>206</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="0" colspan="4">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
114,6 → 147,22
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QRadioButton" name="rbInverse">
<property name="toolTip">
<string>Inverse if map file is geographic.</string>
</property>
<property name="statusTip">
<string/>
</property>
<property name="whatsThis">
<string>Makes an inverse projection if the map file is geographic.</string>
</property>
<property name="text">
<string>Inversed</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
132,12 → 181,12
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
<x>257</x>
<y>204</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
<y>213</y>
</hint>
</hints>
</connection>
148,14 → 197,50
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
<x>325</x>
<y>204</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
<y>213</y>
</hint>
</hints>
</connection>
<connection>
<sender>rbForward</sender>
<signal>clicked(bool)</signal>
<receiver>shapeWidgetBase</receiver>
<slot>slotForwarded(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>232</x>
<y>151</y>
</hint>
<hint type="destinationlabel">
<x>155</x>
<y>165</y>
</hint>
</hints>
</connection>
<connection>
<sender>rbInverse</sender>
<signal>clicked(bool)</signal>
<receiver>shapeWidgetBase</receiver>
<slot>slotInversed(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>348</x>
<y>150</y>
</hint>
<hint type="destinationlabel">
<x>405</x>
<y>152</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>slotForwarded(bool)</slot>
<slot>slotInversed(bool)</slot>
</slots>
</ui>