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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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();
}
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;
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 {
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;
&& 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--;
/* 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();
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;
}
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);
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);
_("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
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) {
}
}
if (_show_tracks & TRACKS_MASK)
- map_render_path(&_track, _gc + COLORABLE_TRACK);
+ map_render_path(_track, _gc + COLORABLE_TRACK);
}
/**
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
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";
void
path_free(Path *p)
{
+g_return_if_fail(p);
MACRO_PATH_FREE(*p);
g_slice_free(Path, p);
}
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)
{
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();
}
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"));
{
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."));
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);
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),
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);
}
/* 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;
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;
/* 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) {
_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))))
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)))))
{
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;
}
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;
{
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;
{
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 {
#include "mapper-types.h"
/** The current route. */
-Path _route;
+Path *_route;
/** Data for tracking waypoints for the purpose of announcement. */
/* 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)
{
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);
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);
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 {
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."));
}
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();
/* 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);
}
}
- 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. */
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;
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;
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();
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;
#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 (?,?,?,?);