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)
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);
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();
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."));
_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);
_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. */
{
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;
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);
}
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;
}
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();
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);
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;
db_close(&_db);
path_free(_track);
path_free(_route);
+position_free(_home);
+position_free(_dest);
gnome_vfs_shutdown();
#ifdef WITH_OSSO
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";
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;
}
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;
}
#include <glib.h>
#include <gtk/gtk.h>
+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. */
/** 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. */
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);
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; \
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();
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;
}
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;