]> git.street.me.uk Git - andy/viking.git/blobdiff - src/vikdemlayer.c
Merge branch 'i18n-launchpad'
[andy/viking.git] / src / vikdemlayer.c
index c9f24f579f4c975d851efc46736ba067c0cb0a41..d66bd4bb25e082c728f243c8e7f5eed536de1a5d 100644 (file)
@@ -71,6 +71,7 @@
 
 #define UNUSED_LINE_THICKNESS 3
 
 
 #define UNUSED_LINE_THICKNESS 3
 
+static const gchar* dem_layer_tooltip( VikDEMLayer *vdl );
 static void dem_layer_marshall( VikDEMLayer *vdl, guint8 **data, gint *len );
 static VikDEMLayer *dem_layer_unmarshall( guint8 *data, gint len, VikViewport *vvp );
 static gboolean dem_layer_set_param ( VikDEMLayer *vdl, guint16 id, VikLayerParamData data, VikViewport *vp, gboolean is_file_operation );
 static void dem_layer_marshall( VikDEMLayer *vdl, guint8 **data, gint *len );
 static VikDEMLayer *dem_layer_unmarshall( guint8 *data, gint len, VikViewport *vvp );
 static gboolean dem_layer_set_param ( VikDEMLayer *vdl, guint16 id, VikLayerParamData data, VikViewport *vp, gboolean is_file_operation );
@@ -93,7 +94,6 @@ static gchar *params_source[] = {
 #ifdef VIK_CONFIG_DEM24K
        "USA 10m (USGS 24k)",
 #endif
 #ifdef VIK_CONFIG_DEM24K
        "USA 10m (USGS 24k)",
 #endif
-        "None",
        NULL
        };
 
        NULL
        };
 
