From 9f781c7340345b40a836936485a748bf1b7f8267 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Fri, 4 Jan 2008 14:22:08 +0200 Subject: [PATCH] Start to make a simple library for osm database and common latlon handling. --- src/Makefile.am | 19 ++++++++--------- src/cb.c | 8 +++---- src/config-gconf.c | 1 + src/gps-panels.c | 8 +++---- src/latlon.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ src/latlon.h | 18 ++++++++++++++++ src/mapper-types.h | 11 ---------- src/mapper.c | 3 ++- src/osm-db.c | 4 ++-- src/poi-gui.c | 5 +++-- src/poi.c | 8 +++---- src/settings-gui.c | 1 + src/track.c | 4 ++-- src/ui-common.c | 14 +------------ src/utils.c | 39 ---------------------------------- src/utils.h | 4 ---- 16 files changed, 103 insertions(+), 96 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index e47140a..44c0b08 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -41,17 +41,14 @@ mapper_LDADD = $(GLIBGTK_LIBS) \ $(SQLITE_LIBS) $(LIBCURL_LIBS) \ $(DBUS_GLIB_LIBS) $(BLUEZ_LIBS) \ $(GYPSY_LIBS) \ - -lm libgtkgps.la + -lm libgtkgps.la libosmdb.la mapper_SOURCES = utils.c \ - db.c \ file.c \ gpx.c \ bt-bluez.c \ bt-maemo-marshal.c \ bt-maemo.c \ - latlon.c \ - osm-db.c \ gps.c \ gps-browse.c \ gps-nmea-parse.c \ @@ -83,19 +80,21 @@ mapper_SOURCES = utils.c \ mapper.c osm2db_CFLAGS = $(EXPAT_CFLAGS) $(SQLITE_CFLAGS) $(GLIBGTK_CFLAGS) +osm2db_LDADD = $(EXPAT_LIBS) $(SQLITE_LIBS) $(GLIBGTK_LIBS) $(BZ2_LIBS) -lm libosmdb.la +osm2db_SOURCES = osm.c -osm2db_LDADD = $(EXPAT_LIBS) $(SQLITE_LIBS) $(GLIBGTK_LIBS) $(BZ2_LIBS) -lm - -osm2db_SOURCES = latlon.c db.c osm.c - -lib_LTLIBRARIES = libgtkgps.la +lib_LTLIBRARIES = libgtkgps.la libosmdb.la libgtkgps_la_SOURCES = gtkgps.c gtkcompass.c - libgtkgps_la_CFLAGS = $(GLIBGTK_CFLAGS) $(defines) libgtkgps_la_LIBADD = $(GLIBGTK_LIBS) libgtkgps_la_LDFLAGS = -lm -no-undefined +libosmdb_la_SOURCES = db.c osm-db.c latlon.c +libosmdb_la_CFLAGS = $(GLIBGTK_CFLAGS) $(SQLITE_CFLAGS) $(defines) +libosmdb_la_LIBADD = $(GLIBGTK_LIBS) $(SQLITE_LIBS) +libosmdb_la_LDFLAGS = -lm -no-undefined + EXTRA_DIST = bt-maemo-marshal.list BUILT_SOURCES = bt-maemo-marshal.h bt-maemo-marshal.c diff --git a/src/cb.c b/src/cb.c index 60d507b..ef9b27b 100644 --- a/src/cb.c +++ b/src/cb.c @@ -702,8 +702,8 @@ gdouble lat, lon; gchar buffer[80], tmp1[16], tmp2[16]; unit2latlon(unitx, unity, lat, lon); -lat_format(lat, tmp1); -lon_format(lon, tmp2); +lat_format(_degformat, lat, tmp1); +lon_format(_degformat, lon, tmp2); g_snprintf(buffer, sizeof(buffer), "%s: %s\n" @@ -790,8 +790,8 @@ dialog = gtk_dialog_new_with_buttons(_("Add Waypoint"), gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); unit2latlon(unitx, unity, lat, lon); - lat_format(lat, tmp1); - lon_format(lon, tmp2); + lat_format(_degformat, lat, tmp1); + lon_format(_degformat, lon, tmp2); p_latlon = g_strdup_printf("%s, %s", tmp1, tmp2); gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(p_latlon), diff --git a/src/config-gconf.c b/src/config-gconf.c index 7614e3c..a7e0283 100644 --- a/src/config-gconf.c +++ b/src/config-gconf.c @@ -46,6 +46,7 @@ #include "config-gconf.h" #include "utils.h" #include "mapper-types.h" +#include "latlon.h" #include "map.h" #include "route.h" #include "db.h" diff --git a/src/gps-panels.c b/src/gps-panels.c index 72f8d07..a614e69 100644 --- a/src/gps-panels.c +++ b/src/gps-panels.c @@ -151,11 +151,11 @@ if (_gps.fix < 2) { gps_clear_text_fields(); } else { /* latitude */ - lat_format(_gps.lat, buffer); + lat_format(_degformat, _gps.lat, buffer); gtk_label_set_label(GTK_LABEL(text_lat), buffer); /* longitude */ - lon_format(_gps.lon, buffer); + lon_format(_degformat, _gps.lon, buffer); gtk_label_set_label(GTK_LABEL(text_lon), buffer); /* speed */ @@ -218,11 +218,11 @@ if (_gps.fix < 2) { gtk_label_set_label(GTK_LABEL(_sdi_tim), " --:--:-- "); } else { /* latitude */ - lat_format(_gps.lat, buffer); + lat_format(_degformat, _gps.lat, buffer); gtk_label_set_label(GTK_LABEL(_sdi_lat), buffer); /* longitude */ - lon_format(_gps.lon, buffer); + lon_format(_degformat, _gps.lon, buffer); gtk_label_set_label(GTK_LABEL(_sdi_lon), buffer); /* speed */ diff --git a/src/latlon.c b/src/latlon.c index e8a78d7..a73d680 100644 --- a/src/latlon.c +++ b/src/latlon.c @@ -40,6 +40,17 @@ #define EARTH_RADIUS (3440.06479f) +void +latlon_init(void) +{ +DEG_FORMAT_TEXT[DDPDDDDD] = "-dd.ddddd°"; +DEG_FORMAT_TEXT[DD_MMPMMM] = "-dd°mm.mmm'"; +DEG_FORMAT_TEXT[DD_MM_SSPS] = "-dd°mm'ss.s\""; +DEG_FORMAT_TEXT[DDPDDDDD_NSEW] = "dd.ddddd° S"; +DEG_FORMAT_TEXT[DD_MMPMMM_NSEW] = "dd°mm.mmm' S"; +DEG_FORMAT_TEXT[DD_MM_SSPS_NSEW] = "dd°mm'ss.s\" S"; +} + static inline gdouble magnitude(gdouble x1, gdouble y1, gdouble x2, gdouble y2) { @@ -209,3 +220,44 @@ c*=180.f/M_PIl; c=c+360 % 360; return c; } + +void +deg_format(DegFormat degformat, gdouble coor, gchar * scoor, gchar neg_char, gchar pos_char) +{ +gdouble min; +gdouble acoor=fabs(coor); + +switch (degformat) { + case DDPDDDDD: + g_sprintf(scoor, "%.5f°", coor); + break; + case DDPDDDDD_NSEW: + g_sprintf(scoor, "%.5f° %c", acoor, + coor < 0.f ? neg_char : pos_char); + break; + + case DD_MMPMMM: + g_sprintf(scoor, "%d°%06.3f'", + (int)coor, (acoor - (int)acoor) * 60.0); + break; + case DD_MMPMMM_NSEW: + g_sprintf(scoor, "%d°%06.3f' %c", + (int)acoor, (acoor - (int)acoor) * 60.0, + coor < 0.f ? neg_char : pos_char); + break; + + case DD_MM_SSPS: + min = (acoor - (int)acoor) * 60.0; + g_sprintf(scoor, "%d°%02d'%04.1f\"", (int)coor, (int)min, + ((min - (int)min) * 60.0)); + break; + case DD_MM_SSPS_NSEW: + min = (acoor - (int)acoor) * 60.0; + g_sprintf(scoor, "%d°%02d'%04.1f\" %c", (int)acoor, (int)min, + ((min - (int)min) * 60.0), + coor < 0.f ? neg_char : pos_char); + break; + default:; +} +} + diff --git a/src/latlon.h b/src/latlon.h index 5ac94ae..e2eefb1 100644 --- a/src/latlon.h +++ b/src/latlon.h @@ -8,6 +8,22 @@ #define LATLON_MIN -2147483646 #define EARTH_RADIUS (3440.06479f) +typedef enum { + DDPDDDDD, + DD_MMPMMM, + DD_MM_SSPS, + DDPDDDDD_NSEW, + DD_MMPMMM_NSEW, + DD_MM_SSPS_NSEW, + DEG_FORMAT_ENUM_COUNT +} DegFormat; +gchar *DEG_FORMAT_TEXT[DEG_FORMAT_ENUM_COUNT]; + +#define lat_format(F, A, B) deg_format((F),(A), (B), 'S', 'N') +#define lon_format(F, A, B) deg_format((F),(A), (B), 'W', 'E') + +void latlon_init(void); + gint32 lon2mp_int(gdouble lon); gint32 lat2mp_int(gdouble lat); gdouble calculate_distance(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2); @@ -22,4 +38,6 @@ guint32 xy2tile(guint x, guint y); guint32 lon2x(gdouble lon); guint32 lat2y(gdouble lat); +void deg_format(DegFormat degformat, gdouble coor, gchar *scoor, gchar neg_char, gchar pos_char); + #endif diff --git a/src/mapper-types.h b/src/mapper-types.h index ac1f859..6792b4b 100644 --- a/src/mapper-types.h +++ b/src/mapper-types.h @@ -149,17 +149,6 @@ typedef enum { gchar *COLORABLE_GCONF[COLORABLE_ENUM_COUNT]; GdkColor COLORABLE_DEFAULT[COLORABLE_ENUM_COUNT]; -typedef enum { - DDPDDDDD, - DD_MMPMMM, - DD_MM_SSPS, - DDPDDDDD_NSEW, - DD_MMPMMM_NSEW, - DD_MM_SSPS_NSEW, - DEG_FORMAT_ENUM_COUNT -} DegFormat; -gchar *DEG_FORMAT_TEXT[DEG_FORMAT_ENUM_COUNT]; - typedef enum { SPEED_LOCATION_TOP_LEFT, SPEED_LOCATION_TOP_RIGHT, diff --git a/src/mapper.c b/src/mapper.c index 4857844..470c7f3 100644 --- a/src/mapper.c +++ b/src/mapper.c @@ -211,7 +211,8 @@ switch (mis) { gnome_vfs_init(); timezone_init(); gpx_init(); - mapper_init_variables(); + variables_init(); + latlon_init(); track_init(); route_init(); mis=MAPPER_INIT_CONFIG; diff --git a/src/osm-db.c b/src/osm-db.c index 317a1b0..18ad92e 100644 --- a/src/osm-db.c +++ b/src/osm-db.c @@ -1047,8 +1047,8 @@ while (SQLITE_ROW == sqlite3_step(sql.select_way_name_search)) { rlat=sqlite3_column_double(sql.select_way_name_search, 3); rlon=sqlite3_column_double(sql.select_way_name_search, 4); - lat_format(rlat, tmp1); - lon_format(rlon, tmp2); + lat_format(_degformat, rlat, tmp1); + lon_format(_degformat, rlon, tmp2); dist=calculate_distance(lat, lon, rlat, rlon) * UNITS_CONVERT[_units]; gtk_list_store_append(*store, &iter); diff --git a/src/poi-gui.c b/src/poi-gui.c index 65ec0a5..bb3cfff 100644 --- a/src/poi-gui.c +++ b/src/poi-gui.c @@ -23,6 +23,7 @@ #include "gps.h" #include "map.h" #include "mapper-types.h" +#include "latlon.h" #include "ui-common.h" #include "settings.h" #include "poi-gui.h" @@ -821,8 +822,8 @@ if (action == ACTION_EDIT_POI) { } /* Set the p_latlon string. */ -lat_format(poi->lat, tmp1); -lon_format(poi->lon, tmp2); +lat_format(_degformat, poi->lat, tmp1); +lon_format(_degformat, poi->lon, tmp2); p_latlon=g_strdup_printf("%s, %s", tmp1, tmp2); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), table = gtk_table_new(6, 4, FALSE), TRUE, TRUE, 0); diff --git a/src/poi.c b/src/poi.c index 8b1ce81..60861b1 100644 --- a/src/poi.c +++ b/src/poi.c @@ -626,8 +626,8 @@ while (SQLITE_ROW == sqlite3_step(sql)) { rlat=sqlite3_column_double(sql, 0); rlon=sqlite3_column_double(sql, 1); - lat_format(rlat, tmp1); - lon_format(rlon, tmp2); + lat_format(_degformat, rlat, tmp1); + lon_format(_degformat, rlon, tmp2); dist=calculate_distance(lat, lon, rlat, rlon) * UNITS_CONVERT[_units]; gtk_list_store_append(*store, &iter); @@ -679,8 +679,8 @@ while (SQLITE_ROW == sqlite3_step(poisql.select_poi)) { lat=sqlite3_column_double(poisql.select_poi, 0); lon=sqlite3_column_double(poisql.select_poi, 1); - lat_format(lat, tmp1); - lon_format(lon, tmp2); + lat_format(_degformat, lat, tmp1); + lon_format(_degformat, lon, tmp2); gtk_list_store_append(*store, &iter); gtk_list_store_set(*store, &iter, diff --git a/src/settings-gui.c b/src/settings-gui.c index 598d885..dc6d734 100644 --- a/src/settings-gui.c +++ b/src/settings-gui.c @@ -29,6 +29,7 @@ #include "gps.h" #include "map.h" #include "mapper-types.h" +#include "latlon.h" #include "bt.h" #include "ui-common.h" #include "settings.h" diff --git a/src/track.c b/src/track.c index a4642cd..f6194c5 100644 --- a/src/track.c +++ b/src/track.c @@ -296,8 +296,8 @@ gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Lat, Lon")), 0, 1, 0 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); unit2latlon(_pos.unitx, _pos.unity, lat, lon); -lat_format(lat, tmp1); -lon_format(lon, tmp2); +lat_format(_degformat, lat, tmp1); +lon_format(_degformat, lon, tmp2); p_latlon = g_strdup_printf("%s, %s", tmp1, tmp2); gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(p_latlon), 1, 2, 0, 1, GTK_FILL, 0, 2, 4); gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f); diff --git a/src/ui-common.c b/src/ui-common.c index 02777dd..f051ddb 100644 --- a/src/ui-common.c +++ b/src/ui-common.c @@ -537,7 +537,7 @@ _menu_map = menu; } void -mapper_init_variables(void) +variables_init(void) { UNITS_TEXT[UNITS_KM] = _("km"); UNITS_TEXT[UNITS_MI] = _("mi."); @@ -612,18 +612,6 @@ COLORABLE_GCONF[COLORABLE_ROUTE] = GCONF_KEY_PREFIX "/color_route"; COLORABLE_GCONF[COLORABLE_ROUTE_WAY] = GCONF_KEY_PREFIX "/color_route_way"; COLORABLE_GCONF[COLORABLE_ROUTE_BREAK] = GCONF_KEY_PREFIX "/color_route_break"; COLORABLE_GCONF[COLORABLE_POI] = GCONF_KEY_PREFIX "/color_poi"; - -DEG_FORMAT_TEXT[DDPDDDDD] = "-dd.ddddd°"; -DEG_FORMAT_TEXT[DD_MMPMMM] = "-dd°mm.mmm'"; -DEG_FORMAT_TEXT[DD_MM_SSPS] = "-dd°mm'ss.s\""; -DEG_FORMAT_TEXT[DDPDDDDD_NSEW] = "dd.ddddd° S"; -DEG_FORMAT_TEXT[DD_MMPMMM_NSEW] = "dd°mm.mmm' S"; -DEG_FORMAT_TEXT[DD_MM_SSPS_NSEW] = "dd°mm'ss.s\" S"; - -SPEED_LOCATION_TEXT[SPEED_LOCATION_TOP_LEFT] = _("Top-Left"); -SPEED_LOCATION_TEXT[SPEED_LOCATION_TOP_RIGHT] = _("Top-Right"); -SPEED_LOCATION_TEXT[SPEED_LOCATION_BOTTOM_RIGHT] = _("Bottom-Right"); -SPEED_LOCATION_TEXT[SPEED_LOCATION_BOTTOM_LEFT] = _("Bottom-Left"); } /** diff --git a/src/utils.c b/src/utils.c index 98cbac0..5cef141 100644 --- a/src/utils.c +++ b/src/utils.c @@ -36,45 +36,6 @@ gdk_beep(); #endif } -void -deg_format(DegFormat degformat, gdouble coor, gchar * scoor, gchar neg_char, gchar pos_char) -{ -gdouble min; -gdouble acoor=fabs(coor); - -switch (degformat) { - case DDPDDDDD: - sprintf(scoor, "%.5f°", coor); - break; - case DDPDDDDD_NSEW: - sprintf(scoor, "%.5f° %c", acoor, - coor < 0.f ? neg_char : pos_char); - break; - - case DD_MMPMMM: - sprintf(scoor, "%d°%06.3f'", - (int)coor, (acoor - (int)acoor) * 60.0); - break; - case DD_MMPMMM_NSEW: - sprintf(scoor, "%d°%06.3f' %c", - (int)acoor, (acoor - (int)acoor) * 60.0, - coor < 0.f ? neg_char : pos_char); - break; - - case DD_MM_SSPS: - min = (acoor - (int)acoor) * 60.0; - sprintf(scoor, "%d°%02d'%04.1f\"", (int)coor, (int)min, - ((min - (int)min) * 60.0)); - break; - case DD_MM_SSPS_NSEW: - min = (acoor - (int)acoor) * 60.0; - sprintf(scoor, "%d°%02d'%04.1f\" %c", (int)acoor, (int)min, - ((min - (int)min) * 60.0), - coor < 0.f ? neg_char : pos_char); - break; - default:; -} -} /** * Convert the float lat/lon/speed/heading data into integer units. diff --git a/src/utils.h b/src/utils.h index 1b9f0bc..f7b0cb3 100644 --- a/src/utils.h +++ b/src/utils.h @@ -282,9 +282,6 @@ #define KEEP_DISPLAY_ON() #endif -#define lat_format(A, B) deg_format(_degformat,(A), (B), 'S', 'N') -#define lon_format(A, B) deg_format(_degformat,(A), (B), 'W', 'E') - #define TRACKS_MASK 0x00000001 #define ROUTES_MASK 0x00000002 @@ -340,7 +337,6 @@ if (_http_proxy_host) { \ void sound_noise(void); gint download_comparefunc(const ProgressUpdateInfo * a, const ProgressUpdateInfo * b, gpointer user_data); -void deg_format(DegFormat degformat, gdouble coor, gchar *scoor, gchar neg_char, gchar pos_char); void integerize_data(GpsData *gps, Point *pos); #endif -- 2.39.5