]> err.no Git - mapper/commitdiff
Use dynamicaly allocated _track and _route.
authorKaj-Michael Lang <milang@onion.tal.org>
Thu, 13 Mar 2008 14:48:29 +0000 (16:48 +0200)
committerKaj-Michael Lang <milang@onion.tal.org>
Thu, 13 Mar 2008 14:48:29 +0000 (16:48 +0200)
src/cb.c
src/map-repo.c
src/map.c
src/mapper.c
src/path.c
src/route.c
src/route.h
src/track.c
src/track.h

index 4a0c3945dce0a7c27754b6a19ed2dcb54e1b8bc8..c5989b6000c8916a741f7e258e09d14c7a68256f 100644 (file)
--- a/src/cb.c
+++ b/src/cb.c
@@ -80,7 +80,7 @@ gboolean
 menu_cb_route_download(GtkAction * action)
 {
 route_download(NULL);
-path_tree_view_update_store(route_tree_view, &_route);
+path_tree_view_update_store(route_tree_view, _route);
 return TRUE;
 }
 
@@ -90,7 +90,7 @@ menu_cb_route_open(GtkAction * action)
 GtkListStore *store;
 
 route_open_file();
-path_tree_view_update_store(route_tree_view, &_route);
+path_tree_view_update_store(route_tree_view, _route);
 return TRUE;
 }
 
@@ -129,7 +129,7 @@ gboolean
 menu_cb_track_open(GtkAction * action)
 {
 track_open();
-path_tree_view_update_store(track_tree_view, &_track);
+path_tree_view_update_store(track_tree_view, _track);
 return TRUE;
 }
 
@@ -137,7 +137,7 @@ gboolean
 menu_cb_track_save(GtkAction * action)
 {
 track_save();
-path_tree_view_update_store(track_tree_view, &_track);
+path_tree_view_update_store(track_tree_view, _track);
 return TRUE;
 }
 
@@ -145,7 +145,7 @@ gboolean
 menu_cb_track_insert_break(GtkAction * action)
 {
 track_insert_break();
-path_tree_view_update_store(track_tree_view, &_track);
+path_tree_view_update_store(track_tree_view, _track);
 return TRUE;
 }
 
@@ -155,7 +155,7 @@ menu_cb_track_insert_mark(GtkAction * action)
 if (track_insert_mark()) {
        map_render_paths();
        MACRO_QUEUE_DRAW_AREA();
-       path_tree_view_update_store(track_tree_view, &_track);
+       path_tree_view_update_store(track_tree_view, _track);
 }
 return TRUE;
 }
@@ -185,7 +185,7 @@ gboolean
 menu_cb_track_clear(GtkAction * action)
 {
 track_clear();
-path_tree_view_update_store(track_tree_view, &_track);
+path_tree_view_update_store(track_tree_view, _track);
 return TRUE;
 }
 
@@ -800,9 +800,9 @@ MACRO_BANNER_SHOW_INFO(_window, buffer);
 void 
 cmenu_add_route(guint unitx, guint unity)
 {
-MACRO_PATH_INCREMENT_TAIL(_route);
-_route.tail->unitx = x2unit(_cmenu_position_x);
-_route.tail->unity = y2unit(_cmenu_position_y);
+MACRO_PATH_INCREMENT_TAIL(*_route);
+_route->tail->unitx = x2unit(_cmenu_position_x);
+_route->tail->unity = y2unit(_cmenu_position_y);
 route_find_nearest_point();
 map_force_redraw();
 }