@@ -107,7 +107,6 @@ enum { DEM_SOURCE_SRTM,
 #ifdef VIK_CONFIG_DEM24K
        DEM_SOURCE_DEM24K,
 #endif
 #ifdef VIK_CONFIG_DEM24K
        DEM_SOURCE_DEM24K,
 #endif
-       DEM_SOURCE_NONE,
      };
 
 enum { DEM_TYPE_HEIGHT = 0,
      };
 
 enum { DEM_TYPE_HEIGHT = 0,
@@ -165,7 +164,7 @@ static const guint DEM_N_HEIGHT_COLORS = sizeof(dem_height_colors)/sizeof(dem_he
 */
 
 static gchar *dem_gradient_colors[] = {
 */
 
 static gchar *dem_gradient_colors[] = {
-"#AAAAAA"
+"#AAAAAA",
 "#000000", "#000011", "#000022", "#000033", "#000044", "#00004c", "#000055", "#00005d", "#000066", "#00006e",
 "#000077", "#00007f", "#000088", "#000090", "#000099", "#0000a1", "#0000aa", "#0000b2", "#0000bb", "#0000c3",
 "#0000cc", "#0000d4", "#0000dd", "#0000e5", "#0000ee", "#0000f6", "#0000ff", "#0008f7", "#0011ee", "#0019e6",
 "#000000", "#000011", "#000022", "#000033", "#000044", "#00004c", "#000055", "#00005d", "#000066", "#00006e",
 "#000077", "#00007f", "#000088", "#000090", "#000099", "#0000a1", "#0000aa", "#0000b2", "#0000bb", "#0000c3",
 "#0000cc", "#0000d4", "#0000dd", "#0000e5", "#0000ee", "#0000f6", "#0000ff", "#0008f7", "#0011ee", "#0019e6",
@@ -212,6 +211,9 @@ VikLayerInterface vik_dem_layer_interface = {
 
   (VikLayerFuncSublayerRenameRequest)   NULL,
   (VikLayerFuncSublayerToggleVisible)   NULL,
 
   (VikLayerFuncSublayerRenameRequest)   NULL,
   (VikLayerFuncSublayerToggleVisible)   NULL,
+  (VikLayerFuncSublayerTooltip)         NULL,
+  (VikLayerFuncLayerTooltip)            dem_layer_tooltip,
+  (VikLayerFuncLayerSelected)           NULL,
 
   (VikLayerFuncMarshall)               dem_layer_marshall,
   (VikLayerFuncUnmarshall)             dem_layer_unmarshall,
 
   (VikLayerFuncMarshall)               dem_layer_marshall,
   (VikLayerFuncUnmarshall)             dem_layer_unmarshall,
@@ -223,10 +225,16 @@ VikLayerInterface vik_dem_layer_interface = {
   (VikLayerFuncWriteFileData)           NULL,
 
   (VikLayerFuncDeleteItem)              NULL,
   (VikLayerFuncWriteFileData)           NULL,
 
   (VikLayerFuncDeleteItem)              NULL,
+  (VikLayerFuncCutItem)                 NULL,
   (VikLayerFuncCopyItem)                NULL,
   (VikLayerFuncPasteItem)               NULL,
   (VikLayerFuncFreeCopiedItem)          NULL,
   (VikLayerFuncDragDropRequest)                NULL,
   (VikLayerFuncCopyItem)                NULL,
   (VikLayerFuncPasteItem)               NULL,
   (VikLayerFuncFreeCopiedItem)          NULL,
   (VikLayerFuncDragDropRequest)                NULL,
+
+  (VikLayerFuncSelectClick)             NULL,
+  (VikLayerFuncSelectMove)              NULL,
+  (VikLayerFuncSelectRelease)           NULL,
+  (VikLayerFuncSelectedViewportMenu)    NULL,
 };
 
 struct _VikDEMLayer {
 };
 
 struct _VikDEMLayer {
@@ -265,6 +273,13 @@ GType vik_dem_layer_get_type ()
   return vdl_type;
 }
 
   return vdl_type;
 }
 
+static const gchar* dem_layer_tooltip( VikDEMLayer *vdl )
+{
+  static gchar tmp_buf[100];
+  g_snprintf (tmp_buf, sizeof(tmp_buf), _("Number of files: %d"), g_list_length (vdl->files));
+  return tmp_buf;
+}
+
 static void dem_layer_marshall( VikDEMLayer *vdl, guint8 **data, gint *len )
 {
   vik_layer_marshall_params ( VIK_LAYER(vdl), data, len );
 static void dem_layer_marshall( VikDEMLayer *vdl, guint8 **data, gint *len )
 {
   vik_layer_marshall_params ( VIK_LAYER(vdl), data, len );
@@ -286,6 +301,47 @@ static VikDEMLayer *dem_layer_unmarshall( guint8 *data, gint len, VikViewport *v
   return rv;
 }
 
   return rv;
 }
 
+/* Structure for DEM data used in background thread */
+typedef struct {
+  VikDEMLayer *vdl;
+} dem_load_thread_data;
+
+/*
+ * Function for starting the DEM file loading as a background thread
+ */
+static int dem_layer_load_list_thread ( dem_load_thread_data *dltd, gpointer threaddata )
+{
+  int result = 0; // Default to good
+  // Actual Load
+  if ( a_dems_load_list ( &(dltd->vdl->files), threaddata ) ) {
+    // Thread cancelled
+    result = -1;
+  }
+
+  // ATM as each file is processed the screen is not updated (no mechanism exposed to a_dems_load_list)
+  // Thus force draw only at the end, as loading is complete/aborted
+  //gdk_threads_enter();
+  // Test is helpful to prevent Gtk-CRITICAL warnings if the program is exitted whilst loading
+  if ( IS_VIK_LAYER(dltd->vdl) )
+    vik_layer_emit_update ( VIK_LAYER(dltd->vdl), TRUE ); // Yes update from background thread
+  //gdk_threads_leave();
+
+  return result;
+}
+
+static void dem_layer_thread_data_free ( dem_load_thread_data *data )
+{
+  // Simple release
+  g_free ( data );
+}
+
+static void dem_layer_thread_cancel ( dem_load_thread_data *data )
+{
+  // Abort loading
+  // Instead of freeing the list, leave it as partially processed
+  // Thus we can see/use what was done
+}
+
 gboolean dem_layer_set_param ( VikDEMLayer *vdl, guint16 id, VikLayerParamData data, VikViewport *vp, gboolean is_file_operation )
 {
   switch ( id )
 gboolean dem_layer_set_param ( VikDEMLayer *vdl, guint16 id, VikLayerParamData data, VikViewport *vp, gboolean is_file_operation )
 {
   switch ( id )
@@ -309,7 +365,26 @@ gboolean dem_layer_set_param ( VikDEMLayer *vdl, guint16 id, VikLayerParamData d
       else
         vdl->max_elev = data.d;
       break;
       else
         vdl->max_elev = data.d;
       break;
-    case PARAM_FILES: a_dems_load_list ( &(data.sl) ); a_dems_list_free ( vdl->files ); vdl->files = data.sl; break;
+    case PARAM_FILES:
+    {
+      // Clear out old settings - if any commonalities with new settings they will have to be read again
+      a_dems_list_free ( vdl->files );
+      // Set file list so any other intermediate screen drawing updates will show currently loaded DEMs by the working thread
+      vdl->files = data.sl;
+      // Thread Load
+      dem_load_thread_data *dltd = g_malloc ( sizeof(dem_load_thread_data) );
+      dltd->vdl = vdl;
+      dltd->vdl->files = data.sl;
+
+      a_background_thread ( VIK_GTK_WINDOW_FROM_WIDGET(vp),
+                           _("DEM Loading"),
+                           (vik_thr_func) dem_layer_load_list_thread,
+                           dltd,
+                           (vik_thr_free_func) dem_layer_thread_data_free,
+                           (vik_thr_free_func) dem_layer_thread_cancel,
+                           g_list_length ( data.sl ) ); // Number of DEM files
+      break;
+    }
   }
   return TRUE;
 }
   }
   return TRUE;
 }
@@ -818,7 +893,7 @@ static void srtm_dem_download_thread ( DEMDownloadParams *p, gpointer threaddata
                (intlon >= 0) ? 'E' : 'W',
                ABS(intlon) );
 
                (intlon >= 0) ? 'E' : 'W',
                ABS(intlon) );
 
-  static DownloadOptions options = { 0, NULL, 0, a_check_map_file };
+  static DownloadMapOptions options = { FALSE, FALSE, NULL, 0, a_check_map_file };
   a_http_download_get_url ( SRTM_HTTP_SITE, src_fn, p->dest, &options, NULL );
   g_free ( src_fn );
 }
   a_http_download_get_url ( SRTM_HTTP_SITE, src_fn, p->dest, &options, NULL );
   g_free ( src_fn );
 }
@@ -903,6 +978,7 @@ static void dem24k_dem_download_thread ( DEMDownloadParams *p, gpointer threadda
        ceil(p->lon*8)/8 );
   /* FIX: don't use system, use execv or something. check for existence */
   system(cmdline);
        ceil(p->lon*8)/8 );
   /* FIX: don't use system, use execv or something. check for existence */
   system(cmdline);
