]> err.no Git - mapper/commitdiff
Add route_generate_store that return a list store of the route
authorKaj-Michael Lang <milang@angel.tal.org>
Fri, 19 Oct 2007 10:58:07 +0000 (13:58 +0300)
committerKaj-Michael Lang <milang@angel.tal.org>
Fri, 19 Oct 2007 10:58:07 +0000 (13:58 +0300)
src/route.c

index c9886542b32a61065e85db664aa2ee7d10543db8..07772aa6aab3bab0be85e44b133a896872a4a5b4 100644 (file)
@@ -720,4 +720,47 @@ if (_route.head != _route.tail) {
        }
 }
 
+/***/
 
+GtkListStore *
+route_generate_store(void)
+{
+WayPoint *wcurr;
+GtkTreeIter iter;
+GtkListStore *store;
+gchar buffer1[80];
+gchar buffer2[32];
+gdouble lat1, lon1, lat2, lon2;
+gfloat sum=0.0;
+
+if (_route.whead==_route.wtail)
+       return NULL;
+
+store = gtk_list_store_new(ROUTE_NUM_COLUMNS,G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+wcurr = _route.whead;
+unit2latlon(wcurr->point->unitx, wcurr->point->unity, lat1, lon1);
+
+while (wcurr!=_route.wtail) {
+       if (!wcurr)
+               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]);
+
+       lat1=lat2;
+       lon1=lon2;
+
+       gtk_list_store_append(store, &iter);
+       gtk_list_store_set(store, &iter,
+        ROUTE_LATLON, buffer1,
+               ROUTE_DISTANCE, buffer2,
+               ROUTE_WAYPOINT, wcurr->desc,
+               -1);
+
+       wcurr++;
+}
+
+return store;
+}