summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortinloaf <tinloaf@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-10-15 19:57:25 +0000
committertinloaf <tinloaf@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-10-15 19:57:25 +0000
commit77d14352045c96fede95afdbd3c23ac57449e443 (patch)
tree0e0b7c380d2172af632547bb2c0a026a43ab5967
parentbf3971336f9b7b9ac95edf97649adb7f79b8a04c (diff)
downloadnavit-77d14352045c96fede95afdbd3c23ac57449e443.tar.gz
Add:Core:Make Navit stop routing when the destination is reached
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@1478 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r--navit/attr_def.h1
-rw-r--r--navit/navit.c5
-rw-r--r--navit/navit.xml2
-rw-r--r--navit/route.c44
-rw-r--r--navit/route.h1
5 files changed, 52 insertions, 1 deletions
diff --git a/navit/attr_def.h b/navit/attr_def.h
index 6129f3ee2..08ac4daf6 100644
--- a/navit/attr_def.h
+++ b/navit/attr_def.h
@@ -70,6 +70,7 @@ ATTR(icon_xs)
ATTR(icon_l)
ATTR(icon_s)
ATTR(spacing)
+ATTR(destination_distance)
ATTR2(0x00028000,type_boolean_begin)
/* boolean */
ATTR(overwrite)
diff --git a/navit/navit.c b/navit/navit.c
index f0b7f282b..d506b3eed 100644
--- a/navit/navit.c
+++ b/navit/navit.c
@@ -1674,6 +1674,11 @@ navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv)
callback_list_call_attr_2(this_->attr_cbl, attr_position_coord_geo, this_, nv->vehicle);
if (pnt)
navit_vehicle_draw(this_, nv, pnt);
+
+ /* Finally, if we reached our destination, stop navigation. */
+ if (route_destination_reached(this_->route)) {
+ navit_set_destination(this_, NULL, NULL);
+ }
}
/**
diff --git a/navit/navit.xml b/navit/navit.xml
index 7fd81bfe4..48ee4f68d 100644
--- a/navit/navit.xml
+++ b/navit/navit.xml
@@ -71,7 +71,7 @@ http://wiki.navit-project.org/index.php/Configuring_NavIt
<tracking>
</tracking>
- <route>
+ <route destination_distance="50">
<speed type="street_0,street_1_city" value="10" />
<speed type="street_2_city" value="30" />
<speed type="street_3_city" value="40" />
diff --git a/navit/route.c b/navit/route.c
index 1a465f38b..df8016bc3 100644
--- a/navit/route.c
+++ b/navit/route.c
@@ -186,6 +186,7 @@ struct route {
struct route_path *path2; /**< Pointer to the route path */
struct map *map;
struct map *graph_map;
+ int destination_distance; /**< Distance to the destination at which the destination is considered "reached" */
int speedlist[route_item_last-route_item_first+1]; /**< The speedlist for this route */
};
@@ -261,10 +262,19 @@ struct route *
route_new(struct attr **attrs)
{
struct route *this=g_new0(struct route, 1);
+ struct attr dest_attr;
+
if (!this) {
printf("%s:Out of memory\n", __FUNCTION__);
return NULL;
}
+
+ if (attr_generic_get_attr(attrs, NULL, attr_destination_distance, &dest_attr, NULL)) {
+ this->destination_distance = dest_attr.u.num;
+ } else {
+ this->destination_distance = 50; // Default value
+ }
+
return this;
}
@@ -394,6 +404,39 @@ route_pos_contains(struct route *this, struct item *item)
}
/**
+ * @brief Checks if a route has reached its destination
+ *
+ * @param this The route to be checked
+ * @return True if the destination is "reached", false otherwise.
+ */
+int
+route_destination_reached(struct route *this)
+{
+ struct street_data *sd = this->pos->street;
+
+ if (!this->path2) {
+ return 0;
+ }
+
+ if (! item_is_equal(this->pos->street->item, this->dst->street->item)) {
+ return 0;
+ }
+
+ if ((sd->flags & AF_ONEWAY) && (this->pos->lenneg >= this->dst->lenneg)) { // We would have to drive against the one-way road
+ return 0;
+ }
+ if ((sd->flags & AF_ONEWAYREV) && (this->pos->lenpos >= this->dst->lenpos)) {
+ return 0;
+ }
+
+ if (transform_distance(projection_mg, &this->pos->c, &this->dst->lp) > this->destination_distance) {
+ return 0;
+ }
+
+ return 1;
+}
+
+/**
* @brief Updates the route graph and the route path if something changed with the route
*
* This will update the route graph and the route path of the route if some of the
@@ -426,6 +469,7 @@ route_path_update(struct route *this)
profile(1,"route_path_new");
profile(0,"end");
}
+
if (oldpath) {
/* Destroy what's left */
route_path_destroy(oldpath);
diff --git a/navit/route.h b/navit/route.h
index 4db9e2359..c020385a1 100644
--- a/navit/route.h
+++ b/navit/route.h
@@ -109,6 +109,7 @@ struct map *route_get_map(struct route *route);
struct map *route_get_graph_map(struct route *route);
void route_toggle_routegraph_display(struct route *route);
void route_set_projection(struct route *this_, enum projection pro);
+int route_destination_reached(struct route *this);
void route_init(void);
/* end of prototypes */