]> err.no Git - mapper/commitdiff
Path and Position:
authorKaj-Michael Lang <milang@tal.org>
Tue, 6 May 2008 12:59:39 +0000 (15:59 +0300)
committerKaj-Michael Lang <milang@tal.org>
Tue, 6 May 2008 12:59:39 +0000 (15:59 +0300)
- Add type and id fields
- Add position_new/_free
- Use dynamic _home and _dest positions
- Modify all Position users for the above changes

src/cb.c
src/config-gconf.c
src/gps.c
src/map.c
src/mapper.c
src/path.c
src/path.h
src/poi-gui.c
src/route.c
src/search.c

index 0df1230bf882f5501f98f936659f20d38bd3d3c0..8d7ca1bc61f8c946d5dd592a52cee366d6937c9a 100644 (file)
--- 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."));
 
index 2966e958447b919cbacf8f6e52d36f5d56449dba..28dd16ce3abbfc8d4bfd326d9c2e5fa556977374 100644 (file)
@@ -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. */
 {
index 7f89ae9dc796b9cb2fb986522d3a64ff20efaa2e..f4c2a389c82b5348e2d75ce4e724b3b8557d2c27 100644 (file)
--- 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);
index 4363fb73a0ecf88236e9cc04a810bfc5b4155510..4354b9b332a78a9878fe0156107ae2ed36c91644 100644 (file)
--- 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;
index a7d75d0b6dd3bc16b063ace1308d428821b8f60c..19679c64b8c9067c04ef10a8af26698ef1c76c1f 100644 (file)
@@ -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";
index a26d874d0b9f457449b57874ecc92a218b92d3a6..bd8d3522d2aee1a38b08320baaff4b66332ce593 100644 (file)
@@ -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;
 }
index 95f977c688d712a16d965db0b262286c2a0b4cee..54ca7f20bdfc745fab51de2d0f2dd58be1fca79b 100644 (file)
 #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. */
@@ -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; \
index c84b28e66912e85e2d0bf8c0406ce0d94bd6168a..0ec3f203bab9fd9ef7f7f919d4389fda4b5175f6 100644 (file)
@@ -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();
 
index 88fd3fe5a0f16dcca3b5c11723face2a2febe3b3..6ef68cd50bde646dba056c3ffeabb0be81fba7cf 100644 (file)
@@ -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;
 }
index 08cc4b4b00e0724852c31ed3947d37be7188a930..ae113bd6fdbcfcfa3549ecdd2472b4a508d31b96 100644 (file)
@@ -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;