From: Kaj-Michael Lang Date: Tue, 6 May 2008 12:59:39 +0000 (+0300) Subject: Path and Position: X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48ad2777ad395e7991964549e78402fe120ca84e;p=mapper Path and Position: - Add type and id fields - Add position_new/_free - Use dynamic _home and _dest positions - Modify all Position users for the above changes --- diff --git a/src/cb.c b/src/cb.c index 0df1230..8d7ca1b 100644 --- a/src/cb.c +++ b/src/cb.c @@ -314,7 +314,7 @@ return TRUE; gboolean menu_cb_goto_home(GtkAction *action) { -if (map_goto_position(&_home)==FALSE) { +if (map_goto_position(_home)==FALSE) { MACRO_BANNER_SHOW_INFO(_window, _("Home not set.")); } else { if (map_get_zoom()>3) @@ -327,7 +327,7 @@ return TRUE; gboolean menu_cb_goto_destination(GtkAction *action) { -if (map_goto_position(&_dest)==FALSE) { +if (map_goto_position(_dest)==FALSE) { MACRO_BANNER_SHOW_INFO(_window, _("Destination not set.")); } else { map_set_zoom(3); @@ -1081,10 +1081,10 @@ guint unitx, unity; unitx = x2unit(_cmenu_position_x); unity = y2unit(_cmenu_position_y); -unit2latlon(unitx, unity, _home.lat, _home.lon); -_home.valid=TRUE; +unit2latlon(unitx, unity, _home->lat, _home->lon); +_home->valid=TRUE; -if (!config_save_position(&_home, GCONF_KEY_POSITION_HOME)) +if (!config_save_position(_home, GCONF_KEY_POSITION_HOME)) popup_error(_window, _("Failed to save home position.")); map_render_data(); @@ -1098,8 +1098,8 @@ guint unitx, unity; unitx = x2unit(_cmenu_position_x); unity = y2unit(_cmenu_position_y); -unit2latlon(unitx, unity, _dest.lat, _dest.lon); -_dest.valid=TRUE; +unit2latlon(unitx, unity, _dest->lat, _dest->lon); +_dest->valid=TRUE; if (!config_save_position(&_dest, GCONF_KEY_POSITION_DEST)) popup_error(_window, _("Failed to save destination.")); diff --git a/src/config-gconf.c b/src/config-gconf.c index 2966e95..28dd16c 100644 --- a/src/config-gconf.c +++ b/src/config-gconf.c @@ -423,7 +423,7 @@ _lead_ratio=mapper_gconf_get_int(GCONF_KEY_LEAD_AMOUNT, 5); _draw_width=mapper_gconf_get_int(GCONF_KEY_DRAW_WIDTH, 4); /* Invalidate destination */ -_dest.valid=FALSE; +_dest->valid=FALSE; /* Get Announce Advance Notice - Default is 30. */ _announce_notice_ratio=mapper_gconf_get_int(GCONF_KEY_ANNOUNCE_NOTICE, 8); @@ -516,8 +516,8 @@ _gps->data.lat=mapper_gconf_get_float(GCONF_KEY_LAT, 60.20); _gps->data.lon=mapper_gconf_get_float(GCONF_KEY_LON, 22.20); /* Special positions Home and Dest */ -config_load_position(&_home, GCONF_KEY_POSITION_HOME); -config_load_position(&_dest, GCONF_KEY_POSITION_DEST); +config_load_position(_home, GCONF_KEY_POSITION_HOME); +config_load_position(_dest, GCONF_KEY_POSITION_DEST); /* Get last center point. */ { diff --git a/src/gps.c b/src/gps.c index 7f89ae9..f4c2a38 100644 --- a/src/gps.c +++ b/src/gps.c @@ -403,9 +403,9 @@ static void gps_simulate_start(Gps *gps) { g_assert(gps); -if (_home.valid) { - gps->data.lat=_home.lat; - gps->data.lon=_home.lon; +if (_home->valid) { + gps->data.lat=_home->lat; + gps->data.lon=_home->lon; } else { gps->data.lat=60.45; gps->data.lon=22.26; @@ -427,16 +427,16 @@ gfloat h; g_assert(gps); -if (_dest.valid) { +if (_dest->valid) { gdouble c; - c=calculate_course_rad(_dest.lat,_dest.lon, gps->data.lat, gps->data.lon); + c=calculate_course_rad(_dest->lat,_dest->lon, gps->data.lat, gps->data.lon); c-=G_PI; accel=0.005*g_random_double(); slat=accel*cos(c); slon=accel*sin(c); - g_debug("Sim: %f %f %f %f", slat, slon, accel, _dest.angle); + g_debug("Sim: %f %f %f %f", slat, slon, accel, _dest->angle); } else { if (g_random_double()<0.2) { slat=g_random_double_range(-0.0009, 0.0009); diff --git a/src/map.c b/src/map.c index 4363fb7..4354b9b 100644 --- a/src/map.c +++ b/src/map.c @@ -490,7 +490,10 @@ for (zoff = (_curr_repo->double_size ? 1 : 0); !pixbuf && (_zoom + zoff) <= map_ } if (pixbuf) { - gdk_draw_pixbuf(map_pixmap, _gc[COLORABLE_MARK], pixbuf, 0, 0, destx, desty, TILE_SIZE_PIXELS, TILE_SIZE_PIXELS, GDK_RGB_DITHER_NONE, 0, 0); + gdk_draw_pixbuf(map_pixmap, _gc[COLORABLE_MARK], + pixbuf, 0, 0, destx, desty, + TILE_SIZE_PIXELS, TILE_SIZE_PIXELS, GDK_RGB_DITHER_NONE, 0, 0); + g_object_unref(pixbuf); return TRUE; } @@ -508,11 +511,11 @@ if (map_drag_id>0) if(_show_poi) map_render_all_pois(buf_width_pixels, buf_height_pixels); -if (_home.valid) - map_draw_position_icon(&_home, "home"); +if (_home->valid) + map_draw_position_icon(_home, "home"); -if (_dest.valid) - map_draw_position_icon(&_dest, "destination"); +if (_dest->valid) + map_draw_position_icon(_dest, "destination"); if(_show_tracks>0) map_render_paths(); @@ -1310,9 +1313,9 @@ static gdouble prev_dt=99999.0; static gboolean dest_reached=FALSE; gchar buffer[64]; -if (_dest.valid) { - dt=calculate_distance(lat, lon, _dest.lat, _dest.lon); - dh=calculate_course(lat, lon, _dest.lat, _dest.lon); +if (_dest->valid) { + dt=calculate_distance(lat, lon, _dest->lat, _dest->lon); + dh=calculate_course(lat, lon, _dest->lat, _dest->lon); cdist=dt*UNITS_CONVERT[_units]; g_snprintf(buffer, sizeof(buffer), "%.02f %s (%0.02f)", cdist, UNITS_TEXT[_units], dh<0 ? 360+dh : dh); @@ -1339,8 +1342,8 @@ if (_dest.valid) { gtk_label_set_label(GTK_LABEL(info_banner.distance), ""); } -gtk_compass_set_dest_heading(_gps_compass, _dest.valid, (gfloat)dh); -gtk_compass_set_dest_heading(_tab_compass, _dest.valid, (gfloat)dh); +gtk_compass_set_dest_heading(_gps_compass, _dest->valid, (gfloat)dh); +gtk_compass_set_dest_heading(_tab_compass, _dest->valid, (gfloat)dh); if (_route->next_way && _route->next_way->point) { gdouble wp_lat, wp_lon; diff --git a/src/mapper.c b/src/mapper.c index a7d75d0..19679c6 100644 --- a/src/mapper.c +++ b/src/mapper.c @@ -235,6 +235,8 @@ osm_deinit(); db_close(&_db); path_free(_track); path_free(_route); +position_free(_home); +position_free(_dest); gnome_vfs_shutdown(); #ifdef WITH_OSSO @@ -362,8 +364,10 @@ switch (mis) { gpx_init(); variables_init(); latlon_init(); - _track=path_new(); - _route=path_new(); + _track=path_new(PATH_TYPE_TRACK, 0); + _route=path_new(PATH_TYPE_ROUTE, 1); + _home=position_new(POSITION_TYPE_HOME, 0); + _dest=position_new(POSITION_TYPE_DESTINATION, 1); mis=MAPPER_INIT_CONFIG; p=0.1; w="Init"; diff --git a/src/path.c b/src/path.c index a26d874..bd8d352 100644 --- a/src/path.c +++ b/src/path.c @@ -67,12 +67,14 @@ static struct sql_select_stmt sql; static gint sensitivity=3; Path * -path_new(void) +path_new(PathType type, guint id) { Path *p; p=g_slice_new0(Path); MACRO_PATH_INIT(*p); +p->type=type; +p->id=id; return p; } @@ -375,11 +377,30 @@ while (wcurr!=path->wtail) { return store; } +Position * +position_new(PositionType type, guint id) +{ +Position *pos; + +pos=g_slice_new0(Position); +pos->type=type; +pos->id=id; +return pos; +} + +void +position_free(Position *pos) +{ +g_return_if_fail(pos); +g_slice_free(Position, pos); +} + void -position_set(Position *pos, gboolean valid, gdouble lat, gdouble lon) +position_set(Position *pos, gboolean valid, gdouble lat, gdouble lon, gfloat alt) { -g_assert(pos); +g_return_if_fail(pos); pos->valid=valid; pos->lat=valid ? lat : NAN; pos->lon=valid ? lon : NAN; +pos->altitude=valid ? lon : NAN; } diff --git a/src/path.h b/src/path.h index 95f977c..54ca7f2 100644 --- a/src/path.h +++ b/src/path.h @@ -24,17 +24,37 @@ #include #include +typedef enum { + PATH_TYPE_TRACK=0, + PATH_TYPE_ROUTE, + PATH_TYPE_FRIEND, +} PathType; + +/* Fixed ID's */ +#define PATH_ID_MY_TRACK (1) +#define PATH_ID_MY_ROUTE (2) + +typedef enum { + POSITION_TYPE_GPS, + POSITION_TYPE_HOME, + POSITION_TYPE_DESTINATION, + POSITION_TYPE_WAYPOINT, + POSITION_TYPE_FRIEND, +} PositionType; + /** A lat/lon/alt position */ typedef struct _Position Position; struct _Position { - gchar *name; - gboolean valid; + gchar *name; /* Name of position */ + guint id; /* Unique ID of position */ + PositionType type; /* Type of position (Home, Destination, Waypoint, etc) */ + gboolean valid; /* Is lat/lon valid ? */ gdouble lat; gdouble lon; gfloat altitude; + gfloat heading; /* Where is it heading ? */ gfloat angle; /* Course from current position to this one */ - time_t time; - guint type; /* Type of position (Home, Destination, Waypoint, etc) */ + time_t time; /* Time last changed */ }; /** A general definition of a point in the Mapper unit system. */ @@ -56,6 +76,9 @@ struct _WayPoint { /** A Path is a set of PathPoints and WayPoints. */ typedef struct _Path Path; struct _Path { + PathType type; + guint id; + /* Path points */ Point *head; /* points to first element in array; NULL if empty. */ Point *tail; /* points to last element in array. */ @@ -100,10 +123,10 @@ struct _Path { Point _point_null; /* Special positions */ -Position _home; -Position _dest; +Position *_home; +Position *_dest; -Path *path_new(void); +Path *path_new(PathType type, guint id); void path_free(Path *p); void path_clear(Path *p); @@ -119,10 +142,12 @@ void path_insert_mark_text(Path *path, gchar *text); void path_insert_mark_autonumber(Path *path); void path_insert_mark_audio(Path *path, gchar *audio); -void position_set(Position *pos, gboolean valid, gdouble lat, gdouble lon); - GtkListStore *path_generate_store(Path *path); +Position *position_new(PositionType type, guint id); +void position_free(Position *p); +void position_set(Position *pos, gboolean valid, gdouble lat, gdouble lon, gfloat alt); + #define MACRO_PATH_INIT(path) { \ (path).head = (path).tail = g_new0(Point, ARRAY_CHUNK_SIZE); \ *((path).tail) = _point_null; \ diff --git a/src/poi-gui.c b/src/poi-gui.c index c84b28e..0ec3f20 100644 --- a/src/poi-gui.c +++ b/src/poi-gui.c @@ -544,9 +544,9 @@ model=gtk_tree_view_get_model(GTK_TREE_VIEW(sd->list)); if (!model) return TRUE; -_dest.valid=TRUE; -gtk_tree_model_get(model, &iter, ITEM_LAT, &_dest.lat, -1); -gtk_tree_model_get(model, &iter, ITEM_LON, &_dest.lon, -1); +_dest->valid=TRUE; +gtk_tree_model_get(model, &iter, ITEM_LAT, &_dest->lat, -1); +gtk_tree_model_get(model, &iter, ITEM_LON, &_dest->lon, -1); map_update_location_from_center(); diff --git a/src/route.c b/src/route.c index 88fd3fe..6ef68cd 100644 --- a/src/route.c +++ b/src/route.c @@ -693,14 +693,14 @@ g_return_val_if_fail(route, FALSE); g_return_val_if_fail(pos, FALSE); if (route->head==route->tail) { - position_set(pos, FALSE, NAN, NAN); + position_set(pos, FALSE, NAN, NAN, NAN); return FALSE; } p=path_find_last_point(route); if (p) { unit2latlon(p->unitx, p->unity, lat, lon); - position_set(pos, TRUE, lat, lon); + position_set(pos, TRUE, lat, lon, 0); } return TRUE; } diff --git a/src/search.c b/src/search.c index 08cc4b4..ae113bd 100644 --- a/src/search.c +++ b/src/search.c @@ -362,14 +362,14 @@ while ((res=gtk_dialog_run(GTK_DIALOG(sd.dialog)))!=GTK_RESPONSE_REJECT) { continue; break; case SBTN_ROUTETO: - if (search_get_list_item_latlon(sd.list, &_dest.lat, &_dest.lon)==FALSE) { + if (search_get_list_item_latlon(sd.list, &lat, &lon)==FALSE) { #ifdef WITH_HILDON hildon_banner_show_information(sd.dialog, NULL, _("Select a location from the list.")); #else popup_error(sd.dialog, _("Select a location from the list.")); #endif } else { - _dest.valid=TRUE; + position_set(_dest, TRUE, lat, lon, 0); g_idle_add_full(G_PRIORITY_HIGH_IDLE,(GSourceFunc)map_update_location_from_center, NULL, NULL); } continue;