]> err.no Git - mapper/blobdiff - src/path.h
Path: Add a function to add a raw point, more documentation
[mapper] / src / path.h
index 12ed0ab82f0251639a8f78eb03d931f2418076f9..2f9ecd16d1b983c1c40ff4d073e577a9f57cfb72 100644 (file)
@@ -1,48 +1,65 @@
+/*
+ * This file is part of mapper
+ *
+ * Copyright (C) 2008 Kaj-Michael Lang
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
 #ifndef _PATH_H
 #define _PATH_H
 
 #include <glib.h>
+#include <glib-object.h>
+#include <gtk/gtk.h>
 
-#define MACRO_PATH_INIT(path) { \
-    (path).head = (path).tail = g_new(Point, ARRAY_CHUNK_SIZE); \
-    *((path).tail) = _point_null; \
-    (path).cap = (path).head + ARRAY_CHUNK_SIZE; \
-    (path).whead = g_new(WayPoint, ARRAY_CHUNK_SIZE); \
-    (path).wtail = (path).whead - 1; \
-    (path).wcap = (path).whead + ARRAY_CHUNK_SIZE; \
-}
+#include "gpsdata.h"
 
-#define MACRO_PATH_FREE(path) if((path).head) { \
-    WayPoint *curr; \
-    g_free((path).head); \
-    (path).head = (path).tail = (path).cap = NULL; \
-    for(curr = (path).whead - 1; curr++ != (path).wtail; ) \
-        g_free(curr->desc); \
-    g_free((path).whead); \
-    (path).whead = (path).wtail = (path).wcap = NULL; \
-}
+G_BEGIN_DECLS
 
-#define MACRO_PATH_INCREMENT_TAIL(route) { \
-    if(++(route).tail == (route).cap) \
-        path_resize(&(route), (route).cap - (route).head + ARRAY_CHUNK_SIZE);\
-}
+#define PATH_TYPE                              (path_get_type ())
+#define PATH(obj)                              (G_TYPE_CHECK_INSTANCE_CAST ((obj), PATH_TYPE, Path))
+#define PATH_CLASS(klass)              (G_TYPE_CHECK_CLASS_CAST ((klass), PATH_TYPE, PathClass))
+#define IS_PATH(obj)                   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PATH_TYPE))
+#define IS_PATH_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), PATH_TYPE))
+#define PATH_GET_CLASS(obj)            (G_TYPE_INSTANCE_GET_CLASS ((obj), PATH_TYPE, PathClass))
 
-#define MACRO_PATH_INCREMENT_WTAIL(route) { \
-    if(++(route).wtail == (route).wcap) \
-        path_wresize(&(route), \
-                (route).wcap - (route).whead + ARRAY_CHUNK_SIZE); \
-}
+typedef enum {
+       PATH_TYPE_TRACK=0,
+       PATH_TYPE_ROUTE,
+       PATH_TYPE_FRIEND,
+} PathType;
 
-/** A lat/lon/alt position */
-typedef struct _Position Position;
-struct _Position {
-       gdouble lat;
-       gdouble lon;
-       gfloat altitude;
-       gboolean valid;
-};
+/* Path store items */
+typedef enum {
+    PATH_LATLON,
+    PATH_DISTANCE,
+    PATH_WAYPOINT,
+    PATH_LAT,
+    PATH_LON,
+    PATH_NUM_COLUMNS
+} PathStoreList;
+
+
+/* Fixed ID's */
+#define PATH_ID_MY_TRACK       (1)
+#define PATH_ID_MY_ROUTE       (2)
 
