From 6e73734930503c104ddc16091467f30093f42aa9 Mon Sep 17 00:00:00 2001 From: camel Date: Thu, 1 Jan 2009 18:09:06 +0000 Subject: [PATCH] Improved alternate coordinate system support (e.g. OS NGR) git-svn-id: svn+ssh://garage/var/lib/gforge/svnroot/maemo-mapper/trunk@240 6c538b50-5814-0410-93ad-8bdf4c0149d1 --- src/path.c | 61 ++++++++++++++++++++++++++----- src/poi.c | 103 ++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 123 insertions(+), 41 deletions(-) diff --git a/src/path.c b/src/path.c index b98a177..7f31690 100644 --- a/src/path.c +++ b/src/path.c @@ -1496,10 +1496,34 @@ route_add_way_dialog(gint unitx, gint unity) static GtkWidget *dialog = NULL; static GtkWidget *table = NULL; static GtkWidget *label = NULL; + static GtkWidget *label_lat_lon = NULL; static GtkWidget *txt_scroll = NULL; static GtkWidget *txt_desc = NULL; + static int last_deg_format = 0; + printf("%s()\n", __PRETTY_FUNCTION__); + unit2latlon(unitx, unity, lat, lon); + + gint fallback_deg_format = _degformat; + + if(!coord_system_check_lat_lon (lat, lon, &fallback_deg_format)) + { + last_deg_format = _degformat; + _degformat = fallback_deg_format; + + if(dialog != NULL) gtk_widget_destroy(dialog); + dialog = NULL; + } + else if(_degformat != last_deg_format) + { + last_deg_format = _degformat; + + if(dialog != NULL) gtk_widget_destroy(dialog); + dialog = NULL; + } + + if(dialog == NULL) { dialog = gtk_dialog_new_with_buttons(_("Add Waypoint"), @@ -1511,20 +1535,27 @@ route_add_way_dialog(gint unitx, gint unity) gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), table = gtk_table_new(2, 2, FALSE), TRUE, TRUE, 0); + + + if(DEG_FORMAT_ENUM_TEXT[_degformat].field_2_in_use) + p_latlon = g_strdup_printf("%s, %s", + DEG_FORMAT_ENUM_TEXT[_degformat].short_field_1, + DEG_FORMAT_ENUM_TEXT[_degformat].short_field_2); + else + p_latlon = g_strdup_printf("%s", DEG_FORMAT_ENUM_TEXT[_degformat].short_field_1); + gtk_table_attach(GTK_TABLE(table), - label = gtk_label_new(_("Lat, Lon:")), + label = gtk_label_new(p_latlon), 0, 1, 0, 1, GTK_FILL, 0, 2, 4); gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); - unit2latlon(unitx, unity, lat, lon); - lat_format(lat, tmp1); - lon_format(lon, tmp2); - p_latlon = g_strdup_printf("%s, %s", tmp1, tmp2); + g_free(p_latlon); + gtk_table_attach(GTK_TABLE(table), - label = gtk_label_new(p_latlon), + label_lat_lon = gtk_label_new(_("") ), 1, 2, 0, 1, GTK_FILL, 0, 2, 4); - gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f); - g_free(p_latlon); + gtk_misc_set_alignment(GTK_MISC(label_lat_lon), 0.0f, 0.5f); + gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Description")), @@ -1548,6 +1579,17 @@ route_add_way_dialog(gint unitx, gint unity) gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 400, 60); } + format_lat_lon(lat, lon, tmp1, tmp2); + + if(DEG_FORMAT_ENUM_TEXT[_degformat].field_2_in_use) + p_latlon = g_strdup_printf("%s, %s", tmp1, tmp2); + else + p_latlon = g_strdup_printf("%s", tmp1); + + + gtk_label_set_text(GTK_LABEL(label_lat_lon), p_latlon); + g_free(p_latlon); + gtk_text_buffer_set_text( gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc)), "", 0); @@ -1620,6 +1662,9 @@ route_add_way_dialog(gint unitx, gint unity) break; } gtk_widget_hide(dialog); + + _degformat = last_deg_format; + vprintf("%s(): return\n", __PRETTY_FUNCTION__); } diff --git a/src/poi.c b/src/poi.c index 38f1f33..41d9f68 100644 --- a/src/poi.c +++ b/src/poi.c @@ -1143,8 +1143,34 @@ poi_add_dialog(GtkWidget *parent, gint unitx, gint unity) static GtkTextIter begin, end; static DeletePOI dpoi = {NULL, NULL, 0}; static PoiCategoryEditInfo pcedit; + static int last_deg_format = 0; + printf("%s()\n", __PRETTY_FUNCTION__); + unit2latlon(unitx, unity, poi.lat, poi.lon); + + + gint fallback_deg_format = _degformat; + + if(!coord_system_check_lat_lon (poi.lat, poi.lon, &fallback_deg_format)) + { + last_deg_format = _degformat; + _degformat = fallback_deg_format; + + if(dialog != NULL) gtk_widget_destroy(dialog); + dialog = NULL; + } + else if(_degformat != last_deg_format) + { + last_deg_format = _degformat; + + if(dialog != NULL) gtk_widget_destroy(dialog); + dialog = NULL; + } + + + + if(dialog == NULL) { dialog = gtk_dialog_new_with_buttons(_("Add POI"), @@ -1158,21 +1184,25 @@ poi_add_dialog(GtkWidget *parent, gint unitx, gint unity) table = gtk_table_new(6, 4, FALSE), TRUE, TRUE, 0); gtk_table_attach(GTK_TABLE(table), - label = gtk_label_new(_("Lat")), + label = gtk_label_new(DEG_FORMAT_ENUM_TEXT[_degformat].short_field_1), 0, 1, 0, 1, GTK_FILL, 0, 2, 0); gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); gtk_table_attach(GTK_TABLE(table), txt_lat = gtk_entry_new(), - 1, 2, 0, 1, GTK_FILL, 0, 2, 0); - - gtk_table_attach(GTK_TABLE(table), - label = gtk_label_new(_("Lon")), - 2, 3, 0, 1, GTK_FILL, 0, 2, 0); - gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); - gtk_table_attach(GTK_TABLE(table), - txt_lon = gtk_entry_new(), - 3, 4, 0, 1, GTK_FILL, 0, 2, 0); + 1, (DEG_FORMAT_ENUM_TEXT[_degformat].field_2_in_use ? 2 : 4), + 0, 1, GTK_FILL, 0, 2, 0); + if(DEG_FORMAT_ENUM_TEXT[_degformat].field_2_in_use ) + { + gtk_table_attach(GTK_TABLE(table), + label = gtk_label_new(DEG_FORMAT_ENUM_TEXT[_degformat].short_field_2), + 2, 3, 0, 1, GTK_FILL, 0, 2, 0); + gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); + gtk_table_attach(GTK_TABLE(table), + txt_lon = gtk_entry_new(), + 3, 4, 0, 1, GTK_FILL, 0, 2, 0); + } + gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Label")), 0, 1, 1, 2, GTK_FILL, 0, 2, 0); @@ -1228,7 +1258,6 @@ poi_add_dialog(GtkWidget *parent, gint unitx, gint unity) poi.cat_id = -1; poi.clabel = NULL; poi.desc = g_strdup(""); - unit2latlon(unitx, unity, poi.lat, poi.lon); /* Lat/Lon */ { @@ -1239,7 +1268,9 @@ poi_add_dialog(GtkWidget *parent, gint unitx, gint unity) //lon_format(poi.lon, tmp2); gtk_entry_set_text(GTK_ENTRY(txt_lat), tmp1); - gtk_entry_set_text(GTK_ENTRY(txt_lon), tmp2); + + if(txt_lon != NULL) + gtk_entry_set_text(GTK_ENTRY(txt_lon), tmp2); } /* Label */ @@ -1288,23 +1319,19 @@ poi_add_dialog(GtkWidget *parent, gint unitx, gint unity) while(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { GtkTreeIter iter; - const gchar *text; - gchar *error_check; + const gchar *lat, *lon = NULL; - text = gtk_entry_get_text(GTK_ENTRY(txt_lat)); - poi.lat = strdmstod(text, &error_check); - if(text == error_check || poi.lat < -90. || poi.lat > 90.) { - popup_error(dialog, _("Invalid Latitude")); - continue; - } - - text = gtk_entry_get_text(GTK_ENTRY(txt_lon)); - poi.lon = strdmstod(text, &error_check); - if(text == error_check || poi.lon < -180. || poi.lon > 180.) { - popup_error(dialog, _("Invalid Longitude")); - continue; + lat = gtk_entry_get_text(GTK_ENTRY(txt_lat)); + + if(txt_lon != NULL) + lon = gtk_entry_get_text(GTK_ENTRY(txt_lon)); + + if(!parse_coords(lat, lon, &poi.lat, &poi.lon)) + { + popup_error(dialog, _("Invalid Coordinate specified")); + continue; } - + if(strlen(gtk_entry_get_text(GTK_ENTRY(txt_label)))) { if(poi.label) @@ -1365,6 +1392,8 @@ poi_add_dialog(GtkWidget *parent, gint unitx, gint unity) gtk_widget_hide(dialog); + _degformat = last_deg_format; + vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__); return !dpoi.deleted; } @@ -1393,8 +1422,17 @@ poi_view_dialog(GtkWidget *parent, PoiInfo *poi) printf("%s()\n", __PRETTY_FUNCTION__); - - if(_degformat != last_deg_format) + gint fallback_deg_format = _degformat; + + if(!coord_system_check_lat_lon (poi->lat, poi->lon, &fallback_deg_format)) + { + last_deg_format = _degformat; + _degformat = fallback_deg_format; + + if(dialog != NULL) gtk_widget_destroy(dialog); + dialog = NULL; + } + else if(_degformat != last_deg_format) { last_deg_format = _degformat; @@ -1535,8 +1573,7 @@ poi_view_dialog(GtkWidget *parent, PoiInfo *poi) while(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { - const gchar *text, *text_lat, *text_lon; - gchar *error_check; + const gchar *text_lat, *text_lon; text_lat = gtk_entry_get_text(GTK_ENTRY(txt_lat)); text_lon = gtk_entry_get_text(GTK_ENTRY(txt_lon)); @@ -1611,6 +1648,8 @@ poi_view_dialog(GtkWidget *parent, PoiInfo *poi) gtk_widget_hide(dialog); /* Destroying causes a crash.... ??? */ + _degformat = last_deg_format; + vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__); return !dpoi.deleted; } @@ -3293,9 +3332,7 @@ extern AprsDataRow *n_first; // pointer to first element in name s void map_render_aprs() { - printf("%s()\n", __PRETTY_FUNCTION__); - int mm; if(_poi_zoom > _zoom) { -- 2.45.0