]> err.no Git - mapper/blob - src/path.h
Add path metadata fields, names from GPX metadata.
[mapper] / src / path.h
1 #ifndef _PATH_H
2 #define _PATH_H
3
4 #include <glib.h>
5 #include <gtk/gtk.h>
6
7 #define MACRO_PATH_INIT(path) { \
8         (path).head = (path).tail = g_new0(Point, ARRAY_CHUNK_SIZE); \
9         *((path).tail) = _point_null; \
10         (path).cap = (path).head + ARRAY_CHUNK_SIZE; \
11         (path).whead = g_new0(WayPoint, ARRAY_CHUNK_SIZE); \
12         (path).wtail = (path).whead - 1; \
13         (path).wcap = (path).whead + ARRAY_CHUNK_SIZE; \
14         (path).length=(path).maxspeed=(path).tspeed=(path).avgspeed=(path).points=0; \
15 }
16
17 #define MACRO_PATH_FREE(path) if((path).head) { \
18         WayPoint *curr; \
19         g_free((path).head); \
20         (path).head = (path).tail = (path).cap = NULL; \
21         for(curr = (path).whead - 1; curr++ != (path).wtail; ) \
22                 g_free(curr->desc); \
23         g_free((path).whead); \
24         (path).whead = (path).wtail = (path).wcap = NULL; \
25 }
26
27 #define MACRO_PATH_INCREMENT_TAIL(route) { \
28         if(++(route).tail == (route).cap) \
29                 path_resize(&(route), (route).cap - (route).head + ARRAY_CHUNK_SIZE);\
30 }
31
32 #define MACRO_PATH_INCREMENT_WTAIL(route) { \
33         if(++(route).wtail == (route).wcap) \
34                 path_wresize(&(route), (route).wcap - (route).whead + ARRAY_CHUNK_SIZE); \
35 }
36
37 /** A lat/lon/alt position */
38 typedef struct _Position Position;
39 struct _Position {
40         gdouble lat;
41         gdouble lon;
42         gfloat altitude;
43         gboolean valid;
44         gchar *desc;
45         time_t time;
46         guint type;
47 };
48
49 /** A general definition of a point in the Mapper unit system. */
50 typedef struct _Point Point;
51 struct _Point {
52         guint unitx;
53         guint unity;
54         time_t time;
55         gfloat altitude;
56 };
57
58 /** A WayPoint, which is a Point with a description. */
59 typedef struct _WayPoint WayPoint;
60 struct _WayPoint {
61         Point *point;
62         gchar *desc;
63 };
64
65 /** A Path is a set of PathPoints and WayPoints. */
66 typedef struct _Path Path;
67 struct _Path {
68         /* Path points */
69         Point *head;            /* points to first element in array; NULL if empty. */
70         Point *tail;            /* points to last element in array. */
71         Point *cap;                     /* points after last slot in array. */
72
73         /* Path waypoints */
74         WayPoint *whead;        /* points to first element in array; NULL if empty. */
75         WayPoint *wtail;        /* points to last element in array. */
76         WayPoint *wcap;         /* points after last slot in array. */
77
78         /* Path statistics */
79         guint32 points;
80         gdouble length;
81         gdouble tspeed;
82         gdouble avgspeed;
83         gfloat maxspeed;
84
85         /* GPX metadata fields */
86         gchar *name;
87         gchar *desc;
88         gchar *author;
89         gchar *keywords;
90         time_t time;
91         gchar *copyright;
92         gchar *src;
93 };
94
95 /* Null point */
96 Point _point_null;
97
98 /* Special positions */
99 Position _home;
100 Position _dest;
101
102 void path_resize(Path *path, guint size);
103 void path_wresize(Path *path, guint wsize);
104
105 GtkListStore *path_generate_store(Path *path);
106
107 #endif