[PATCH] Work on a dive localisation tool using GPS coordinates

Dirk Hohndel dirk at hohndel.org
Sun Jan 13 10:05:24 PST 2013


And another email on this patch, now that I have it working.

I am glad that we are making progress in this direction - I am not sure
I like the underlying design idea here. Ctrl^M now displays a complete
world map with tiny little dots for each dive site that has GPS
coordinates. This is completely disconnected from the currently
displayed dive and IMHO rather unintuitive.

I could envision two more intuitive integration approaches:

a) turn those locations that have GPS information into something people
can click on (so maybe underline them, change their color) and then have
the map open when this is clicked on and have the map centered and
reasonably zoomed to show THAT dive site).

b) stay with the Ctrl^M (or Log menu) approach, but again as the current
dive changes, have the map shift and zoom to the active dive site.

I will apply this as is as I believe it's a good start - but it's not
there, yet.

/D

PS: there also seems to be something wrong with the display of the
actual coordinates... The if you zoom in on the dots of one of your
dives then it is offset quite a bit from the correct location.
Oh, I see, you are doing integer math when you should be doing floating
point math... I'll modify your patch to fix that as well as the Gtk
warning... 
PPS: the map window doesn't respond to any of the usual keyboard driven
ways to close it (hit ESC or Ctrl^W). That also should be addressed

Pierre-Yves Chibon <pingou at pingoured.fr> writes:

