Diff of /trunk/src/info.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 152 by harbaum, Fri Mar 27 14:49:30 2009 UTC revision 153 by harbaum, Mon Mar 30 11:14:20 2009 UTC
# Line 211  static void on_tag_last(GtkWidget *butto Line 211  static void on_tag_last(GtkWidget *butto
211                _("This will overwrite all tags of this %s with the "                _("This will overwrite all tags of this %s with the "
212                  "ones from the %s selected last.\n\n"                  "ones from the %s selected last.\n\n"
213                  "Do you really want this?"),                  "Do you really want this?"),
214                type_name[context->type], type_name[context->type])) {                type_name[context->object.type], type_name[context->object.type])) {
215    
216      osm_tags_free(*context->tag);      osm_tags_free(*context->tag);
217    
218      if(context->type == NODE)      if(context->object.type == NODE)
219        *context->tag = osm_tags_copy(context->appdata->map->last_node_tags, TRUE);        *context->tag = osm_tags_copy(context->appdata->map->last_node_tags, TRUE);
220      else      else
221        *context->tag = osm_tags_copy(context->appdata->map->last_way_tags, TRUE);        *context->tag = osm_tags_copy(context->appdata->map->last_way_tags, TRUE);
# Line 303  static GtkWidget *tag_widget(tag_context Line 303  static GtkWidget *tag_widget(tag_context
303    
304    /* disable if no appropriate "last" tags have been stored or if the */    /* disable if no appropriate "last" tags have been stored or if the */
305    /* selected item isn't a node or way */    /* selected item isn't a node or way */
306    if(((context->type == NODE) &&    if(((context->object.type == NODE) &&
307        (!context->appdata->map->last_node_tags)) ||        (!context->appdata->map->last_node_tags)) ||
308       ((context->type == WAY) &&       ((context->object.type == WAY) &&
309        (!context->appdata->map->last_way_tags)) ||        (!context->appdata->map->last_way_tags)) ||
310       ((context->type != NODE) && (context->type != WAY)))       ((context->object.type != NODE) && (context->object.type != WAY)))
311          list_button_enable(context->list, LIST_BUTTON_USER0, FALSE);          list_button_enable(context->list, LIST_BUTTON_USER0, FALSE);
312    
313    /* --------- build and fill the store ------------ */    /* --------- build and fill the store ------------ */
# Line 337  static GtkWidget *tag_widget(tag_context Line 337  static GtkWidget *tag_widget(tag_context
337    
338  /* edit tags of currently selected node or way or of the relation */  /* edit tags of currently selected node or way or of the relation */
339  /* given */  /* given */
340  gboolean info_dialog(GtkWidget *parent, appdata_t *appdata, relation_t *relation) {  gboolean info_dialog(GtkWidget *parent, appdata_t *appdata, object_t *object) {
   if(!relation)  
     g_assert(appdata->map->selected.type != MAP_TYPE_ILLEGAL);  
341    
342    tag_context_t *context = g_new0(tag_context_t, 1);    tag_context_t *context = g_new0(tag_context_t, 1);
343    user_t *user = NULL;    user_t *user = NULL;
# Line 350  gboolean info_dialog(GtkWidget *parent, Line 348  gboolean info_dialog(GtkWidget *parent,
348    context->appdata = appdata;    context->appdata = appdata;
349    context->tag = &work_copy;    context->tag = &work_copy;
350    
351    if(!relation) {    /* use implicit selection if not explicitely given */
352      if(!object) {
353        g_assert(appdata->map->selected.type != MAP_TYPE_ILLEGAL);
354      switch(appdata->map->selected.type) {      switch(appdata->map->selected.type) {
355      case MAP_TYPE_NODE:      case MAP_TYPE_NODE:
356        str = g_strdup_printf(_("Node #%ld"), appdata->map->selected.node->id);        context->object.type = NODE;
357        user = appdata->map->selected.node->user;        context->object.node = appdata->map->selected.node;
       work_copy = osm_tags_copy(appdata->map->selected.node->tag, FALSE);  
       stime = appdata->map->selected.node->time;  
       context->type = NODE;  
       context->presets_type = PRESETS_TYPE_NODE;  
358        break;        break;
359      case MAP_TYPE_WAY:      case MAP_TYPE_WAY:
360        str = g_strdup_printf(_("Way #%ld"), appdata->map->selected.way->id);        context->object.type = WAY;
361        user = appdata->map->selected.way->user;        context->object.way = appdata->map->selected.way;
362        work_copy = osm_tags_copy(appdata->map->selected.way->tag, FALSE);        break;
363        stime = appdata->map->selected.way->time;      case MAP_TYPE_RELATION:
364        context->type = WAY;        context->object.type = RELATION;
365        context->presets_type = PRESETS_TYPE_WAY;        context->object.relation = appdata->map->selected.relation;
   
       if(osm_way_get_last_node(appdata->map->selected.way) ==  
          osm_way_get_first_node(appdata->map->selected.way))  
         context->presets_type |= PRESETS_TYPE_CLOSEDWAY;  
   
366        break;        break;
367      default:      default:
368        g_assert((appdata->map->selected.type == MAP_TYPE_NODE) ||        printf("ERROR: info_dialog not on NODE, WAY or RELATION\n");
369                 (appdata->map->selected.type == MAP_TYPE_WAY));        g_assert(0);
370        break;        break;
371      }      }
372    } else {    } else
373      str = g_strdup_printf(_("Relation #%ld"), relation->id);      context->object = *object;
374      user = relation->user;  
375      work_copy = osm_tags_copy(relation->tag, FALSE);    switch(context->object.type) {
376      stime = relation->time;    case NODE:
377      context->type = RELATION;      str = g_strdup_printf(_("Node #%ld"), context->object.node->id);
378        user = context->object.node->user;
379        work_copy = osm_tags_copy(context->object.node->tag, FALSE);
380        stime = context->object.node->time;
381        context->presets_type = PRESETS_TYPE_NODE;
382        break;
383    
384      case WAY:
385        str = g_strdup_printf(_("Way #%ld"), context->object.way->id);
386        user = context->object.way->user;
387        work_copy = osm_tags_copy(context->object.way->tag, FALSE);
388        stime = context->object.way->time;
389        context->presets_type = PRESETS_TYPE_WAY;
390    
391        if(osm_way_get_last_node(context->object.way) ==
392           osm_way_get_first_node(context->object.way))
393          context->presets_type |= PRESETS_TYPE_CLOSEDWAY;
394    
395        break;
396    
397      case MAP_TYPE_RELATION:
398        str = g_strdup_printf(_("Relation #%ld"), context->object.relation->id);
399        user = context->object.relation->user;
400        work_copy = osm_tags_copy(context->object.relation->tag, FALSE);
401        stime = context->object.relation->time;
402      context->presets_type = PRESETS_TYPE_RELATION;      context->presets_type = PRESETS_TYPE_RELATION;
403        break;
404    
405      default:
406        g_assert((context->object.type == MAP_TYPE_NODE) ||
407                 (context->object.type == MAP_TYPE_WAY) ||
408                 (context->object.type == MAP_TYPE_RELATION));
409        break;
410    }    }
411    
412    context->dialog = gtk_dialog_new_with_buttons(str,    context->dialog = gtk_dialog_new_with_buttons(str,
# Line 427  gboolean info_dialog(GtkWidget *parent, Line 449  gboolean info_dialog(GtkWidget *parent,
449    gtk_table_attach_defaults(GTK_TABLE(table),  label, 1, 2, 0, 1);    gtk_table_attach_defaults(GTK_TABLE(table),  label, 1, 2, 0, 1);
450    
451    /* ------------ coordinate (only for nodes) ----------------- */    /* ------------ coordinate (only for nodes) ----------------- */
452    if(!relation) {    switch(context->object.type) {
453      if(appdata->map->selected.type == MAP_TYPE_NODE) {    case NODE: {
454        char pos_str[32];      char pos_str[32];
455        pos_lat_str(pos_str, sizeof(pos_str),appdata->map->selected.node->pos.lat);      pos_lat_str(pos_str, sizeof(pos_str),appdata->map->selected.node->pos.lat);
456        label = gtk_label_new(pos_str);      label = gtk_label_new(pos_str);
457        gtk_table_attach_defaults(GTK_TABLE(table),  label, 0, 1, 1, 2);      gtk_table_attach_defaults(GTK_TABLE(table),  label, 0, 1, 1, 2);
458        pos_lat_str(pos_str, sizeof(pos_str),appdata->map->selected.node->pos.lon);      pos_lat_str(pos_str, sizeof(pos_str),appdata->map->selected.node->pos.lon);
459        label = gtk_label_new(pos_str);      label = gtk_label_new(pos_str);
460        gtk_table_attach_defaults(GTK_TABLE(table),  label, 1, 2, 1, 2);      gtk_table_attach_defaults(GTK_TABLE(table),  label, 1, 2, 1, 2);
461      } else {    } break;
462        char *nodes_str = g_strdup_printf(_("Length: %u nodes"),    case WAY: {
463                  osm_way_number_of_nodes(appdata->map->selected.way));      char *nodes_str = g_strdup_printf(_("Length: %u nodes"),
464        label = gtk_label_new(nodes_str);                                        osm_way_number_of_nodes(appdata->map->selected.way));
465        gtk_table_attach_defaults(GTK_TABLE(table),  label, 0, 1, 1, 2);      label = gtk_label_new(nodes_str);
466        g_free(nodes_str);      gtk_table_attach_defaults(GTK_TABLE(table),  label, 0, 1, 1, 2);
467        g_free(nodes_str);
468        char *type_str = g_strdup_printf("%s (%s)",  
469           (osm_way_get_last_node(appdata->map->selected.way) ==      char *type_str = g_strdup_printf("%s (%s)",
470            osm_way_get_first_node(appdata->map->selected.way))?                               (osm_way_get_last_node(appdata->map->selected.way) ==
471                                         "closed way":"open way",                                osm_way_get_first_node(appdata->map->selected.way))?
472           (appdata->map->selected.way->draw.flags & OSM_DRAW_FLAG_AREA)?                               "closed way":"open way",
473                                         "area":"line");               (appdata->map->selected.way->draw.flags & OSM_DRAW_FLAG_AREA)?
474                                   "area":"line");
475    
476        label = gtk_label_new(type_str);      label = gtk_label_new(type_str);
477        gtk_table_attach_defaults(GTK_TABLE(table),  label, 1, 2, 1, 2);      gtk_table_attach_defaults(GTK_TABLE(table),  label, 1, 2, 1, 2);
478        g_free(type_str);      g_free(type_str);
479      }    } break;
480    } else {  
481      case RELATION: {
482      /* relations tell something about their members */      /* relations tell something about their members */
483      gint nodes = 0, ways = 0, relations = 0;      gint nodes = 0, ways = 0, relations = 0;
484      member_t *member = relation->member;      member_t *member = context->object.relation->member;
485      while(member) {      while(member) {
486        switch(member->type) {        switch(member->type) {
487        case NODE:        case NODE:
# Line 472  gboolean info_dialog(GtkWidget *parent, Line 496  gboolean info_dialog(GtkWidget *parent,
496        case RELATION_ID:        case RELATION_ID:
497          relations++;          relations++;
498          break;          break;
499    
500        default:        default:
501          break;          break;
502        }        }
# Line 485  gboolean info_dialog(GtkWidget *parent, Line 509  gboolean info_dialog(GtkWidget *parent,
509    
510      gtk_table_attach_defaults(GTK_TABLE(table), gtk_label_new(str), 0, 2, 1, 2);      gtk_table_attach_defaults(GTK_TABLE(table), gtk_label_new(str), 0, 2, 1, 2);
511      g_free(str);      g_free(str);
512    }      break;
513    
514      default:
515        printf("ERROR: No node, way or relation\n");
516        g_assert(0);
517        break;
518      } }
519    
520    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(context->dialog)->vbox), table,    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(context->dialog)->vbox), table,
521                       FALSE, FALSE, 0);                       FALSE, FALSE, 0);
# Line 506  gboolean info_dialog(GtkWidget *parent, Line 536  gboolean info_dialog(GtkWidget *parent,
536    
537      gtk_widget_destroy(context->dialog);      gtk_widget_destroy(context->dialog);
538    
539      if(!relation) {      /* replace original tags with work copy */
540        /* replace original tags with work copy */      switch(context->object.type) {
541        switch(appdata->map->selected.type) {  
542        case NODE:
543        case MAP_TYPE_NODE:        osm_tags_free(context->object.node->tag);
544          osm_tags_free(appdata->map->selected.node->tag);        context->object.node->tag = osm_tags_copy(work_copy, TRUE);
545          appdata->map->selected.node->tag = osm_tags_copy(work_copy, TRUE);        break;
         break;  
546    
547        case MAP_TYPE_WAY:      case WAY:
548          osm_tags_free(appdata->map->selected.way->tag);        osm_tags_free(context->object.way->tag);
549          appdata->map->selected.way->tag = osm_tags_copy(work_copy, TRUE);        context->object.way->tag = osm_tags_copy(work_copy, TRUE);
550          break;        break;
551    
552        default:      case RELATION:
553          break;        osm_tags_free(context->object.relation->tag);
554        }        context->object.relation->tag = osm_tags_copy(work_copy, TRUE);
555          break;
556        /* since nodes being parts of ways but with no tags are invisible, */  
557        /* the result of editing them may have changed their visibility */      default:
558        map_item_redraw(appdata, &appdata->map->selected);        break;
       map_item_set_flags(&context->appdata->map->selected, OSM_FLAG_DIRTY, 0);  
     } else {  
       osm_tags_free(relation->tag);  
       relation->tag = osm_tags_copy(work_copy, TRUE);  
       relation->flags |= OSM_FLAG_DIRTY;  
559      }      }
560    
561        /* since nodes being parts of ways but with no tags are invisible, */
562        /* the result of editing them may have changed their visibility */
563        if(!object && context->object.type != RELATION)
564          map_item_redraw(appdata, &appdata->map->selected);
565    
566        osm_object_set_flags(&context->object, OSM_FLAG_DIRTY, 0);
567    } else {    } else {
568      gtk_widget_destroy(context->dialog);      gtk_widget_destroy(context->dialog);
569      osm_tags_free(work_copy);      osm_tags_free(work_copy);
570    }    }
571    
572    g_free(context);    g_free(context);
573    return ok;    return ok;
574  }  }

Legend:
Removed from v.152  
changed lines
  Added in v.153