From 8254106c554a277a7090a691cdb90b2da2fab718 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Fri, 9 May 2008 14:10:19 +0300 Subject: [PATCH] Paths/Positions: - Split position stuff from path.c/.h - Adjust other sources for above change - Fix warnings with static functions --- src/Makefile.am | 2 ++ src/cb.c | 2 +- src/config-gconf.h | 2 +- src/gps.c | 1 + src/map.c | 2 ++ src/map.h | 2 +- src/path.c | 56 ++++++++++++++++++---------------------------- src/path.h | 38 +++++-------------------------- src/position.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ src/position.h | 39 ++++++++++++++++++++++++++++++++ src/route.h | 2 ++ 11 files changed, 130 insertions(+), 70 deletions(-) create mode 100644 src/position.c create mode 100644 src/position.h diff --git a/src/Makefile.am b/src/Makefile.am index 2cb6bc8..c76dd35 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 \ diff --git a/src/cb.c b/src/cb.c index 8d7ca1b..95b2779 100644 --- 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; diff --git a/src/config-gconf.h b/src/config-gconf.h index 3b41427..b1c4e37 100644 --- a/src/config-gconf.h +++ b/src/config-gconf.h @@ -6,7 +6,7 @@ #include "filter.h" #include "mapper-types.h" #include "map-repo.h" -#include "path.h" +#include "position.h" GConfClient *gconf_client; diff --git a/src/gps.c b/src/gps.c index f4c2a38..1d27c44 100644 --- 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 diff --git a/src/map.c b/src/map.c index 4354b9b..8dd2617 100644 --- 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); diff --git a/src/map.h b/src/map.h index 5105a48..134f346 100644 --- 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); diff --git a/src/path.c b/src/path.c index bd8d352..a840603 100644 --- a/src/path.c +++ b/src/path.c @@ -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; -} diff --git a/src/path.h b/src/path.h index 54ca7f2..78cf283 100644 --- a/src/path.h +++ b/src/path.h @@ -22,6 +22,7 @@ #define _PATH_H #include +#include #include 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 index 0000000..c6558d7 --- /dev/null +++ b/src/position.c @@ -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 + +#include +#include + +#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 index 0000000..58e54ee --- /dev/null +++ b/src/position.h @@ -0,0 +1,39 @@ +#ifndef _POSITION_H +#define _POSITION_H + +#include +#include + +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 diff --git a/src/route.h b/src/route.h index b39dca1..b45031c 100644 --- a/src/route.h +++ b/src/route.h @@ -18,6 +18,8 @@ #include "utils.h" #include "mapper-types.h" +#include "path.h" +#include "position.h" /** The current route. */ Path *_route; -- 2.39.5