+  g_free ( cmdline );
 }
 
 static gchar *dem24k_lat_lon_to_dest_fn ( gdouble lat, gdouble lon )
 }
 
 static gchar *dem24k_lat_lon_to_dest_fn ( gdouble lat, gdouble lon )
@@ -993,7 +1069,6 @@ static gboolean dem_layer_add_file ( VikDEMLayer *vdl, const gchar *full_path )
       vdl->files = g_list_prepend ( vdl->files, duped_path );
       a_dems_load ( duped_path );
       g_debug("%s: %s", __FUNCTION__, duped_path);
       vdl->files = g_list_prepend ( vdl->files, duped_path );
       a_dems_load ( duped_path );
       g_debug("%s: %s", __FUNCTION__, duped_path);
-      vik_layer_emit_update ( VIK_LAYER(vdl) );
     }
     return TRUE;
   } else
     }
     return TRUE;
   } else
@@ -1008,17 +1083,19 @@ static void dem_download_thread ( DEMDownloadParams *p, gpointer threaddata )
   else if ( p->source == DEM_SOURCE_DEM24K )
     dem24k_dem_download_thread ( p, threaddata );
 #endif
   else if ( p->source == DEM_SOURCE_DEM24K )
     dem24k_dem_download_thread ( p, threaddata );
 #endif
+  else
+    return;
 
 
-  gdk_threads_enter();
+  //gdk_threads_enter();
   g_mutex_lock ( p->mutex );
   if ( p->vdl ) {
     g_object_weak_unref ( G_OBJECT(p->vdl), weak_ref_cb, p );
 
     if ( dem_layer_add_file ( p->vdl, p->dest ) )
   g_mutex_lock ( p->mutex );
   if ( p->vdl ) {
     g_object_weak_unref ( G_OBJECT(p->vdl), weak_ref_cb, p );
 
     if ( dem_layer_add_file ( p->vdl, p->dest ) )
-      vik_layer_emit_update ( VIK_LAYER(p->vdl) );
+      vik_layer_emit_update ( VIK_LAYER(p->vdl), TRUE ); // Yes update from background thread
   }
   g_mutex_unlock ( p->mutex );
   }
   g_mutex_unlock ( p->mutex );
-  gdk_threads_leave();
+  //gdk_threads_leave();
 }
 
 
 }
 
 
@@ -1043,9 +1120,6 @@ static gboolean dem_layer_download_release ( VikDEMLayer *vdl, GdkEventButton *e
   gchar *full_path;
   gchar *dem_file = NULL;
 
   gchar *full_path;
   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.") );
-
   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 );
 
@@ -1083,6 +1157,8 @@ static gboolean dem_layer_download_release ( VikDEMLayer *vdl, GdkEventButton *e
 
     g_free ( tmp );
   }
 
     g_free ( tmp );
   }
+  else
+    vik_layer_emit_update ( VIK_LAYER(vdl), FALSE );
 
   g_free ( dem_file );
   g_free ( full_path );
 
   g_free ( dem_file );
   g_free ( full_path );