FIX:core: routegraph map - copy paste error cousing endless loop from popup
authorzaxl <zaxl@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 21 Oct 2008 19:14:54 +0000 (19:14 +0000)
committerzaxl <zaxl@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 21 Oct 2008 19:14:54 +0000 (19:14 +0000)
FIX:core: work with projections different than mg
FIX:core: rename item_coord_is_segment to is_node, since a single
coordinate can not form a segment, it's just a node
FIX:garmin: report correctly segments so coordinates routing is working,
may be need to add align in some places and fix drawing of segments
in some cases.

git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@1524 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/data/garmin/garmin.c
navit/navit/item.c
navit/navit/item.h
navit/navit/route.c

index f2e75a0..065a961 100644 (file)
@@ -294,14 +294,14 @@ point_coord_get(void *priv_data, struct coord *c, int count)
 }
 
 static int
-coord_is_segment(void *priv_data)
+coord_is_node(void *priv_data)
 {
        struct gobject *g = priv_data;
        struct map_rect_priv *mr = g->priv_data;
 
        if (mr->last_coord == 0)
-               return 0;
-       return gar_is_object_dcoord_node(mr->gmap, g, mr->last_coord - 1);
+               return 1;
+       return gar_is_object_dcoord_node(mr->gmap, g, mr->last_coord);
 }
 
 static int 
@@ -401,7 +401,7 @@ point_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
                attr->type = attr_town_name;
                return garmin_object_label(g, attr);
        case attr_street_name:
-               attr->type = attr_street_name;
+               attr->type = attr_type;
                return garmin_object_label(g, attr);
        case attr_flags:
                attr->type = attr_flags;
@@ -431,7 +431,7 @@ static struct item_methods methods_garmin_poly = {
        poly_coord_get,
        attr_rewind,    // point_attr_rewind,
        point_attr_get, // poly_attr_get,
-       coord_is_segment,
+       coord_is_node,
 };
 
 static int
index c6de4ba..e0c3e31 100644 (file)
@@ -62,10 +62,10 @@ item_coord_get_pro(struct item *it, struct coord *c, int count, enum projection
 }
 
 int 
-item_coord_is_segment(struct item *it)
+item_coord_is_node(struct item *it)
 {
-       if (it->meth->item_coord_is_segment)
-               return it->meth->item_coord_is_segment(it->priv_data);
+       if (it->meth->item_coord_is_node)
+               return it->meth->item_coord_is_node(it->priv_data);
        return 0;
 }
 
