403 |
|
|
404 |
void map_edit_way_node_add(map_t *map, gint x, gint y) { |
void map_edit_way_node_add(map_t *map, gint x, gint y) { |
405 |
/* check if we are still hovering above the selected way */ |
/* check if we are still hovering above the selected way */ |
406 |
map_item_t *item = map_real_item_at(map, x, y); |
map_item_t *item = map_item_at(map, x, y); |
407 |
if(item && map_item_is_selected_way(map, item)) { |
if(item && map_item_is_selected_way(map, item)) { |
408 |
/* convert mouse position to canvas (world) position */ |
/* convert mouse position to canvas (world) position */ |
409 |
canvas_window2world(map->canvas, x, y, &x, &y); |
canvas_window2world(map->canvas, x, y, &x, &y); |
414 |
osm_node_attach(map->appdata->osm, node); |
osm_node_attach(map->appdata->osm, node); |
415 |
|
|
416 |
/* insert it into ways chain of nodes */ |
/* insert it into ways chain of nodes */ |
417 |
way_t *way = item->way; |
way_t *way = item->object.way; |
418 |
|
|
419 |
/* search correct position */ |
/* search correct position */ |
420 |
node_chain_t **chain = &way->node_chain; |
node_chain_t **chain = &way->node_chain; |
465 |
gint x0, y0, x1, y1; |
gint x0, y0, x1, y1; |
466 |
canvas_item_get_segment_pos(item->item, seg, &x0, &y0, &x1, &y1); |
canvas_item_get_segment_pos(item->item, seg, &x0, &y0, &x1, &y1); |
467 |
|
|
468 |
gint width = (item->way->draw.flags & |
gint width = (item->object.way->draw.flags & |
469 |
OSM_DRAW_FLAG_BG)? |
OSM_DRAW_FLAG_BG)? |
470 |
2*item->way->draw.bg.width: |
2*item->object.way->draw.bg.width: |
471 |
3*item->way->draw.width; |
3*item->object.way->draw.width; |
472 |
map_hl_segment_draw(map, width, x0, y0, x1, y1); |
map_hl_segment_draw(map, width, x0, y0, x1, y1); |
473 |
} |
} |
474 |
} else if(map_item_is_selected_node(map, item)) { |
} else if(map_item_is_selected_node(map, item)) { |
475 |
node_t *nfirst = osm_way_get_first_node(map->selected.way); |
node_t *nfirst = osm_way_get_first_node(map->selected.object.way); |
476 |
node_t *nlast = osm_way_get_last_node(map->selected.way); |
node_t *nlast = osm_way_get_last_node(map->selected.object.way); |
477 |
|
|
478 |
/* cutting a way at its first or last node doesn't make much sense ... */ |
/* cutting a way at its first or last node doesn't make much sense ... */ |
479 |
if((nfirst != item->node) && (nlast != item->node)) |
if((nfirst != item->object.node) && (nlast != item->object.node)) |
480 |
map_hl_cursor_draw(map, item->node->lpos.x, item->node->lpos.y, |
map_hl_cursor_draw(map, item->object.node->lpos.x, item->object.node->lpos.y, |
481 |
TRUE, 2*map->style->node.radius); |
TRUE, 2*map->style->node.radius); |
482 |
} |
} |
483 |
} |
} |
486 |
void map_edit_way_cut(map_t *map, gint x, gint y) { |
void map_edit_way_cut(map_t *map, gint x, gint y) { |
487 |
|
|
488 |
/* check if we are still hovering above the selected way */ |
/* check if we are still hovering above the selected way */ |
489 |
map_item_t *item = map_real_item_at(map, x, y); |
map_item_t *item = map_item_at(map, x, y); |
490 |
if(item && (map_item_is_selected_way(map, item) || |
if(item && (map_item_is_selected_way(map, item) || |
491 |
map_item_is_selected_node(map, item))) { |
map_item_is_selected_node(map, item))) { |
492 |
gboolean cut_at_node = map_item_is_selected_node(map, item); |
gboolean cut_at_node = map_item_is_selected_node(map, item); |
500 |
printf(" cut at node\n"); |
printf(" cut at node\n"); |
501 |
|
|
502 |
/* node must not be first or last node of way */ |
/* node must not be first or last node of way */ |
503 |
g_assert(map->selected.type == MAP_TYPE_WAY); |
g_assert(map->selected.object.type == WAY); |
504 |
|
|
505 |
if((osm_way_get_first_node(map->selected.way) != item->node) && |
if((osm_way_get_first_node(map->selected.object.way) != |
506 |
(osm_way_get_last_node(map->selected.way) != item->node)) { |
item->object.node) && |
507 |
way = map->selected.way; |
(osm_way_get_last_node(map->selected.object.way) != |
508 |
|
item->object.node)) { |
509 |
|
way = map->selected.object.way; |
510 |
|
|
511 |
cut_at = 0; |
cut_at = 0; |
512 |
node_chain_t *chain = way->node_chain; |
node_chain_t *chain = way->node_chain; |
513 |
while(chain && chain->node != item->node) { |
while(chain && chain->node != item->object.node) { |
514 |
chain = chain->next; |
chain = chain->next; |
515 |
cut_at++; |
cut_at++; |
516 |
} |
} |
521 |
} else { |
} else { |
522 |
printf(" cut at segment\n"); |
printf(" cut at segment\n"); |
523 |
cut_at = canvas_item_get_segment(item->item, x, y); |
cut_at = canvas_item_get_segment(item->item, x, y); |
524 |
if(cut_at >= 0) way = item->way; |
if(cut_at >= 0) way = item->object.way; |
525 |
} |
} |
526 |
|
|
527 |
if(way) { |
if(way) { |
636 |
map_t *map = appdata->map; |
map_t *map = appdata->map; |
637 |
osm_t *osm = appdata->osm; |
osm_t *osm = appdata->osm; |
638 |
|
|
639 |
g_assert(map_item->type == MAP_TYPE_NODE); |
g_assert(map_item->object.type == NODE); |
640 |
node_t *node = map_item->node; |
node_t *node = map_item->object.node; |
641 |
|
|
642 |
printf("released dragged node #%ld\n", node->id); |
printf("released dragged node #%ld\n", node->id); |
643 |
printf(" was at %d %d (%f %f)\n", |
printf(" was at %d %d (%f %f)\n", |
761 |
/* way[1] gets destroyed and attached to way[0] */ |
/* way[1] gets destroyed and attached to way[0] */ |
762 |
/* so check if way[1] is selected and exchainge ways then */ |
/* so check if way[1] is selected and exchainge ways then */ |
763 |
/* so that way may stay selected */ |
/* so that way may stay selected */ |
764 |
if((map->selected.type == MAP_TYPE_WAY) && |
if((map->selected.object.type == WAY) && |
765 |
(map->selected.way == ways2join[1])) { |
(map->selected.object.way == ways2join[1])) { |
766 |
printf(" swapping ways to keep selected one alive\n"); |
printf(" swapping ways to keep selected one alive\n"); |
767 |
way_t *tmp = ways2join[1]; |
way_t *tmp = ways2join[1]; |
768 |
ways2join[1] = ways2join[0]; |
ways2join[1] = ways2join[0]; |
930 |
/* deleting the selected item de-selects it ... */ |
/* deleting the selected item de-selects it ... */ |
931 |
map_item_deselect(appdata); |
map_item_deselect(appdata); |
932 |
|
|
933 |
g_assert(item.type == MAP_TYPE_WAY); |
g_assert(item.object.type == WAY); |
934 |
|
|
935 |
osm_way_reverse(item.way); |
osm_way_reverse(item.object.way); |
936 |
guint n_tags_flipped = osm_way_reverse_direction_sensitive_tags(item.way); |
guint n_tags_flipped = |
937 |
guint n_roles_flipped = osm_way_reverse_direction_sensitive_roles(appdata->osm, item.way); |
osm_way_reverse_direction_sensitive_tags(item.object.way); |
938 |
|
guint n_roles_flipped = |
939 |
|
osm_way_reverse_direction_sensitive_roles(appdata->osm, item.object.way); |
940 |
|
|
941 |
item.way->flags |= OSM_FLAG_DIRTY; |
item.object.way->flags |= OSM_FLAG_DIRTY; |
942 |
map_way_select(appdata, item.way); |
map_way_select(appdata, item.object.way); |
943 |
|
|
944 |
// Flash a message about any side-effects |
// Flash a message about any side-effects |
945 |
char *msg = NULL; |
char *msg = NULL; |