From a434e8412bc14d3f7fd5a013a9e8a8b5f215df90 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Wed, 11 Jun 2008 18:15:12 +0300 Subject: [PATCH] Path: misc adjustments --- src/cb.c | 6 +++--- src/map-download.c | 4 ++-- src/path.c | 50 +++++++++++++++++++++++++++++++++++++++++----- src/path.h | 3 +-- 4 files changed, 51 insertions(+), 12 deletions(-) diff --git a/src/cb.c b/src/cb.c index e7274b0..36406cb 100644 --- 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); } diff --git a/src/map-download.c b/src/map-download.c index 8601d0e..d150540 100644 --- a/src/map-download.c +++ b/src/map-download.c @@ -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 { diff --git a/src/path.c b/src/path.c index 0af6311..ec2de14 100644 --- a/src/path.c +++ b/src/path.c @@ -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) { diff --git a/src/path.h b/src/path.h index 05462ee..5cf25be 100644 --- a/src/path.h +++ b/src/path.h @@ -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); -- 2.39.5