[Marble-commits] KDE/kdeedu/marble/src/plugins/runner/monav
Dennis Nienhüser
earthwings at gentoo.org
Wed Sep 15 23:56:06 CEST 2010
SVN commit 1175778 by nienhueser:
Update signals.h to revision 263. Adopt interface changes in the runner and generate driving instructions from the new information.
Please update your monav checkout and re-generate any monav maps (file format has changed) if you use it.
M +72 -21 MonavRunner.cpp
M +53 -14 signals.h
--- trunk/KDE/kdeedu/marble/src/plugins/runner/monav/MonavRunner.cpp #1175777:1175778
@@ -14,7 +14,10 @@
#include "MarbleDebug.h"
#include "MarbleDirs.h"
#include "routing/RouteRequest.h"
+#include "routing/instructions/InstructionTransformation.h"
#include "GeoDataDocument.h"
+#include "GeoDataData.h"
+#include "GeoDataExtendedData.h"
#include <QtCore/QProcess>
#include <QtCore/QTime>
@@ -30,9 +33,9 @@
MonavRunnerPrivate();
- GeoDataLineString* retrieveRoute( RouteRequest *route ) const;
+ GeoDataLineString* retrieveRoute( RouteRequest *route, QVector<GeoDataPlacemark*> *instructions ) const;
- GeoDataDocument* createDocument( GeoDataLineString* geometry ) const;
+ GeoDataDocument* createDocument( GeoDataLineString* geometry, const QVector<GeoDataPlacemark*> &instructions ) const;
};
MonavRunnerPrivate::MonavRunnerPrivate() :
@@ -41,7 +44,7 @@
// nothing to do
}
-GeoDataLineString* MonavRunnerPrivate::retrieveRoute( RouteRequest *route ) const
+GeoDataLineString* MonavRunnerPrivate::retrieveRoute( RouteRequest *route, QVector<GeoDataPlacemark*> *instructions ) const
{
GeoDataLineString* geometry = new GeoDataLineString;
@@ -49,11 +52,10 @@
socket.connectToServer( "MoNavD" );
if ( socket.waitForConnected() ) {
RoutingDaemonCommand command;
- QVector<RoutingDaemonCoordinate> waypoints;
+ QVector<RoutingDaemonNode> waypoints;
- for ( int i = 0; i < route->size(); ++i )
- {
- RoutingDaemonCoordinate coordinate;
+ for ( int i = 0; i < route->size(); ++i ) {
+ RoutingDaemonNode coordinate;
coordinate.longitude = route->at( i ).longitude( GeoDataCoordinates::Degree );
coordinate.latitude = route->at( i ).latitude( GeoDataCoordinates::Degree );
waypoints << coordinate;
@@ -62,38 +64,82 @@
command.dataDirectory = m_mapDir.absolutePath();
command.lookupRadius = 1500;
command.waypoints = waypoints;
+ command.lookupStrings = true;
command.post( &socket );
socket.flush();
RoutingDaemonResult reply;
- if ( reply.read( &socket ) )
- {
- switch (reply.type)
- {
- case RoutingDaemonResult::LoadFail:
+ if ( reply.read( &socket ) ) {
+ switch ( reply.type ) {
+ case RoutingDaemonResult::LoadFailed:
mDebug() << "failed to load monav map from " << m_mapDir.absolutePath();
break;
- case RoutingDaemonResult::RouteFail:
+ case RoutingDaemonResult::RouteFailed:
mDebug() << "failed to retrieve route from monav daemon";
break;
+ case RoutingDaemonResult::TypeLookupFailed:
+ mDebug() << "failed to lookup type from monav daemon";
+ break;
+ case RoutingDaemonResult::NameLookupFailed:
+ mDebug() << "failed to lookup name from monav daemon";
+ break;
case RoutingDaemonResult::Success:
/** @todo: make use of reply.seconds, the estimated travel time */
- for ( int i = 0; i < reply.path.size(); i++ ) {
- qreal lon = reply.path[i].longitude;
- qreal lat = reply.path[i].latitude;
+ for ( int i = 0; i < reply.pathNodes.size(); ++i ) {
+ qreal lon = reply.pathNodes[i].longitude;
+ qreal lat = reply.pathNodes[i].latitude;
GeoDataCoordinates coordinates( lon, lat, 0, GeoDataCoordinates::Degree );
geometry->append( coordinates );
}
+
+ RoutingWaypoints waypoints;
+ int k = 0;
+ for ( int i = 0; i < reply.pathEdges.size(); ++i ) {
+ QString road = reply.nameStrings[reply.pathEdges[i].name];
+ QString type = reply.typeStrings[reply.pathEdges[i].type];
+ for ( unsigned int l = 0; l < reply.pathEdges[i].length; ++k, ++l ) {
+ qreal lon = reply.pathNodes[k].longitude;
+ qreal lat = reply.pathNodes[k].latitude;
+ RoutingPoint point( lon, lat );
+ RoutingWaypoint waypoint( point, RoutingWaypoint::Other, "", type, -1, road );
+ waypoints.push_back( waypoint );
+ }
+ }
+
+ RoutingInstructions directions = InstructionTransformation::process( waypoints );
+ for ( int i = 0; i < directions.size(); ++i ) {
+ GeoDataPlacemark* placemark = new GeoDataPlacemark( directions[i].instructionText() );
+ GeoDataExtendedData extendedData;
+ GeoDataData turnType;
+ turnType.setName( "turnType" );
+ turnType.setValue( qVariantFromValue<int>( int( directions[i].turnType() ) ) );
+ extendedData.addValue( turnType );
+ placemark->setExtendedData( extendedData );
+ Q_ASSERT( !directions[i].points().isEmpty() );
+ GeoDataLineString* geometry = new GeoDataLineString;
+ QVector<RoutingWaypoint> items = directions[i].points();
+ for ( int j = 0; j < items.size(); ++j ) {
+ RoutingPoint point = items[j].point();
+ GeoDataCoordinates coordinates( point.lon(), point.lat(), 0.0, GeoDataCoordinates::Degree );
+ geometry->append( coordinates );
+ }
+ placemark->setGeometry( geometry );
+ instructions->push_back( placemark );
+ }
break;
}
+ } else {
+ mDebug() << "Failed to read reply";
}
+ } else {
+ mDebug() << "No connection to MoNavD";
}
return geometry;
}
-GeoDataDocument* MonavRunnerPrivate::createDocument( GeoDataLineString *geometry ) const
+GeoDataDocument* MonavRunnerPrivate::createDocument( GeoDataLineString *geometry, const QVector<GeoDataPlacemark*> &instructions ) const
{
if ( !geometry || geometry->isEmpty() ) {
return 0;
@@ -108,11 +154,15 @@
QString name = "%1 %2 (Monav)";
QString unit = "m";
qreal length = geometry->length( EARTH_RADIUS );
- if ( length >= 1000 )
- {
+ if ( length >= 1000 ) {
length /= 1000.0;
unit = "km";
}
+
+ foreach( GeoDataPlacemark* placemark, instructions ) {
+ result->append( placemark );
+ }
+
result->setName( name.arg( length, 0, 'f', 1 ).arg( unit ) );
return result;
}
@@ -136,8 +186,9 @@
void MonavRunner::retrieveRoute( RouteRequest *route )
{
- GeoDataLineString* waypoints = d->retrieveRoute( route );
- GeoDataDocument* result = d->createDocument( waypoints );
+ QVector<GeoDataPlacemark*> instructions;
+ GeoDataLineString* waypoints = d->retrieveRoute( route, &instructions );
+ GeoDataDocument* result = d->createDocument( waypoints, instructions );
emit routeCalculated( result );
}
--- trunk/KDE/kdeedu/marble/src/plugins/runner/monav/signals.h #1175777:1175778
@@ -25,45 +25,74 @@
#ifndef SIGNALS_H
#define SIGNALS_H
-#include <QtCore/QIODevice>
#include <QtCore/QString>
#include <QtCore/QVector>
#include <QtCore/QDataStream>
-#include <QtCore/QBuffer>
+#include <QtCore/QStringList>
#include <QtNetwork/QLocalSocket>
-struct RoutingDaemonCoordinate {
+struct RoutingDaemonNode {
double latitude;
double longitude;
- friend QDataStream& operator<< ( QDataStream& out, const RoutingDaemonCoordinate& coordinate )
+ friend QDataStream& operator<< ( QDataStream& out, const RoutingDaemonNode& node )
{
- out << coordinate.latitude;
- out << coordinate.longitude;
+ out << node.latitude;
+ out << node.longitude;
return out;
}
- friend QDataStream& operator>> ( QDataStream& in, RoutingDaemonCoordinate& coordinate )
+ friend QDataStream& operator>> ( QDataStream& in, RoutingDaemonNode& node )
{
- in >> coordinate.latitude;
- in >> coordinate.longitude;
+ in >> node.latitude;
+ in >> node.longitude;
return in;
}
};
+struct RoutingDaemonEdge {
+ unsigned length;
+ unsigned name;
+ unsigned type;
+
+ friend QDataStream& operator<< ( QDataStream& out, const RoutingDaemonEdge& edge )
+ {
+ out << edge.length;
+ out << edge.name;
+ out << edge.type;
+ return out;
+ }
+
+ friend QDataStream& operator>> ( QDataStream& in, RoutingDaemonEdge& edge )
+ {
+ in >> edge.length;
+ in >> edge.name;
+ in >> edge.type;
+ return in;
+ }
+};
+
class RoutingDaemonCommand {
public:
+ RoutingDaemonCommand()
+ {
+ lookupRadius = 10000; // 10km should suffice for most applications
+ lookupStrings = false;
+ }
+
double lookupRadius;
+ bool lookupStrings;
QString dataDirectory;
- QVector< RoutingDaemonCoordinate > waypoints;
+ QVector< RoutingDaemonNode > waypoints;
void post( QIODevice* out )
{
QByteArray buffer;
QDataStream stream( &buffer, QIODevice::WriteOnly );
stream << lookupRadius;
+ stream << lookupStrings;
stream << dataDirectory;
stream << waypoints;
qint32 size = buffer.size();
@@ -91,6 +120,7 @@
QByteArray buffer= in->read( size );
QDataStream stream( buffer );
stream >> lookupRadius;
+ stream >> lookupStrings;
stream >> dataDirectory;
stream >> waypoints;
@@ -104,11 +134,14 @@
public:
enum ResultType {
- LoadFail = 1, RouteFail = 2, Success = 3
+ LoadFailed = 1, RouteFailed = 2, NameLookupFailed = 3, TypeLookupFailed = 4, Success = 5
} type;
double seconds;
- QVector< RoutingDaemonCoordinate > path;
+ QVector< RoutingDaemonNode > pathNodes;
+ QVector< RoutingDaemonEdge > pathEdges;
+ QStringList nameStrings;
+ QStringList typeStrings;
void post( QIODevice* out )
{
@@ -116,7 +149,10 @@
QDataStream stream( &buffer, QIODevice::WriteOnly );
stream << qint32( type );
stream << seconds;
- stream << path;
+ stream << pathNodes;
+ stream << pathEdges;
+ stream << nameStrings;
+ stream << typeStrings;
qint32 size = buffer.size();
out->write( ( const char* ) &size, sizeof( qint32 ) );
out->write( buffer.data(), size );
@@ -145,7 +181,10 @@
stream >> temp;
type = ( ResultType ) temp;
stream >> seconds;
- stream >> path;
+ stream >> pathNodes;
+ stream >> pathEdges;
+ stream >> nameStrings;
+ stream >> typeStrings;
return true;
}
More information about the Marble-commits
mailing list