]> err.no Git - mapper/commitdiff
Split path functions from track.c to path.c
authorKaj-Michael Lang <milang@angel.tal.org>
Wed, 8 Aug 2007 22:18:04 +0000 (01:18 +0300)
committerKaj-Michael Lang <milang@angel.tal.org>
Wed, 8 Aug 2007 22:18:04 +0000 (01:18 +0300)
src/path.c
src/path.h [new file with mode: 0644]
src/track.c
src/track.h

index 68d636faab474763dcd27f422f1812495f6d8210..f4ee62d52b48c0eb048682b9875ef0afec1f56e1 100644 (file)
@@ -1,35 +1,45 @@
-void path_resize(Path * path, guint size)
+#include <config.h>
+
+#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 (file)
index 0000000..4a41b5d
--- /dev/null
@@ -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
index 408e46a83917e87bfc66a6a685687d07e0641d19..540175f07c4ba41f11c69964445154cc0dc06e83 100644 (file)
 #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;
index 91a5b80bacb92f41f2e6745a185edd8f57f4cfb8..a7dfadba61b84f8bf59623b76be6640fa895de4b 100644 (file)
@@ -4,18 +4,6 @@
 #include <glib.h>
 #include <sqlite3.h>
 
-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