Add:Core:Make Navit stop routing when the destination is reached
authortinloaf <tinloaf@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 15 Oct 2008 19:57:25 +0000 (19:57 +0000)
committertinloaf <tinloaf@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 15 Oct 2008 19:57:25 +0000 (19:57 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@1478 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/attr_def.h
navit/navit.c
navit/navit.xml
navit/route.c
navit/route.h

index 6129f3e..08ac4da 100644 (file)
@@ -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)
index f0b7f28..d506b3e 100644 (file)
@@ -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);
+       }
 }
 
 /**
index 7fd81bf..48ee4f6 100644 (file)
@@ -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" />
index 1a465f3..df8016b 100644 (file)
@@ -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);
index 4db9e23..c020385 100644 (file)
@@ -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 */