]> err.no Git - mapper/blobdiff - src/path.c
Include settings.h so the banner macro hildon version works.
[mapper] / src / path.c
index 68d636faab474763dcd27f422f1812495f6d8210..8876587918a341336c63376fc8e60fcbe8866da2 100644 (file)
@@ -1,35 +1,97 @@
-void path_resize(Path * path, guint size)
+#include <config.h>
+
+#include <gtk/gtk.h>
+
+#include "utils.h"
+#include "map.h"
+#include "route.h"
+#include "mapper-types.h"
+#include "track.h"
+#include "path.h"
+#include "settings.h"
+#include "latlon.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);
-               }
+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)
+{
+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;
+}
 }
 
-void path_wresize(Path * path, guint wsize)
+GtkListStore *
+path_generate_store(Path *path)
 {
-       printf("%s()\n", __PRETTY_FUNCTION__);
+WayPoint *wcurr;
+GtkTreeIter iter;
+GtkListStore *store;
+gchar buffer1[80];
+gchar buffer2[32];
+gdouble lat1, lon1, lat2, lon2;
+gdouble sum=0.0;
 
-       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==path->wtail)
+       return NULL;
+
+wcurr=path->whead;
+
+if (!wcurr)
+       return NULL;
+
+if (!wcurr->point)
+       return NULL;
+
+unit2latlon(wcurr->point->unitx, wcurr->point->unity, lat1, lon1);
+
+store = gtk_list_store_new(ROUTE_NUM_COLUMNS,G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
+
+while (wcurr!=path->wtail) {
+       if (!wcurr)
+               break;
+
+       if (!wcurr->point)
+               break;
+
+       unit2latlon(wcurr->point->unitx, wcurr->point->unity, lat2, lon2);
+       g_snprintf(buffer1, sizeof(buffer1), "%.05f,%.05f", lat2, lon2);
+       sum += calculate_distance(lat1, lon1, lat2, lon2);
+       g_snprintf(buffer2, sizeof(buffer2), "%.02f %s", sum * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
+
+       gtk_list_store_append(store, &iter);
+       gtk_list_store_set(store, &iter,
+        ROUTE_LATLON, buffer1,
+               ROUTE_DISTANCE, buffer2,
+               ROUTE_WAYPOINT, wcurr->desc,
+               ROUTE_LAT, lat2,
+               ROUTE_LON, lon2,
+               -1);
+
+       lat1=lat2;
+       lon1=lon2;
+
+       wcurr++;
+}
 
-       vprintf("%s(): return\n", __PRETTY_FUNCTION__);
+return store;
 }