Diff of /trunk/src/map.c

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

revision 153 by harbaum, Mon Mar 30 11:14:20 2009 UTC revision 154 by harbaum, Tue Mar 31 06:31:53 2009 UTC
# Line 30  static void map_statusbar(map_t *map, ma Line 30  static void map_statusbar(map_t *map, ma
30    tag_t *tag = NULL;    tag_t *tag = NULL;
31    char *str = NULL;    char *str = NULL;
32    
33    switch(map_item->type) {    switch(map_item->object.type) {
34    case MAP_TYPE_NODE:    case NODE:
35      item_str = "Node";      item_str = "Node";
36      id = map_item->node->id;      id = map_item->object.node->id;
37      tag = map_item->node->tag;      tag = map_item->object.node->tag;
38      break;      break;
39    
40    case MAP_TYPE_WAY:    case WAY:
41      item_str = "Way";      item_str = "Way";
42      id = map_item->way->id;      id = map_item->object.way->id;
43      tag = map_item->way->tag;      tag = map_item->object.way->tag;
44      break;      break;
45    
46    case MAP_TYPE_RELATION:    case RELATION:
47      item_str = "Relation";      item_str = "Relation";
48      id = map_item->relation->id;      id = map_item->object.relation->id;
49      tag = map_item->relation->tag;      tag = map_item->object.relation->tag;
50      break;      break;
51    
52    default:    default:
# Line 138  static void map_node_select(appdata_t *a Line 138  static void map_node_select(appdata_t *a
138    
139    g_assert(!map->highlight);    g_assert(!map->highlight);
140    
141    map_item->type      = MAP_TYPE_NODE;    map_item->object.type      = NODE;
142    map_item->node      = node;    map_item->object.node      = node;
143    map_item->highlight = FALSE;    map_item->highlight = FALSE;
144    
145    /* node may not have any visible representation at all */    /* node may not have any visible representation at all */
# Line 152  static void map_node_select(appdata_t *a Line 152  static void map_node_select(appdata_t *a
152    icon_bar_map_item_selected(appdata, map_item, TRUE);    icon_bar_map_item_selected(appdata, map_item, TRUE);
153    
154    /* highlight node */    /* highlight node */
155    gint x = map_item->node->lpos.x, y = map_item->node->lpos.y;    gint x = map_item->object.node->lpos.x, y = map_item->object.node->lpos.y;
156    
157    /* create a copy of this map item and mark it as being a highlight */    /* create a copy of this map item and mark it as being a highlight */
158    map_item_t *new_map_item = g_new0(map_item_t, 1);    map_item_t *new_map_item = g_new0(map_item_t, 1);
# Line 163  static void map_node_select(appdata_t *a Line 163  static void map_node_select(appdata_t *a
163    if(!node->ways) radius += map->style->node.border_radius;    if(!node->ways) radius += map->style->node.border_radius;
164    if(node->icon_buf && map->style->icon.enable &&    if(node->icon_buf && map->style->icon.enable &&
165       !appdata->settings->no_icons) {       !appdata->settings->no_icons) {
166      gint w = gdk_pixbuf_get_width(map_item->node->icon_buf);      gint w = gdk_pixbuf_get_width(map_item->object.node->icon_buf);
167      gint h = gdk_pixbuf_get_height(map_item->node->icon_buf);      gint h = gdk_pixbuf_get_height(map_item->object.node->icon_buf);
168      /* icons are technically square, so a radius slightly bigger */      /* icons are technically square, so a radius slightly bigger */
169      /* than sqrt(2)*MAX(w,h) should fit nicely */      /* than sqrt(2)*MAX(w,h) should fit nicely */
170      radius =  0.75 * map->style->icon.scale * ((w>h)?w:h);      radius =  0.75 * map->style->icon.scale * ((w>h)?w:h);
# Line 190  void map_way_select(appdata_t *appdata, Line 190  void map_way_select(appdata_t *appdata,
190    
191    g_assert(!map->highlight);    g_assert(!map->highlight);
192    
193    map_item->type      = MAP_TYPE_WAY;    map_item->object.type      = WAY;
194    map_item->way       = way;    map_item->object.way       = way;
195    map_item->highlight = FALSE;    map_item->highlight = FALSE;
196    map_item->item      = way->map_item_chain->map_item->item;    map_item->item      = way->map_item_chain->map_item->item;
197    
# Line 199  void map_way_select(appdata_t *appdata, Line 199  void map_way_select(appdata_t *appdata,
199    icon_bar_map_item_selected(appdata, map_item, TRUE);    icon_bar_map_item_selected(appdata, map_item, TRUE);
200    gtk_widget_set_sensitive(appdata->menu_item_map_hide_sel, TRUE);    gtk_widget_set_sensitive(appdata->menu_item_map_hide_sel, TRUE);
201    
202    gint arrow_width = (map_item->way->draw.flags & OSM_DRAW_FLAG_BG)?    gint arrow_width = (map_item->object.way->draw.flags & OSM_DRAW_FLAG_BG)?
203      map->style->highlight.width + map_item->way->draw.bg.width/2:      map->style->highlight.width + map_item->object.way->draw.bg.width/2:
204      map->style->highlight.width + map_item->way->draw.width/2;      map->style->highlight.width + map_item->object.way->draw.width/2;
205    
206    node_chain_t *node_chain = map_item->way->node_chain;    node_chain_t *node_chain = map_item->object.way->node_chain;
207    node_t *last = NULL;    node_t *last = NULL;
208    while(node_chain) {    while(node_chain) {
209      map_item_t item;      map_item_t item;
210      item.type = MAP_TYPE_NODE;      item.object.type = NODE;
211      item.node = node_chain->node;      item.object.node = node_chain->node;
212    
213      /* draw an arrow between every two nodes */      /* draw an arrow between every two nodes */
214      if(last) {      if(last) {
215        /* create a new map item for every arrow */        /* create a new map item for every arrow */
216        map_item_t *new_map_item = g_new0(map_item_t, 1);        map_item_t *new_map_item = g_new0(map_item_t, 1);
217        new_map_item->type = MAP_TYPE_WAY;        new_map_item->object.type = WAY;
218        new_map_item->way = way;        new_map_item->object.way = way;
219        new_map_item->highlight = TRUE;        new_map_item->highlight = TRUE;
220    
221        struct { float x, y;} center, diff;        struct { float x, y;} center, diff;
# Line 251  void map_way_select(appdata_t *appdata, Line 251  void map_way_select(appdata_t *appdata,
251    
252        /* create a new map item for every node */        /* create a new map item for every node */
253        map_item_t *new_map_item = g_new0(map_item_t, 1);        map_item_t *new_map_item = g_new0(map_item_t, 1);
254        new_map_item->type = MAP_TYPE_NODE;        new_map_item->object.type = NODE;
255        new_map_item->node = node_chain->node;        new_map_item->object.node = node_chain->node;
256        new_map_item->highlight = TRUE;        new_map_item->highlight = TRUE;
257    
258        gint x = node_chain->node->lpos.x;        gint x = node_chain->node->lpos.x;
# Line 275  void map_way_select(appdata_t *appdata, Line 275  void map_way_select(appdata_t *appdata,
275      canvas_points_t *points = canvas_points_new(nodes);      canvas_points_t *points = canvas_points_new(nodes);
276    
277      int node = 0;      int node = 0;
278      node_chain = map_item->way->node_chain;      node_chain = map_item->object.way->node_chain;
279      while(node_chain) {      while(node_chain) {
280        canvas_point_set_pos(points, node++, &node_chain->node->lpos);        canvas_point_set_pos(points, node++, &node_chain->node->lpos);
281        node_chain = node_chain->next;        node_chain = node_chain->next;
# Line 287  void map_way_select(appdata_t *appdata, Line 287  void map_way_select(appdata_t *appdata,
287      new_map_item->highlight = TRUE;      new_map_item->highlight = TRUE;
288    
289      map_hl_polyline_new(map, CANVAS_GROUP_WAYS_HL, new_map_item, points,      map_hl_polyline_new(map, CANVAS_GROUP_WAYS_HL, new_map_item, points,
290                  (map_item->way->draw.flags & OSM_DRAW_FLAG_BG)?                  (map_item->object.way->draw.flags & OSM_DRAW_FLAG_BG)?
291                  2*map->style->highlight.width + map_item->way->draw.bg.width:                  2*map->style->highlight.width + map_item->object.way->draw.bg.width:
292                  2*map->style->highlight.width + map_item->way->draw.width,                  2*map->style->highlight.width + map_item->object.way->draw.width,
293                  map->style->highlight.color);                  map->style->highlight.color);
294    
295      canvas_points_free(points);      canvas_points_free(points);
# Line 305  void map_relation_select(appdata_t *appd Line 305  void map_relation_select(appdata_t *appd
305    map_highlight_t **hl = &map->highlight;    map_highlight_t **hl = &map->highlight;
306    
307    map_item_t *map_item = &map->selected;    map_item_t *map_item = &map->selected;
308    map_item->type      = MAP_TYPE_RELATION;    map_item->object.type      = RELATION;
309    map_item->relation  = relation;    map_item->object.relation  = relation;
310    map_item->highlight = FALSE;    map_item->highlight = FALSE;
311    map_item->item      = NULL;    map_item->item      = NULL;
312    
# Line 374  void map_relation_select(appdata_t *appd Line 374  void map_relation_select(appdata_t *appd
374    }    }
375  }  }
376    
377  static void map_item_select(appdata_t *appdata, map_item_t *map_item) {  static void map_object_select(appdata_t *appdata, object_t *object) {
378    switch(map_item->type) {    switch(object->type) {
379    case MAP_TYPE_NODE:    case NODE:
380      map_node_select(appdata, map_item->node);      map_node_select(appdata, object->node);
381      break;      break;
382    case MAP_TYPE_WAY:    case WAY:
383      map_way_select(appdata, map_item->way);      map_way_select(appdata, object->way);
384        break;
385      case RELATION:
386        map_relation_select(appdata, object->relation);
387      break;      break;
388    default:    default:
389      g_assert((map_item->type == MAP_TYPE_NODE)||      g_assert((object->type == NODE)||(object->type == RELATION)||
390               (map_item->type == MAP_TYPE_WAY));               (object->type == WAY));
391      break;      break;
392    }    }
393  }  }
# Line 392  static void map_item_select(appdata_t *a Line 395  static void map_item_select(appdata_t *a
395  void map_item_deselect(appdata_t *appdata) {  void map_item_deselect(appdata_t *appdata) {
396    
397    /* save tags for "last" function in info dialog */    /* save tags for "last" function in info dialog */
398    if(appdata->map->selected.type == MAP_TYPE_NODE) {    if(appdata->map->selected.object.type == NODE) {
399      if(appdata->map->last_node_tags)      if(appdata->map->last_node_tags)
400        osm_tags_free(appdata->map->last_node_tags);        osm_tags_free(appdata->map->last_node_tags);
401    
402      appdata->map->last_node_tags =      appdata->map->last_node_tags =
403        osm_tags_copy(appdata->map->selected.node->tag, FALSE);        osm_tags_copy(appdata->map->selected.object.node->tag, FALSE);
404    } else if(appdata->map->selected.type == MAP_TYPE_WAY) {    } else if(appdata->map->selected.object.type == WAY) {
405      if(appdata->map->last_way_tags)      if(appdata->map->last_way_tags)
406        osm_tags_free(appdata->map->last_way_tags);        osm_tags_free(appdata->map->last_way_tags);
407    
408      appdata->map->last_way_tags =      appdata->map->last_way_tags =
409        osm_tags_copy(appdata->map->selected.way->tag, FALSE);        osm_tags_copy(appdata->map->selected.object.way->tag, FALSE);
410    }    }
411    
412    /* remove statusbar message */    /* remove statusbar message */
# Line 417  void map_item_deselect(appdata_t *appdat Line 420  void map_item_deselect(appdata_t *appdat
420    map_hl_remove(appdata);    map_hl_remove(appdata);
421    
422    /* forget about selection */    /* forget about selection */
423    appdata->map->selected.type = MAP_TYPE_ILLEGAL;    appdata->map->selected.object.type = ILLEGAL;
424  }  }
425    
426  /* called whenever a map item is to be destroyed */  /* called whenever a map item is to be destroyed */
# Line 429  static gint map_item_destroy_event(GtkWi Line 432  static gint map_item_destroy_event(GtkWi
432  #ifdef DESTROY_WAIT_FOR_GTK  #ifdef DESTROY_WAIT_FOR_GTK
433    /* remove item from nodes/ways map_item_chain */    /* remove item from nodes/ways map_item_chain */
434    map_item_chain_t **chain = NULL;    map_item_chain_t **chain = NULL;
435    if(map_item->type == MAP_TYPE_NODE)    if(map_item->object.type == NODE)
436      chain = &map_item->node->map_item_chain;      chain = &map_item->object.node->map_item_chain;
437    else if(map_item->type == MAP_TYPE_WAY)    else if(map_item->object.type == WAY)
438      chain = &map_item->way->map_item_chain;      chain = &map_item->object.way->map_item_chain;
439    
440    /* there must be a chain with content, otherwise things are broken */    /* there must be a chain with content, otherwise things are broken */
441    g_assert(chain);    g_assert(chain);
# Line 459  static canvas_item_t *map_node_new(map_t Line 462  static canvas_item_t *map_node_new(map_t
462                     gint width, canvas_color_t fill, canvas_color_t border) {                     gint width, canvas_color_t fill, canvas_color_t border) {
463    
464    map_item_t *map_item = g_new0(map_item_t, 1);    map_item_t *map_item = g_new0(map_item_t, 1);
465    map_item->type = MAP_TYPE_NODE;    map_item->object.type = NODE;
466    map_item->node = node;    map_item->object.node = node;
467    
468    if(!node->icon_buf || !map->style->icon.enable ||    if(!node->icon_buf || !map->style->icon.enable ||
469       map->appdata->settings->no_icons)       map->appdata->settings->no_icons)
# Line 497  static canvas_item_t *map_way_single_new Line 500  static canvas_item_t *map_way_single_new
500                     gint width, canvas_color_t fill, canvas_color_t border) {                     gint width, canvas_color_t fill, canvas_color_t border) {
501    
502    map_item_t *map_item = g_new0(map_item_t, 1);    map_item_t *map_item = g_new0(map_item_t, 1);
503    map_item->type = MAP_TYPE_WAY;    map_item->object.type = WAY;
504    map_item->way = way;    map_item->object.way = way;
505    map_item->item = canvas_circle_new(map->canvas, CANVAS_GROUP_WAYS,    map_item->item = canvas_circle_new(map->canvas, CANVAS_GROUP_WAYS,
506            way->node_chain->node->lpos.x, way->node_chain->node->lpos.y,            way->node_chain->node->lpos.x, way->node_chain->node->lpos.y,
507                                       radius, width, fill, border);                                       radius, width, fill, border);
# Line 523  static canvas_item_t *map_way_new(map_t Line 526  static canvas_item_t *map_way_new(map_t
526            way_t *way, canvas_points_t *points, gint width,            way_t *way, canvas_points_t *points, gint width,
527            canvas_color_t color, canvas_color_t fill_color) {            canvas_color_t color, canvas_color_t fill_color) {
528    map_item_t *map_item = g_new0(map_item_t, 1);    map_item_t *map_item = g_new0(map_item_t, 1);
529    map_item->type = MAP_TYPE_WAY;    map_item->object.type = WAY;
530    map_item->way = way;    map_item->object.way = way;
531    
532    if(way->draw.flags & OSM_DRAW_FLAG_AREA) {    if(way->draw.flags & OSM_DRAW_FLAG_AREA) {
533      if(map->style->area.color & 0xff)      if(map->style->area.color & 0xff)
# Line 626  void map_node_draw(map_t *map, node_t *n Line 629  void map_node_draw(map_t *map, node_t *n
629  }  }
630    
631  static void map_item_draw(map_t *map, map_item_t *map_item) {  static void map_item_draw(map_t *map, map_item_t *map_item) {
632    switch(map_item->type) {    switch(map_item->object.type) {
633    case MAP_TYPE_NODE:    case NODE:
634      map_node_draw(map, map_item->node);      map_node_draw(map, map_item->object.node);
635      break;      break;
636    case MAP_TYPE_WAY:    case WAY:
637      map_way_draw(map, map_item->way);      map_way_draw(map, map_item->object.way);
638      break;      break;
639    default:    default:
640      g_assert((map_item->type == MAP_TYPE_NODE) ||      g_assert((map_item->object.type == NODE) ||
641               (map_item->type == MAP_TYPE_WAY));               (map_item->object.type == WAY));
642    }    }
643  }  }
644    
645  static void map_item_remove(map_t *map, map_item_t *map_item) {  static void map_item_remove(map_t *map, map_item_t *map_item) {
646    map_item_chain_t **chainP = NULL;    map_item_chain_t **chainP = NULL;
647    
648    switch(map_item->type) {    switch(map_item->object.type) {
649    case MAP_TYPE_NODE:    case NODE:
650      chainP = &map_item->node->map_item_chain;      chainP = &map_item->object.node->map_item_chain;
651      break;      break;
652    case MAP_TYPE_WAY:    case WAY:
653      chainP = &map_item->way->map_item_chain;      chainP = &map_item->object.way->map_item_chain;
654      break;      break;
655    default:    default:
656      g_assert((map_item->type == MAP_TYPE_NODE) ||      g_assert((map_item->object.type == NODE) ||
657               (map_item->type == MAP_TYPE_WAY));               (map_item->object.type == WAY));
658    }    }
659    
660    map_item_chain_destroy(chainP);    map_item_chain_destroy(chainP);
661  }  }
662    
663  static void map_item_init(style_t *style, map_item_t *map_item) {  static void map_item_init(style_t *style, map_item_t *map_item) {
664    switch (map_item->type){    switch (map_item->object.type){
665      case MAP_TYPE_WAY:      case WAY:
666        josm_elemstyles_colorize_way(style, map_item->way);        josm_elemstyles_colorize_way(style, map_item->object.way);
667        break;        break;
668      case MAP_TYPE_NODE:      case NODE:
669        josm_elemstyles_colorize_node(style, map_item->node);        josm_elemstyles_colorize_node(style, map_item->object.node);
670        break;        break;
671      default:      default:
672        g_assert((map_item->type == MAP_TYPE_NODE) ||        g_assert((map_item->object.type == NODE) ||
673                     (map_item->type == MAP_TYPE_WAY));                     (map_item->object.type == WAY));
674    }    }
675  }  }
676    
# Line 676  void map_item_redraw(appdata_t *appdata, Line 679  void map_item_redraw(appdata_t *appdata,
679    
680    /* check if the item to be redrawn is the selected one */    /* check if the item to be redrawn is the selected one */
681    gboolean is_selected = FALSE;    gboolean is_selected = FALSE;
682    if(map_item->ptr == appdata->map->selected.ptr) {    if(map_item->object.ptr == appdata->map->selected.object.ptr) {
683      map_item_deselect(appdata);      map_item_deselect(appdata);
684      is_selected = TRUE;      is_selected = TRUE;
685    }    }
# Line 687  void map_item_redraw(appdata_t *appdata, Line 690  void map_item_redraw(appdata_t *appdata,
690    
691    /* restore selection if there was one */    /* restore selection if there was one */
692    if(is_selected)    if(is_selected)
693      map_item_select(appdata, &item);      map_object_select(appdata, &item.object);
694  }  }
695    
696  static void map_frisket_rectangle(canvas_points_t *points,  static void map_frisket_rectangle(canvas_points_t *points,
# Line 877  map_item_t *map_item_at(map_t *map, gint Line 880  map_item_t *map_item_at(map_t *map, gint
880    if(map_item->highlight)    if(map_item->highlight)
881      printf("  item is highlight\n");      printf("  item is highlight\n");
882    
883    switch(map_item->type) {    switch(map_item->object.type) {
884    case MAP_TYPE_NODE:    case NODE:
885      printf("  item is node #%ld\n", map_item->node->id);      printf("  item is node #%ld\n", map_item->object.node->id);
886      break;      break;
887    case MAP_TYPE_WAY:    case WAY:
888      printf("  item is way #%ld\n", map_item->way->id);      printf("  item is way #%ld\n", map_item->object.way->id);
889      break;      break;
890    default:    default:
891      printf("  unknown item\n");      printf("  unknown item\n");
# Line 901  map_item_t *map_real_item_at(map_t *map, Line 904  map_item_t *map_real_item_at(map_t *map,
904    
905    /* get the item (parent) this item is the highlight of */    /* get the item (parent) this item is the highlight of */
906    map_item_t *parent = NULL;    map_item_t *parent = NULL;
907    switch(map_item->type) {    switch(map_item->object.type) {
908    
909    case MAP_TYPE_NODE:    case NODE:
910      if(map_item->node->map_item_chain)      if(map_item->object.node->map_item_chain)
911        parent = map_item->node->map_item_chain->map_item;        parent = map_item->object.node->map_item_chain->map_item;
912    
913      if(parent)      if(parent)
914        printf("  using parent item node #%ld\n", parent->node->id);        printf("  using parent item node #%ld\n", parent->object.node->id);
915      break;      break;
916    
917    case MAP_TYPE_WAY:    case WAY:
918      if(map_item->way->map_item_chain)      if(map_item->object.way->map_item_chain)
919        parent = map_item->way->map_item_chain->map_item;        parent = map_item->object.way->map_item_chain->map_item;
920    
921      if(parent)      if(parent)
922        printf("  using parent item way #%ld\n", parent->way->id);        printf("  using parent item way #%ld\n", parent->object.way->id);
923      break;      break;
924    
925    default:    default:
926      g_assert((map_item->type == MAP_TYPE_NODE) ||      g_assert((map_item->object.type == NODE) ||
927               (map_item->type == MAP_TYPE_WAY));               (map_item->object.type == WAY));
928      break;      break;
929    }    }
930    
# Line 1078  void map_scroll_to_if_offscreen(map_t *m Line 1081  void map_scroll_to_if_offscreen(map_t *m
1081  /* Deselects the current way or node if its zoom_max  /* Deselects the current way or node if its zoom_max
1082   * means that it's not going to render at the current map zoom. */   * means that it's not going to render at the current map zoom. */
1083  void map_deselect_if_zoom_below_zoom_max(map_t *map) {  void map_deselect_if_zoom_below_zoom_max(map_t *map) {
1084      if (map->selected.type == MAP_TYPE_WAY) {      if (map->selected.object.type == WAY) {
1085          printf("will deselect way if zoomed below %f\n",          printf("will deselect way if zoomed below %f\n",
1086                 map->selected.way->draw.zoom_max);                 map->selected.object.way->draw.zoom_max);
1087          if (map->state->zoom < map->selected.way->draw.zoom_max) {          if (map->state->zoom < map->selected.object.way->draw.zoom_max) {
1088              printf("  deselecting way!\n");              printf("  deselecting way!\n");
1089              map_item_deselect(map->appdata);              map_item_deselect(map->appdata);
1090          }          }
1091      }      }
1092      else if (map->selected.type == MAP_TYPE_NODE) {      else if (map->selected.object.type == NODE) {
1093          printf("will deselect node if zoomed below %f\n",          printf("will deselect node if zoomed below %f\n",
1094                 map->selected.node->zoom_max);                 map->selected.object.node->zoom_max);
1095          if (map->state->zoom < map->selected.node->zoom_max) {          if (map->state->zoom < map->selected.object.node->zoom_max) {
1096              printf("  deselecting node!\n");              printf("  deselecting node!\n");
1097              map_item_deselect(map->appdata);              map_item_deselect(map->appdata);
1098          }          }
# Line 1189  gboolean map_item_is_selected_node(map_t Line 1192  gboolean map_item_is_selected_node(map_t
1192      return FALSE;      return FALSE;
1193    }    }
1194    
1195    if(map->selected.type == MAP_TYPE_ILLEGAL) {    if(map->selected.object.type == ILLEGAL) {
1196      printf("  nothing is selected\n");      printf("  nothing is selected\n");
1197      return FALSE;      return FALSE;
1198    }    }
1199    
1200    /* clicked the highlight directly */    /* clicked the highlight directly */
1201    if(map_item->type != MAP_TYPE_NODE) {    if(map_item->object.type != NODE) {
1202      printf("  didn't click node\n");      printf("  didn't click node\n");
1203      return FALSE;      return FALSE;
1204    }    }
1205    
1206    if(map->selected.type == MAP_TYPE_NODE) {    if(map->selected.object.type == NODE) {
1207      printf("  selected item is a node\n");      printf("  selected item is a node\n");
1208    
1209      if(map_item->node == map->selected.node) {      if(map_item->object.node == map->selected.object.node) {
1210        printf("  requested item is a selected node\n");        printf("  requested item is a selected node\n");
1211        return TRUE;        return TRUE;
1212      }      }
1213      printf("  but it's not the requested one\n");      printf("  but it's not the requested one\n");
1214      return FALSE;      return FALSE;
1215    
1216    } else if(map->selected.type == MAP_TYPE_WAY) {    } else if(map->selected.object.type == WAY) {
1217      printf("  selected item is a way\n");      printf("  selected item is a way\n");
1218    
1219      node_chain_t *node_chain = map->selected.way->node_chain;      node_chain_t *node_chain = map->selected.object.way->node_chain;
1220      while(node_chain) {      while(node_chain) {
1221        if(node_chain->node == map_item->node) {        if(node_chain->node == map_item->object.node) {
1222          printf("  requested item is part of selected way\n");          printf("  requested item is part of selected way\n");
1223          return TRUE;          return TRUE;
1224        }        }
# Line 1243  gboolean map_item_is_selected_way(map_t Line 1246  gboolean map_item_is_selected_way(map_t
1246      return FALSE;      return FALSE;
1247    }    }
1248    
1249    if(map->selected.type == MAP_TYPE_ILLEGAL) {    if(map->selected.object.type == ILLEGAL) {
1250      printf("  nothing is selected\n");      printf("  nothing is selected\n");
1251      return FALSE;      return FALSE;
1252    }    }
1253    
1254    /* clicked the highlight directly */    /* clicked the highlight directly */
1255    if(map_item->type != MAP_TYPE_WAY) {    if(map_item->object.type != WAY) {
1256      printf("  didn't click way\n");      printf("  didn't click way\n");
1257      return FALSE;      return FALSE;
1258    }    }
1259    
1260    if(map->selected.type == MAP_TYPE_WAY) {    if(map->selected.object.type == WAY) {
1261      printf("  selected item is a way\n");      printf("  selected item is a way\n");
1262    
1263      if(map_item->way == map->selected.way) {      if(map_item->object.way == map->selected.object.way) {
1264        printf("  requested item is a selected way\n");        printf("  requested item is a selected way\n");
1265        return TRUE;        return TRUE;
1266      }      }
# Line 1272  gboolean map_item_is_selected_way(map_t Line 1275  gboolean map_item_is_selected_way(map_t
1275    
1276  void map_highlight_refresh(appdata_t *appdata) {  void map_highlight_refresh(appdata_t *appdata) {
1277    map_t *map = appdata->map;    map_t *map = appdata->map;
1278    map_item_t old = map->selected;    object_t old = map->selected.object;
1279    
1280    printf("type to refresh is %d\n", old.type);    printf("type to refresh is %d\n", old.type);
1281    if(old.type == MAP_TYPE_ILLEGAL)    if(old.type == ILLEGAL)
1282      return;      return;
1283    
1284    map_item_deselect(appdata);    map_item_deselect(appdata);
1285    map_item_select(appdata, &old);    map_object_select(appdata, &old);
1286  }  }
1287    
1288  void map_way_delete(appdata_t *appdata, way_t *way) {  void map_way_delete(appdata_t *appdata, way_t *way) {
# Line 1307  static void map_handle_click(appdata_t * Line 1310  static void map_handle_click(appdata_t *
1310    /* problem: on_item may be the highlight itself! So store it! */    /* problem: on_item may be the highlight itself! So store it! */
1311    map_item_t map_item;    map_item_t map_item;
1312    if(map->pen_down.on_item) map_item = *map->pen_down.on_item;    if(map->pen_down.on_item) map_item = *map->pen_down.on_item;
1313    else                      map_item.type = MAP_TYPE_ILLEGAL;    else                      map_item.object.type = ILLEGAL;
1314    
1315    /* if we aready have something selected, then de-select it */    /* if we aready have something selected, then de-select it */
1316    map_item_deselect(appdata);    map_item_deselect(appdata);
1317    
1318    /* select the clicked item (if there was one) */    /* select the clicked item (if there was one) */
1319    if(map_item.type != MAP_TYPE_ILLEGAL) {    if(map_item.object.type != ILLEGAL) {
1320      switch(map_item.type) {      switch(map_item.object.type) {
1321      case MAP_TYPE_NODE:      case NODE:
1322        map_node_select(appdata, map_item.node);        map_node_select(appdata, map_item.object.node);
1323        break;        break;
1324    
1325      case MAP_TYPE_WAY:      case WAY:
1326        map_way_select(appdata, map_item.way);        map_way_select(appdata, map_item.object.way);
1327        break;        break;
1328    
1329      default:      default:
1330        g_assert((map_item.type == MAP_TYPE_NODE) ||        g_assert((map_item.object.type == NODE) ||
1331                 (map_item.type == MAP_TYPE_WAY));                 (map_item.object.type == WAY));
1332        break;        break;
1333      }      }
1334    }    }
# Line 1345  static void map_touchnode_update(appdata Line 1348  static void map_touchnode_update(appdata
1348      /* in idle mode the dragged node is not highlighted */      /* in idle mode the dragged node is not highlighted */
1349    case MAP_ACTION_IDLE:    case MAP_ACTION_IDLE:
1350      g_assert(map->pen_down.on_item);      g_assert(map->pen_down.on_item);
1351      g_assert(map->pen_down.on_item->type == MAP_TYPE_NODE);      g_assert(map->pen_down.on_item->object.type == NODE);
1352      cur_node = map->pen_down.on_item->node;      cur_node = map->pen_down.on_item->object.node;
1353      break;      break;
1354    
1355    default:    default:
# Line 1469  static void map_button_release(map_t *ma Line 1472  static void map_button_release(map_t *ma
1472        map_item_t old_sel = map->selected;        map_item_t old_sel = map->selected;
1473        map_handle_click(map->appdata, map);        map_handle_click(map->appdata, map);
1474    
1475        if((old_sel.type != MAP_TYPE_ILLEGAL) &&        if((old_sel.object.type != ILLEGAL) &&
1476           (old_sel.type == map->selected.type) &&           (old_sel.object.type == map->selected.object.type) &&
1477           (old_sel.ptr == map->selected.ptr)) {           (old_sel.object.ptr == map->selected.object.ptr)) {
1478          printf("re-selected same item of type %d, "          printf("re-selected same item of type %d, "
1479                 "pushing it to the bottom\n", old_sel.type);                 "pushing it to the bottom\n", old_sel.object.type);
1480    
1481          if(!map->selected.item) {          if(!map->selected.item) {
1482            printf("  item has no visible representation to push\n");            printf("  item has no visible representation to push\n");
# Line 1814  void map_init(appdata_t *appdata) { Line 1817  void map_init(appdata_t *appdata) {
1817  }  }
1818    
1819    
 void map_item_set_flags(map_item_t *map_item, int set, int clr) {  
   
   switch(map_item->type) {  
   case MAP_TYPE_NODE:  
     map_item->node->flags |=  set;  
     map_item->node->flags &= ~clr;  
     break;  
   
   case MAP_TYPE_WAY:  
     map_item->way->flags |=  set;  
     map_item->way->flags &= ~clr;  
     break;  
   
   case MAP_TYPE_RELATION:  
     map_item->relation->flags |=  set;  
     map_item->relation->flags &= ~clr;  
     break;  
   
   default:  
     g_assert(0);  
     break;  
   }  
 }  
   
1820  void map_clear(appdata_t *appdata, gint group_mask) {  void map_clear(appdata_t *appdata, gint group_mask) {
1821    map_t *map = appdata->map;    map_t *map = appdata->map;
1822    
# Line 1888  void map_action_set(appdata_t *appdata, Line 1867  void map_action_set(appdata_t *appdata,
1867    
1868      /* remember if there was a way selected */      /* remember if there was a way selected */
1869      way_t *way_sel = NULL;      way_t *way_sel = NULL;
1870      if(appdata->map->selected.type == MAP_TYPE_WAY)      if(appdata->map->selected.object.type == WAY)
1871        way_sel = appdata->map->selected.way;        way_sel = appdata->map->selected.object.way;
1872    
1873      map_item_deselect(appdata);      map_item_deselect(appdata);
1874      map_edit_way_add_begin(appdata->map, way_sel);      map_edit_way_add_begin(appdata->map, way_sel);
# Line 1988  void map_delete_selected(appdata_t *appd Line 1967  void map_delete_selected(appdata_t *appd
1967    /* deleting the selected item de-selects it ... */    /* deleting the selected item de-selects it ... */
1968    map_item_deselect(appdata);    map_item_deselect(appdata);
1969    
1970    undo_remember_delete(appdata, item.type, item.ptr);    undo_remember_delete(appdata, item.object.type, item.object.ptr);
1971    
1972    switch(item.type) {    switch(item.object.type) {
1973    case MAP_TYPE_NODE:    case NODE:
1974      printf("request to delete node #%ld\n", item.node->id);      printf("request to delete node #%ld\n", item.object.node->id);
1975    
1976      /* check if this node is part of a way with two nodes only. */      /* check if this node is part of a way with two nodes only. */
1977      /* we cannot delete this as this would also delete the way */      /* we cannot delete this as this would also delete the way */
1978      way_chain_t *way_chain = osm_node_to_way(appdata->osm, item.node);      way_chain_t *way_chain = osm_node_to_way(appdata->osm, item.object.node);
1979      if(way_chain) {      if(way_chain) {
1980        gboolean short_way = FALSE;        gboolean short_way = FALSE;
1981    
# Line 2022  void map_delete_selected(appdata_t *appd Line 2001  void map_delete_selected(appdata_t *appd
2001      }      }
2002    
2003      /* remove it visually from the screen */      /* remove it visually from the screen */
2004      map_item_chain_destroy(&item.node->map_item_chain);      map_item_chain_destroy(&item.object.node->map_item_chain);
2005    
2006      /* and mark it "deleted" in the database */      /* and mark it "deleted" in the database */
2007      osm_node_remove_from_relation(appdata->osm, item.node);      osm_node_remove_from_relation(appdata->osm, item.object.node);
2008      way_chain_t *chain = osm_node_delete(appdata->osm,      way_chain_t *chain = osm_node_delete(appdata->osm,
2009                           &appdata->icon, item.node, FALSE, TRUE);                           &appdata->icon, item.object.node, FALSE, TRUE);
2010    
2011      /* redraw all affected ways */      /* redraw all affected ways */
2012      while(chain) {      while(chain) {
# Line 2040  void map_delete_selected(appdata_t *appd Line 2019  void map_delete_selected(appdata_t *appd
2019          map_way_delete(appdata, chain->way);          map_way_delete(appdata, chain->way);
2020        } else {        } else {
2021          map_item_t item;          map_item_t item;
2022          item.type = MAP_TYPE_WAY;          item.object.type = WAY;
2023          item.way = chain->way;          item.object.way = chain->way;
2024          map_item_redraw(appdata, &item);          map_item_redraw(appdata, &item);
2025        }        }
2026    
# Line 2052  void map_delete_selected(appdata_t *appd Line 2031  void map_delete_selected(appdata_t *appd
2031    
2032      break;      break;
2033    
2034    case MAP_TYPE_WAY:    case WAY:
2035      printf("request to delete way #%ld\n", item.way->id);      printf("request to delete way #%ld\n", item.object.way->id);
2036      map_way_delete(appdata, item.way);      map_way_delete(appdata, item.object.way);
2037      break;      break;
2038    
2039    default:    default:
2040      g_assert((item.type == MAP_TYPE_NODE) ||      g_assert((item.object.type == NODE) ||
2041               (item.type == MAP_TYPE_WAY));               (item.object.type == WAY));
2042      break;      break;
2043    }    }
2044  }  }
# Line 2220  void map_hide_selected(appdata_t *appdat Line 2199  void map_hide_selected(appdata_t *appdat
2199    map_t *map = appdata->map;    map_t *map = appdata->map;
2200    if(!map) return;    if(!map) return;
2201    
2202    if(map->selected.type != MAP_TYPE_WAY) {    if(map->selected.object.type != WAY) {
2203      printf("selected item is not a way\n");      printf("selected item is not a way\n");
2204      return;      return;
2205    }    }
2206    
2207    way_t *way = map->selected.way;    way_t *way = map->selected.object.way;
2208    printf("hiding way #%ld\n", way->id);    printf("hiding way #%ld\n", way->id);
2209    
2210    map_item_deselect(appdata);    map_item_deselect(appdata);

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