From 9ac586eb371ed0da43726254ff081eb0bbf4f7dc Mon Sep 17 00:00:00 2001 From: martin-s Date: Wed, 26 Dec 2007 10:39:48 +0000 Subject: [PATCH] Add:Core:Support for position_coord_geo parsing git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@670 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- src/attr.c | 12 ++++++++++++ src/log.c | 2 +- src/navigation.c | 4 ++-- src/popup.c | 16 ++++++++++------ src/route.c | 2 +- src/vehicle/demo/vehicle_demo.c | 32 +++++++++++++++++--------------- 6 files changed, 43 insertions(+), 25 deletions(-) diff --git a/src/attr.c b/src/attr.c index 8feecd7..0516327 100644 --- a/src/attr.c +++ b/src/attr.c @@ -4,6 +4,8 @@ #include #include "debug.h" #include "item.h" +#include "coord.h" +#include "transform.h" #include "color.h" #include "attr.h" @@ -50,6 +52,8 @@ attr_new_from_text(const char *name, const char *value) { enum attr_type attr; struct attr *ret; + struct coord_geo *g; + struct coord c; ret=g_new0(struct attr, 1); dbg(1,"enter name='%s' value='%s'\n", name, value); @@ -59,6 +63,12 @@ attr_new_from_text(const char *name, const char *value) case attr_item_type: ret->u.item_type=item_from_name(value); break; + case attr_position_coord_geo: + g=g_new(struct coord_geo, 1); + ret->u.coord_geo=g; + coord_parse(value, projection_mg, &c); + transform_to_geo(projection_mg, &c, g); + break; default: if (attr >= attr_type_string_begin && attr <= attr_type_string_end) { ret->u.str=(char *)value; @@ -148,6 +158,8 @@ attr_data_set(struct attr *attr, void *data) void attr_free(struct attr *attr) { + if (attr->type == attr_position_coord_geo) + g_free(attr->u.coord_geo); if (attr->type >= attr_type_color_begin && attr->type <= attr_type_color_end) g_free(attr->u.color); g_free(attr); diff --git a/src/log.c b/src/log.c index ab70dfe..1c4a49a 100644 --- a/src/log.c +++ b/src/log.c @@ -145,7 +145,7 @@ log_new(struct attr **attrs) struct log *ret=g_new0(struct log, 1); struct attr *data,*overwrite,*flush_size,*flush_time; - dbg(0,"enter\n"); + dbg(1,"enter\n"); data=attr_search(attrs, NULL, attr_data); if (! data) return NULL; diff --git a/src/navigation.c b/src/navigation.c index d09493b..023947c 100644 --- a/src/navigation.c +++ b/src/navigation.c @@ -330,8 +330,8 @@ static int maneuver_required2(struct navigation_itm *old, struct navigation_itm *new, int *delta) { dbg(1,"enter %p %p %p\n",old, new, delta); - if (new->item.type == type_ramp && old && (old->item.type == type_highway_land || old->item.type == type_highway_city)) { - dbg(1, "maneuver_required: new is ramp from highway: yes\n"); + if (new->item.type != old->item.type && (new->item.type == type_ramp || old->item.type == type_ramp)) { + dbg(1, "maneuver_required: old or new is ramp\n"); return 1; } if (is_same_street2(old, new)) { diff --git a/src/popup.c b/src/popup.c index 812ed3e..69b1b6b 100644 --- a/src/popup.c +++ b/src/popup.c @@ -120,14 +120,18 @@ popup_printf_cb(void *menu, enum menu_type type, struct callback *cb, const char } static void -popup_show_attr_val(void *menu, struct attr *attr) +popup_show_attr_val(struct map *map, void *menu, struct attr *attr) { char *attr_name=attr_to_name(attr->type); + char *str; if (attr->type >= attr_type_int_begin && attr->type <= attr_type_int_end) popup_printf(menu, menu_type_menu, "%s: %d", attr_name, attr->u.num); - else - popup_printf(menu, menu_type_menu, "%s: %s", attr_name, attr->u.str); + else { + str=map_convert_string(map, attr->u.str); + popup_printf(menu, menu_type_menu, "%s: %s", attr_name, str); + map_convert_free(str); + } } #if 0 @@ -143,7 +147,7 @@ popup_show_attr(void *menu, struct item *item, enum attr_type attr_type) #endif static void -popup_show_attrs(void *menu, struct item *item) +popup_show_attrs(struct map *map, void *menu, struct item *item) { #if 0 popup_show_attr(menu, item, attr_debug); @@ -157,7 +161,7 @@ popup_show_attrs(void *menu, struct item *item) for (;;) { memset(&attr, 0, sizeof(attr)); if (item_attr_get(item, attr_any, &attr)) - popup_show_attr_val(menu, &attr); + popup_show_attr_val(map, menu, &attr); else break; } @@ -188,7 +192,7 @@ popup_show_item(void *popup, struct displayitem *di) item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo); dbg(1,"item=%p\n", item); if (item) { - popup_show_attrs(menu_item, item); + popup_show_attrs(item->map, menu_item, item); } map_rect_destroy(mr); menu_map=popup_printf(menu, menu_type_submenu, "Map"); diff --git a/src/route.c b/src/route.c index 98f9d67..a7a40d1 100644 --- a/src/route.c +++ b/src/route.c @@ -699,7 +699,7 @@ route_path_coord_get(struct route_path_coord_handle *h) h->pos=0; h->rp=route_path_open(h->route); case 0: - if (! h->street_data) { + if (! h->street_data && h->rp) { seg=route_path_get_segment(h->rp); if (seg) { item=route_path_segment_get_item(seg); diff --git a/src/vehicle/demo/vehicle_demo.c b/src/vehicle/demo/vehicle_demo.c index 5f0533c..a87e873 100644 --- a/src/vehicle/demo/vehicle_demo.c +++ b/src/vehicle/demo/vehicle_demo.c @@ -11,6 +11,7 @@ struct vehicle_priv { int interval; + int position_set; struct callback_list *cbl; struct navit *navit; struct coord_geo geo; @@ -37,7 +38,6 @@ vehicle_demo_position_attr_get(struct vehicle_priv *priv, attr->u.numd = &priv->direction; break; case attr_position_coord_geo: - dbg(1, "coord %f,%f\n", priv->geo.lat, priv->geo.lng); attr->u.coord_geo = &priv->geo; break; default: @@ -67,8 +67,8 @@ struct vehicle_methods vehicle_demo_methods = { static int vehicle_demo_timer(struct vehicle_priv *priv) { - struct route_path_coord_handle *h; - struct coord *c, *pos, ci; + struct route_path_coord_handle *h=NULL; + struct coord *c, *pos=NULL, ci; int slen, len, dx, dy; len = (priv->speed * priv->interval / 1000)/ 3.6; @@ -78,19 +78,13 @@ vehicle_demo_timer(struct vehicle_priv *priv) return 1; } struct route *vehicle_route = navit_get_route(priv->navit); - if (!vehicle_route) { - dbg(1, "navit_get_route NOK\n"); - return 1; - } - - h = route_path_coord_open(vehicle_route); - if (!h) { - dbg(1, "navit_path_coord_open NOK\n"); - return 1; - } - pos = route_path_coord_get(h); + if (vehicle_route) + h = route_path_coord_open(vehicle_route); + if (h) + pos = route_path_coord_get(h); dbg(1, "current pos=%p\n", pos); if (pos) { + priv->position_set=0; dbg(1, "current pos=0x%x,0x%x\n", pos->x, pos->y); dbg(1, "last pos=0x%x,0x%x\n", priv->last.x, priv->last.y); if (priv->last.x == pos->x && priv->last.y == pos->y) { @@ -122,6 +116,9 @@ vehicle_demo_timer(struct vehicle_priv *priv) break; } } + } else { + if (priv->position_set) + callback_list_call_0(priv->cbl); } return 1; } @@ -134,7 +131,7 @@ vehicle_demo_new(struct vehicle_methods *cbl, struct attr **attrs) { struct vehicle_priv *ret; - struct attr *interval,*speed; + struct attr *interval,*speed,*position_coord_geo; dbg(1, "enter\n"); ret = g_new0(struct vehicle_priv, 1); @@ -145,6 +142,11 @@ vehicle_demo_new(struct vehicle_methods ret->speed=speed->u.num; if ((interval=attr_search(attrs, NULL, attr_interval))) ret->interval=speed->u.num; + if ((position_coord_geo=attr_search(attrs, NULL, attr_position_coord_geo))) { + ret->geo=*(position_coord_geo->u.coord_geo); + ret->position_set=1; + dbg(0,"position_set %f %f\n", ret->geo.lat, ret->geo.lng); + } *meth = vehicle_demo_methods; g_timeout_add(ret->interval, (GSourceFunc) vehicle_demo_timer, ret); return ret; -- 1.7.9.5