]> err.no Git - mapper/blob - src/path.c
More map widget integration changes
[mapper] / src / path.c
1 /*
2  * This file is part of mapper
3  *
4  * Copyright (C) 2008 Kaj-Michael Lang
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 #include <config.h>
21
22 #include <glib.h>
23 #include <gtk/gtk.h>
24 #include <sqlite3.h>
25
26 #include "path.h"
27 #include "position.h"
28 #include "utils.h"
29 #include "gps.h"
30 #include "settings.h"
31 #include "latlon.h"
32 #include "gpx.h"
33
34 struct sql_select_stmt {
35         sqlite3_stmt *select_paths;
36         sqlite3_stmt *select_path_nodes;
37
38         sqlite3_stmt *insert_path;
39         sqlite3_stmt *insert_path_node;
40
41         sqlite3_stmt *delete_path;
42         sqlite3_stmt *delete_path_nodes;
43 };
44 static struct sql_select_stmt sql;
45
46 #define PATH_TABLE_PATHS "create table IF NOT EXISTS paths ( \
47         nid             int primary key, \
48         name    text not null, \
49         desc    text, \
50         t               int not null);"
51
52 #define PATH_TABLE_NODES "create table IF NOT EXISTS path_nodes ( \
53         nid             int not null, \
54         lat     real not null, \
55         lon     real not null, \
56         sats    int, \
57         speed   real, \
58         course  real, \
59         pdop    real, \
60         hdop    real, \
61         vdop    real, \
62         name    text default null, \
63         t               int not null);"
64
65 enum {
66         NEW_POINT,                              /* A new point was appended to track track */
67         NEW_BREAK,                              /* A break was appended to the track */
68         NEW_WAYPOINT,                   /* A new waypoint/marker has been added */
69         NEAR_WAYPOINT,                  /* We are near the next route waypoint */
70         REACHED_WAYPOINT,               /* We have reached the next route waypoint */
71         REACHED_DESTINATION,    /* We have reached the last route waypoint */
72         CLEARED,                                /* Path was cleared */
73         LAST_SIGNAL
74 };
75 static guint32 signals[LAST_SIGNAL] = {0};
76
77 G_DEFINE_TYPE(Path, path, G_TYPE_OBJECT);
78
79 /* #define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PATH_TYPE, PathPrivate)) */
80
81 static void
82 path_dispose(GObject *object)
83 {
84 g_debug("path_dispose");
85
86 G_OBJECT_CLASS(path_parent_class)->dispose(object);
87 }
88
89 static void
90 path_finalize(GObject *object)
91 {
92 Path *path=PATH(object);
93
94 g_debug("path_finalize");
95 MACRO_PATH_FREE(*path);
96
97 if (path->name)
98         g_free(path->name);
99 if (path->desc)
100         g_free(path->desc);
101 if (path->author)
102         g_free(path->author);
103 if (path->keywords)
104         g_free(path->keywords);
105 if (path->copyright)
106         g_free(path->copyright);
107 if (path->src)
108         g_free(path->src);
109 }
110
111 static void
112 path_class_init(PathClass *klass)
113 {
114 GObjectClass *object_class=G_OBJECT_CLASS(klass);
115
116 g_debug("path_class_init");
117
118 object_class->dispose=path_dispose;
119 object_class->finalize=path_finalize;
120 /* g_type_class_add_private (klass, sizeof(PathPrivate)); */
121
122 signals[NEW_POINT]=g_signal_new("new-point", G_OBJECT_CLASS_TYPE(object_class),
123         G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(PathClass, new_point),
124         NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, NULL);
125 signals[NEW_BREAK]=g_signal_new("new-break", G_OBJECT_CLASS_TYPE(object_class),
126         G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(PathClass, new_break),
127         NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, NULL);
128 signals[NEW_WAYPOINT]=g_signal_new("new-waypoint", G_OBJECT_CLASS_TYPE(object_class),
129         G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(PathClass, new_waypoint),
130         NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, NULL);
131 }
132
133 static void
134 path_init(Path *path)
135 {
136 g_debug("path_init");
137 MACRO_PATH_INIT(*path);
138 }
139
140 Path *
141 path_new(PathType type, guint id)
142 {
143 Path *p;
144
145 p=g_object_new(PATH_TYPE, NULL);
146 p->type=type;
147 p->id=id;
148 p->sensitivity=3;
149 return p;
150 }
151
152 void
153 path_free(Path *path)
154 {
155 g_return_if_fail(path);
156 g_object_unref(path);
157 }
158
159 void
160 path_clear(Path *path)
161 {
162 g_return_if_fail(path);
163 MACRO_PATH_FREE(*path);
164 path->length=path->avgspeed=0.0;
165 path->points=0;
166 }
167
168 gboolean
169 path_resize(Path *path, guint size)
170 {
171 g_return_val_if_fail(path, FALSE);
172
173 if (path->head + size != path->cap) {
174         WayPoint *curr;
175         Point *old_head = path->head;
176
177         path->head = g_renew(Point, old_head, size);
178         g_assert(path->head);
179         path->cap = path->head + size;
180         if (path->head != old_head) {
181                 path->tail = path->head + (path->tail - old_head);
182
183                 /* Adjust all of the waypoints. */
184                 for (curr = path->whead - 1; curr++ != path->wtail;)
185                         curr->point = path->head + (curr->point - old_head);
186         }
187         return TRUE;
188 }
189 return FALSE;
190 }
191
192 gboolean 
193 path_wresize(Path *path, guint wsize)
194 {
195 g_return_val_if_fail(path, FALSE);
196
197 if (path->whead + wsize != path->wcap) {
198         WayPoint *old_whead = path->whead;
199
200         path->whead = g_renew(WayPoint, old_whead, wsize);
201         path->wtail = path->whead + (path->wtail - old_whead);
202         path->wcap = path->whead + wsize;
203
204         return TRUE;
205 }
206 return FALSE;
207 }
208
209 /**
210  * Append a waypoint to path at given lat, lon with description desc
211  */
212 gboolean
213 path_add_waypoint(Path *path, gdouble lat, gdouble lon, gchar *desc)
214 {
215 guint unitx, unity;
216
217 latlon2unit(lat, lon, unitx, unity);
218 MACRO_PATH_INCREMENT_TAIL(*path);
219 path->tail->unitx=unitx;
220 path->tail->unity=unity;
221 path->tail->time=0;
222 path->tail->altitude=NAN;
223
224 MACRO_PATH_INCREMENT_WTAIL(*path);
225 path->wtail->point=path->tail;
226 path->wtail->desc=desc;
227
228 path_find_nearest_point(path);
229
230 g_signal_emit(G_OBJECT(path), signals[NEW_WAYPOINT], 0, NULL);
231
232 return TRUE;
233 }
234
235 /**
236  * Append a path point to path
237  *
238  * Returns: TRUE if the new point was added. FALSE is returned if new point distance was under sensitivity setting.
239  */
240 gboolean
241 path_add_point(Path *path, GpsData *gps)
242 {
243 guint unitx, unity;
244
245 g_return_val_if_fail(path, FALSE);
246
247 if (!gps) {
248         path_add_break(path);
249         return FALSE;
250 }
251
252 latlon2unit(gps->lat, gps->lon, unitx, unity);
253
254 if (abs((gint)unitx-path->tail->unitx) > path->sensitivity || abs((gint)unity-path->tail->unity) > path->sensitivity) {
255         if (path->tail->unity && path->tail->unitx) {
256                 gdouble lat, lon;
257
258                 unit2latlon(path->tail->unitx, path->tail->unity, lat, lon);
259                 path->length+=calculate_distance(lat, lon, gps->lat, gps->lon);
260         }
261         MACRO_PATH_INCREMENT_TAIL(*path);
262         path->tail->unitx=unitx;
263         path->tail->unity=unity;
264         path->tail->time=gps->time;
265         path->tail->altitude=gps->altitude;
266         path->maxspeed=gps->maxspeed;
267         path->tspeed+=gps->speed;
268         path->avgspeed=(path->points>0) ? path->tspeed/path->points : 0.0;
269         path->points++;
270         g_debug("TRACK: %f %f (%d)", path->length, path->avgspeed, path->points);
271
272         g_signal_emit(G_OBJECT(path), signals[NEW_POINT], 0, NULL);
273         return TRUE;
274 }
275
276 return FALSE;
277 }
278
279 gboolean 
280 path_add_break(Path *path)
281 {
282 g_return_val_if_fail(path, FALSE);
283 g_return_val_if_fail(path->tail, FALSE);
284
285 if (path->tail->unity && path->tail->unitx) {
286         guint x1, y1;
287
288         /* To mark a "break" in a track, we'll add a (0, 0) point and then 
289            another instance of the most recent track point. */
290
291         MACRO_PATH_INCREMENT_TAIL(*path);
292         *path->tail=_point_null;
293         MACRO_PATH_INCREMENT_TAIL(*path);
294         *path->tail=path->tail[-2];
295
296         g_signal_emit(G_OBJECT(path), signals[NEW_BREAK], 0, NULL);
297
298         return TRUE;
299 }
300 return FALSE;
301 }
302
303 gboolean
304 path_has_points(Path *path)
305 {
306 g_return_val_if_fail(path, FALSE);
307 return path->head==path->tail ? FALSE : TRUE;
308 }
309
310 gboolean
311 path_has_waypoints(Path *path)
312 {
313 g_return_val_if_fail(path, FALSE);
314 return path->whead==path->wtail ? FALSE : TRUE;
315 }
316
317 Point *
318 path_find_last_point(Path *path)
319 {
320 Point *p=NULL;
321
322 g_return_val_if_fail(path, NULL);
323
324 if (!path_has_points(path))
325         return p;
326
327 for (p=path->tail; !p->unity; p--) {
328 }
329 return p;
330 }
331
332 /**
333  * Updates near_point, next_way, and next_wpt.  If quick is FALSE (as
334  * it is when this function is called from route_find_nearest_point), then
335  * the entire list (starting from near_point) is searched.  Otherwise, we
336  * stop searching when we find a point that is farther away.
337  */
338 gboolean 
339 path_update_nears(Path *path, Point *point, gboolean quick)
340 {
341 gboolean ret = FALSE;
342 Point *curr, *near;
343 WayPoint *wcurr, *wnext;
344 guint64 near_dist_squared;
345
346 g_return_val_if_fail(path, FALSE);
347
348 /* If we have waypoints (_next_way != NULL), then determine the "next
349  * waypoint", which is defined as the waypoint after the nearest point,
350  * UNLESS we've passed that waypoint, in which case the waypoint after
351  * that waypoint becomes the "next" waypoint. */
352 if (path->next_way) {
353         /* First, set near_dist_squared with the new distance from
354          * near_point. */
355         near = path->near_point;
356         near_dist_squared = DISTANCE_SQUARED(*point, *near);
357
358         /* Now, search path for a closer point.  If quick is TRUE, then we'll
359          * only search forward, only as long as we keep finding closer points.
360          */
361         for (curr = path->near_point; curr++ != path->tail;) {
362                 if (curr->unity) {
363                         guint dist_squared = DISTANCE_SQUARED(*point, *curr);
364                         if (dist_squared <= near_dist_squared) {
365                                 near = curr;
366                                 near_dist_squared = dist_squared;
367                         } else if (quick)
368                                 break;
369                 }
370         }
371
372         /* Update _near_point. */
373         path->near_point = near;
374         path->near_point_dist_squared = near_dist_squared;
375
376         for (wnext = wcurr = path->next_way; wcurr != path->wtail; wcurr++) {
377                 if (wcurr->point < near || (wcurr->point == near && quick 
378                                 && (path->next_wpt && (DISTANCE_SQUARED(*point, *near) > path->next_way_dist_squared
379                                 && DISTANCE_SQUARED(*point, *path->next_wpt) < path->next_wpt_dist_squared))))
380                     /* Okay, this else if expression warrants explanation.  If the
381                      * nearest track point happens to be a waypoint, then we want to
382                      * check if we have "passed" that waypoint.  To check this, we
383                      * test the distance from _gps to the waypoint and from _gps to
384                      * _next_wpt, and if the former is increasing and the latter is
385                      * decreasing, then we have passed the waypoint, and thus we
386                      * should skip it.  Note that if there is no _next_wpt, then
387                      * there is no next waypoint, so we do not skip it in that case. */
388                         wnext = wcurr + 1;
389                 else
390                         break;
391         }
392
393         if (wnext == path->wtail && (wnext->point < near || (wnext->point == near && quick
394                                           && (path->next_wpt && (DISTANCE_SQUARED (*point, *near) > path->next_way_dist_squared
395                                                && DISTANCE_SQUARED(*point, *path->next_wpt) < path->next_wpt_dist_squared)))))
396         {
397                 path->next_way = NULL;
398                 path->next_wpt = NULL;
399                 path->next_way_dist_squared = -1;
400                 path->next_wpt_dist_squared = -1;
401                 ret = TRUE;
402         }
403         /* Only update next_way (and consequently _next_wpt) if _next_way is
404          * different, and record that fact for return. */
405         else {
406                 if (!quick || path->next_way != wnext) {
407                         path->next_way = wnext;
408                         path->next_wpt = wnext->point;
409                         if (path->next_wpt == path->tail)
410                                 path->next_wpt = NULL;
411                         else {
412                                 while (!(++path->next_wpt)->unity) {
413                                         if (path->next_wpt == path->tail) {
414                                                 path->next_wpt = NULL;
415                                                 break;
416                                         }
417                                 }
418                         }
419                         ret = TRUE;
420                 }
421                 path->next_way_dist_squared = DISTANCE_SQUARED(*point, *wnext->point);
422                 if (path->next_wpt)
423                         path->next_wpt_dist_squared = DISTANCE_SQUARED(*point, *path->next_wpt);
424         }
425 }
426 return ret;
427 }
428
429 /**
430  * Reset the near_point data by searching the entire path for the nearest point and waypoint.
431  */
432 void 
433 path_find_nearest_point(Path *path)
434 {
435 g_return_if_fail(path);
436
437 /* Initialize near_point to first non-zero point. */
438 path->near_point=path->head;
439 while (!path->near_point->unity && path->near_point != path->tail)
440         path->near_point++;
441
442 /* Initialize next_way */
443 if (path->wtail==path->whead)
444         path->next_way=NULL;
445 else
446         path->next_way=path->whead;
447 path->next_way_dist_squared=-1;
448
449 /* Initialize next_wpt */
450 path->next_wpt=NULL;
451 path->next_wpt_dist_squared=-1;
452
453 }
454
455 WayPoint *
456 path_find_nearest_waypoint(Path *path, guint unitx, guint unity)
457 {
458 WayPoint *wcurr;
459 WayPoint *wnear;
460 guint64 nearest_squared;
461 Point pos = { unitx, unity, 0, NAN };
462
463 g_return_val_if_fail(path, NULL);
464
465 wcurr=wnear=path->whead;
466 if (wcurr && wcurr->point && wcurr!=path->wtail) {
467         nearest_squared=DISTANCE_SQUARED(pos, *(wcurr->point));
468
469         while (wcurr++!=path->wtail) {
470                 guint64 test_squared=DISTANCE_SQUARED(pos, *(wcurr->point));
471                 if (test_squared < nearest_squared) {
472                         wnear=wcurr;
473                         nearest_squared=test_squared;
474                 }
475         }
476 }
477
478 if (wnear && wnear->point) {
479         /* Only use the waypoint if it is within a 6*_draw_width square drawn
480          * around the position. This is consistent with select_poi(). */
481         if (abs(unitx - wnear->point->unitx) < pixel2unit(3 * path->sensitivity) && abs(unity - wnear->point->unity) < pixel2unit(3 * path->sensitivity))
482                 return wnear;
483 }
484
485 return NULL;
486 }
487
488 /******************************************************************************/
489
490 gdouble
491 path_get_distance_to(Path *path, Point *point, gdouble lat, gdouble lon)
492 {
493 gdouble lat1, lon1, lat2, lon2;
494 gdouble sum=0.0;
495
496 g_return_val_if_fail(path, 0.0);
497
498 /* If point is NULL, use the next waypoint. */
499 if (point == NULL && path->next_way)
500         point = path->next_way->point;
501
502 /* If point is still NULL, return an error. */
503 if (point==NULL)
504         return FALSE;
505
506 lat1=lat;
507 lon1=lon;
508
509 if (point > path->near_point) {
510         Point *curr;
511         /* Skip _near_point in case we have already passed it. */
512         for (curr = path->near_point + 1; curr <= point; ++curr) {
513                 if (curr->unity) {
514                         unit2latlon(curr->unitx, curr->unity, lat2, lon2);
515                         sum += calculate_distance(lat1, lon1, lat2, lon2);
516                         lat1 = lat2;
517                         lon1 = lon2;
518                 }
519         }
520 } else if (point < path->near_point) {
521         Point *curr;
522         /* Skip near_point in case we have already passed it. */
523         for (curr = path->near_point - 1; curr >= point; --curr) {
524                 if (curr->unity) {
525                         unit2latlon(curr->unitx, curr->unity, lat2, lon2);
526                         sum += calculate_distance(lat1, lon1, lat2, lon2);
527                         lat1 = lat2;
528                         lon1 = lon2;
529                 }
530         }
531 } else {
532         /* Waypoint _is_ the nearest point. */
533         unit2latlon(path->near_point->unitx, path->near_point->unity, lat2, lon2);
534         sum += calculate_distance(lat1, lon1, lat2, lon2);
535 }
536 return sum;
537 }
538
539 /******************************************************************************/
540
541 gboolean
542 path_load(Path *path, const gchar *config_dir, const gchar *file)
543 {
544 gchar *pfile;
545 gchar *bytes;
546 gint size;
547
548 g_return_val_if_fail(path, FALSE);
549 g_return_val_if_fail(config_dir, FALSE);
550 g_return_val_if_fail(file, FALSE);
551
552 pfile = gnome_vfs_uri_make_full_from_relative(config_dir, file);
553 if (gnome_vfs_read_entire_file(pfile, &size, &bytes)==GNOME_VFS_OK)
554         gpx_parse(path, bytes, size, GPX_PATH_NEW);
555 g_free(pfile);
556 return TRUE;
557 }
558
559 gboolean 
560 path_save(Path *path, const gchar *config_dir, const gchar *file)
561 {
562 GnomeVFSHandle *handle;
563 gchar *tfile;
564
565 g_return_val_if_fail(path, FALSE);
566 g_return_val_if_fail(config_dir, FALSE);
567 g_return_val_if_fail(file, FALSE);
568
569 tfile=gnome_vfs_uri_make_full_from_relative(config_dir, file);
570 if (gnome_vfs_create(&handle, tfile, GNOME_VFS_OPEN_WRITE, FALSE, 0600)==GNOME_VFS_OK) {
571         gpx_write(path, handle);
572         gnome_vfs_close(handle);
573 }
574 g_free(tfile);
575 return TRUE;
576 }
577
578 /******************************************************************************/
579
580 gboolean
581 path_set_destination_from_last(Path *path, Position *pos)
582 {
583 Point *p;
584 gdouble lat,lon;
585
586 g_return_val_if_fail(path, FALSE);
587 g_return_val_if_fail(pos, FALSE);
588
589 if (path->head==path->tail) {
590         position_set(pos, FALSE, NAN, NAN, NAN);
591         return FALSE;
592 }
593
594 p=path_find_last_point(path);
595 if (p) {
596         unit2latlon(p->unitx, p->unity, &lat, &lon);
597         position_set(pos, TRUE, lat, lon, 0);
598 } else {
599         position_set(pos, FALSE, NAN, NAN, NAN);
600         return FALSE;
601 }
602 return TRUE;
603 }
604
605 gboolean
606 path_get_waypoint_latlon(WayPoint *way, gdouble *lat, gdouble *lon)
607 {
608 gdouble tlat, tlon;
609
610 g_return_val_if_fail(way, FALSE);
611 g_return_val_if_fail(way->point, FALSE);
612 g_return_val_if_fail(lat, FALSE);
613 g_return_val_if_fail(lon, FALSE);
614
615 unit2latlon(way->point->unitx, way->point->unity, tlat, tlon);
616
617 *lat=tlat;
618 *lon=tlon;
619
620 return TRUE;
621 }
622
623 /**
624  * Add a text description at current point
625  * 
626  */
627 void 
628 path_insert_mark_text(Path *path, gchar *text)
629 {
630 g_return_if_fail(path);
631 MACRO_PATH_INCREMENT_WTAIL(*path);
632 path->wtail->point=path->tail;
633 if (text) {
634         path->wtail->desc=text;
635 } else {
636         path->wpcnt++;
637         path->wtail->desc=g_strdup_printf("WPT:#%u", path->wpcnt);
638 }
639 g_signal_emit(G_OBJECT(path), signals[NEW_WAYPOINT], 0, NULL);
640 }
641
642 void
643 path_insert_mark_autonumber(Path *path)
644 {
645 path_insert_mark_text(path, NULL);
646 }
647
648 /******************************************************************************/
649 #if 0
650 static void
651 path_store_append_waypoint(GtkListStore *, WayPoint *w)
652 {
653 gchar tmp1[16], tmp2[16];
654 gdouble lat2, lon2;
655
656 unit2latlon(wcurr->point->unitx, wcurr->point->unity, lat2, lon2);
657 lat_format(_degformat, lat2, tmp1);
658 lon_format(_degformat, lon2, tmp2);
659
660 g_snprintf(buffer1, sizeof(buffer1), "%s,%s", tmp1, tmp2);
661 sum += calculate_distance(lat1, lon1, lat2, lon2);
662 g_snprintf(buffer2, sizeof(buffer2), "%.02f %s", sum * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
663
664 gtk_list_store_append(store, &iter);
665 gtk_list_store_set(store, &iter,
666         PATH_LATLON, buffer1,
667         PATH_DISTANCE, buffer2,
668         PATH_WAYPOINT, wcurr->desc,
669         PATH_LAT, lat2,
670         PATH_LON, lon2,
671         -1);
672
673 lat1=lat2;
674 lon1=lon2;
675 }
676 #endif
677
678 /**
679  * Generate a GtkListStore with information about path waypoints (location, distance)
680  */
681 GtkListStore *
682 path_get_waypoints_store(Path *path)
683 {
684 WayPoint *wcurr;
685 GtkTreeIter iter;
686 GtkListStore *store;
687 gchar buffer1[80];
688 gchar buffer2[32];
689 gchar tmp1[16], tmp2[16];
690 gdouble lat1, lon1, lat2, lon2;
691 gdouble sum=0.0;
692
693 g_return_val_if_fail(path!=NULL, NULL);
694
695 wcurr=path->whead;
696
697 g_return_val_if_fail(wcurr!=NULL, NULL);
698 g_return_val_if_fail(wcurr->point!=NULL, NULL);
699 if (!path_has_waypoints(path))
700         return NULL;
701
702 store=gtk_list_store_new(PATH_NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
703
704 unit2latlon(wcurr->point->unitx, wcurr->point->unity, lat1, lon1);
705
706 while (wcurr!=path->wtail) {
707         if (!wcurr)
708                 break;
709
710         if (!wcurr->point) {
711                 g_debug("PSTORE: No point for waypoint (%s) skipping", wcurr->desc);
712                 wcurr++;
713                 continue;
714         }
715
716         unit2latlon(wcurr->point->unitx, wcurr->point->unity, lat2, lon2);
717         lat_format(_degformat, lat2, tmp1);
718         lon_format(_degformat, lon2, tmp2);
719
720         g_snprintf(buffer1, sizeof(buffer1), "%s,%s", tmp1, tmp2);
721         sum += calculate_distance(lat1, lon1, lat2, lon2);
722         g_snprintf(buffer2, sizeof(buffer2), "%.02f %s", sum * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
723
724         gtk_list_store_append(store, &iter);
725         gtk_list_store_set(store, &iter,
726                 PATH_LATLON, buffer1,
727                 PATH_DISTANCE, buffer2,
728                 PATH_WAYPOINT, wcurr->desc,
729                 PATH_LAT, lat2,
730                 PATH_LON, lon2,
731                 -1);
732
733         lat1=lat2;
734         lon1=lon2;
735
736         wcurr++;
737 }
738
739 return store;
740 }