@@ -878,15 +878,15 @@ dialog = gtk_dialog_new_with_buttons(_("Add Waypoint"),
 
                if (*desc) {
                        /* There's a description.  Add a waypoint. */
-                       MACRO_PATH_INCREMENT_TAIL(_route);
-                       _route.tail->unitx = unitx;
-                       _route.tail->unity = unity;
-                       _route.tail->time = 0;
-                       _route.tail->altitude = NAN;
-
-                       MACRO_PATH_INCREMENT_WTAIL(_route);
-                       _route.wtail->point = _route.tail;
-                       _route.wtail->desc
+                       MACRO_PATH_INCREMENT_TAIL(*_route);
+                       _route->tail->unitx = unitx;
+                       _route->tail->unity = unity;
+                       _route->tail->time = 0;
+                       _route->tail->altitude = NAN;
+
+                       MACRO_PATH_INCREMENT_WTAIL(*_route);
+                       _route->wtail->point = _route->tail;
+                       _route->wtail->desc
                            = gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE);
                } else {
                        GtkWidget *confirm;
@@ -900,16 +900,16 @@ dialog = gtk_dialog_new_with_buttons(_("Add Waypoint"),
                        if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
                                /* There's no description.  Add a break by adding a (0, 0)
                                 * point (if necessary), and then the ordinary route point. */
-                               if (_route.tail->unity) {
-                                       MACRO_PATH_INCREMENT_TAIL(_route);
-                                       *_route.tail = _point_null;
+                               if (_route->tail->unity) {
+                                       MACRO_PATH_INCREMENT_TAIL(*_route);
+                                       *_route->tail = _point_null;
                                }
 
-                               MACRO_PATH_INCREMENT_TAIL(_route);
-                               _route.tail->unitx = unitx;
-                               _route.tail->unity = unity;
-                               _route.tail->time = 0;
-                               _route.tail->altitude = NAN;
+                               MACRO_PATH_INCREMENT_TAIL(*_route);
+                               _route->tail->unitx = unitx;
+                               _route->tail->unity = unity;
+                               _route->tail->time = 0;
+                               _route->tail->altitude = NAN;
 
                                gtk_widget_destroy(confirm);
                        } else {
@@ -1172,13 +1172,13 @@ if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_positi
                guint num_del;
 
                /* Delete surrounding route data, too. */
-               if (way == _route.whead)
-                       pdel_min = _route.head;
+               if (way == _route->whead)
+                       pdel_min = _route->head;
                else
                        pdel_min = way[-1].point;
 
-               if (way == _route.wtail)
-                       pdel_max = _route.tail;
+               if (way == _route->wtail)
+                       pdel_max = _route->tail;
                else
                        pdel_max = way[1].point;
 
@@ -1191,10 +1191,10 @@ if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_positi
                     && pdel_end < pdel_max; pdel_end++) {
                }
 
-               /* If pdel_end is set to _route.tail, and if _route.tail is a
-                * non-zero point, then delete _route.tail. */
-               if (pdel_end == _route.tail && pdel_end->unity)
-                       pdel_end++;     /* delete _route.tail too */
+               /* If pdel_end is set to _route->tail, and if _route->tail is a
+                * non-zero point, then delete _route->tail. */
+               if (pdel_end == _route->tail && pdel_end->unity)
+                       pdel_end++;     /* delete _route->tail too */
                /* else, if *both* endpoints are zero points, delete one. */
                else if (!pdel_start->unity && !pdel_end->unity)
                        pdel_start--;
@@ -1202,16 +1202,16 @@ if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_positi
                /* Delete BETWEEN pdel_start and pdel_end, exclusive. */
                num_del = pdel_end - pdel_start - 1;
 
-               memmove(pdel_start + 1, pdel_end,(_route.tail - pdel_end + 1) * sizeof(Point));
-               _route.tail -= num_del;
+               memmove(pdel_start + 1, pdel_end,(_route->tail - pdel_end + 1) * sizeof(Point));
+               _route->tail -= num_del;
 
                /* Remove waypoint and move/adjust subsequent waypoints. */
                g_free(way->desc);
-               while (way++ != _route.wtail) {
+               while (way++ != _route->wtail) {
                        way[-1] = *way;
                        way[-1].point -= num_del;
                }
-               _route.wtail--;
+               _route->wtail--;
 
                route_find_nearest_point();
                map_force_redraw();
@@ -1340,7 +1340,7 @@ case 1:
 break;
 case 0:
 default:
-       path_insert_mark_text(&_track, g_strdup("Mark"));
+       path_insert_mark_text(_track, g_strdup("Mark"));
        hildon_banner_show_information(_window, NULL, _("Mark added"));
 break;
 }
index db804047eb3dfb132ab3e498579d8409fbe42f73..7289d0361f0152e492afb42362c0c2ea806fcb49 100644 (file)
@@ -643,7 +643,7 @@ for (i = 0; i < MAX_ZOOM; i++) {
                prev_tilex = 0;
                prev_tiley = 0;
 
-               for (curr = _route.head - 1; curr++ != _route.tail;) {
+               for (curr = _route->head - 1; curr++ != _route->tail;) {
                        if (curr->unity) {
                                guint tilex = unit2ztile(curr->unitx, i);
                                guint tiley = unit2ztile(curr->unity, i);
@@ -683,7 +683,7 @@ for (i = 0; i < MAX_ZOOM; i++) {
                prev_tilex = 0;
                prev_tiley = 0;
 
-               for (curr = _route.head - 1; curr++ != _route.tail;) {
+               for (curr = _route->head - 1; curr++ != _route->tail;) {
                        if (curr->unity) {
                                guint tilex = unit2ztile(curr->unitx, i);
                                guint tiley = unit2ztile(curr->unity, i);
@@ -822,7 +822,7 @@ gboolean menu_cb_mapman(GtkAction * action)
                            _("Along Route - Radius (tiles):")), FALSE, FALSE,
                           0);
        gtk_widget_set_sensitive(mapman_info.rad_by_route,
-                                _route.head != _route.tail);
+                                _route->head != _route->tail);
        gtk_box_pack_start(GTK_BOX(hbox), mapman_info.num_route_radius =
                           hildon_number_editor_new(0, 100), FALSE, FALSE, 0);
        hildon_number_editor_set_value(HILDON_NUMBER_EDITOR
index 91b9e405e12a8816dae44d951787f0d62217b326..b390fe3239f5f9ec0316c053d5cb1267e85394cb 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -897,8 +897,8 @@ for (curr = path->head, wcurr = path->whead; curr++ != path->tail;) {
 void 
 map_render_paths(void)
 {
-if ((_show_tracks & ROUTES_MASK) && _route.head != _route.tail) {
-       map_render_path(&_route, _gc + COLORABLE_ROUTE);
+if ((_show_tracks & ROUTES_MASK) && _route->head != _route->tail) {
+       map_render_path(_route, _gc + COLORABLE_ROUTE);
 
        /* Now, draw the next waypoint on top of all other waypoints. */
        if (_next_way) {
@@ -914,7 +914,7 @@ if ((_show_tracks & ROUTES_MASK) && _route.head != _route.tail) {
        }
 }
 if (_show_tracks & TRACKS_MASK)
-       map_render_path(&_track, _gc + COLORABLE_TRACK);
+       map_render_path(_track, _gc + COLORABLE_TRACK);
 }
 
 /**
index ae97f8beba53a743b50f3be60d8064bac269960f..00798cdff08b12772f0a6a418ba01ce057f3a893 100644 (file)
@@ -232,8 +232,8 @@ gps_free(_gps);
 osm_db_enable_mainloop(_db, FALSE);
 osm_deinit();
 db_close(&_db);
-track_deinit();
-route_deinit();
+path_free(_track);
+path_free(_route);
 
 gnome_vfs_shutdown();
 #ifdef WITH_OSSO
@@ -361,8 +361,8 @@ switch (mis) {
                gpx_init();
                variables_init();
                latlon_init();
-               track_init();
-               route_init();
+               _track=path_new();
+               _route=path_new();
                mis=MAPPER_INIT_CONFIG;
                p=0.1;
                w="Init";
index df0ce1c9f7fe490b4e74227225ddeb9408007642..fbb734c359282afa96f082a0a81747f9d6af43b1 100644 (file)
@@ -24,6 +24,7 @@ return p;
 void
 path_free(Path *p)
 {
+g_return_if_fail(p);
 MACRO_PATH_FREE(*p);
 g_slice_free(Path, p);
 }
index 2042c4a3d3baac5bb5a81cd4582a7eb3a3c7c7d1..db15a84d56c980b5b049cb00fd6dafec797f5177 100644 (file)
@@ -52,19 +52,6 @@ void route_cancel_autoroute(gboolean temporary);
 void route_show_distance_to_last(void);
 void route_set_destination_from_last(void);
 
-void
-route_init(void)
-{
-memset(&_route, 0, sizeof(_route));
-MACRO_PATH_INIT(_route);
-}
-
-void
-route_deinit(void)
-{
-MACRO_PATH_FREE(_route);
-}
-
 void
 route_clear(void)
 {
@@ -74,8 +61,8 @@ confirm = hildon_note_new_confirmation(GTK_WINDOW(_window), _("Really clear the
 
 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
        route_cancel_autoroute(FALSE);
-       route_deinit();
-       route_init();
+       path_free(_route);
+       _route=path_new();
        route_find_nearest_point();
        map_force_redraw();
 }
@@ -120,9 +107,9 @@ route_open_file(void)
 gchar *buffer;
 gint size;
 
-if (file_open_get_contents(&_route_dir_uri, &buffer, &size)) {
+if (file_open_get_contents(_route_dir_uri, &buffer, &size)) {
        /* If auto is enabled, append the route, otherwise replace it. */
-       if (parse_gpx(&_route, buffer, size, _autoroute_data.enabled ? 0 : 1)) {
+       if (parse_gpx(_route, buffer, size, _autoroute_data.enabled ? 0 : 1)) {
                route_cancel_autoroute(FALSE);
 
                MACRO_BANNER_SHOW_INFO(_window, _("Route Opened"));
@@ -148,13 +135,13 @@ route_save(void)
 {
 GnomeVFSHandle *handle;
 
-if (_route.head==_route.tail) {
+if (_route->head==_route->tail) {
        MACRO_BANNER_SHOW_INFO(_window, _("No route exist."));
        return FALSE;
 }
 
 if (file_save(&_route_dir_uri, &_route_dir_uri, &handle)) {
-       if (write_gpx(&_route, handle)) {
+       if (write_gpx(_route, handle)) {
                MACRO_BANNER_SHOW_INFO(_window, _("Route Saved"));
        } else {
                popup_error(_window, _("Error writing GPX file."));
@@ -188,7 +175,7 @@ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle))) {
                gdouble lat, lon;
 
                /* Use last non-zero route point. */
-               for (p = _route.tail; !p->unity; p--) {
+               for (p = _route->tail; !p->unity; p--) {
                }
 
                unit2latlon(p->unitx, p->unity, lat, lon);
@@ -352,7 +339,7 @@ gtk_box_pack_start(GTK_BOX(hbox),
                   gtk_radio_button_new_with_label_from_widget
                   (GTK_RADIO_BUTTON(oti.rad_use_gps),
                    _("Use End of Route")), TRUE, TRUE, 0);
-gtk_widget_set_sensitive(oti.rad_use_route, _route.head != _route.tail);
+gtk_widget_set_sensitive(oti.rad_use_route, _route->head != _route->tail);
 
 /* Origin. */
 gtk_table_attach(GTK_TABLE(table),
@@ -392,7 +379,7 @@ gtk_entry_set_text(GTK_ENTRY(oti.txt_to), (to ? to : ""));
 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(oti.rad_use_text), TRUE);
 
 /* Use "End of Route" by default if they have a route. */
-if (_route.head != _route.tail) {
+if (_route->head != _route->tail) {
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(oti.rad_use_route), TRUE);
        gtk_widget_grab_focus(oti.rad_use_route);
 }
@@ -466,7 +453,7 @@ while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
                /* Let them try again. */
        }
        /* Else, if GPS is enabled, replace the route, otherwise append it. */
-       else if (parse_gpx(&_route, rdl_data.bytes, rdl_data.bytes_read,
+       else if (parse_gpx(_route, rdl_data.bytes, rdl_data.bytes_read,
                           (gtk_toggle_button_get_active
                            (GTK_TOGGLE_BUTTON(oti.rad_use_gps)) ? 0 : 1))) {
                GtkTreeIter iter;
@@ -525,11 +512,11 @@ WayPoint *wnear;
 guint64 nearest_squared;
 Point pos = { unitx, unity, 0, NAN };
 
-wcurr = wnear = _route.whead;
-if (wcurr && wcurr->point && wcurr != _route.wtail) {
+wcurr = wnear = _route->whead;
+if (wcurr && wcurr->point && wcurr != _route->wtail) {
        nearest_squared = DISTANCE_SQUARED(pos, *(wcurr->point));
 
-       while (wcurr++ != _route.wtail) {
+       while (wcurr++ != _route->wtail) {
                guint64 test_squared = DISTANCE_SQUARED(pos, *(wcurr->point));
                if (test_squared < nearest_squared) {
                        wnear = wcurr;
@@ -578,7 +565,7 @@ if (_next_way) {
        /* Now, search _route for a closer point.  If quick is TRUE, then we'll
         * only search forward, only as long as we keep finding closer points.
         */
-       for (curr = _near_point; curr++ != _route.tail;) {
+       for (curr = _near_point; curr++ != _route->tail;) {
                if (curr->unity) {
                        guint dist_squared = DISTANCE_SQUARED(_gps->data, *curr);
                        if (dist_squared <= near_dist_squared) {
@@ -593,7 +580,7 @@ if (_next_way) {
        _near_point = near;
        _near_point_dist_squared = near_dist_squared;
 
-       for (wnext = wcurr = _next_way; wcurr != _route.wtail; wcurr++) {
+       for (wnext = wcurr = _next_way; wcurr != _route->wtail; wcurr++) {
                if (wcurr->point < near || (wcurr->point == near && quick 
                                && (_next_wpt && (DISTANCE_SQUARED(_gps->data, *near) > _next_way_dist_squared
                                && DISTANCE_SQUARED(_gps->data, *_next_wpt) < _next_wpt_dist_squared))))
@@ -610,7 +597,7 @@ if (_next_way) {
                        break;
        }
 
-       if (wnext == _route.wtail && (wnext->point < near || (wnext->point == near && quick
+       if (wnext == _route->wtail && (wnext->point < near || (wnext->point == near && quick
                                          && (_next_wpt && (DISTANCE_SQUARED (_gps->data, *near) > _next_way_dist_squared
                                               && DISTANCE_SQUARED(_gps->data, *_next_wpt) < _next_wpt_dist_squared)))))
        {
@@ -626,11 +613,11 @@ if (_next_way) {
                if (!quick || _next_way != wnext) {
                        _next_way = wnext;
                        _next_wpt = wnext->point;
-                       if (_next_wpt == _route.tail)
+                       if (_next_wpt == _route->tail)
                                _next_wpt = NULL;
                        else {
                                while (!(++_next_wpt)->unity) {
-                                       if (_next_wpt == _route.tail) {
+                                       if (_next_wpt == _route->tail) {
                                                _next_wpt = NULL;
                                                break;
                                        }
@@ -654,16 +641,16 @@ void
 route_find_nearest_point()
 {
 /* Initialize _near_point to first non-zero point. */
-_near_point = _route.head;
-while (!_near_point->unity && _near_point != _route.tail)
+_near_point = _route->head;
+while (!_near_point->unity && _near_point != _route->tail)
        _near_point++;
 
 /* Initialize _next_way. */
-if (_route.wtail == _route.whead - 1 || (_autoroute_data.enabled && _route.wtail == _route.whead))
+if (_route->wtail == _route->whead - 1 || (_autoroute_data.enabled && _route->wtail == _route->whead))
        _next_way = NULL;
 else
        /* We have at least one waypoint. */
-       _next_way = (_autoroute_data.enabled ? _route.whead + 1 : _route.whead);
+       _next_way = (_autoroute_data.enabled ? _route->whead + 1 : _route->whead);
 
 _next_way_dist_squared = -1;
 
@@ -742,11 +729,11 @@ route_set_destination_from_last(void)
 {
 Point *p;
 gdouble lat,lon;
-if (_route.head == _route.tail)
+if (_route->head == _route->tail)
        return;
 
 /* Find last non-zero point. */
-for (p = _route.tail; !p->unity; p--) {
+for (p = _route->tail; !p->unity; p--) {
 }
 unit2latlon(p->unitx, p->unity, lat, lon);
 _dest.valid=TRUE;
@@ -759,9 +746,9 @@ route_show_distance_to_last(void)
 {
 Point *p;
 
-if (_route.head != _route.tail) {
+if (_route->head != _route->tail) {
        /* Find last non-zero point. */
-       for (p = _route.tail; !p->unity; p--) {
+       for (p = _route->tail; !p->unity; p--) {
        }
        route_show_distance_to(p);
 } else {
index 31a65bfe1245953edd009d558fdbd2be099520d2..665025858f108485aa759be29d93e1ad967e08b5 100644 (file)
@@ -20,7 +20,7 @@
 #include "mapper-types.h"
 
 /** The current route. */
-Path _route;
+Path *_route;
 
 /** Data for tracking waypoints for the purpose of announcement. */
 
index c1797ac832d6d8ca625d166d0e8e88ffbd560daa..38166b87d8b08b6e80a27d18d8300d54ec2df46e 100644 (file)
@@ -31,19 +31,6 @@ static struct sql_select_stmt sql;
 /* Add sensitivity */
 static gint sensitivity=3;
 
-void
-track_init(void)
-{
-memset(&_track, 0, sizeof(_track));
-MACRO_PATH_INIT(_track);
-}
-
-void
-track_deinit(void)
-{
-MACRO_PATH_FREE(_track);
-}
-
 void 
 track_clear(void)
 {
@@ -52,9 +39,9 @@ GtkWidget *confirm;
 confirm = hildon_note_new_confirmation(GTK_WINDOW(_window), _("Clear the track?"));
 
 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
-       _track.tail = _track.head;
-       _track.length=_track.avgspeed=0.0;
-       _track.points=0;
+       _track->tail = _track->head;
+       _track->length=_track->avgspeed=0.0;
+       _track->points=0;
        map_force_redraw();
 }
 gtk_widget_destroy(confirm);
@@ -68,8 +55,8 @@ gdouble sum = 0.0;
 Point *curr;
 unit2latlon(_gps->data.unitx, _gps->data.unity, lat1, lon1);
 
-/* Skip _track.tail because that should be _gps. */
-for (curr = _track.tail; curr > point; --curr) {
+/* Skip _track->tail because that should be _gps. */
+for (curr = _track->tail; curr > point; --curr) {
        if (curr->unity) {
                unit2latlon(curr->unitx, curr->unity, lat2, lon2);
                sum += calculate_distance(lat1, lon1, lat2, lon2);
@@ -97,10 +84,10 @@ void
 track_show_distance_from_last()
 {
 /* Find last zero point. */
-if (_track.head != _track.tail) {
+if (_track->head != _track->tail) {
        Point *point;
        /* Find last zero point. */
-       for (point = _track.tail; point->unity; point--) {
+       for (point = _track->tail; point->unity; point--) {
        }
        track_show_distance_from(point);
 } else {
@@ -111,8 +98,8 @@ if (_track.head != _track.tail) {
 void 
 track_show_distance_from_first()
 {
-if (_track.head != _track.tail) {
-       track_show_distance_from(_track.head);
+if (_track->head != _track->tail) {
+       track_show_distance_from(_track->head);
 } else {
        MACRO_BANNER_SHOW_INFO(_window, _("The current track is empty."));
 }
@@ -129,15 +116,15 @@ gboolean
 track_add(GpsData *gps)
 {
 if (!gps) {
-       MACRO_PATH_INCREMENT_TAIL(_track);
-       *_track.tail=_point_null;
+       MACRO_PATH_INCREMENT_TAIL(*_track);
+       *_track->tail=_point_null;
        return FALSE;
 }
 
-if (abs((gint)gps->unitx-_track.tail->unitx) > sensitivity || abs((gint)gps->unity-_track.tail->unity) > sensitivity) {
+if (abs((gint)gps->unitx-_track->tail->unitx) > sensitivity || abs((gint)gps->unity-_track->tail->unity) > sensitivity) {
 
        /* If gps is available, update the nearest-waypoint data. */
-       if (gps && _route.head != _route.tail && (gps->newly_fixed ? (route_find_nearest_point(), TRUE) : route_update_nears(TRUE))) {
+       if (gps && _route->head != _route->tail && (gps->newly_fixed ? (route_find_nearest_point(), TRUE) : route_update_nears(TRUE))) {
                /* Nearest waypoint has changed - re-render paths. */
                map_render_paths();
                MACRO_QUEUE_DRAW_AREA();
@@ -149,11 +136,11 @@ if (abs((gint)gps->unitx-_track.tail->unitx) > sensitivity || abs((gint)gps->uni
                /* Instead of calling map_render_paths(), we'll draw the new line
                 * ourselves and call gtk_widget_queue_draw_area(). */
                map_render_segment(_gc[COLORABLE_TRACK], _gc[COLORABLE_TRACK_BREAK], 
-                       _track.tail->unitx, _track.tail->unity, gps->unitx, gps->unity);
+                       _track->tail->unitx, _track->tail->unity, gps->unitx, gps->unity);
 
-               if (_track.tail->unity && _track.tail->unitx) {
-                       tx1 = unit2x(_track.tail->unitx);
-                       ty1 = unit2y(_track.tail->unity);
+               if (_track->tail->unity && _track->tail->unitx) {
+                       tx1 = unit2x(_track->tail->unitx);
+                       ty1 = unit2y(_track->tail->unity);
                        tx2 = unit2x(gps->unitx);
                        ty2 = unit2y(gps->unity);
 
@@ -166,26 +153,26 @@ if (abs((gint)gps->unitx-_track.tail->unitx) > sensitivity || abs((gint)gps->uni
                }
        }
 
-       if (_track.tail->unity && _track.tail->unitx) {
+       if (_track->tail->unity && _track->tail->unitx) {
                gdouble lat, lon;
 
-               unit2latlon(_track.tail->unitx, _track.tail->unity, lat, lon);
-               _track.length += calculate_distance(lat, lon, gps->lat, gps->lon);
-               _track.tspeed+=gps->speed;
-               if (_track.points>0)
-                       _track.avgspeed=_track.tspeed/_track.points;
+               unit2latlon(_track->tail->unitx, _track->tail->unity, lat, lon);
+               _track->length += calculate_distance(lat, lon, gps->lat, gps->lon);
+               _track->tspeed+=gps->speed;
+               if (_track->points>0)
+                       _track->avgspeed=_track->tspeed/_track->points;
                else
-                       _track.avgspeed=0.0;
-               g_debug("TRACK: %f %f (%d)", _track.length, _track.avgspeed, _track.points);
+                       _track->avgspeed=0.0;
+               g_debug("TRACK: %f %f (%d)", _track->length, _track->avgspeed, _track->points);
        }
 
-       MACRO_PATH_INCREMENT_TAIL(_track);
-       _track.tail->unitx=gps->unitx;
-       _track.tail->unity=gps->unity;
-       _track.tail->time=gps->time;
-       _track.tail->altitude=gps->altitude;
-       _track.maxspeed=gps->maxspeed;
-       _track.points++;
+       MACRO_PATH_INCREMENT_TAIL(*_track);
+       _track->tail->unitx=gps->unitx;
+       _track->tail->unity=gps->unity;
+       _track->tail->time=gps->time;
+       _track->tail->altitude=gps->altitude;
+       _track->maxspeed=gps->maxspeed;
+       _track->points++;
 }
 
 /* Keep the display on if we are moving. */
@@ -196,19 +183,19 @@ return TRUE;
 gboolean 
 track_insert_break(void)
 {
-if (_track.tail->unity) {
+if (_track->tail->unity) {
        guint x1, y1;
 
        /* To mark a "waypoint" in a track, we'll add a (0, 0) point and then
         * another instance of the most recent track point. */
-       MACRO_PATH_INCREMENT_TAIL(_track);
-       *_track.tail=_point_null;
-       MACRO_PATH_INCREMENT_TAIL(_track);
-       *_track.tail=_track.tail[-2];
+       MACRO_PATH_INCREMENT_TAIL(*_track);
+       *_track->tail=_point_null;
+       MACRO_PATH_INCREMENT_TAIL(*_track);
+       *_track->tail=_track->tail[-2];
 
        /* Instead of calling map_render_paths(), we'll just draw the waypoint ourselves. */
-       x1 = unit2bufx(_track.tail->unitx);
-       y1 = unit2bufy(_track.tail->unity);
+       x1 = unit2bufx(_track->tail->unitx);
+       y1 = unit2bufy(_track->tail->unity);
        map_render_waypoint(x1, y1, _gc[COLORABLE_TRACK_BREAK]);
 }
 return FALSE;
@@ -222,7 +209,7 @@ gint size;
 gboolean r = FALSE;
 
 if (file_open_get_contents(&_track_file_uri, &buffer, &size)) {
-       if (parse_gpx(&_track, buffer, size, -1)) {
+       if (parse_gpx(_track, buffer, size, -1)) {
                map_force_redraw();
                MACRO_BANNER_SHOW_INFO(_window, _("Track Opened"));
                r = TRUE;
@@ -241,7 +228,7 @@ GnomeVFSHandle *handle;
 gboolean r = FALSE;
 
 if (file_save(&_track_file_uri, &_track_file_uri, &handle)) {
-       if (write_gpx(&_track, handle)) {
+       if (write_gpx(_track, handle)) {
                MACRO_BANNER_SHOW_INFO(_window, _("Track Saved"));
                r = TRUE;
                track_clear();
@@ -315,7 +302,7 @@ while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
        gtk_text_buffer_get_end_iter(tbuf, &ti2);
 
        if (gtk_text_buffer_get_char_count(tbuf)>0) {
-               path_insert_mark_text(&_track, gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE));
+               path_insert_mark_text(_track, gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE));
        } else {
                popup_error(dialog, _("Please provide a description for the mark."));
                continue;
index ffd179e75351d7c180f77da992429b7dde892413..43370d93dde06af595ccf0de87edbf3cbcbee140 100644 (file)
@@ -5,7 +5,7 @@
 #include <sqlite3.h>
 #include "filter.h"
 
-Path _track;
+Path *_track;
 
 #define TRACK_SQL_SELECT_TRACKS "select id,name,slat,slon,elat,elon,len,sdate,edate from tracks order by sdate"
 #define TRACK_SQL_INSERT_TRACK "insert into tracks (id,name,sloc,sdate) values (?,?,?,?);