]> git.street.me.uk Git - andy/viking.git/blobdiff - src/vikdemlayer.c
Add Terraserver
[andy/viking.git] / src / vikdemlayer.c
index 63814556b0a5773efcefb9316fbd641b18892b71..bfe51ab2395e025793e04940f64aeca83e17f31f 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  */
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 #include <math.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <string.h>
 #include <stdlib.h>
 #include <math.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <string.h>
 #include <stdlib.h>
+#include <glib/gi18n.h>
 
 #include "config.h"
 #include "globals.h"
 
 #include "config.h"
 #include "globals.h"
@@ -38,8 +42,6 @@
 #include "vikaggregatelayer.h"
 #include "viklayerspanel.h"
 #include "vikdemlayer.h"
 #include "vikaggregatelayer.h"
 #include "viklayerspanel.h"
 #include "vikdemlayer.h"
-#include "vikdemlayer_pixmap.h"
-#include "vikmapslayer.h"
 #include "dialog.h"
 
 #include "dem.h"
 #include "dialog.h"
 
 #include "dem.h"
@@ -82,6 +84,7 @@ static gchar *params_source[] = {
        "USA 10m (USGS 24k)",
 #endif
         "None",
        "USA 10m (USGS 24k)",
 #endif
         "None",
+       NULL
        };
 
 enum { DEM_SOURCE_SRTM,
        };
 
 enum { DEM_SOURCE_SRTM,
@@ -92,12 +95,12 @@ enum { DEM_SOURCE_SRTM,
      };
 
 static VikLayerParam dem_layer_params[] = {
      };
 
 static VikLayerParam dem_layer_params[] = {
-  { "files", VIK_LAYER_PARAM_STRING_LIST, VIK_LAYER_GROUP_NONE, "DEM Files:", VIK_LAYER_WIDGET_FILELIST },
-  { "source", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, "Download Source:", VIK_LAYER_WIDGET_RADIOGROUP_STATIC, params_source, NULL },
-  { "color", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, "Color:", VIK_LAYER_WIDGET_ENTRY },
-  { "min_elev", VIK_LAYER_PARAM_DOUBLE, VIK_LAYER_GROUP_NONE, "Min Elev:", VIK_LAYER_WIDGET_SPINBUTTON, param_scales + 0 },
-  { "max_elev", VIK_LAYER_PARAM_DOUBLE, VIK_LAYER_GROUP_NONE, "Max Elev:", VIK_LAYER_WIDGET_SPINBUTTON, param_scales + 0 },
-  { "line_thickness", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, "Line Thickness:", VIK_LAYER_WIDGET_SPINBUTTON, param_scales + 1 },
+  { "files", VIK_LAYER_PARAM_STRING_LIST, VIK_LAYER_GROUP_NONE, N_("DEM Files:"), VIK_LAYER_WIDGET_FILELIST },
+  { "source", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Download Source:"), VIK_LAYER_WIDGET_RADIOGROUP_STATIC, params_source, NULL },
+  { "color", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, N_("Color:"), VIK_LAYER_WIDGET_ENTRY },
+  { "min_elev", VIK_LAYER_PARAM_DOUBLE, VIK_LAYER_GROUP_NONE, N_("Min Elev:"), VIK_LAYER_WIDGET_SPINBUTTON, param_scales + 0 },
+  { "max_elev", VIK_LAYER_PARAM_DOUBLE, VIK_LAYER_GROUP_NONE, N_("Max Elev:"), VIK_LAYER_WIDGET_SPINBUTTON, param_scales + 0 },
+  { "line_thickness", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Line Thickness:"), VIK_LAYER_WIDGET_SPINBUTTON, param_scales + 1 },
 };
 
 
 };
 
 
@@ -108,9 +111,9 @@ static gboolean dem_layer_download_release ( VikDEMLayer *vdl, GdkEventButton *e
 static gboolean dem_layer_download_click ( VikDEMLayer *vdl, GdkEventButton *event, VikViewport *vvp );
 
 static VikToolInterface dem_tools[] = {
 static gboolean dem_layer_download_click ( VikDEMLayer *vdl, GdkEventButton *event, VikViewport *vvp );
 
 static VikToolInterface dem_tools[] = {
-  { "DEM Download/Import", (VikToolConstructorFunc) dem_layer_download_create, NULL, NULL, NULL,
+  { N_("DEM Download/Import"), (VikToolConstructorFunc) dem_layer_download_create, NULL, NULL, NULL,
     (VikToolMouseFunc) dem_layer_download_click, NULL,  (VikToolMouseFunc) dem_layer_download_release,
     (VikToolMouseFunc) dem_layer_download_click, NULL,  (VikToolMouseFunc) dem_layer_download_release,
-    (VikToolKeyFunc) NULL, &cursor_demdl },
+    (VikToolKeyFunc) NULL, GDK_CURSOR_IS_PIXMAP, &cursor_demdl_pixbuf },
 };
 
 
 };
 
 
@@ -228,7 +231,7 @@ static const guint DEM_N_COLORS = sizeof(dem_colors)/sizeof(dem_colors[0]);
 
 VikLayerInterface vik_dem_layer_interface = {
   "DEM",
 
 VikLayerInterface vik_dem_layer_interface = {
   "DEM",
-  &demlayer_pixbuf,
+  &vikdemlayer_pixbuf,
 
   dem_tools,
   sizeof(dem_tools) / sizeof(dem_tools[0]),
 
   dem_tools,
   sizeof(dem_tools) / sizeof(dem_tools[0]),
@@ -631,7 +634,7 @@ static const gchar *srtm_continent_dir ( gint lat, gint lon )
     while (*s != (gchar *)-1) {
       continent = *s++;
       while (*s) {
     while (*s != (gchar *)-1) {
       continent = *s++;
       while (*s) {
-        g_hash_table_insert(srtm_continent, *s, continent);
+        g_hash_table_insert(srtm_continent, (gpointer) *s, (gpointer) continent);
         s++;
       }
       s++;
         s++;
       }
       s++;
@@ -738,7 +741,7 @@ static void srtm_dem_download_thread ( DEMDownloadParams *p, gpointer threaddata
   continent_dir = srtm_continent_dir(intlat, intlon);
 
   if (!continent_dir) {
   continent_dir = srtm_continent_dir(intlat, intlon);
 
   if (!continent_dir) {
-    g_warning("No SRTM data available for %f, %f\n", p->lat, p->lon);
+    g_warning(N_("No SRTM data available for %f, %f"), p->lat, p->lon);
     return;
   }
 
     return;
   }
 
@@ -751,7 +754,7 @@ static void srtm_dem_download_thread ( DEMDownloadParams *p, gpointer threaddata
                (intlon >= 0) ? 'E' : 'W',
                ABS(intlon) );
 
                (intlon >= 0) ? 'E' : 'W',
                ABS(intlon) );
 
-  DownloadOptions options = { NULL, 0 };
+  static DownloadOptions options = { NULL, 0, a_check_map_file };
   a_ftp_download_get_url ( SRTM_FTP_SITE, src_fn, p->dest, &options );
   g_free ( src_fn );
 }
   a_ftp_download_get_url ( SRTM_FTP_SITE, src_fn, p->dest, &options );
   g_free ( src_fn );
 }
@@ -800,7 +803,7 @@ static void srtm_draw_existence ( VikViewport *vp )
                ABS(i),
                (j >= 0) ? 'E' : 'W',
                ABS(j) );
                ABS(i),
                (j >= 0) ? 'E' : 'W',
                ABS(j) );
-      if ( access(buf, F_OK ) == 0 ) {
+      if ( g_file_test(buf, G_FILE_TEST_EXISTS ) == TRUE ) {
         VikCoord ne, sw;
         gint x1, y1, x2, y2;
         sw.north_south = i;
         VikCoord ne, sw;
         gint x1, y1, x2, y2;
         sw.north_south = i;
@@ -861,7 +864,7 @@ static void dem24k_draw_existence ( VikViewport *vp )
     g_snprintf(buf, sizeof(buf), "%sdem24k/%d/",
         MAPS_CACHE_DIR,
        (gint) i );
     g_snprintf(buf, sizeof(buf), "%sdem24k/%d/",
         MAPS_CACHE_DIR,
        (gint) i );
-    if ( access(buf, F_OK) != 0 )
+    if ( g_file_test(buf, G_FILE_TEST_EXISTS) == FALSE )
       continue;
     for (j = floor(min_lon*8)/8; j <= floor(max_lon*8)/8; j+=0.125) {
       /* check lon dir first -- faster */
       continue;
     for (j = floor(min_lon*8)/8; j <= floor(max_lon*8)/8; j+=0.125) {
       /* check lon dir first -- faster */
@@ -869,7 +872,7 @@ static void dem24k_draw_existence ( VikViewport *vp )
         MAPS_CACHE_DIR,
        (gint) i,
         (gint) j );
         MAPS_CACHE_DIR,
        (gint) i,
         (gint) j );
-      if ( access(buf, F_OK) != 0 )
+      if ( g_file_test(buf, G_FILE_TEST_EXISTS) == FALSE )
         continue;
       g_snprintf(buf, sizeof(buf), "%sdem24k/%d/%d/%.03f,%.03f.dem",
                MAPS_CACHE_DIR,
         continue;
       g_snprintf(buf, sizeof(buf), "%sdem24k/%d/%d/%.03f,%.03f.dem",
                MAPS_CACHE_DIR,
@@ -877,7 +880,7 @@ static void dem24k_draw_existence ( VikViewport *vp )
                (gint) j,
                floor(i*8)/8,
                floor(j*8)/8 );
                (gint) j,
                floor(i*8)/8,
                floor(j*8)/8 );
-      if ( access(buf, F_OK ) == 0 ) {
+      if ( g_file_test(buf, G_FILE_TEST_EXISTS ) == TRUE ) {
         VikCoord ne, sw;
         gint x1, y1, x2, y2;
         sw.north_south = i;
         VikCoord ne, sw;
         gint x1, y1, x2, y2;
         sw.north_south = i;
@@ -917,15 +920,15 @@ static void weak_ref_cb ( gpointer ptr, GObject * dead_vdl )
  */
 static gboolean dem_layer_add_file ( VikDEMLayer *vdl, const gchar *full_path )
 {
  */
 static gboolean dem_layer_add_file ( VikDEMLayer *vdl, const gchar *full_path )
 {
-  if ( access(full_path, F_OK ) == 0 ) {
-    /* only load if file size is not 0 (not in progress */
+  if ( g_file_test(full_path, G_FILE_TEST_EXISTS ) == TRUE ) {
+    /* only load if file size is not 0 (not in progress) */
     struct stat sb;
     stat (full_path, &sb);
     if ( sb.st_size ) {
       gchar *duped_path = g_strdup(full_path);
       vdl->files = g_list_prepend ( vdl->files, duped_path );
       a_dems_load ( duped_path );
     struct stat sb;
     stat (full_path, &sb);
     if ( sb.st_size ) {
       gchar *duped_path = g_strdup(full_path);
       vdl->files = g_list_prepend ( vdl->files, duped_path );
       a_dems_load ( duped_path );
-      g_warning(duped_path);
+      g_debug("%s: %s", __FUNCTION__, duped_path);
       vik_layer_emit_update ( VIK_LAYER(vdl) );
     }
     return TRUE;
       vik_layer_emit_update ( VIK_LAYER(vdl) );
     }
     return TRUE;
@@ -977,7 +980,7 @@ static gboolean dem_layer_download_release ( VikDEMLayer *vdl, GdkEventButton *e
   gchar *dem_file = NULL;
 
   if ( vdl->source == DEM_SOURCE_NONE )
   gchar *dem_file = NULL;
 
   if ( vdl->source == DEM_SOURCE_NONE )
-    a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_LAYER(vdl), "No download source selected. Edit layer properties." );
+    a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_LAYER(vdl), _("No download source selected. Edit layer properties.") );
 
   vik_viewport_screen_to_coord ( vvp, event->x, event->y, &coord );
   vik_coord_to_latlon ( &coord, &ll );
 
   vik_viewport_screen_to_coord ( vvp, event->x, event->y, &coord );
   vik_coord_to_latlon ( &coord, &ll );
@@ -995,12 +998,12 @@ static gboolean dem_layer_download_release ( VikDEMLayer *vdl, GdkEventButton *e
 
   full_path = g_strdup_printf("%s%s", MAPS_CACHE_DIR, dem_file );
 
 
   full_path = g_strdup_printf("%s%s", MAPS_CACHE_DIR, dem_file );
 
-  g_warning(full_path);
+  g_debug("%s: %s", __FUNCTION__, full_path);
 
   // TODO: check if already in filelist
 
   if ( ! dem_layer_add_file(vdl, full_path) ) {
 
   // TODO: check if already in filelist
 
   if ( ! dem_layer_add_file(vdl, full_path) ) {
-    gchar *tmp = g_strdup_printf ( "Downloading DEM %s ", dem_file );
+    gchar *tmp = g_strdup_printf ( _("Downloading DEM %s"), dem_file );
     DEMDownloadParams *p = g_malloc(sizeof(DEMDownloadParams));
     p->dest = g_strdup(full_path);
     p->lat = ll.lat;
     DEMDownloadParams *p = g_malloc(sizeof(DEMDownloadParams));
     p->dest = g_strdup(full_path);
     p->lat = ll.lat;