]> err.no Git - mapper/commitdiff
Paths/Positions:
authorKaj-Michael Lang <milang@tal.org>
Fri, 9 May 2008 11:10:19 +0000 (14:10 +0300)
committerKaj-Michael Lang <milang@tal.org>
Fri, 9 May 2008 11:10:19 +0000 (14:10 +0300)
- Split position stuff from path.c/.h
- Adjust other sources for above change
- Fix warnings with static functions

src/Makefile.am
src/cb.c
src/config-gconf.h
src/gps.c
src/map.c
src/map.h
src/path.c
src/path.h
src/position.c [new file with mode: 0644]
src/position.h [new file with mode: 0644]
src/route.h

index 2cb6bc81db401b9c4dc18c9385103aff7225d13b..c76dd35443c88c35cc7d19cc74231761bcbf7bb4 100644 (file)
@@ -87,6 +87,8 @@ mapper_SOURCES = \
        mapper.h \
        path.c \
        path.h \
+       position.c \
+       position.h \
        image-cache.c \
        image-cache.h \
        poi-gui.c \
index 8d7ca1bc61f8c946d5dd592a52cee366d6937c9a..95b2779357770443ac68eba0cbc05e63d2d0c081 100644 (file)
--- a/src/cb.c
+++ b/src/cb.c
@@ -73,7 +73,7 @@ GtkListStore *store;
 g_assert(tree_view);
 g_assert(path);
 
-store=path_generate_store(path);
+store=path_get_waypoints_store(path);
 if (!store)
        return FALSE;
 
index 3b4142719bf301ec0c36187e66730b13aa34a4bf..b1c4e372780e317377a6116c6dfe7eef5a3a3971 100644 (file)
@@ -6,7 +6,7 @@
 #include "filter.h"
 #include "mapper-types.h"
 #include "map-repo.h"
-#include "path.h"
+#include "position.h"
 
 GConfClient *gconf_client;
 
index f4c2a389c82b5348e2d75ce4e724b3b8557d2c27..1d27c444a618d4487c534f7b0f1b9b0732ac2fdd 100644 (file)
--- a/src/gps.c
+++ b/src/gps.c
@@ -49,6 +49,7 @@
 #include "map.h"
 #include "gps-conn.h"
 #include "gps-nmea-parse.h"
+#include "position.h"
 
 #ifdef WITH_HILDON_DBUS_BT
 #include <bt-dbus.h>
index 4354b9b332a78a9878fe0156107ae2ed36c91644..8dd2617e0a31562cab09e665705efba4bd340f32 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -155,6 +155,8 @@ static GTimer *map_timer;
 
 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);
index 5105a48a0c62f0a652ce54d6629edb5ec365de38..134f34695905b2a88d6ed03639208f7691eb3473 100644 (file)
--- a/src/map.h
+++ b/src/map.h
@@ -18,6 +18,7 @@
 
 #include "utils.h"
 #include "mapper-types.h"
+#include "position.h"
 #include "osm.h"
 
 /** MAX_ZOOM defines the largest map zoom level we will download.
@@ -206,7 +207,6 @@ gboolean map_render_tile(guint tilex, guint tiley, guint destx, guint desty, gbo
 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);
index bd8d3522d2aee1a38b08320baaff4b66332ce593..a84060387653d8303e4cf1a03e1e5419c775b2cd 100644 (file)
@@ -196,6 +196,20 @@ if (path->tail->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)
 {
@@ -203,7 +217,7 @@ Point *p=NULL;
 
 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--) {
@@ -315,8 +329,11 @@ if (text) {
 }
 }
 
+/**
+ * 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;
@@ -333,12 +350,11 @@ wcurr=path->whead;
 
 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) {
@@ -361,7 +377,7 @@ 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,
@@ -376,31 +392,3 @@ while (wcurr!=path->wtail) {
 
 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;
-}
index 54ca7f20bdfc745fab51de2d0f2dd58be1fca79b..78cf2835cd83be1fa11d52b7cda5b90e19b2ceea 100644 (file)
@@ -22,6 +22,7 @@
 #define _PATH_H
 
 #include <glib.h>
+#include <glib-object.h>
 #include <gtk/gtk.h>
 
 typedef enum {
@@ -34,29 +35,6 @@ 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 {
@@ -122,9 +100,7 @@ struct _Path {
 /* Null point */
 Point _point_null;
 
-/* Special positions */
-Position *_home;
-Position *_dest;
+
 
 Path *path_new(PathType type, guint id);
 void path_free(Path *p);
@@ -142,18 +118,14 @@ 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);
 
-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; \
 }
 
@@ -161,7 +133,7 @@ void position_set(Position *pos, gboolean valid, gdouble lat, gdouble lon, gfloa
        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; \
diff --git a/src/position.c b/src/position.c
new file mode 100644 (file)
index 0000000..c6558d7
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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;
+}
diff --git a/src/position.h b/src/position.h
new file mode 100644 (file)
index 0000000..58e54ee
--- /dev/null
@@ -0,0 +1,39 @@
+#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
index b39dca1dc3bce5d6b38cd2cde741aafa6daf02b9..b45031c05854dd730ab91fcea2c099f55a903eb7 100644 (file)
@@ -18,6 +18,8 @@
 
 #include "utils.h"
 #include "mapper-types.h"
+#include "path.h"
+#include "position.h"
 
 /** The current route. */
 Path *_route;