index a6db888..460f119 100644 (file)
@@ -54,7 +54,7 @@ struct item_methods {
        int (*item_coord_get)(void *priv_data, struct coord *c, int count);
        void (*item_attr_rewind)(void *priv_data);
        int (*item_attr_get)(void *priv_data, enum attr_type attr_type, struct attr *attr);
-       int (*item_coord_is_segment)(void *priv_data);
+       int (*item_coord_is_node)(void *priv_data);
 };
 
 struct item {
@@ -62,7 +62,7 @@ struct item {
        int id_hi;
        int id_lo;
        struct map *map;
-       struct item_methods *meth;      
+       struct item_methods *meth;
        void *priv_data;
 };
 
@@ -76,8 +76,8 @@ struct item_hash;
 void item_coord_rewind(struct item *it);
 int item_coord_get(struct item *it, struct coord *c, int count);
 int item_coord_get_pro(struct item *it, struct coord *c, int count, enum projection pro);
-/* does the next returned coordinate mark a segment */
-int item_coord_is_segment(struct item *it);
+/* does the next returned coordinate mark a node */
+int item_coord_is_node(struct item *it);
 void item_attr_rewind(struct item *it);
 int item_attr_get(struct item *it, enum attr_type attr_type, struct attr *attr);
 struct item *item_new(char *type, int zoom);
index 3b9d8c4..d7d506a 100644 (file)
@@ -412,18 +412,18 @@ route_pos_contains(struct route *this, struct item *item)
 int
 route_destination_reached(struct route *this)
 {
-       struct street_data *sd = NULL;
+       struct street_data *sd = NULL;
 
-       if(! this->pos)
-         return 0;
-       
-       sd = this->pos->street;
+       if (!this->pos)
+               return 0;
+
+       sd = this->pos->street;
 
        if (!this->path2) {
                return 0;
        }
 
-       if (! item_is_equal(this->pos->street->item, this->dst->street->item)) { 
+       if (!item_is_equal(this->pos->street->item, this->dst->street->item)) { 
                return 0;
        }
 
@@ -434,7 +434,7 @@ route_destination_reached(struct route *this)
                return 0;
        }
         
-       if (transform_distance(projection_mg, &this->pos->c, &this->dst->lp) > this->destination_distance) {
+       if (transform_distance(route_projection(this), &this->pos->c, &this->dst->lp) > this->destination_distance) {
                return 0;
        }
        
@@ -781,12 +781,17 @@ route_graph_add_segment(struct route_graph *this, struct route_graph_point *star
                        int flags, int offset)
 {
        struct route_graph_segment *s;
+/*     
+       FIXME: commented out becouse
+       it is possible to have one item with two different
+       offsets as segments 
        s=start->start;
        while (s) {
                if (item_is_equal(*item, s->item)) 
                        return;
                s=s->start_next;
-       }
+       } 
+*/
        s = g_new0(struct route_graph_segment, 1);
        if (!s) {
                printf("%s:Out of memory\n", __FUNCTION__);
@@ -1127,7 +1132,7 @@ route_process_street_graph(struct route_graph *this, struct item *item)
                        int isseg,rc;
                        int sc = 0;
                        do {
-                               isseg = item_coord_is_segment(item);
+                               isseg = item_coord_is_node(item);
                                rc = item_coord_get(item, &c, 1);
                                if (rc) {
                                        len+=transform_distance(map_projection(item->map), &l, &c);
@@ -1918,7 +1923,11 @@ rm_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
                        else
                                return 0;
                        return 1;
+               case attr_label:
+                       mr->attr_next=attr_none;
+                       return 0;
                default:
+                       mr->attr_next=attr_none;
                        attr->type=attr_none;
                        return 0;
        }
@@ -1931,6 +1940,9 @@ rm_coord_get(void *priv_data, struct coord *c, int count)
        struct map_rect_priv *mr = priv_data;
        struct route_path_segment *seg = mr->seg;
        int i,rc=0;
+       struct route *r = mr->mpriv->route;
+       enum projection pro = route_projection(r);
+
        if (! seg)
                return 0;
        for (i=0; i < count; i++) {
@@ -1938,7 +1950,11 @@ rm_coord_get(void *priv_data, struct coord *c, int count)
                        break;
                if (i >= seg->ncoords)
                        break;
-               c[i] = seg->c[mr->last_coord++];
+               if (pro != projection_mg)
+                       transform_from_to(&seg->c[mr->last_coord++], pro,
+                               &c[i],projection_mg);
+               else
+                       c[i] = seg->c[mr->last_coord++];
                rc++;
        }
        dbg(1,"return %d\n",rc);
@@ -1969,9 +1985,10 @@ rp_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
        switch (attr_type) {
        case attr_any:
                while (mr->attr_next != attr_none) {
-                       if (rm_attr_get(priv_data, mr->attr_next, attr))
+                       if (rp_attr_get(priv_data, mr->attr_next, attr))
                                return 1;
                }
+               return 0;
        case attr_label:
                attr->type = attr_label;
                if (mr->str)
@@ -1992,6 +2009,8 @@ rp_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
                mr->attr_next=attr_none;
                return 1;
        default:
+               mr->attr_next=attr_none;
+               attr->type=attr_none;
                return 0;
        }
 }
@@ -2003,11 +2022,18 @@ rp_coord_get(void *priv_data, struct coord *c, int count)
        struct route_graph_point *p = mr->point;
        struct route_graph_segment *seg = mr->rseg;
        int rc = 0,i,dir;
+       struct route *r = mr->mpriv->route;
+       enum projection pro = route_projection(r);
+
        for (i=0; i < count; i++) {
                if (mr->item.type == type_rg_point) {
                        if (mr->last_coord >= 1)
                                break;
-                       c[i] = p->c;
+                       if (pro != projection_mg)
+                               transform_from_to(&p->c, pro,
+                                       &c[i],projection_mg);
+                       else
+                               c[i] = p->c;
                } else {
                        if (mr->last_coord >= 2)
                                break;
@@ -2016,10 +2042,19 @@ rp_coord_get(void *priv_data, struct coord *c, int count)
                                dir=1;
                        if (mr->last_coord)
                                dir=1-dir;
-                       if (dir)
-                               c[i] = seg->end->c;
-                       else
-                               c[i] = seg->start->c;
+                       if (dir) {
+                               if (pro != projection_mg)
+                                       transform_from_to(&seg->end->c, pro,
+                                               &c[i],projection_mg);
+                               else
+                                       c[i] = seg->end->c;
+                       } else {
+                               if (pro != projection_mg)
+                                       transform_from_to(&seg->start->c, pro,
+                                               &c[i],projection_mg);
+                               else
+                                       c[i] = seg->start->c;
+                       }
                }
                mr->last_coord++;
                rc++;
@@ -2157,7 +2192,7 @@ rm_get_item_byid(struct map_rect_priv *mr, int id_hi, int id_lo)
 
 static struct map_methods route_meth = {
        projection_mg,
-       NULL,
+       "utf-8",
        rm_destroy,
        rm_rect_new,
        rm_rect_destroy,
@@ -2170,7 +2205,7 @@ static struct map_methods route_meth = {
 
 static struct map_methods route_graph_meth = {
        projection_mg,
-       NULL,
+       "utf-8",
        rm_destroy,
        rp_rect_new,
        rm_rect_destroy,