From cce854af5945810bcbf0faabda2a10d6e654945a Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Thu, 9 Aug 2007 01:18:04 +0300 Subject: [PATCH] Split path functions from track.c to path.c --- src/path.c | 64 ++++++++++-------- src/path.h | 7 ++ src/track.c | 183 ++++++++++++++++++++++++---------------------------- src/track.h | 23 ++++--- 4 files changed, 139 insertions(+), 138 deletions(-) create mode 100644 src/path.h diff --git a/src/path.c b/src/path.c index 68d636f..f4ee62d 100644 --- a/src/path.c +++ b/src/path.c @@ -1,35 +1,45 @@ -void path_resize(Path * path, guint size) +#include + +#include "utils.h" +#include "map.h" +#include "route.h" +#include "mapper-types.h" + +#include "track.h" + +void +path_resize(Path * path, guint size) { - printf("%s()\n", __PRETTY_FUNCTION__); - - if (path->head + size != path->cap) { - Point *old_head = path->head; - WayPoint *curr; - path->head = g_renew(Point, old_head, size); - path->cap = path->head + size; - if (path->head != old_head) { - path->tail = path->head + (path->tail - old_head); - - /* Adjust all of the waypoints. */ - for (curr = path->whead - 1; curr++ != path->wtail;) - curr->point = - path->head + (curr->point - old_head); - } - } +printf("%s()\n", __PRETTY_FUNCTION__); + +if (path->head + size != path->cap) { + Point *old_head = path->head; + WayPoint *curr; + path->head = g_renew(Point, old_head, size); + path->cap = path->head + size; + if (path->head != old_head) { + path->tail = path->head + (path->tail - old_head); - vprintf("%s(): return\n", __PRETTY_FUNCTION__); + /* Adjust all of the waypoints. */ + for (curr = path->whead - 1; curr++ != path->wtail;) + curr->point = + path->head + (curr->point - old_head); + } +} +vprintf("%s(): return\n", __PRETTY_FUNCTION__); } -void path_wresize(Path * path, guint wsize) +void +path_wresize(Path * path, guint wsize) { - printf("%s()\n", __PRETTY_FUNCTION__); +printf("%s()\n", __PRETTY_FUNCTION__); - if (path->whead + wsize != path->wcap) { - WayPoint *old_whead = path->whead; - path->whead = g_renew(WayPoint, old_whead, wsize); - path->wtail = path->whead + (path->wtail - old_whead); - path->wcap = path->whead + wsize; - } +if (path->whead + wsize != path->wcap) { + WayPoint *old_whead = path->whead; + path->whead = g_renew(WayPoint, old_whead, wsize); + path->wtail = path->whead + (path->wtail - old_whead); + path->wcap = path->whead + wsize; +} - vprintf("%s(): return\n", __PRETTY_FUNCTION__); +vprintf("%s(): return\n", __PRETTY_FUNCTION__); } diff --git a/src/path.h b/src/path.h new file mode 100644 index 0000000..4a41b5d --- /dev/null +++ b/src/path.h @@ -0,0 +1,7 @@ +#ifndef _PATH_H +#define _PATH_H + +void path_resize(Path * path, guint size); +void path_wresize(Path * path, guint wsize); + +#endif diff --git a/src/track.c b/src/track.c index 408e46a..540175f 100644 --- a/src/track.c +++ b/src/track.c @@ -10,44 +10,20 @@ #include "file.h" #include "track.h" - -void path_resize(Path * path, guint size) -{ - printf("%s()\n", __PRETTY_FUNCTION__); - - if (path->head + size != path->cap) { - Point *old_head = path->head; - WayPoint *curr; - path->head = g_renew(Point, old_head, size); - path->cap = path->head + size; - if (path->head != old_head) { - path->tail = path->head + (path->tail - old_head); - - /* Adjust all of the waypoints. */ - for (curr = path->whead - 1; curr++ != path->wtail;) - curr->point = - path->head + (curr->point - old_head); - } - } - - vprintf("%s(): return\n", __PRETTY_FUNCTION__); -} - -void path_wresize(Path * path, guint wsize) -{ - printf("%s()\n", __PRETTY_FUNCTION__); - - if (path->whead + wsize != path->wcap) { - WayPoint *old_whead = path->whead; - path->whead = g_renew(WayPoint, old_whead, wsize); - path->wtail = path->whead + (path->wtail - old_whead); - path->wcap = path->whead + wsize; - } - - vprintf("%s(): return\n", __PRETTY_FUNCTION__); -} - -void track_clear() +#include "path.h" + +struct sql_select_stmt { + sqlite3_stmt *select_track; + sqlite3_stmt *select_track_nodes; + sqlite3_stmt *insert_track; + sqlite3_stmt *insert_track_node; + sqlite3_stmt *delete_track_nodes; + sqlite3_stmt *delete_track; +}; +static struct sql_select_stmt sql; + +void +track_clear(void) { GtkWidget *confirm; @@ -62,7 +38,8 @@ void track_clear() gtk_widget_destroy(confirm); } -gfloat track_calculate_distance_from(Point * point) +gfloat +track_calculate_distance_from(Point * point) { gfloat lat1, lon1, lat2, lon2; gfloat sum = 0.0; @@ -83,7 +60,8 @@ gfloat track_calculate_distance_from(Point * point) return sum; } -void track_show_distance_from(Point * point) +void +track_show_distance_from(Point * point) { gchar buffer[80]; gfloat sum; @@ -95,7 +73,8 @@ void track_show_distance_from(Point * point) MACRO_BANNER_SHOW_INFO(_window, buffer); } -void track_show_distance_from_last() +void +track_show_distance_from_last() { printf("%s()\n", __PRETTY_FUNCTION__); @@ -113,7 +92,8 @@ void track_show_distance_from_last() printf("%s(): return\n", __PRETTY_FUNCTION__); } -void track_show_distance_from_first() +void +track_show_distance_from_first() { printf("%s()\n", __PRETTY_FUNCTION__); @@ -138,7 +118,8 @@ void track_show_distance_from_first() * then _point_null is appended to _track with time zero (this produces a "break" * in the track). */ -void track_add(time_t time, gboolean newly_fixed) +void +track_add(time_t time, gboolean newly_fixed) { gboolean show_directions = TRUE; gint announce_thres_unsquared; @@ -213,77 +194,81 @@ void track_add(time_t time, gboolean newly_fixed) vprintf("%s(): return\n", __PRETTY_FUNCTION__); } -void track_insert_break(void) +void +track_insert_break(void) { - printf("%s()\n", __PRETTY_FUNCTION__); - - if (_track.tail->unity) { - guint x1, y1; +printf("%s()\n", __PRETTY_FUNCTION__); - /* 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]; - - /** Instead of calling map_render_paths(), we'll just add the waypoint - * ourselves. */ - x1 = unit2bufx(_track.tail->unitx); - y1 = unit2bufy(_track.tail->unity); - /* Make sure this circle will be visible. */ - if ((x1 < BUF_WIDTH_PIXELS) && ((unsigned)y1 < BUF_HEIGHT_PIXELS)) - gdk_draw_arc(_map_pixmap, _gc[COLORABLE_TRACK_BREAK], FALSE, /* FALSE: not filled. */ - x1 - _draw_width, y1 - _draw_width, 2 * _draw_width, 2 * _draw_width, 0, /* start at 0 degrees. */ - 360 * 64); - } else { - MACRO_BANNER_SHOW_INFO(_window, _("Break already inserted.")); - } +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]; + +/** Instead of calling map_render_paths(), we'll just add the waypoint + * ourselves. */ +x1 = unit2bufx(_track.tail->unitx); +y1 = unit2bufy(_track.tail->unity); +/* Make sure this circle will be visible. */ +if ((x1 < BUF_WIDTH_PIXELS) && ((unsigned)y1 < BUF_HEIGHT_PIXELS)) + gdk_draw_arc(_map_pixmap, _gc[COLORABLE_TRACK_BREAK], FALSE, /* FALSE: not filled. */ + x1 - _draw_width, y1 - _draw_width, 2 * _draw_width, 2 * _draw_width, 0, /* start at 0 degrees. */ + 360 * 64); +} else { + MACRO_BANNER_SHOW_INFO(_window, _("Break already inserted.")); +} - vprintf("%s(): return\n", __PRETTY_FUNCTION__); +vprintf("%s(): return\n", __PRETTY_FUNCTION__); } -gboolean track_open(void) +gboolean +track_open(void) { - gchar *buffer; - gint size; - gboolean r = FALSE; - - if (open_file(&buffer, NULL, &size, NULL, &_track_file_uri, GTK_FILE_CHOOSER_ACTION_OPEN)) { - if (parse_gpx(&_track, buffer, size, -1)) { - map_force_redraw(); - MACRO_BANNER_SHOW_INFO(_window, _("Track Opened")); - r = TRUE; - } else { - popup_error(_window, _("Error parsing GPX file.")); - } - g_free(buffer); +gchar *buffer; +gint size; +gboolean r = FALSE; + +if (open_file(&buffer, NULL, &size, NULL, &_track_file_uri, GTK_FILE_CHOOSER_ACTION_OPEN)) { + if (parse_gpx(&_track, buffer, size, -1)) { + map_force_redraw(); + MACRO_BANNER_SHOW_INFO(_window, _("Track Opened")); + r = TRUE; + } else { + popup_error(_window, _("Error parsing GPX file.")); } - return r; + g_free(buffer); +} +return r; } -gboolean track_save(void) +gboolean +track_save(void) { - GnomeVFSHandle *handle; - gboolean r = FALSE; - - if (file_save(&_track_file_uri, &_track_file_uri, &handle)) { - if (write_gpx(&_track, handle)) { - MACRO_BANNER_SHOW_INFO(_window, _("Track Saved")); - r = TRUE; - } else { - popup_error(_window, _("Error writing GPX file.")); - } - gnome_vfs_close(handle); +GnomeVFSHandle *handle; +gboolean r = FALSE; + +if (file_save(&_track_file_uri, &_track_file_uri, &handle)) { + if (write_gpx(&_track, handle)) { + MACRO_BANNER_SHOW_INFO(_window, _("Track Saved")); + r = TRUE; + } else { + popup_error(_window, _("Error writing GPX file.")); } - return r; + gnome_vfs_close(handle); +} +return r; } /** * Add a text description at current point * */ -void track_insert_mark_text(gchar *text) +void +track_insert_mark_text(gchar *text) { MACRO_PATH_INCREMENT_WTAIL(_track); _track.wtail->point = _track.tail; @@ -294,8 +279,8 @@ _track.wtail->desc = text; * Ask for a text description for the current point * */ - -gboolean track_insert_mark(void) +gboolean +track_insert_mark(void) { gfloat lat, lon; gchar tmp1[16], tmp2[16], *p_latlon; diff --git a/src/track.h b/src/track.h index 91a5b80..a7dfadb 100644 --- a/src/track.h +++ b/src/track.h @@ -4,18 +4,6 @@ #include #include -void track_add(time_t time, gboolean newly_fixed); -void track_insert_break(void); -gboolean track_insert_mark(void); -gboolean track_save(void); -gboolean track_open(void); - -void track_show_distance_from_first(); -void track_show_distance_from_last(); -void track_show_distance_from(Point * point); -void path_wresize(Path * path, guint wsize); -void path_resize(Path * path, guint size); - #define TRACK_SQL_SELECT_TRACKS "select id,name,sloc,eloc,sdate,edate from tracks order by sdate" #define TRACK_SQL_INSERT_TRACK "insert into tracks (id,name,sloc,sdate) values (?,?,?,?); #define TRACK_SQL_INSERT_TRACK_POINT "insert into trackpoints (tid,dt,lat,lon,alt,hdop,vdop,pdop,sat,fix) values (?,?,?,?,?,?,?,?,?,?)" @@ -28,4 +16,15 @@ struct { sqlite3_stmt *_select_track_points; } track_sql; +void track_add(time_t time, gboolean newly_fixed); +void track_insert_break(void); +gboolean track_insert_mark(void); +gboolean track_save(void); +gboolean track_open(void); +void track_clear(void); + +void track_show_distance_from_first(); +void track_show_distance_from_last(); +void track_show_distance_from(Point * point); + #endif -- 2.39.5