]> git.street.me.uk Git - andy/viking.git/blobdiff - src/vikdemlayer.c
Add track and waypoint highlight for the selected layer or individual item.
[andy/viking.git] / src / vikdemlayer.c
index a9c5a6ece1234763b3fcb077d6b870d561075bf6..0dce1854c63f6403fc893b4066ef4dc2d36831dc 100644 (file)
@@ -71,6 +71,7 @@
 
 #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 );
@@ -212,6 +213,9 @@ VikLayerInterface vik_dem_layer_interface = {
 
   (VikLayerFuncSublayerRenameRequest)   NULL,
   (VikLayerFuncSublayerToggleVisible)   NULL,
+  (VikLayerFuncSublayerTooltip)         NULL,
+  (VikLayerFuncLayerTooltip)            dem_layer_tooltip,
+  (VikLayerFuncLayerSelected)           NULL,
 
   (VikLayerFuncMarshall)               dem_layer_marshall,
   (VikLayerFuncUnmarshall)             dem_layer_unmarshall,
@@ -223,6 +227,7 @@ VikLayerInterface vik_dem_layer_interface = {
   (VikLayerFuncWriteFileData)           NULL,
 
   (VikLayerFuncDeleteItem)              NULL,
+  (VikLayerFuncCutItem)                 NULL,
   (VikLayerFuncCopyItem)                NULL,
   (VikLayerFuncPasteItem)               NULL,
   (VikLayerFuncFreeCopiedItem)          NULL,
@@ -265,6 +270,13 @@ GType vik_dem_layer_get_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 );
@@ -286,6 +298,47 @@ static VikDEMLayer *dem_layer_unmarshall( guint8 *data, gint len, VikViewport *v
   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) );
+  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 )
@@ -309,7 +362,26 @@ gboolean dem_layer_set_param ( VikDEMLayer *vdl, guint16 id, VikLayerParamData d
       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;
 }