From 001500655fc2612c04848144eda841e1b6fcb307 Mon Sep 17 00:00:00 2001 From: martin-s Date: Mon, 3 Nov 2008 17:32:14 +0000 Subject: [PATCH] Fix:Core:Fixed and cleaned up navigation git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@1630 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/attr.c | 10 ++- navit/attr_def.h | 5 ++ navit/item_def.h | 2 + navit/map.c | 27 +++++-- navit/navigation.c | 203 ++++++++++++++++++---------------------------------- navit/navit.c | 13 +++- 6 files changed, 116 insertions(+), 144 deletions(-) diff --git a/navit/attr.c b/navit/attr.c index eba8a08..53fc5a0 100644 --- a/navit/attr.c +++ b/navit/attr.c @@ -192,8 +192,14 @@ attr_to_text(struct attr *attr, struct map *map, int pretty) } if (type >= attr_type_string_begin && type <= attr_type_string_end) { if (map) { - char *mstr=map_convert_string(map, attr->u.str); - ret=g_strdup(mstr); + char *mstr; + if (attr->u.str) { + mstr=map_convert_string(map, attr->u.str); + ret=g_strdup(mstr); + map_convert_free(mstr); + } else + ret=g_strdup("(null)"); + } else ret=g_strdup(attr->u.str); return ret; diff --git a/navit/attr_def.h b/navit/attr_def.h index 64e8f05..e832e64 100644 --- a/navit/attr_def.h +++ b/navit/attr_def.h @@ -217,3 +217,8 @@ ATTR(resize) ATTR(motion) ATTR(keypress) ATTR2(0x000bffff,type_callback_end) +ATTR2(0x000c0000,type_int64_begin) +ATTR(osm_nodeid) +ATTR(osm_wayid) +ATTR(osm_relationid) +ATTR2(0x000cffff,type_int64_end) diff --git a/navit/item_def.h b/navit/item_def.h index 1833fb6..643516d 100644 --- a/navit/item_def.h +++ b/navit/item_def.h @@ -274,6 +274,8 @@ ITEM(poi_toilets) ITEM(poi_viewpoint) ITEM(poi_ruins) ITEM(nav_none) +ITEM(nav_position) +ITEM(nav_destination) /* Line */ ITEM2(0x80000000,line) ITEM2(0x80000001,line_unspecified) diff --git a/navit/map.c b/navit/map.c index 482665d..d36e0de 100644 --- a/navit/map.c +++ b/navit/map.c @@ -579,7 +579,7 @@ map_priv_is(struct map *map, struct map_priv *priv) } void -map_dump(struct map *map) +map_dump_filedesc(struct map *map, FILE *out) { struct map_rect *mr=map_rect_new(map, NULL); struct item *item; @@ -590,14 +590,29 @@ map_dump(struct map *map) while ((item = map_rect_get_item(mr))) { count=item_coord_get(item, ca, item->type < type_line ? 1: max); if (item->type < type_line) - printf("mg:0x%x 0x%x ", ca[0].x, ca[0].y); - printf("%s", item_to_name(item->type)); + fprintf(out,"mg:0x%x 0x%x ", ca[0].x, ca[0].y); + fprintf(out,"%s", item_to_name(item->type)); while (item_attr_get(item, attr_any, &attr)) - printf(" %s='%s'", attr_to_name(attr.type), attr_to_text(&attr, map, 1)); - printf("\n"); + fprintf(out," %s='%s'", attr_to_name(attr.type), attr_to_text(&attr, map, 1)); + fprintf(out,"\n"); if (item->type >= type_line) for (i = 0 ; i < count ; i++) - printf("mg:0x%x 0x%x\n", ca[i].x, ca[i].y); + fprintf(out,"mg:0x%x 0x%x\n", ca[i].x, ca[i].y); } map_rect_destroy(mr); } + +void +map_dump_file(struct map *map, char *file) +{ + FILE *f; + f=fopen(file,"w"); + map_dump_filedesc(map, f); + fclose(f); +} + +void +map_dump(struct map *map) +{ + map_dump_filedesc(map, stdout); +} diff --git a/navit/navigation.c b/navit/navigation.c index 82fb307..076f6cf 100644 --- a/navit/navigation.c +++ b/navit/navigation.c @@ -133,7 +133,7 @@ struct navigation_itm { int straight; int angle_start; int angle_end; - struct coord c; + struct coord start,end; int time; int length; int dest_time; @@ -317,9 +317,13 @@ navigation_itm_new(struct navigation *this_, struct item *ritem) ret->angle_start=road_angle(&c[0], &c[1], 0); ret->angle_end=road_angle(&c[i-1], &c[i], 0); - ret->c=c[0]; + ret->start=c[0]; + ret->end=c[i]; dbg(1,"i=%d start %d end %d '%s' '%s'\n", i, ret->angle_start, ret->angle_end, ret->name1, ret->name2); map_rect_destroy(mr); + } else { + if (this_->last) + ret->start=ret->end=this_->last->end; } if (! this_->first) this_->first=ret; @@ -758,7 +762,7 @@ navigation_update(struct navigation *this_, struct route *route) struct item *sitem; /* Holds the corresponding item from the actual map */ struct attr street_item,street_direction; struct navigation_itm *itm; - int incr=0; + int incr=0,first=1; if (! route) return; @@ -769,39 +773,32 @@ navigation_update(struct navigation *this_, struct route *route) if (! mr) return; dbg(1,"enter\n"); - ritem=map_rect_get_item(mr); - if (ritem) { - if (!item_attr_get(ritem, attr_street_item, &street_item)) { - ritem=map_rect_get_item(mr); - if (! ritem) { - return; + while ((ritem=map_rect_get_item(mr))) { + if (first && item_attr_get(ritem, attr_street_item, &street_item)) { + first=0; + if (!item_attr_get(ritem, attr_direction, &street_direction)) + street_direction.u.num=0; + sitem=street_item.u.item; + dbg(1,"sitem=%p\n", sitem); + itm=item_hash_lookup(this_->hash, sitem); + dbg(2,"itm for item with id (0x%x,0x%x) is %p\n", sitem->id_hi, sitem->id_lo, itm); + if (itm && itm->direction != street_direction.u.num) { + dbg(2,"wrong direction\n"); + itm=NULL; + } + if (itm) { + navigation_itm_update(itm, ritem); + break; } - if (!item_attr_get(ritem, attr_street_item, &street_item)) { - dbg(0,"no street item\n"); - } - } - if (!item_attr_get(ritem, attr_direction, &street_direction)) - street_direction.u.num=0; - sitem=street_item.u.item; - dbg(1,"sitem=%p\n", sitem); - itm=item_hash_lookup(this_->hash, sitem); - dbg(2,"itm for item with id (0x%x,0x%x) is %p\n", sitem->id_hi, sitem->id_lo, itm); - if (itm && itm->direction != street_direction.u.num) { - dbg(2,"wrong direction\n"); - itm=NULL; - } - navigation_destroy_itms_cmds(this_, itm); - if (itm) { - incr=1; - navigation_itm_update(itm, ritem); - } else { dbg(1,"not on track\n"); - do { - dbg(1,"item\n"); - navigation_itm_new(this_, ritem); - ritem=map_rect_get_item(mr); - } while (ritem); - itm=navigation_itm_new(this_, NULL); + } + navigation_itm_new(this_, ritem); + } + if (first) + navigation_destroy_itms_cmds(this_, NULL); + else { + if (! ritem) { + navigation_itm_new(this_, NULL); make_maneuvers(this_); } calculate_dest_distance(this_, incr); @@ -818,79 +815,8 @@ navigation_update(struct navigation *this_, struct route *route) this_->distance_last=this_->first->dest_length; profile(0,"end"); navigation_call_callbacks(this_, FALSE); - } else - navigation_destroy_itms_cmds(this_, NULL); - map_rect_destroy(mr); - -#if 0 - struct route_path_handle *rph; - struct route_path_segment *s; - struct navigation_itm *itm; - struct route_info *pos,*dst; - struct street_data *sd; - int *speedlist; - int len,end_flag=0; - int incr; - - profile(0,NULL); - pos=route_get_pos(route); - dst=route_get_dst(route); - if (! pos || ! dst) - return; - speedlist=route_get_speedlist(route); - len=route_info_length(pos, dst, 0); - dbg(2,"len pos,dst = %d\n", len); - if (len == -1) { - len=route_info_length(pos, NULL, 0); - dbg(2,"len pos = %d\n", len); - end_flag=1; - } - sd=route_info_street(pos); - itm=item_hash_lookup(this_->hash, &sd->item); - dbg(2,"itm for item with id (0x%x,0x%x) is %p\n", sd->item.id_hi, sd->item.id_lo, itm); - navigation_destroy_itms_cmds(this_, itm); - if (itm) - incr=1; - else { - itm=navigation_itm_new(this_, &sd->item, route_info_point(pos, -1)); - incr=0; - } - itm->length=len; - itm->time=route_time(speedlist, &sd->item, len); - dbg(2,"%p time = %d\n", itm, itm->time); - if (!incr) { - printf("not on track\n"); - rph=route_path_open(route); - if (rph) { - while((s=route_path_get_segment(rph))) { - itm=navigation_itm_new(this_, route_path_segment_get_item(s),route_path_segment_get_start(s)); - itm->time=route_path_segment_get_time(s); - itm->length=route_path_segment_get_length(s); - } - route_path_close(rph); - } - if (end_flag) { - len=route_info_length(NULL, dst, 0); - dbg(1, "end %d\n", len); - sd=route_info_street(dst); - itm=navigation_itm_new(this_, &sd->item, route_info_point(pos, 2)); - itm->length=len; - itm->time=route_time(speedlist, &sd->item, len); - } - itm=navigation_itm_new(this_, NULL, NULL); - make_maneuvers(this_); } - calculate_dest_distance(this_, incr); - dbg(2,"destination distance old=%d new=%d\n", this_->distance_last, this_->first->dest_length); - if (this_->first->dest_length > this_->distance_last && this_->distance_last >= 0) - this_->turn_around=1; - else - this_->turn_around=0; - dbg(2,"turn_around=%d\n", this_->turn_around); - this_->distance_last=this_->first->dest_length; - profile(0,"end"); - navigation_call_callbacks(this_, FALSE); -#endif + map_rect_destroy(mr); } void @@ -968,7 +894,7 @@ navigation_map_item_coord_get(void *priv_data, struct coord *c, int count) struct map_rect_priv *this=priv_data; if (this->ccount || ! count) return 0; - *c=this->itm->c; + *c=this->itm->start; this->ccount=1; return 1; } @@ -1045,11 +971,13 @@ navigation_map_item_attr_get(void *priv_data, enum attr_type attr_type, struct a case attr_street_name: attr->u.str=itm->name1; this_->attr_next=attr_street_name_systematic; - return 1; + if (attr->u.str) + return 1; case attr_street_name_systematic: attr->u.str=itm->name2; this_->attr_next=attr_debug; - return 1; + if (attr->u.str) + return 1; case attr_debug: switch(this_->debug_idx) { case 0: @@ -1080,8 +1008,10 @@ navigation_map_item_attr_get(void *priv_data, enum attr_type attr_type, struct a } case 5: this_->debug_idx++; - this_->str=attr->u.str=g_strdup_printf("prev angle:%d - %d", prev->angle_start, prev->angle_end); - return 1; + if (prev) { + this_->str=attr->u.str=g_strdup_printf("prev angle:%d - %d", prev->angle_start, prev->angle_end); + return 1; + } case 6: this_->debug_idx++; if (prev) { @@ -1153,36 +1083,43 @@ navigation_map_get_item(struct map_rect_priv *priv) priv->itm=priv->itm_next; priv->cmd=priv->cmd_next; priv->cmd_itm=priv->cmd_itm_next; - if (!priv->show_all) { + if (!priv->show_all && priv->itm->prev != NULL) { if (!priv->cmd) return NULL; priv->itm=priv->cmd->itm; } priv->itm_next=priv->itm->next; - ret->type=type_nav_none; + if (priv->itm->prev) + ret->type=type_nav_none; + else + ret->type=type_nav_position; if (priv->cmd->itm == priv->itm) { priv->cmd_itm_next=priv->cmd->itm; priv->cmd_next=priv->cmd->next; - delta=priv->cmd->delta; - if (delta < 0) { - delta=-delta; - if (delta < 45) - ret->type=type_nav_left_1; - else if (delta < 105) - ret->type=type_nav_left_2; - else if (delta < 165) - ret->type=type_nav_left_3; - else - ret->type=type_none; - } else { - if (delta < 45) - ret->type=type_nav_right_1; - else if (delta < 105) - ret->type=type_nav_right_2; - else if (delta < 165) - ret->type=type_nav_right_3; - else - ret->type=type_none; + if (priv->cmd_itm_next && !priv->cmd_itm_next->next) + ret->type=type_nav_destination; + else { + delta=priv->cmd->delta; + if (delta < 0) { + delta=-delta; + if (delta < 45) + ret->type=type_nav_left_1; + else if (delta < 105) + ret->type=type_nav_left_2; + else if (delta < 165) + ret->type=type_nav_left_3; + else + ret->type=type_none; + } else { + if (delta < 45) + ret->type=type_nav_right_1; + else if (delta < 105) + ret->type=type_nav_right_2; + else if (delta < 165) + ret->type=type_nav_right_3; + else + ret->type=type_none; + } } } priv->ccount=0; diff --git a/navit/navit.c b/navit/navit.c index de75062..a03ee7c 100644 --- a/navit/navit.c +++ b/navit/navit.c @@ -968,10 +968,13 @@ navit_window_roadbook_update(struct navit *this_) while ((item=map_rect_get_item(mr))) { dbg(0,"item=%p\n", item); attr.u.str=NULL; - item_attr_get(item, attr_navigation_long, &attr); - dbg(2, "Command='%s'\n", attr.u.str); + if (item->type != type_nav_position) { + item_attr_get(item, attr_navigation_long, &attr); + dbg(2, "Command='%s'\n", attr.u.str); + param[0].value=g_strdup(attr.u.str); + } else + param[0].value=_("Position"); param[0].name=_("Command"); - param[0].value=g_strdup(attr.u.str); item_attr_get(item, attr_length, &attr); dbg(2, "Length=%d\n", attr.u.num); @@ -1741,6 +1744,10 @@ navit_set_position(struct navit *this_, struct pcoord *c) callback_list_call_attr_0(this_->attr_cbl, attr_position); if (this_->navigation) { navigation_update(this_->navigation, this_->route); +#if 0 + map_dump_file(route_get_map(this_->route), "route.txt"); + map_dump_file(navigation_get_map(this_->navigation), "navigation.txt"); +#endif } } navit_draw(this_); -- 1.7.9.5