]> err.no Git - mapper/commitdiff
Path: misc adjustments
authorKaj-Michael Lang <milang@tal.org>
Wed, 11 Jun 2008 15:15:12 +0000 (18:15 +0300)
committerKaj-Michael Lang <milang@tal.org>
Wed, 11 Jun 2008 15:15:12 +0000 (18:15 +0300)
src/cb.c
src/map-download.c
src/path.c
src/path.h

index e7274b0ebfc5b2d29198548f66b4c6443cc92fae..36406cbc0b2d187c7e993db419b406649901cea1 100644 (file)
--- a/src/cb.c
+++ b/src/cb.c
@@ -123,8 +123,7 @@ return TRUE;
 gboolean 
 menu_cb_route_reset(GtkAction *action)
 {
-path_find_nearest_point(_route);
-gtk_map_refresh(_map);
+path_find_nearest_point(_route, _gps->data.lat, _gps->data.lon);
 return TRUE;
 }
 
@@ -1170,8 +1169,9 @@ if ((way = path_find_nearest_waypoint(_route, lat, lon))) {
                        way[-1].point -= num_del;
                }
                _route->wtail--;
-
+#if 0
                path_find_nearest_point(_route);
+#endif
        }
        gtk_widget_destroy(confirm);
 }
index 8601d0e7475674a1125b2aa89e4a8c017c0e391a..d1505403cd0e93684d2bd72a6eb7f8d120cda9be 100644 (file)
@@ -130,9 +130,9 @@ while (_curl_multi && (msg = curl_multi_info_read(_curl_multi, &num_msgs))) {
                if (msg->easy_handle == _autoroute_data.curl_easy) {
                        /* This is the autoroute download. */
                        /* Now, parse the autoroute and update the display. */
-                       if (_autoroute_data.enabled && gpx_parse(&_route, _autoroute_data.rdl_data.bytes, _autoroute_data.rdl_data.bytes_read, 0)) {
+                       if (_autoroute_data.enabled && path_gpx_parse(_route, _autoroute_data.rdl_data.bytes, _autoroute_data.rdl_data.bytes_read, 0)) {
                                /* Find the nearest route point, if we're connected. */
-                               path_find_nearest_point(_route);
+                               path_find_nearest_point(_route, _gps->data.lat, _gps->data.lon);
                        }
                        route_cancel_autoroute(_route, TRUE);   /* We're done. Clean up. */
                } else {
index 0af63119bb4dbf7f432457234d4bffb5a95c7a75..ec2de141585a29fa8bf27516eadcae970f5719ce 100644 (file)
@@ -62,6 +62,11 @@ static struct sql_select_stmt sql;
        name    text default null, \
        t               int not null);"
 
+#define PATH_SQL_SELECT_TRACKS "select id,name,slat,slon,elat,elon,len,sdate,edate from tracks order by sdate"
+#define PATH_SQL_INSERT_TRACK "insert into tracks (id,name,sloc,sdate) values (?,?,?,?);
+#define PATH_SQL_INSERT_TRACK_POINT "insert into trackpoints (tid,dt,lat,lon,alt,hdop,vdop,pdop,sat,fix) values (?,?,?,?,?,?,?,?,?,?)"
+#define PATH_SQL_SELECT_TRACK_POINTS "select tid,dt,lat,lon,alt,hdop,vdop,pdop,sat,fix from trackpoints where tid=? order by dt"
+
 enum {
        NEW_POINT,                              /* A new point was appended to track track */
        NEW_BREAK,                              /* A break was appended to the track */
@@ -272,8 +277,6 @@ MACRO_PATH_INCREMENT_WTAIL(*path);
 path->wtail->point=path->tail;
 path->wtail->desc=desc;
 
-path_find_nearest_point(path);
-
 g_signal_emit(G_OBJECT(path), signals[NEW_WAYPOINT], 0, NULL);
 
 return TRUE;
@@ -421,14 +424,14 @@ WayPoint *wcurr, *wnext;
 guint64 near_dist_squared;
 
 g_return_val_if_fail(path, FALSE);
+g_return_val_if_fail(point, FALSE);
 
 /* If we have waypoints (_next_way != NULL), then determine the "next
  * waypoint", which is defined as the waypoint after the nearest point,
  * UNLESS we've passed that waypoint, in which case the waypoint after
  * that waypoint becomes the "next" waypoint. */
 if (path->next_way) {
-       /* First, set near_dist_squared with the new distance from
-        * near_point. */
+       /* First, set near_dist_squared with the new distance from near_point. */
        near = path->near_point;
        near_dist_squared = DISTANCE_SQUARED(*point, *near);
 
@@ -509,8 +512,10 @@ return ret;
  * Reset the near_point data by searching the entire path for the nearest point and waypoint.
  */
 void 
-path_find_nearest_point(Path *path)
+path_find_nearest_point(Path *path, gdouble lat, gdouble lon)
 {
+Point p;
+
 g_return_if_fail(path);
 
 /* Initialize near_point to first non-zero point. */
@@ -529,6 +534,8 @@ path->next_way_dist_squared=-1;
 path->next_wpt=NULL;
 path->next_wpt_dist_squared=-1;
 
+latlon2unit(lat, lon, p.unitx, p.unity);
+path_update_nears(path, &p, FALSE);
 }
 
 /**
@@ -599,6 +606,39 @@ if (path->next_way_dist_squared<(a_thres_near * a_thres_near) && path->next_way!
 
 /******************************************************************************/
 
+/**
+ *
+ *
+ */
+gdouble
+path_calculate_distance_from(Path *path, Point *point)
+{
+Point *curr;
+gdouble lat1, lon1, lat2, lon2;
+gdouble sum=0.0;
+
+for (curr = path->tail; curr > point; --curr) {
+       if (curr->unity) {
+               unit2latlon(curr->unitx, curr->unity, &lat2, &lon2);
+               sum += calculate_distance(lat1, lon1, lat2, lon2);
+               lat1 = lat2;
+               lon1 = lon2;
+       }
+}
+return sum;
+}
+
+/**
+ * path_get_distance_to:
+ * @path
+ * @point
+ * @lat
+ * @lon
+ *
+ * Calculate distancance from lat,lon to point in given path.
+ *
+ * Returns: The distance, or 0.0 if path or point is invalid.
+ */
 gdouble
 path_get_distance_to(Path *path, Point *point, gdouble lat, gdouble lon)
 {
index 05462eefa46cfa872626fc12387722c66588025c..5cf25be77e93901a6bc439208a55c03083f5adab 100644 (file)
@@ -181,8 +181,7 @@ gboolean path_wresize(Path *path, guint wsize);
 
 gdouble path_get_distance_to(Path *path, Point *point, gdouble lat, gdouble lon);
 
-void path_find_nearest_point(Path *path);
-gboolean path_update_nears(Path *route, Point *point, gboolean quick);
+void path_find_nearest_point(Path *path, gdouble lat, gdouble lon);
 
 gboolean path_add_latlon(Path *path, gdouble lat, gdouble lon, time_t ptime, gfloat speed, gfloat altitude);