/** * vik_layers_panel_add_layer: * @l: existing layer * * Add an existing layer to panel. */ void vik_layers_panel_add_layer ( VikLayersPanel *vlp, VikLayer *l ) { GtkTreeIter iter; GtkTreeIter *replace_iter = NULL; /* could be something different so we have to do this */ vik_layer_change_coord_mode ( l, vik_viewport_get_coord_mode(vlp->vvp) ); if ( ! vik_treeview_get_selected_iter ( vlp->vt, &iter ) ) vik_aggregate_layer_add_layer ( vlp->toplayer, l ); else { VikAggregateLayer *addtoagg; if (vik_treeview_item_get_type ( vlp->vt, &iter ) == VIK_TREEVIEW_TYPE_LAYER ) { if ( IS_VIK_AGGREGATE_LAYER(vik_treeview_item_get_pointer ( vlp->vt, &iter )) ) addtoagg = VIK_AGGREGATE_LAYER(vik_treeview_item_get_pointer ( vlp->vt, &iter )); else { VikLayer *vl = VIK_LAYER(vik_treeview_item_get_parent ( vlp->vt, &iter )); while ( ! IS_VIK_AGGREGATE_LAYER(vl) ) { iter = vl->iter; vl = VIK_LAYER(vik_treeview_item_get_parent ( vlp->vt, &vl->iter )); g_assert ( vl->realized ); } addtoagg = VIK_AGGREGATE_LAYER(vl); replace_iter = &iter; } } else { /* a sublayer is selected, first get its parent (layer), then find the layer's parent (aggr. layer) */ VikLayer *vl = VIK_LAYER(vik_treeview_item_get_parent ( vlp->vt, &iter )); replace_iter = &(vl->iter); g_assert ( vl->realized ); VikLayer *grandpa = (vik_treeview_item_get_parent ( vlp->vt, &(vl->iter) ) ); if (IS_VIK_AGGREGATE_LAYER(grandpa)) addtoagg = VIK_AGGREGATE_LAYER(grandpa); else { addtoagg = vlp->toplayer; replace_iter = &grandpa->iter; } } if ( replace_iter ) vik_aggregate_layer_insert_layer ( addtoagg, l, replace_iter ); else vik_aggregate_layer_add_layer ( addtoagg, l ); } vik_layers_panel_emit_update ( vlp ); }
VikAggregateLayer *vik_aggregate_layer_new () { VikAggregateLayer *val = VIK_AGGREGATE_LAYER ( g_object_new ( VIK_AGGREGATE_LAYER_TYPE, NULL ) ); vik_layer_set_type ( VIK_LAYER(val), VIK_LAYER_AGGREGATE ); val->children = NULL; return val; }
static void aggregate_layer_track_list_dialog ( menu_array_values values ) { VikAggregateLayer *val = VIK_AGGREGATE_LAYER ( values[MA_VAL] ); gchar *title = g_strdup_printf ( _("%s: Track and Route List"), VIK_LAYER(val)->name ); vik_trw_layer_track_list_show_dialog ( title, VIK_LAYER(val), NULL, aggregate_layer_track_create_list, TRUE ); g_free ( title ); }
/* returns 0 == we're good, 1 == didn't find any layers, 2 == got rejected */ guint vik_aggregate_layer_tool ( VikAggregateLayer *val, VikLayerTypeEnum layer_type, VikToolInterfaceFunc tool_func, GdkEventButton *event, VikViewport *vvp ) { GList *iter = val->children; gboolean found_rej = FALSE; if (!iter) return FALSE; while (iter->next) iter = iter->next; while ( iter ) { /* if this layer "accepts" the tool call */ if ( VIK_LAYER(iter->data)->visible && VIK_LAYER(iter->data)->type == layer_type ) { if ( tool_func ( VIK_LAYER(iter->data), event, vvp ) ) return 0; else found_rej = TRUE; } /* recursive -- try the same for the child aggregate layer. */ else if ( VIK_LAYER(iter->data)->visible && VIK_LAYER(iter->data)->type == VIK_LAYER_AGGREGATE ) { gint rv = vik_aggregate_layer_tool(VIK_AGGREGATE_LAYER(iter->data), layer_type, tool_func, event, vvp); if ( rv == 0 ) return 0; else if ( rv == 2 ) found_rej = TRUE; } iter = iter->prev; } return found_rej ? 2 : 1; /* no one wanted to accept the tool call in this layer */ }
static void aggregate_layer_track_list_dialog ( gpointer data[2] ) { VikAggregateLayer *val = VIK_AGGREGATE_LAYER(data[0]); gchar *title = g_strdup_printf ( _("%s: Track and Route List"), VIK_LAYER(val)->name ); vik_trw_layer_track_list_show_dialog ( title, VIK_LAYER(val), NULL, aggregate_layer_track_create_list, TRUE ); g_free ( title ); }
static void aggregate_layer_analyse ( menu_array_values values ) { VikAggregateLayer *val = VIK_AGGREGATE_LAYER ( values[MA_VAL] ); // There can only be one! if ( val->tracks_analysis_dialog ) return; val->tracks_analysis_dialog = vik_trw_layer_analyse_this ( VIK_GTK_WINDOW_FROM_LAYER(VIK_LAYER(val)), VIK_LAYER(val)->name, VIK_LAYER(val), NULL, aggregate_layer_track_create_list, aggregate_layer_analyse_close ); }
static void aggregate_layer_analyse ( gpointer data[2] ) { VikAggregateLayer *val = VIK_AGGREGATE_LAYER(data[0]); // There can only be one! if ( val->tracks_analysis_dialog ) return; val->tracks_analysis_dialog = vik_trw_layer_analyse_this ( VIK_GTK_WINDOW_FROM_LAYER(VIK_LAYER(val)), VIK_LAYER(val)->name, VIK_LAYER(val), NULL, aggregate_layer_track_create_list, aggregate_layer_analyse_close ); }
GList *vik_aggregate_layer_get_all_layers_of_type(VikAggregateLayer *val, GList *layers, VikLayerTypeEnum type, gboolean include_invisible) { GList *l = layers; GList *children = val->children; VikLayer *vl; if (!children) return layers; // Where appropriate *don't* include non-visible layers while (children) { vl = VIK_LAYER(children->data); if (vl->type == VIK_LAYER_AGGREGATE ) { // Don't even consider invisible aggregrates, unless told to if (vl->visible || include_invisible) l = vik_aggregate_layer_get_all_layers_of_type(VIK_AGGREGATE_LAYER(children->data), l, type, include_invisible); } else if (vl->type == type) { if (vl->visible || include_invisible) l = g_list_prepend(l, children->data); /* now in top down order */ } else if (type == VIK_LAYER_TRW) { /* GPS layers contain TRW layers. cf with usage in file.c */ if (VIK_LAYER(children->data)->type == VIK_LAYER_GPS) { if (VIK_LAYER(children->data)->visible || include_invisible) { if (!vik_gps_layer_is_empty(VIK_GPS_LAYER(children->data))) { /* can not use g_list_concat due to wrong copy method - crashes if used a couple times !! l = g_list_concat (l, vik_gps_layer_get_children (VIK_GPS_LAYER(children->data))); */ /* create own copy method instead :( */ GList *gps_trw_layers = (GList *)vik_gps_layer_get_children (VIK_GPS_LAYER(children->data)); int n_layers = g_list_length (gps_trw_layers); int layer = 0; for ( layer = 0; layer < n_layers; layer++) { l = g_list_prepend(l, gps_trw_layers->data); gps_trw_layers = gps_trw_layers->next; } g_list_free(gps_trw_layers); } } } } children = children->next; } return l; }
static void aggregate_layer_child_visible_toggle ( menu_array_values values ) { VikAggregateLayer *val = VIK_AGGREGATE_LAYER ( values[MA_VAL] ); VikLayersPanel *vlp = VIK_LAYERS_PANEL ( values[MA_VLP] ); VikLayer *vl; // Loop around all (child) layers applying visibility setting // This does not descend the tree if there are aggregates within aggregrate - just the first level of layers held GList *iter = val->children; while ( iter ) { vl = VIK_LAYER ( iter->data ); vl->visible = !vl->visible; // Also set checkbox on/off vik_treeview_item_toggle_visible ( vik_layers_panel_get_treeview ( vlp ), &(vl->iter) ); iter = iter->next; } // Redraw as view may have changed vik_layer_emit_update ( VIK_LAYER ( val ) ); }
static void aggregate_layer_child_visible ( gpointer data[2], gboolean on_off) { // Convert data back to correct types VikAggregateLayer *val = VIK_AGGREGATE_LAYER ( data[0] ); VikLayersPanel *vlp = VIK_LAYERS_PANEL ( data[1] ); VikLayer *vl; // Loop around all (child) layers applying visibility setting // This does not descend the tree if there are aggregates within aggregrate - just the first level of layers held GList *iter = val->children; while ( iter ) { vl = VIK_LAYER ( iter->data ); vl->visible = on_off; // Also set checkbox on_off vik_treeview_item_set_visible ( vik_layers_panel_get_treeview ( vlp ), &(vl->iter), on_off ); iter = iter->next; } // Redraw as view may have changed vik_layer_emit_update ( VIK_LAYER ( val ) ); }
static void layers_move_item ( VikLayersPanel *vlp, gboolean up ) { GtkTreeIter iter; VikAggregateLayer *parent; /* TODO: deactivate the buttons and stuff */ if ( ! vik_treeview_get_selected_iter ( vlp->vt, &iter ) ) return; vik_treeview_select_iter ( vlp->vt, &iter, FALSE ); /* cancel any layer-name editing going on... */ if ( vik_treeview_item_get_type ( vlp->vt, &iter ) == VIK_TREEVIEW_TYPE_LAYER ) { parent = VIK_AGGREGATE_LAYER(vik_treeview_item_get_parent ( vlp->vt, &iter )); if ( parent ) /* not toplevel */ { vik_aggregate_layer_move_layer ( parent, &iter, up ); vik_layers_panel_emit_update ( vlp ); } } }
/** * aggregate_layer_waypoint_create_list: * @vl: The layer that should create the waypoint and layers list * @user_data: Not used in this function * * Returns: A list of #vik_trw_waypoint_list_t */ static GList* aggregate_layer_waypoint_create_list ( VikLayer *vl, gpointer user_data ) { VikAggregateLayer *val = VIK_AGGREGATE_LAYER(vl); // Get all TRW layers GList *layers = NULL; layers = vik_aggregate_layer_get_all_layers_of_type ( val, layers, VIK_LAYER_TRW, TRUE ); // For each TRW layers keep adding the waypoints to build a list of all of them GList *waypoints_and_layers = NULL; layers = g_list_first ( layers ); while ( layers ) { GList *waypoints = NULL; waypoints = g_list_concat ( waypoints, g_hash_table_get_values ( vik_trw_layer_get_waypoints( VIK_TRW_LAYER(layers->data) ) ) ); waypoints_and_layers = g_list_concat ( waypoints_and_layers, vik_trw_layer_build_waypoint_list_t ( VIK_TRW_LAYER(layers->data), waypoints ) ); layers = g_list_next ( layers ); } g_list_free ( layers ); return waypoints_and_layers; }
/** * Search all TrackWaypoint layers in this aggregate layer for an item on the user specified date */ static void aggregate_layer_search_date ( menu_array_values values ) { VikAggregateLayer *val = VIK_AGGREGATE_LAYER ( values[MA_VAL] ); VikCoord position; gchar *date_str = a_dialog_get_date ( VIK_GTK_WINDOW_FROM_LAYER(val), _("Search by Date") ); if ( !date_str ) return; VikViewport *vvp = vik_window_viewport ( VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(val)) ); GList *gl = NULL; gl = vik_aggregate_layer_get_all_layers_of_type ( val, gl, VIK_LAYER_TRW, TRUE ); gboolean found = FALSE; // Search tracks first while ( gl && !found ) { // Make it auto select the item if found found = vik_trw_layer_find_date ( VIK_TRW_LAYER(gl->data), date_str, &position, vvp, TRUE, TRUE ); gl = g_list_next ( gl ); } g_list_free ( gl ); if ( !found ) { // Reset and try on Waypoints gl = NULL; gl = vik_aggregate_layer_get_all_layers_of_type ( val, gl, VIK_LAYER_TRW, TRUE ); while ( gl && !found ) { // Make it auto select the item if found found = vik_trw_layer_find_date ( VIK_TRW_LAYER(gl->data), date_str, &position, vvp, FALSE, TRUE ); gl = g_list_next ( gl ); } g_list_free ( gl ); } if ( !found ) a_dialog_info_msg ( VIK_GTK_WINDOW_FROM_LAYER(val), _("No items found with the requested date.") ); g_free ( date_str ); }
VikLayer *vik_aggregate_layer_get_top_visible_layer_of_type ( VikAggregateLayer *val, VikLayerTypeEnum type ) { VikLayer *rv; GList *ls = val->children; if (!ls) return NULL; while (ls->next) ls = ls->next; while ( ls ) { VikLayer *vl = VIK_LAYER(ls->data); if ( vl->visible && vl->type == type ) return vl; else if ( vl->visible && vl->type == VIK_LAYER_AGGREGATE ) { rv = vik_aggregate_layer_get_top_visible_layer_of_type(VIK_AGGREGATE_LAYER(vl), type); if ( rv ) return rv; } ls = ls->prev; } return NULL; }
static void aggregate_layer_sort_timestamp_descend ( menu_array_values values ) { VikAggregateLayer *val = VIK_AGGREGATE_LAYER ( values[MA_VAL] ); vik_treeview_sort_children ( VIK_LAYER(val)->vt, &(VIK_LAYER(val)->iter), VL_SO_DATE_DESCENDING ); val->children = g_list_sort_with_data ( val->children, sort_layer_compare_timestamp, GINT_TO_POINTER(FALSE) ); }
/** * Read in a Viking file and return how successful the parsing was * ATM this will always work, in that even if there are parsing problems * then there will be no new values to override the defaults * * TODO flow up line number(s) / error messages of problems encountered... * */ static gboolean file_read ( VikAggregateLayer *top, FILE *f, const gchar *dirpath, VikViewport *vp ) { Stack *stack; struct LatLon ll = { 0.0, 0.0 }; gchar buffer[4096]; gchar *line; guint16 len; long line_num = 0; VikLayerParam *params = NULL; /* for current layer, so we don't have to keep on looking up interface */ guint8 params_count = 0; GHashTable *string_lists = g_hash_table_new(g_direct_hash,g_direct_equal); gboolean successful_read = TRUE; push(&stack); stack->under = NULL; stack->data = (gpointer) top; while ( fgets ( buffer, 4096, f ) ) { line_num++; line = buffer; while ( *line == ' ' || *line =='\t' ) line++; if ( line[0] == '#' ) continue; len = strlen(line); if ( len > 0 && line[len-1] == '\n' ) line[--len] = '\0'; if ( len > 0 && line[len-1] == '\r' ) line[--len] = '\0'; if ( len == 0 ) continue; if ( line[0] == '~' ) { line++; len--; if ( *line == '\0' ) continue; else if ( str_starts_with ( line, "Layer ", 6, TRUE ) ) { int parent_type = VIK_LAYER(stack->data)->type; if ( ( ! stack->data ) || ((parent_type != VIK_LAYER_AGGREGATE) && (parent_type != VIK_LAYER_GPS)) ) { successful_read = FALSE; g_warning ( "Line %ld: Layer command inside non-Aggregate Layer (type %d)", line_num, parent_type ); push(&stack); /* inside INVALID layer */ stack->data = NULL; continue; } else { VikLayerTypeEnum type = vik_layer_type_from_string ( line+6 ); push(&stack); if ( type == VIK_LAYER_NUM_TYPES ) { successful_read = FALSE; g_warning ( "Line %ld: Unknown type %s", line_num, line+6 ); stack->data = NULL; } else if (parent_type == VIK_LAYER_GPS) { stack->data = (gpointer) vik_gps_layer_get_a_child(VIK_GPS_LAYER(stack->under->data)); params = vik_layer_get_interface(type)->params; params_count = vik_layer_get_interface(type)->params_count; } else { stack->data = (gpointer) vik_layer_create ( type, vp, FALSE ); params = vik_layer_get_interface(type)->params; params_count = vik_layer_get_interface(type)->params_count; } } } else if ( str_starts_with ( line, "EndLayer", 8, FALSE ) ) { if ( stack->under == NULL ) { successful_read = FALSE; g_warning ( "Line %ld: Mismatched ~EndLayer command", line_num ); } else { /* add any string lists we've accumulated */ gpointer layer_and_vp[2]; layer_and_vp[0] = stack->data; layer_and_vp[1] = vp; g_hash_table_foreach ( string_lists, (GHFunc) string_list_set_param, layer_and_vp ); g_hash_table_remove_all ( string_lists ); if ( stack->data && stack->under->data ) { if (VIK_LAYER(stack->under->data)->type == VIK_LAYER_AGGREGATE) { vik_aggregate_layer_add_layer ( VIK_AGGREGATE_LAYER(stack->under->data), VIK_LAYER(stack->data), FALSE ); vik_layer_post_read ( VIK_LAYER(stack->data), vp, TRUE ); } else if (VIK_LAYER(stack->under->data)->type == VIK_LAYER_GPS) { /* TODO: anything else needs to be done here ? */ } else { successful_read = FALSE; g_warning ( "Line %ld: EndLayer command inside non-Aggregate Layer (type %d)", line_num, VIK_LAYER(stack->data)->type ); } } pop(&stack); } } else if ( str_starts_with ( line, "LayerData", 9, FALSE ) ) { if ( stack->data && vik_layer_get_interface(VIK_LAYER(stack->data)->type)->read_file_data ) { /* must read until hits ~EndLayerData */ if ( ! vik_layer_get_interface(VIK_LAYER(stack->data)->type)->read_file_data ( VIK_LAYER(stack->data), f, dirpath ) ) successful_read = FALSE; } else { /* simply skip layer data over */ while ( fgets ( buffer, 4096, f ) ) { line_num++; line = buffer; len = strlen(line); if ( len > 0 && line[len-1] == '\n' ) line[--len] = '\0'; if ( len > 0 && line[len-1] == '\r' ) line[--len] = '\0'; if ( strcasecmp ( line, "~EndLayerData" ) == 0 ) break; } continue; } } else { successful_read = FALSE; g_warning ( "Line %ld: Unknown tilde command", line_num ); } } else { gint32 eq_pos = -1; guint16 i; if ( ! stack->data ) continue; for ( i = 0; i < len; i++ ) if ( line[i] == '=' ) eq_pos = i; if ( stack->under == NULL && eq_pos == 12 && strncasecmp ( line, "FILE_VERSION", eq_pos ) == 0) { gint version = strtol(line+13, NULL, 10); g_debug ( "%s: reading file version %d", __FUNCTION__, version ); if ( version > VIKING_FILE_VERSION ) successful_read = FALSE; // However we'll still carry and attempt to read whatever we can } else if ( stack->under == NULL && eq_pos == 4 && strncasecmp ( line, "xmpp", eq_pos ) == 0) /* "hard coded" params: global & for all layer-types */ vik_viewport_set_xmpp ( VIK_VIEWPORT(vp), strtod ( line+5, NULL ) ); else if ( stack->under == NULL && eq_pos == 4 && strncasecmp ( line, "ympp", eq_pos ) == 0) vik_viewport_set_ympp ( VIK_VIEWPORT(vp), strtod ( line+5, NULL ) ); else if ( stack->under == NULL && eq_pos == 3 && strncasecmp ( line, "lat", eq_pos ) == 0 ) ll.lat = strtod ( line+4, NULL ); else if ( stack->under == NULL && eq_pos == 3 && strncasecmp ( line, "lon", eq_pos ) == 0 ) ll.lon = strtod ( line+4, NULL ); else if ( stack->under == NULL && eq_pos == 4 && strncasecmp ( line, "mode", eq_pos ) == 0 && strcasecmp ( line+5, "utm" ) == 0) vik_viewport_set_drawmode ( VIK_VIEWPORT(vp), VIK_VIEWPORT_DRAWMODE_UTM); else if ( stack->under == NULL && eq_pos == 4 && strncasecmp ( line, "mode", eq_pos ) == 0 && strcasecmp ( line+5, "expedia" ) == 0) vik_viewport_set_drawmode ( VIK_VIEWPORT(vp), VIK_VIEWPORT_DRAWMODE_EXPEDIA ); else if ( stack->under == NULL && eq_pos == 4 && strncasecmp ( line, "mode", eq_pos ) == 0 && strcasecmp ( line+5, "google" ) == 0) { successful_read = FALSE; g_warning ( _("Draw mode '%s' no more supported"), "google" ); } else if ( stack->under == NULL && eq_pos == 4 && strncasecmp ( line, "mode", eq_pos ) == 0 && strcasecmp ( line+5, "kh" ) == 0) { successful_read = FALSE; g_warning ( _("Draw mode '%s' no more supported"), "kh" ); } else if ( stack->under == NULL && eq_pos == 4 && strncasecmp ( line, "mode", eq_pos ) == 0 && strcasecmp ( line+5, "mercator" ) == 0) vik_viewport_set_drawmode ( VIK_VIEWPORT(vp), VIK_VIEWPORT_DRAWMODE_MERCATOR ); else if ( stack->under == NULL && eq_pos == 4 && strncasecmp ( line, "mode", eq_pos ) == 0 && strcasecmp ( line+5, "latlon" ) == 0) vik_viewport_set_drawmode ( VIK_VIEWPORT(vp), VIK_VIEWPORT_DRAWMODE_LATLON ); else if ( stack->under == NULL && eq_pos == 5 && strncasecmp ( line, "color", eq_pos ) == 0 ) vik_viewport_set_background_color ( VIK_VIEWPORT(vp), line+6 ); else if ( stack->under == NULL && eq_pos == 14 && strncasecmp ( line, "highlightcolor", eq_pos ) == 0 ) vik_viewport_set_highlight_color ( VIK_VIEWPORT(vp), line+15 ); else if ( stack->under == NULL && eq_pos == 9 && strncasecmp ( line, "drawscale", eq_pos ) == 0 ) vik_viewport_set_draw_scale ( VIK_VIEWPORT(vp), TEST_BOOLEAN(line+10) ); else if ( stack->under == NULL && eq_pos == 14 && strncasecmp ( line, "drawcentermark", eq_pos ) == 0 ) vik_viewport_set_draw_centermark ( VIK_VIEWPORT(vp), TEST_BOOLEAN(line+15) ); else if ( stack->under == NULL && eq_pos == 13 && strncasecmp ( line, "drawhighlight", eq_pos ) == 0 ) vik_viewport_set_draw_highlight ( VIK_VIEWPORT(vp), TEST_BOOLEAN(line+14) ); else if ( stack->under && eq_pos == 4 && strncasecmp ( line, "name", eq_pos ) == 0 ) vik_layer_rename ( VIK_LAYER(stack->data), line+5 ); else if ( eq_pos == 7 && strncasecmp ( line, "visible", eq_pos ) == 0 ) VIK_LAYER(stack->data)->visible = TEST_BOOLEAN(line+8); else if ( eq_pos != -1 && stack->under ) { gboolean found_match = FALSE; /* go thru layer params. if len == eq_pos && starts_with jazz, set it. */ /* also got to check for name and visible. */ if ( ! params ) { successful_read = FALSE; g_warning ( "Line %ld: No options for this kind of layer", line_num ); continue; } for ( i = 0; i < params_count; i++ ) if ( strlen(params[i].name) == eq_pos && strncasecmp ( line, params[i].name, eq_pos ) == 0 ) { VikLayerParamData x; line += eq_pos+1; if ( params[i].type == VIK_LAYER_PARAM_STRING_LIST ) { GList *l = g_list_append ( g_hash_table_lookup ( string_lists, GINT_TO_POINTER ((gint) i) ), g_strdup(line) ); g_hash_table_replace ( string_lists, GINT_TO_POINTER ((gint)i), l ); /* add the value to a list, possibly making a new list. * this will be passed to the layer when we read an ~EndLayer */ } else { switch ( params[i].type ) { case VIK_LAYER_PARAM_DOUBLE: x.d = strtod(line, NULL); break; case VIK_LAYER_PARAM_UINT: x.u = strtoul(line, NULL, 10); break; case VIK_LAYER_PARAM_INT: x.i = strtol(line, NULL, 10); break; case VIK_LAYER_PARAM_BOOLEAN: x.b = TEST_BOOLEAN(line); break; case VIK_LAYER_PARAM_COLOR: memset(&(x.c), 0, sizeof(x.c)); /* default: black */ gdk_color_parse ( line, &(x.c) ); break; /* STRING or STRING_LIST -- if STRING_LIST, just set param to add a STRING */ default: x.s = line; } vik_layer_set_param ( VIK_LAYER(stack->data), i, x, vp, TRUE ); } found_match = TRUE; break; } if ( ! found_match ) { // ATM don't flow up this issue because at least one internal parameter has changed from version 1.3 // and don't what to worry users about raising such issues // TODO Maybe hold old values here - compare the line value against them and if a match // generate a different style of message in the GUI... // successful_read = FALSE; g_warning ( "Line %ld: Unknown parameter. Line:\n%s", line_num, line ); } } else { successful_read = FALSE; g_warning ( "Line %ld: Invalid parameter or parameter outside of layer.", line_num ); } } /* could be: [Layer Type=Bla] [EndLayer] [LayerData] name=this #comment */ } while ( stack ) { if ( stack->under && stack->under->data && stack->data ) { vik_aggregate_layer_add_layer ( VIK_AGGREGATE_LAYER(stack->under->data), VIK_LAYER(stack->data), FALSE ); vik_layer_post_read ( VIK_LAYER(stack->data), vp, TRUE ); } pop(&stack); } if ( ll.lat != 0.0 || ll.lon != 0.0 ) vik_viewport_set_center_latlon ( VIK_VIEWPORT(vp), &ll, TRUE ); if ( ( ! VIK_LAYER(top)->visible ) && VIK_LAYER(top)->realized ) vik_treeview_item_set_visible ( VIK_LAYER(top)->vt, &(VIK_LAYER(top)->iter), FALSE ); /* delete anything we've forgotten about -- should only happen when file ends before an EndLayer */ g_hash_table_foreach ( string_lists, string_list_delete, NULL ); g_hash_table_destroy ( string_lists ); return successful_read; }
static void file_write ( VikAggregateLayer *top, FILE *f, gpointer vp ) { Stack *stack = NULL; VikLayer *current_layer; struct LatLon ll; VikViewportDrawMode mode; gchar *modestring = NULL; push(&stack); stack->data = (gpointer) vik_aggregate_layer_get_children(VIK_AGGREGATE_LAYER(top)); stack->under = NULL; /* crazhy CRAZHY */ vik_coord_to_latlon ( vik_viewport_get_center ( VIK_VIEWPORT(vp) ), &ll ); mode = vik_viewport_get_drawmode ( VIK_VIEWPORT(vp) ); switch ( mode ) { case VIK_VIEWPORT_DRAWMODE_UTM: modestring = "utm"; break; case VIK_VIEWPORT_DRAWMODE_EXPEDIA: modestring = "expedia"; break; case VIK_VIEWPORT_DRAWMODE_MERCATOR: modestring = "mercator"; break; case VIK_VIEWPORT_DRAWMODE_LATLON: modestring = "latlon"; break; default: g_critical("Houston, we've had a problem. mode=%d", mode); } fprintf ( f, "#VIKING GPS Data file " VIKING_URL "\n" ); fprintf ( f, "FILE_VERSION=%d\n", VIKING_FILE_VERSION ); fprintf ( f, "\nxmpp=%f\nympp=%f\nlat=%f\nlon=%f\nmode=%s\ncolor=%s\nhighlightcolor=%s\ndrawscale=%s\ndrawcentermark=%s\ndrawhighlight=%s\n", vik_viewport_get_xmpp ( VIK_VIEWPORT(vp) ), vik_viewport_get_ympp ( VIK_VIEWPORT(vp) ), ll.lat, ll.lon, modestring, vik_viewport_get_background_color(VIK_VIEWPORT(vp)), vik_viewport_get_highlight_color(VIK_VIEWPORT(vp)), vik_viewport_get_draw_scale(VIK_VIEWPORT(vp)) ? "t" : "f", vik_viewport_get_draw_centermark(VIK_VIEWPORT(vp)) ? "t" : "f", vik_viewport_get_draw_highlight(VIK_VIEWPORT(vp)) ? "t" : "f" ); if ( ! VIK_LAYER(top)->visible ) fprintf ( f, "visible=f\n" ); while (stack && stack->data) { current_layer = VIK_LAYER(((GList *)stack->data)->data); fprintf ( f, "\n~Layer %s\n", vik_layer_get_interface(current_layer->type)->fixed_layer_name ); write_layer_params_and_data ( current_layer, f ); if ( current_layer->type == VIK_LAYER_AGGREGATE && !vik_aggregate_layer_is_empty(VIK_AGGREGATE_LAYER(current_layer)) ) { push(&stack); stack->data = (gpointer) vik_aggregate_layer_get_children(VIK_AGGREGATE_LAYER(current_layer)); } else if ( current_layer->type == VIK_LAYER_GPS && !vik_gps_layer_is_empty(VIK_GPS_LAYER(current_layer)) ) { push(&stack); stack->data = (gpointer) vik_gps_layer_get_children(VIK_GPS_LAYER(current_layer)); } else { stack->data = (gpointer) ((GList *)stack->data)->next; fprintf ( f, "~EndLayer\n\n" ); while ( stack && (!stack->data) ) { pop(&stack); if ( stack ) { stack->data = (gpointer) ((GList *)stack->data)->next; fprintf ( f, "~EndLayer\n\n" ); } } } } /* get vikaggregatelayer's children (?) foreach write ALL params, then layer data (IF function exists) then endlayer impl: stack of layers (LIST) we are working on when layer->next == NULL ... we move on. */ }
/** * aggregate_layer_analyse_close: * * Stuff to do on dialog closure */ static void aggregate_layer_analyse_close ( GtkWidget *dialog, gint resp, VikLayer* vl ) { VikAggregateLayer *val = VIK_AGGREGATE_LAYER(vl); gtk_widget_destroy ( dialog ); val->tracks_analysis_dialog = NULL; }
static void aggregate_layer_sort_a2z ( menu_array_values values ) { VikAggregateLayer *val = VIK_AGGREGATE_LAYER ( values[MA_VAL] ); vik_treeview_sort_children ( VIK_LAYER(val)->vt, &(VIK_LAYER(val)->iter), VL_SO_ALPHABETICAL_ASCENDING ); val->children = g_list_sort_with_data ( val->children, sort_layer_compare, GINT_TO_POINTER(TRUE) ); }
static void aggregate_layer_sort_z2a ( gpointer lav[2] ) { VikAggregateLayer *val = VIK_AGGREGATE_LAYER(lav[0]); vik_treeview_sort_children ( VIK_LAYER(val)->vt, &(VIK_LAYER(val)->iter), VL_SO_ALPHABETICAL_DESCENDING ); val->children = g_list_sort_with_data ( val->children, sort_layer_compare, GINT_TO_POINTER(FALSE) ); }