-/** A general definition of a point in the Mapper unit system. */
+/** 
+ * A general definition of a point in the Map unit system. 
+ */
 typedef struct _Point Point;
 struct _Point {
        guint unitx;
@@ -51,29 +68,157 @@ struct _Point {
        gfloat altitude;
 };
 
-/** A WayPoint, which is a Point with a description. */
+#define DISTANCE_SQUARED(a, b) \
+       ((guint64)((((gint64)(b).unitx)-(a).unitx)*(((gint64)(b).unitx)-(a).unitx)) \
+       + (guint64)((((gint64)(b).unity)-(a).unity)*(((gint64)(b).unity)-(a).unity)))
+
+/**
+ * A latitude/longitue pair
+ */
+typedef struct _LatLon LatLon;
+struct _LatLon {
+       gdouble lat;
+       gdouble lon;
+};
+
+/** 
+ * A WayPoint, which is a Point with a description. 
+ */
 typedef struct _WayPoint WayPoint;
 struct _WayPoint {
        Point *point;
        gchar *desc;
 };
 
-/** A Path is a set of PathPoints and WayPoints. */
+/** 
+ * Path GObject
+ */
 typedef struct _Path Path;
 struct _Path {
+       GObject parent;
+
+       PathType type;
+       guint id;
+       gint sensitivity;
+
+       /* Path points */
        Point *head;            /* points to first element in array; NULL if empty. */
        Point *tail;            /* points to last element in array. */
-       Point *cap;             /* points after last slot in array. */
+       Point *cap;                     /* points after last slot in array. */
+
+       /* Path bounding box */
+       LatLon min;
+       LatLon max;
+
+       /* Path waypoints */
        WayPoint *whead;        /* points to first element in array; NULL if empty. */
        WayPoint *wtail;        /* points to last element in array. */
        WayPoint *wcap;         /* points after last slot in array. */
+
+       /* Internal waypoint data */
+       Point *near_point;
+       guint64 near_point_dist_squared;
+
+       /* next_way is what we currently interpret to be the next waypoint. */
+       WayPoint *next_way;
+       guint64 next_way_dist_squared;
+
+       /* next_wpt is the route point immediately following next_way. */
+       Point *next_wpt;
+       guint64 next_wpt_dist_squared;
+
+       /* The waypoint we last announced */
+       WayPoint *announced_waypoint;
+       gint announce_notice_ratio;
+
+       /* Path statistics */
+       guint32 points;
+       guint32 wpcnt;          /* Auto waypoint number counter */
+       gdouble length;
+       gdouble tspeed;
+       gdouble avgspeed;
+       gfloat maxspeed;
+
+       /* GPX metadata fields */
+       gchar *name;
+       gchar *desc;
+       gchar *author;
+       gchar *keywords;
+       gchar *copyright;
+       gchar *src;
+       time_t time;
 };
 
+typedef struct _PathClass PathClass;
+struct _PathClass {
+       GObjectClass parent;
+
+       void (*new_point) (Path *path);
+       void (*new_break) (Path *path);
+       void (*new_waypoint) (Path *path);
+};
+
+/* Null point */
 Point _point_null;
-Position _home;
-Position _dest;
 
-void path_resize(Path *path, guint size);
-void path_wresize(Path *path, guint wsize);
+Path *path_new(PathType type, guint id);
+void path_free(Path *p);
+void path_clear(Path *p);
+
+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);
+gboolean path_update_nears(Path *route, Point *point, gboolean quick);
+
+gboolean path_add_latlon(Path *path, gdouble lat, gdouble lon, time_t ptime, gfloat speed, gfloat altitude);
+gboolean path_add_point(Path *path, GpsData *gps);
+
+gboolean path_has_points(Path *path);
+gboolean path_has_waypoints(Path *path);
+
+gboolean path_add_break(Path *path);
+void path_insert_mark_text(Path *path, gchar *text);
+void path_insert_mark_autonumber(Path *path);
+void path_insert_mark_audio(Path *path, gchar *audio);
+
+gboolean path_get_waypoint_latlon(WayPoint *way, gdouble *lat, gdouble *lon);
+
+GtkListStore *path_get_waypoints_store(Path *path);
+
+#define MACRO_PATH_INIT(path) { \
+       (path).head = (path).tail = g_new0(Point, ARRAY_CHUNK_SIZE); \
+       *((path).tail) = _point_null; \
+       (path).cap = (path).head + ARRAY_CHUNK_SIZE; \
+       (path).whead = g_new0(WayPoint, ARRAY_CHUNK_SIZE); \
+       (path).wtail = (path).whead; \
+       (path).wcap = (path).whead + ARRAY_CHUNK_SIZE; \
+}
+
+#define MACRO_PATH_FREE(path) if((path).head) { \
+       WayPoint *curr; \
+       g_free((path).head); \
+       (path).head = (path).tail = (path).cap = NULL; \
+       for(curr = (path).whead; curr++ != (path).wtail; ) \
+               g_free(curr->desc); \
+       g_free((path).whead); \
+       (path).whead = (path).wtail = (path).wcap = NULL; \
+}
+
+#define MACRO_PATH_INCREMENT_TAIL(route) { \
+       if(++(route).tail == (route).cap) \
+               path_resize(&(route), (route).cap - (route).head + ARRAY_CHUNK_SIZE);\
+}
+
+#define MACRO_PATH_INCREMENT_WTAIL(route) { \
+       if(++(route).wtail == (route).wcap) \
+               path_wresize(&(route), (route).wcap - (route).whead + ARRAY_CHUNK_SIZE); \
+}
+
+G_END_DECLS
 
 #endif