From 6846aafb0e96db37ded043efebf86588a4974a24 Mon Sep 17 00:00:00 2001 From: Guilhem Bonnefille Date: Tue, 13 Jan 2009 22:25:51 +0100 Subject: [PATCH 1/1] Add compatibility facilities --- src/Makefile.am | 5 ++++- src/bluemarble.c | 2 +- src/old-vik-map-type.gob | 40 +++++++++++++++++++++++++++++++++++++ src/openaerial.c | 2 +- src/osm.c | 8 ++++---- src/terraserver.c | 6 +++--- src/vikmapslayer.c | 5 +++-- src/vikmapslayer.h | 3 ++- src/vikmapslayer_compat.c | 38 +++++++++++++++++++++++++++++++++++ src/vikmapslayer_compat.h | 42 +++++++++++++++++++++++++++++++++++++++ 10 files changed, 138 insertions(+), 13 deletions(-) create mode 100644 src/old-vik-map-type.gob create mode 100644 src/vikmapslayer_compat.c create mode 100644 src/vikmapslayer_compat.h diff --git a/src/Makefile.am b/src/Makefile.am index 8bfabad6..9cbd2de9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -56,8 +56,10 @@ libviking_a_SOURCES = \ vikcoord.c vikcoord.h \ mapcache.c mapcache.h \ vikmapslayer.c vikmapslayer.h \ + vikmapslayer_compat.c vikmapslayer_compat.h \ vik-map-type.c vik-map-type.h \ vik-map-type-default.c vik-map-type-default.h \ + old-vik-map-type.c old-vik-map-type.h \ slippy-map-type-abstract.c slippy-map-type-abstract.h \ slippy-map-type.c slippy-map-type.h \ gpx.c gpx.h \ @@ -84,7 +86,8 @@ BUILT_SOURCES += \ vik-map-type.c vik-map-type.h \ vik-map-type-default.c vik-map-type-default.h \ slippy-map-type-abstract.c slippy-map-type-abstract.h \ - slippy-map-type.c slippy-map-type.h + slippy-map-type.c slippy-map-type.h \ + old-vik-map-type.c old-vik-map-type.h if GOOGLE libviking_a_SOURCES += \ diff --git a/src/bluemarble.c b/src/bluemarble.c index 5028a681..bfc710a0 100644 --- a/src/bluemarble.c +++ b/src/bluemarble.c @@ -28,6 +28,6 @@ void bluemarble_init () { VikMapType *bluemarble_type = VIK_MAP_TYPE(slippy_map_type_new_with_id( 15, "s3.amazonaws.com", "/com.modestmaps.bluemarble/%d-r%3$d-c%2$d.jpg" )); - maps_layer_register_type("BlueMarble", 15, bluemarble_type); + maps_layer_register_map_type("BlueMarble", bluemarble_type); } diff --git a/src/old-vik-map-type.gob b/src/old-vik-map-type.gob new file mode 100644 index 00000000..df168117 --- /dev/null +++ b/src/old-vik-map-type.gob @@ -0,0 +1,40 @@ +%headertop{ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "vik-map-type.h" +#include "vikmapslayer_compat.h" +%} + +class Old:Vik:Map:Type from Vik:Map:Type { + + private VikMapsLayer_MapType map_type; + + public GObject * + new_with_id (VikMapsLayer_MapType map_type) { + OldVikMapType *ret = GET_NEW; + ret->_priv->map_type = map_type; + return G_OBJECT (ret); + } + + override (Vik:Map:Type) gboolean + coord_to_mapcoord ( Vik:Map:Type *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest ) + { + return SELF(self)->_priv->map_type.coord_to_mapcoord (src, xzoom, yzoom, dest); + } + + override (Vik:Map:Type) void + mapcoord_to_center_coord ( Vik:Map:Type *self, MapCoord *src, VikCoord *dest ) + { + SELF(self)->_priv->map_type.mapcoord_to_center_coord (src, dest); + } + + override (Vik:Map:Type) int + download ( Vik:Map:Type *self, MapCoord *src, const gchar *dest_fn ) + { + return SELF(self)->_priv->map_type.download(src, dest_fn); + } + +} + diff --git a/src/openaerial.c b/src/openaerial.c index 2fd3853f..5f1de45a 100644 --- a/src/openaerial.c +++ b/src/openaerial.c @@ -28,6 +28,6 @@ void openaerial_init () { VikMapType *openaerialmap_type = VIK_MAP_TYPE(slippy_map_type_new_with_id( 20, "tile.openaerialmap.org", "/tiles/1.0.0/openaerialmap-900913/%d/%d/%d.jpg" )); - maps_layer_register_type("OpenAerialMap", 20, openaerialmap_type); + maps_layer_register_map_type("OpenAerialMap", openaerialmap_type); } diff --git a/src/osm.c b/src/osm.c index 5fc9043d..1f72675a 100644 --- a/src/osm.c +++ b/src/osm.c @@ -30,9 +30,9 @@ void osm_init () { VikMapType *maplint_type = VIK_MAP_TYPE(slippy_map_type_new_with_id( 14, "tah.openstreetmap.org", "/Tiles/maplint.php/%d/%d/%d.png")); VikMapType *cycle_type = VIK_MAP_TYPE(slippy_map_type_new_with_id( 17, "thunderflames.org/tiles/cycle/", "%d/%d/%d.png" )); - maps_layer_register_type("OpenStreetMap (Osmarender)", 12, osmarender_type); - maps_layer_register_type("OpenStreetMap (Mapnik)", 13, mapnik_type); - maps_layer_register_type("OpenStreetMap (Maplint)", 14, maplint_type); - maps_layer_register_type("OpenStreetMap (Cycle)", 17, cycle_type); + maps_layer_register_map_type("OpenStreetMap (Osmarender)", osmarender_type); + maps_layer_register_map_type("OpenStreetMap (Mapnik)", mapnik_type); + maps_layer_register_map_type("OpenStreetMap (Maplint)", maplint_type); + maps_layer_register_map_type("OpenStreetMap (Cycle)", cycle_type); } diff --git a/src/terraserver.c b/src/terraserver.c index 78c14867..9bbc6abf 100644 --- a/src/terraserver.c +++ b/src/terraserver.c @@ -28,7 +28,7 @@ void terraserver_init () { VikMapType *map_type_2 = VIK_MAP_TYPE(terraserver_map_type_new_with_id( 1, 1 )); VikMapType *map_type_3 = VIK_MAP_TYPE(terraserver_map_type_new_with_id( 4, 4 )); - maps_layer_register_type("Terraserver Topos", 2, map_type_1); - maps_layer_register_type("Terraserver Aerials", 1, map_type_2); - maps_layer_register_type("Terraserver Urban Areas", 4, map_type_3); + maps_layer_register_map_type("Terraserver Topos", map_type_1); + maps_layer_register_map_type("Terraserver Aerials", map_type_2); + maps_layer_register_map_type("Terraserver Urban Areas", map_type_3); } diff --git a/src/vikmapslayer.c b/src/vikmapslayer.c index cdb3d677..c229ca6f 100644 --- a/src/vikmapslayer.c +++ b/src/vikmapslayer.c @@ -201,11 +201,12 @@ enum { REDOWNLOAD_NONE = 0, REDOWNLOAD_BAD, REDOWNLOAD_ALL, DOWNLOAD_OR_REFRESH /******** MAPS LAYER TYPES **************/ /****************************************/ -void maps_layer_register_type ( const char *label, guint id, VikMapType *map_type ) +void maps_layer_register_map_type ( const char *label, VikMapType *map_type ) { g_assert(label != NULL); g_assert(map_type != NULL); - g_assert(id == vik_map_type_get_uniq_id(map_type)); + + guint id = vik_map_type_get_uniq_id(map_type); /* Add the label */ params_maptypes = g_list_append(params_maptypes, g_strdup(label)); diff --git a/src/vikmapslayer.h b/src/vikmapslayer.h index 7686d3f2..20822d74 100644 --- a/src/vikmapslayer.h +++ b/src/vikmapslayer.h @@ -27,6 +27,7 @@ #include "vikviewport.h" #include "vik-map-type.h" #include "mapcoord.h" +#include "vikmapslayer_compat.h" #define VIK_MAPS_LAYER_TYPE (vik_maps_layer_get_type ()) #define VIK_MAPS_LAYER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIK_MAPS_LAYER_TYPE, VikMapsLayer)) @@ -44,7 +45,7 @@ GType vik_maps_layer_get_type (); typedef struct _VikMapsLayer VikMapsLayer; -void maps_layer_register_type ( const char *label, guint id, VikMapType *map_type ); +void maps_layer_register_map_type ( const char *label, VikMapType *map_type ); void maps_layer_download_section_without_redraw ( VikMapsLayer *vml, VikViewport *vvp, VikCoord *ul, VikCoord *br, gdouble zoom); gint vik_maps_layer_get_map_type(VikMapsLayer *vml); gchar *vik_maps_layer_get_map_label(VikMapsLayer *vml); diff --git a/src/vikmapslayer_compat.c b/src/vikmapslayer_compat.c new file mode 100644 index 00000000..b5177c6f --- /dev/null +++ b/src/vikmapslayer_compat.c @@ -0,0 +1,38 @@ +/* + * viking -- GPS Data and Topo Analyzer, Explorer, and Manager + * + * Copyright (C) 2005, Evan Battaglia + * Copyright (C) 2008-2009, Guilhem Bonnefille + * UTM multi-zone stuff by Kit Transue + * Dynamic map type by Guilhem Bonnefille + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "vikmapslayer.h" +#include "vikmapslayer_compat.h" +#include "old-vik-map-type.h" + +void maps_layer_register_type ( const char *label, guint id, VikMapsLayer_MapType *map_type ) +{ + g_assert(id == map_type->uniq_id); + GObject *object = old_vik_map_type_new_with_id (*map_type); + maps_layer_register_map_type ( label, VIK_MAP_TYPE (object) ); +} diff --git a/src/vikmapslayer_compat.h b/src/vikmapslayer_compat.h new file mode 100644 index 00000000..67ec71a5 --- /dev/null +++ b/src/vikmapslayer_compat.h @@ -0,0 +1,42 @@ +/* + * viking -- GPS Data and Topo Analyzer, Explorer, and Manager + * + * Copyright (C) 2003-2005, Evan Battaglia + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef _VIKING_MAPSLAYER_COMPAT_H +#define _VIKING_MAPSLAYER_COMPAT_H + +#include "vikcoord.h" +#include "vikviewport.h" +#include "mapcoord.h" + +typedef struct { + guint8 uniq_id; + guint16 tilesize_x; + guint16 tilesize_y; + guint drawmode; + gboolean (*coord_to_mapcoord) ( const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest ); + void (*mapcoord_to_center_coord) ( MapCoord *src, VikCoord *dest ); + int (*download) ( MapCoord *src, const gchar *dest_fn ); + /* TODO: constant size (yay!) */ +} VikMapsLayer_MapType; + +void maps_layer_register_type ( const char *label, guint id, VikMapsLayer_MapType *map_type ); + +#endif -- 2.39.5