mapper.h \
path.c \
path.h \
+ position.c \
+ position.h \
image-cache.c \
image-cache.h \
poi-gui.c \
g_assert(tree_view);
g_assert(path);
-store=path_generate_store(path);
+store=path_get_waypoints_store(path);
if (!store)
return FALSE;
#include "filter.h"
#include "mapper-types.h"
#include "map-repo.h"
-#include "path.h"
+#include "position.h"
GConfClient *gconf_client;
#include "map.h"
#include "gps-conn.h"
#include "gps-nmea-parse.h"
+#include "position.h"
#ifdef WITH_HILDON_DBUS_BT
#include <bt-dbus.h>
static void map_update_location(gdouble lat, gdouble lon, gboolean force);
static void map_speed_draw(void);
+static void map_draw_position_icon(Position *pos, const gchar *icon);
+
static gboolean map_cb_after_realize(GtkWidget *map_widget, gpointer data);
static gboolean map_cb_configure(GtkWidget *widget, GdkEventConfigure *event);
static gboolean map_cb_expose(GtkWidget * widget, GdkEventExpose * event);
#include "utils.h"
#include "mapper-types.h"
+#include "position.h"
#include "osm.h"
/** MAX_ZOOM defines the largest map zoom level we will download.
void map_render_waypoint(guint x1, guint y1, GdkGC *gc);
void map_render_paths(void);
void map_force_redraw(void);
-void map_draw_position_icon(Position *pos, const gchar *icon);
GdkPixmap *map_pixmap_get(void);
void map_center_unit(guint new_center_unitx, guint new_center_unity);
return FALSE;
}
+gboolean
+path_has_points(Path *path)
+{
+g_return_val_if_fail(path, FALSE);
+return path->head==path->tail ? FALSE : TRUE;
+}
+
+gboolean
+path_has_waypoints(Path *path)
+{
+g_return_val_if_fail(path, FALSE);
+return path->whead==path->wtail ? FALSE : TRUE;
+}
+
Point *
path_find_last_point(Path *path)
{
g_return_val_if_fail(path, NULL);
-if (path->head == path->tail)
+if (!path_has_points(path))
return p;
for (p=path->tail; !p->unity; p--) {
}
}
+/**
+ * Generate a GtkListStore with information about path waypoints (location, distance)
+ */
GtkListStore *
-path_generate_store(Path *path)
+path_get_waypoints_store(Path *path)
{
WayPoint *wcurr;
GtkTreeIter iter;
g_return_val_if_fail(wcurr, NULL);
g_return_val_if_fail(wcurr->point, NULL);
+if (!path_has_waypoints(path))
+ return NULL;
store=gtk_list_store_new(ROUTE_NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
-if (path->whead==path->wtail)
- return store;
-
unit2latlon(wcurr->point->unitx, wcurr->point->unity, lat1, lon1);
while (wcurr!=path->wtail) {
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter,
- ROUTE_LATLON, buffer1,
+ ROUTE_LATLON, buffer1,
ROUTE_DISTANCE, buffer2,
ROUTE_WAYPOINT, wcurr->desc,
ROUTE_LAT, lat2,
return store;
}
-
-Position *
-position_new(PositionType type, guint id)
-{
-Position *pos;
-
-pos=g_slice_new0(Position);
-pos->type=type;
-pos->id=id;
-return pos;
-}
-
-void
-position_free(Position *pos)
-{
-g_return_if_fail(pos);
-g_slice_free(Position, pos);
-}
-
-void
-position_set(Position *pos, gboolean valid, gdouble lat, gdouble lon, gfloat alt)
-{
-g_return_if_fail(pos);
-pos->valid=valid;
-pos->lat=valid ? lat : NAN;
-pos->lon=valid ? lon : NAN;
-pos->altitude=valid ? lon : NAN;
-}
#define _PATH_H
#include <glib.h>
+#include <glib-object.h>
#include <gtk/gtk.h>
typedef enum {
#define PATH_ID_MY_TRACK (1)
#define PATH_ID_MY_ROUTE (2)
-typedef enum {
- POSITION_TYPE_GPS,
- POSITION_TYPE_HOME,
- POSITION_TYPE_DESTINATION,
- POSITION_TYPE_WAYPOINT,
- POSITION_TYPE_FRIEND,
-} PositionType;
-
-/** A lat/lon/alt position */
-typedef struct _Position Position;
-struct _Position {
- gchar *name; /* Name of position */
- guint id; /* Unique ID of position */
- PositionType type; /* Type of position (Home, Destination, Waypoint, etc) */
- gboolean valid; /* Is lat/lon valid ? */
- gdouble lat;
- gdouble lon;
- gfloat altitude;
- gfloat heading; /* Where is it heading ? */
- gfloat angle; /* Course from current position to this one */
- time_t time; /* Time last changed */
-};
-
/** A general definition of a point in the Mapper unit system. */
typedef struct _Point Point;
struct _Point {
/* Null point */
Point _point_null;
-/* Special positions */
-Position *_home;
-Position *_dest;
+
Path *path_new(PathType type, guint id);
void path_free(Path *p);
void path_insert_mark_autonumber(Path *path);
void path_insert_mark_audio(Path *path, gchar *audio);
-GtkListStore *path_generate_store(Path *path);
-
-Position *position_new(PositionType type, guint id);
-void position_free(Position *p);
-void position_set(Position *pos, gboolean valid, gdouble lat, gdouble lon, gfloat alt);
+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 - 1; \
+ (path).wtail = (path).whead; \
(path).wcap = (path).whead + ARRAY_CHUNK_SIZE; \
}
WayPoint *curr; \
g_free((path).head); \
(path).head = (path).tail = (path).cap = NULL; \
- for(curr = (path).whead - 1; curr++ != (path).wtail; ) \
+ for(curr = (path).whead; curr++ != (path).wtail; ) \
g_free(curr->desc); \
g_free((path).whead); \
(path).whead = (path).wtail = (path).wcap = NULL; \
--- /dev/null
+/*
+ * 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.
+ */
+
+#include <config.h>
+
+#include <math.h>
+#include <glib.h>
+
+#include "position.h"
+
+Position *
+position_new(PositionType type, guint id)
+{
+Position *pos;
+
+pos=g_slice_new0(Position);
+pos->type=type;
+pos->id=id;
+return pos;
+}
+
+void
+position_free(Position *pos)
+{
+g_return_if_fail(pos);
+g_slice_free(Position, pos);
+}
+
+void
+position_set(Position *pos, gboolean valid, gdouble lat, gdouble lon, gfloat alt)
+{
+g_return_if_fail(pos);
+pos->valid=valid;
+pos->lat=valid ? lat : NAN;
+pos->lon=valid ? lon : NAN;
+pos->altitude=valid ? lon : NAN;
+}
--- /dev/null
+#ifndef _POSITION_H
+#define _POSITION_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+typedef enum {
+ POSITION_TYPE_GPS,
+ POSITION_TYPE_HOME,
+ POSITION_TYPE_DESTINATION,
+ POSITION_TYPE_WAYPOINT,
+ POSITION_TYPE_FRIEND,
+} PositionType;
+
+/** A lat/lon/alt position */
+
+typedef struct _Position Position;
+struct _Position {
+ gchar *name; /* Name of position */
+ guint id; /* Unique ID of position */
+ PositionType type; /* Type of position (Home, Destination, Waypoint, etc) */
+ gboolean valid; /* Is lat/lon valid ? */
+ gdouble lat;
+ gdouble lon;
+ gfloat altitude;
+ gfloat heading; /* Where is it heading ? */
+ gfloat angle; /* Course from current position to this one */
+ time_t time; /* Time last changed */
+};
+
+/* Special positions */
+Position *_home;
+Position *_dest;
+
+Position *position_new(PositionType type, guint id);
+void position_free(Position *p);
+void position_set(Position *pos, gboolean valid, gdouble lat, gdouble lon, gfloat alt);
+
+#endif
#include "utils.h"
#include "mapper-types.h"
+#include "path.h"
+#include "position.h"
/** The current route. */
Path *_route;