2 * This file is part of mapper
4 * Copyright (C) 2008 Kaj-Michael Lang
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.
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.
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.
25 #include <glib-object.h>
27 #include <libgnomevfs/gnome-vfs.h>
31 #define PATH_TYPE (path_get_type ())
32 #define PATH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PATH_TYPE, Path))
33 #define PATH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PATH_TYPE, PathClass))
34 #define IS_PATH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PATH_TYPE))
35 #define IS_PATH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PATH_TYPE))
36 #define PATH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PATH_TYPE, PathClass))
50 /* Path store items */
62 #define PATH_ID_MY_TRACK (1)
63 #define PATH_ID_MY_ROUTE (2)
66 * A general definition of a point in the Map unit system.
68 typedef struct _Point Point;
76 #define DISTANCE_SQUARED(a, b) \
77 ((guint64)((((gint64)(b).unitx)-(a).unitx)*(((gint64)(b).unitx)-(a).unitx)) \
78 + (guint64)((((gint64)(b).unity)-(a).unity)*(((gint64)(b).unity)-(a).unity)))
81 * A latitude/longitue pair
83 typedef struct _LatLon LatLon;
90 * A WayPoint, which is a Point with a description.
92 typedef struct _WayPoint WayPoint;
101 typedef struct _Path Path;
110 Point *head; /* points to first element in array; NULL if empty. */
111 Point *tail; /* points to last element in array. */
112 Point *cap; /* points after last slot in array. */
114 /* Path bounding box */
119 WayPoint *whead; /* points to first element in array; NULL if empty. */
120 WayPoint *wtail; /* points to last element in array. */
121 WayPoint *wcap; /* points after last slot in array. */
123 /* Internal waypoint data */
125 guint64 near_point_dist_squared;
127 /* next_way is what we currently interpret to be the next waypoint. */
129 guint64 next_way_dist_squared;
131 /* next_wpt is the route point immediately following next_way. */
133 guint64 next_wpt_dist_squared;
135 /* The waypoint we last announced */
136 WayPoint *announced_waypoint;
137 gint announce_notice_ratio;
139 /* Path statistics */
141 guint32 wpcnt; /* Auto waypoint number counter */
147 /* GPX metadata fields */
157 typedef struct _PathClass PathClass;
161 void (*new_point) (Path *path);
162 void (*new_break) (Path *path);
163 void (*new_waypoint) (Path *path);
169 Path *path_new(PathType type, guint id);
170 void path_free(Path *p);
171 void path_clear(Path *p);
173 gboolean path_gpx_read(Path *path, GnomeVFSHandle *handle);
174 gboolean path_gpx_write(Path *path, GnomeVFSHandle *handle, GError **error);
175 gboolean path_gpx_parse(Path *to_replace, gchar *buffer, gint size, gpx_path_policy policy);
177 Point *path_find_last_point(Path *path);
179 gboolean path_resize(Path *path, guint size);
180 gboolean path_wresize(Path *path, guint wsize);
182 gdouble path_get_distance_to(Path *path, Point *point, gdouble lat, gdouble lon);
184 void path_find_nearest_point(Path *path);
185 gboolean path_update_nears(Path *route, Point *point, gboolean quick);
187 gboolean path_add_latlon(Path *path, gdouble lat, gdouble lon, time_t ptime, gfloat speed, gfloat altitude);
189 gboolean path_has_points(Path *path);
190 gboolean path_has_waypoints(Path *path);
192 gboolean path_add_break(Path *path);
193 void path_insert_mark_text(Path *path, gchar *text);
194 void path_insert_mark_autonumber(Path *path);
195 void path_insert_mark_audio(Path *path, gchar *audio);
197 gboolean path_get_waypoint_latlon(WayPoint *way, gdouble *lat, gdouble *lon);
199 GtkListStore *path_get_waypoints_store(Path *path);
201 #define MACRO_PATH_INIT(path) { \
202 (path).head = (path).tail = g_new0(Point, ARRAY_CHUNK_SIZE); \
203 *((path).tail) = _point_null; \
204 (path).cap = (path).head + ARRAY_CHUNK_SIZE; \
205 (path).whead = g_new0(WayPoint, ARRAY_CHUNK_SIZE); \
206 (path).wtail = (path).whead; \
207 (path).wcap = (path).whead + ARRAY_CHUNK_SIZE; \
210 #define MACRO_PATH_FREE(path) if((path).head) { \
212 g_free((path).head); \
213 (path).head = (path).tail = (path).cap = NULL; \
214 for(curr = (path).whead; curr++ != (path).wtail; ) \
215 g_free(curr->desc); \
216 g_free((path).whead); \
217 (path).whead = (path).wtail = (path).wcap = NULL; \
220 #define MACRO_PATH_INCREMENT_TAIL(route) { \
221 if(++(route).tail == (route).cap) \
222 path_resize(&(route), (route).cap - (route).head + ARRAY_CHUNK_SIZE);\
225 #define MACRO_PATH_INCREMENT_WTAIL(route) { \
226 if(++(route).wtail == (route).wcap) \
227 path_wresize(&(route), (route).wcap - (route).whead + ARRAY_CHUNK_SIZE); \