*/
#include <config.h>
+#include <string.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <sqlite3.h>
#include "path.h"
#include "position.h"
-#include "utils.h"
-#include "settings.h"
#include "latlon.h"
struct sql_select_stmt {
#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"
+#define ARRAY_CHUNK_SIZE (1024)
+
#define MACRO_PATH_INIT(path) { \
(path).head = (path).tail = g_new0(Point, ARRAY_CHUNK_SIZE); \
*((path).tail) = _point_null; \
#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PATH_TYPE, PathPrivate))
+static void path_dispose(GObject *object);
+static void path_finalize(GObject *object);
+static void path_class_init(PathClass *klass);
+static void path_init(Path *path);
+static gboolean path_resize(Path *path, guint size);
+
+static void path_check_waypoint_announce(Path *path);
+
static void
path_dispose(GObject *object)
{
path->tail->altitude=altitude;
if (speed>path->maxspeed)
path->maxspeed=speed;
+ path->speed=speed;
path->tspeed+=speed;
path->avgspeed=(path->points>0) ? path->tspeed/path->points : 0.0;
path->points++;
*
*/
WayPoint *
-path_find_nearest_waypoint(Path *path, guint unitx, guint unity)
+path_find_nearest_waypoint(Path *path, gdouble lat, gdouble lon)
{
WayPoint *wcurr;
WayPoint *wnear;
guint64 nearest_squared;
-Point pos = { unitx, unity, 0, NAN };
+Point pos = { 0, 0, 0, NAN };
g_return_val_if_fail(path, NULL);
+latlon2unit(lat, lon, pos.unitx, pos.unity);
+
wcurr=wnear=path->whead;
if (wcurr && wcurr->point && wcurr!=path->wtail) {
nearest_squared=DISTANCE_SQUARED(pos, *(wcurr->point));
}
if (wnear && wnear->point) {
- if (abs(unitx - wnear->point->unitx) < path->sensitivity && abs(unity - wnear->point->unity) < path->sensitivity)
+ if (abs(pos.unitx - wnear->point->unitx) < path->sensitivity && abs(pos.unity - wnear->point->unity) < path->sensitivity)
return wnear;
}
/**
* path_check_waypoint_announce:
* @path
- * @gps
+ * @lat
+ * @lon
*
* Check if we should announce upcoming waypoint.
*
*/
static void
-path_check_waypoint_announce(Path *path, GpsData *gps)
+path_check_waypoint_announce(Path *path)
{
guint a_thres_near, a_thres_at;
g_return_if_fail(path);
-g_return_if_fail(gps);
if (!path->next_way)
return;
-a_thres_near=(20+(guint)gps->speed)*path->announce_notice_ratio*3;
-a_thres_at=(20+(guint)gps->speed);
+a_thres_near=(20+(guint)path->speed)*path->announce_notice_ratio*3;
+a_thres_at=(20+(guint)path->speed);
if (path->next_way_dist_squared<(a_thres_near * a_thres_near) && path->next_way!=path->announced_waypoint) {
g_signal_emit(G_OBJECT(path), signals[NEAR_WAYPOINT], 0, NULL);
/******************************************************************************/
-gboolean
+static gboolean
path_set_destination_from_last(Path *path, Position *pos)
{
Point *p;
#define WRITE_STRING(string) { \
if(GNOME_VFS_OK != (vfs_result = gnome_vfs_write(handle, (string), strlen((string)), &size))) { \
- g_set_error(error, \
- PATH_GPX_WRITE_ERROR, G_FILE_ERROR_FAILED, \
- "%s:\n%s\n%s", \
- _("Error while writing to file"), \
- _("File is incomplete."), \
- gnome_vfs_result_to_string(vfs_result)); \
+ g_set_error(error, PATH_GPX_WRITE_ERROR, G_FILE_ERROR_FAILED, \
+ "%s", gnome_vfs_result_to_string(vfs_result)); \
return FALSE; \
} \
}
gpx_time = time(NULL);
/* Find first non-zero point. */
-for (curr = path->head - 1, wcurr = path->whead; curr++ != path->tail;) {
- if (curr->unity)
+for (curr=path->head, wcurr=path->whead; curr++!=path->tail;) {
+ if (curr->unity && curr->unitx)
break;
- else if (wcurr && curr == wcurr->point)
+ else if (wcurr && curr==wcurr->point)
wcurr++;
}
* Handle a start tag in the parsing of a GPX file.
*/
#define MACRO_SET_UNKNOWN(utag) { \
- data->prev_state = data->state; \
- data->state = UNKNOWN; \
- data->unknown_depth = 1; \
- g_debug("GPX: unknown tag [%s]", (gchar *)utag); }
+ data->prev_state = data->state; \
+ data->state = UNKNOWN; \
+ data->unknown_depth = 1; \
+ g_warning("GPX: unknown tag [%s]", (gchar *)utag); }
static void
gpx_start_element(SaxData *data, const xmlChar *name, const xmlChar **attrs)
* Generate a GtkListStore with information about path waypoints (location, distance)
*/
GtkListStore *
-path_get_waypoints_store(Path *path)
+path_get_waypoints_store(Path *path, DegFormat degformat)
{
WayPoint *wcurr;
GtkTreeIter iter;
}
unit2latlon(wcurr->point->unitx, wcurr->point->unity, lat2, lon2);
- lat_format(_degformat, lat2, tmp1);
- lon_format(_degformat, lon2, tmp2);
+ lat_format(degformat, lat2, tmp1);
+ lon_format(degformat, lon2, tmp2);
g_snprintf(buffer1, sizeof(buffer1), "%s,%s", tmp1, tmp2);
sum += calculate_distance(lat1, lon1, lat2, lon2);
#include <gtk/gtk.h>
#include <libgnomevfs/gnome-vfs.h>
+#include "position.h"
+#include "latlon.h"
+
G_BEGIN_DECLS
#define PATH_TYPE (path_get_type ())
gdouble length;
gdouble tspeed;
gdouble avgspeed;
+ gfloat speed;
gfloat maxspeed;
/* GPX metadata fields */
Point *path_find_last_point(Path *path);
-gboolean path_resize(Path *path, guint size);
-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, gdouble lat, gdouble lon);
gboolean path_add_latlon(Path *path, gdouble lat, gdouble lon, time_t ptime, gfloat speed, gfloat altitude);
+gboolean path_add_waypoint(Path *path, gdouble lat, gdouble lon, gchar *desc);
gboolean path_has_points(Path *path);
gboolean path_has_waypoints(Path *path);
gboolean path_get_waypoint_latlon(WayPoint *way, gdouble *lat, gdouble *lon);
-GtkListStore *path_get_waypoints_store(Path *path);
+GtkListStore *path_get_waypoints_store(Path *path, DegFormat degformat);
G_END_DECLS