> For each dive recorded, place their GPS coordinates onto a map using the
> OSM-GPS-MAP library.
>
> This map is accessible via the "log" menu or the shortcut ctrl+M (M as map).
>
> We check for the GPS coordinates "0, 0" which are the default when we do not
> have real GPS coordinates set.
>
> Signed-off-by: Pierre-Yves Chibon <pingou at pingoured.fr>
> Signed-Off-By: Henrik Brautaset Aronsen <subsurface at henrik.synth.no>
> ---
>  Makefile  |  8 ++++--
>  dive.h    |  2 ++
>  gps.c     | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  gtk-gui.c |  2 ++
>  4 files changed, 107 insertions(+), 2 deletions(-)
>  create mode 100644 gps.c
>
> diff --git a/Makefile b/Makefile
> index 1a75435..d866a5c 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -90,6 +90,7 @@ XML2CFLAGS = $(shell $(XML2CONFIG) --cflags)
>  GLIB2CFLAGS = $(shell $(PKGCONFIG) --cflags glib-2.0)
>  GTK2CFLAGS = $(shell $(PKGCONFIG) --cflags gtk+-2.0)
>  CFLAGS += $(shell $(XSLCONFIG) --cflags)
> +OSMGPSMAPFLAGS += $(shell $(PKGCONFIG) --cflags osmgpsmap)
>  
>  LIBZIP = $(shell $(PKGCONFIG) --libs libzip 2> /dev/null)
>  ifneq ($(strip $(LIBZIP)),)
> @@ -125,7 +126,7 @@ ifneq ($(strip $(LIBXSLT)),)
>  	endif
>  endif
>  
> -LIBS = $(LIBXML2) $(LIBXSLT) $(LIBGTK) $(LIBGCONF2) $(LIBDIVECOMPUTER) $(EXTRALIBS) $(LIBZIP) -lpthread -lm -lssl -lcrypto
> +LIBS = $(LIBXML2) $(LIBXSLT) $(LIBGTK) $(LIBGCONF2) $(LIBDIVECOMPUTER) $(EXTRALIBS) $(LIBZIP) -lpthread -lm -lssl -lcrypto -losmgpsmap
>  
>  MSGLANGS=$(notdir $(wildcard po/*po))
>  MSGOBJS=$(addprefix share/locale/,$(MSGLANGS:.po=.UTF-8/LC_MESSAGES/subsurface.mo))
> @@ -133,7 +134,7 @@ MSGOBJS=$(addprefix share/locale/,$(MSGLANGS:.po=.UTF-8/LC_MESSAGES/subsurface.m
>  OBJS =	main.o dive.o time.o profile.o info.o equipment.o divelist.o deco.o planner.o \
>  	parse-xml.o save-xml.o libdivecomputer.o print.o uemis.o uemis-downloader.o \
>  	gtk-gui.o statistics.o file.o cochran.o device.o download-dialog.o prefs.o \
> -	$(OSSUPPORT).o $(RESFILE)
> +	gps.o $(OSSUPPORT).o $(RESFILE)
>  
>  $(NAME): $(OBJS) $(MSGOBJS)
>  	$(CC) $(LDFLAGS) -o $(NAME) $(OBJS) $(LIBS)
> @@ -239,6 +240,9 @@ equipment.o: equipment.c dive.h display.h divelist.h
>  statistics.o: statistics.c dive.h display.h divelist.h
>  	$(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c statistics.c
>  
> +gps.o: gps.c dive.h display.h divelist.h
> +		$(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) $(OSMGPSMAPFLAGS) -c gps.c
> +
>  divelist.o: divelist.c dive.h display.h divelist.h
>  	$(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c divelist.c
>  
> diff --git a/dive.h b/dive.h
> index b80e6bf..19a1768 100644
> --- a/dive.h
> +++ b/dive.h
> @@ -490,6 +490,8 @@ extern void clear_equipment_widgets(void);
>  extern void show_dive_stats(struct dive *);
>  extern void clear_stats_widgets(void);
>  
> +extern void show_gps_locations(void);
> +
>  extern void show_yearly_stats(void);
>  
>  extern void update_dive(struct dive *new_dive);
> diff --git a/gps.c b/gps.c
> new file mode 100644
> index 0000000..e70c719
> --- /dev/null
> +++ b/gps.c
> @@ -0,0 +1,97 @@
> +/* gps.c */
> +/* Creates the UI displaying the dives locations on a map.
> + */
> +#include <glib/gi18n.h>
> +
> +#include "osm-gps-map.h"
> +
> +#include "dive.h"
> +#include "display.h"
> +#include "display-gtk.h"
> +#include "divelist.h"
> +
> +static OsmGpsMapSource_t opt_map_provider = OSM_GPS_MAP_SOURCE_OPENSTREETMAP;
> +
> +
> +static void on_close (GtkWidget *widget, gpointer user_data)
> +{
> +	gtk_widget_destroy(widget);
> +}
> +
> +static void add_gps_point(OsmGpsMap *map, float latitude, float longitude)
> +{
> +	OsmGpsMapTrack * track = osm_gps_map_track_new ();
> +	OsmGpsMapPoint * point = osm_gps_map_point_new_degrees (
> +		latitude, longitude);
> +	osm_gps_map_track_add_point(track, point);
> +	osm_gps_map_track_add (map, track);
> +}
> +
> +
> +void show_gps_locations()
> +{
> +	GtkWidget *window;
> +
> +	OsmGpsMap *map;
> +	OsmGpsMapLayer *osd;
> +	char *cachedir, *cachebasedir;
> +    int idx;
> +    struct dive *dp;
> +
> +	cachebasedir = osm_gps_map_get_default_cache_directory();
> +	cachedir = g_strdup(OSM_GPS_MAP_CACHE_AUTO);
> +
> +	map = g_object_new (OSM_TYPE_GPS_MAP,
> +						"map-source",opt_map_provider,
> +						"tile-cache",cachedir,
> +						"tile-cache-base", cachebasedir,
> +						"proxy-uri",g_getenv("http_proxy"),
> +						NULL);
> +	osd = g_object_new (OSM_TYPE_GPS_MAP_OSD,
> +						"show-scale",TRUE,
> +						"show-coordinates",TRUE,
> +						"show-crosshair",TRUE,
> +						"show-dpad",TRUE,
> +						"show-zoom",TRUE,
> +						"show-gps-in-dpad",TRUE,
> +						"show-gps-in-zoom",FALSE,
> +						"dpad-radius", 30,
> +						NULL);
> +
> +	osm_gps_map_layer_add(OSM_GPS_MAP(map), osd);
> +	g_object_unref(G_OBJECT(osd));
> +	for (idx = 0; idx < dive_table.nr; idx++) {
> +		dp = dive_table.dives[idx];
> +		//printf("%s - %u,%u\n", dp->location, dp->latitude.udeg, dp->longitude.udeg);
> +		if (dp->latitude.udeg != 0 && dp->longitude.udeg != 0){
> +			add_gps_point(map, dp->latitude.udeg / 1000000,
> +				dp->longitude.udeg / 1000000);
> +		}
> +	}
> +	osm_gps_map_set_center_and_zoom(map, 0, 0, 0);
> +
> +	//Enable keyboard navigation
> +	osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_FULLSCREEN, GDK_KEY_F11);
> +	osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_UP, GDK_KEY_Up);
> +	osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_DOWN, GDK_KEY_Down);
> +	osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_LEFT, GDK_KEY_Left);
> +	osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_RIGHT, GDK_KEY_Right);
> +
> +	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
> +	//sw = gtk_scrolled_window_new (NULL, NULL);
> +
> +	gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
> +	gtk_window_set_default_size(GTK_WINDOW(window), 640, 480);
> +	gtk_window_set_title(GTK_WINDOW(window), _("Dives locations"));
> +	gtk_container_set_border_width(GTK_CONTAINER(window), 5);
> +	GTK_WINDOW(window)->allow_shrink = TRUE;
> +
> +	//gtk_container_add (GTK_CONTAINER (window), sw);
> +	gtk_container_add (GTK_CONTAINER (window), map);
> +	
> +	//sw = GTK_WIDGET(gtk_builder_get_object(builder, "window1"));
> +	g_signal_connect (window, "destroy",
> +					  G_CALLBACK (on_close), (gpointer) map);
> +
> +	gtk_widget_show_all (window);
> +}
> diff --git a/gtk-gui.c b/gtk-gui.c
> index 1bc3388..f72aac4 100644
> --- a/gtk-gui.c
> +++ b/gtk-gui.c
> @@ -1027,6 +1027,7 @@ static GtkActionEntry menu_items[] = {
>  	{ "Preferences",    GTK_STOCK_PREFERENCES, N_("Preferences..."), PREFERENCE_ACCEL, NULL, G_CALLBACK(preferences_dialog) },
>  	{ "Renumber",       NULL, N_("Renumber..."), NULL, NULL, G_CALLBACK(renumber_dialog) },
>  	{ "YearlyStats",    NULL, N_("Yearly Statistics"), NULL, NULL, G_CALLBACK(show_yearly_stats) },
> +	{ "DivesLocations", NULL, N_("Dives Locations"), CTRLCHAR "M", NULL, G_CALLBACK(show_gps_locations) },
>  	{ "SelectEvents",   NULL, N_("Select Events..."), NULL, NULL, G_CALLBACK(selectevents_dialog) },
>  	{ "Quit",           GTK_STOCK_QUIT, N_("Quit"),   CTRLCHAR "Q", NULL, G_CALLBACK(quit) },
>  	{ "About",          GTK_STOCK_ABOUT, N_("About Subsurface"),  NULL, NULL, G_CALLBACK(about_dialog) },
> @@ -1073,6 +1074,7 @@ static const gchar* ui_string = " \
>  				<menuitem name=\"Autogroup\" action=\"Autogroup\" /> \
>  				<menuitem name=\"Toggle Zoom\" action=\"ToggleZoom\" /> \
>  				<menuitem name=\"YearlyStats\" action=\"YearlyStats\" /> \
> +				<menuitem name=\"DivesLocations\" action=\"DivesLocations\" /> \
>  				<menu name=\"View\" action=\"ViewMenuAction\"> \
>  					<menuitem name=\"List\" action=\"ViewList\" /> \
>  					<menuitem name=\"Profile\" action=\"ViewProfile\" /> \
> -- 
> 1.8.0.2
>
> _______________________________________________
> subsurface mailing list
> subsurface at hohndel.org
> http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

-- 
Dirk Hohndel
Intel Open Source Technology Center


More information about the subsurface mailing list