28 |
|
|
29 |
while(rchain) { |
while(rchain) { |
30 |
relation_chain_t *next = rchain->next; |
relation_chain_t *next = rchain->next; |
31 |
printf("way #%ld is part of relation #%ld\n", src->id, |
printf("way #"ITEM_ID_FORMAT" is part of relation #"ITEM_ID_FORMAT"\n", |
32 |
rchain->relation->id); |
src->id, rchain->relation->id); |
33 |
|
|
34 |
/* make new member of the same relation */ |
/* make new member of the same relation */ |
35 |
|
|
38 |
char *role = NULL; |
char *role = NULL; |
39 |
while(*member) { |
while(*member) { |
40 |
/* save role of way */ |
/* save role of way */ |
41 |
if(((*member)->type == WAY) && ((*member)->way == src)) |
if(((*member)->object.type == WAY) && ((*member)->object.way == src)) |
42 |
role = (*member)->role; |
role = (*member)->role; |
43 |
member = &(*member)->next; |
member = &(*member)->next; |
44 |
} |
} |
45 |
|
|
46 |
printf(" adding way #%ld to relation\n", dst->id); |
printf(" adding way #"ITEM_ID_FORMAT" to relation\n", dst->id); |
47 |
*member = g_new0(member_t, 1); |
*member = g_new0(member_t, 1); |
48 |
(*member)->type = WAY; |
(*member)->object.type = WAY; |
49 |
(*member)->way = dst; |
(*member)->object.way = dst; |
50 |
if(role) (*member)->role = g_strdup(role); |
if(role) (*member)->role = g_strdup(role); |
51 |
member = &(*member)->next; |
member = &(*member)->next; |
52 |
|
|
93 |
/* -------------------------- way_add ----------------------- */ |
/* -------------------------- way_add ----------------------- */ |
94 |
|
|
95 |
void map_edit_way_add_begin(map_t *map, way_t *way_sel) { |
void map_edit_way_add_begin(map_t *map, way_t *way_sel) { |
96 |
if(way_sel) printf("previously selected way is #%ld\n", way_sel->id); |
if(way_sel) printf("previously selected way is #"ITEM_ID_FORMAT"\n", |
97 |
|
way_sel->id); |
98 |
|
|
99 |
g_assert(!map->action.way); |
g_assert(!map->action.way); |
100 |
map->action.way = osm_way_new(); |
map->action.way = osm_way_new(); |
124 |
/* use the existing node if one was touched */ |
/* use the existing node if one was touched */ |
125 |
node_t *node = map_hl_touchnode_get_node(map); |
node_t *node = map_hl_touchnode_get_node(map); |
126 |
if(node) { |
if(node) { |
127 |
printf(" re-using node #%ld\n", node->id); |
printf(" re-using node #"ITEM_ID_FORMAT"\n", node->id); |
128 |
map_hl_touchnode_clear(map); |
map_hl_touchnode_clear(map); |
129 |
|
|
130 |
g_assert(map->action.way); |
g_assert(map->action.way); |
136 |
way_chain_t *next = way_chain->next; |
way_chain_t *next = way_chain->next; |
137 |
|
|
138 |
if(node == osm_way_get_last_node(way_chain->way)) { |
if(node == osm_way_get_last_node(way_chain->way)) { |
139 |
printf(" way #%ld ends with this node\n", way_chain->way->id); |
printf(" way #"ITEM_ID_FORMAT" ends with this node\n", |
140 |
|
way_chain->way->id); |
141 |
if(!touch_way) touch_way = way_chain->way; |
if(!touch_way) touch_way = way_chain->way; |
142 |
} |
} |
143 |
|
|
144 |
if(node == osm_way_get_first_node(way_chain->way)) { |
if(node == osm_way_get_first_node(way_chain->way)) { |
145 |
printf(" way #%ld starts with this node\n", way_chain->way->id); |
printf(" way #"ITEM_ID_FORMAT" starts with this node\n", |
146 |
|
way_chain->way->id); |
147 |
if(!touch_way) touch_way = way_chain->way; |
if(!touch_way) touch_way = way_chain->way; |
148 |
} |
} |
149 |
|
|
222 |
while(chain) { |
while(chain) { |
223 |
node_chain_t *next = chain->next; |
node_chain_t *next = chain->next; |
224 |
|
|
225 |
printf(" node #%ld (used by %d)\n", |
printf(" node #"ITEM_ID_FORMAT" (used by %d)\n", |
226 |
chain->node->id, chain->node->ways); |
chain->node->id, chain->node->ways); |
227 |
|
|
228 |
chain->node->ways--; |
chain->node->ways--; |
251 |
/* (their way count will be 0 after removing the way) */ |
/* (their way count will be 0 after removing the way) */ |
252 |
node_chain_t *chain = map->action.way->node_chain; |
node_chain_t *chain = map->action.way->node_chain; |
253 |
while(chain) { |
while(chain) { |
254 |
printf(" node #%ld (used by %d)\n", |
printf(" node #"ITEM_ID_FORMAT" (used by %d)\n", |
255 |
chain->node->id, chain->node->ways); |
chain->node->id, chain->node->ways); |
256 |
|
|
257 |
/* a node may have been a stand-alone node before, so remove its */ |
/* a node may have been a stand-alone node before, so remove its */ |
276 |
if(map->action.extending) { |
if(map->action.extending) { |
277 |
node_t *nfirst = map->action.way->node_chain->node; |
node_t *nfirst = map->action.way->node_chain->node; |
278 |
|
|
279 |
printf(" request to extend way #%ld\n", map->action.extending->id); |
printf(" request to extend way #"ITEM_ID_FORMAT"\n", |
280 |
|
map->action.extending->id); |
281 |
|
|
282 |
if(osm_way_get_first_node(map->action.extending) == nfirst) { |
if(osm_way_get_first_node(map->action.extending) == nfirst) { |
283 |
printf(" need to prepend\n"); |
printf(" need to prepend\n"); |
407 |
|
|
408 |
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) { |
409 |
/* check if we are still hovering above the selected way */ |
/* check if we are still hovering above the selected way */ |
410 |
map_item_t *item = map_real_item_at(map, x, y); |
map_item_t *item = map_item_at(map, x, y); |
411 |
if(item && map_item_is_selected_way(map, item)) { |
if(item && map_item_is_selected_way(map, item)) { |
412 |
/* convert mouse position to canvas (world) position */ |
/* convert mouse position to canvas (world) position */ |
413 |
canvas_window2world(map->canvas, x, y, &x, &y); |
canvas_window2world(map->canvas, x, y, &x, &y); |
418 |
osm_node_attach(map->appdata->osm, node); |
osm_node_attach(map->appdata->osm, node); |
419 |
|
|
420 |
/* insert it into ways chain of nodes */ |
/* insert it into ways chain of nodes */ |
421 |
way_t *way = item->way; |
way_t *way = item->object.way; |
422 |
|
|
423 |
/* search correct position */ |
/* search correct position */ |
424 |
node_chain_t **chain = &way->node_chain; |
node_chain_t **chain = &way->node_chain; |
469 |
gint x0, y0, x1, y1; |
gint x0, y0, x1, y1; |
470 |
canvas_item_get_segment_pos(item->item, seg, &x0, &y0, &x1, &y1); |
canvas_item_get_segment_pos(item->item, seg, &x0, &y0, &x1, &y1); |
471 |
|
|
472 |
gint width = (item->way->draw.flags & |
gint width = (item->object.way->draw.flags & |
473 |
OSM_DRAW_FLAG_BG)? |
OSM_DRAW_FLAG_BG)? |
474 |
2*item->way->draw.bg.width: |
2*item->object.way->draw.bg.width: |
475 |
3*item->way->draw.width; |
3*item->object.way->draw.width; |
476 |
map_hl_segment_draw(map, width, x0, y0, x1, y1); |
map_hl_segment_draw(map, width, x0, y0, x1, y1); |
477 |
} |
} |
478 |
} else if(map_item_is_selected_node(map, item)) { |
} else if(map_item_is_selected_node(map, item)) { |
479 |
node_t *nfirst = osm_way_get_first_node(map->selected.way); |
node_t *nfirst = osm_way_get_first_node(map->selected.object.way); |
480 |
node_t *nlast = osm_way_get_last_node(map->selected.way); |
node_t *nlast = osm_way_get_last_node(map->selected.object.way); |
481 |
|
|
482 |
/* 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 ... */ |
483 |
if((nfirst != item->node) && (nlast != item->node)) |
if((nfirst != item->object.node) && (nlast != item->object.node)) |
484 |
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, |
485 |
TRUE, 2*map->style->node.radius); |
TRUE, 2*map->style->node.radius); |
486 |
} |
} |
487 |
} |
} |
490 |
void map_edit_way_cut(map_t *map, gint x, gint y) { |
void map_edit_way_cut(map_t *map, gint x, gint y) { |
491 |
|
|
492 |
/* check if we are still hovering above the selected way */ |
/* check if we are still hovering above the selected way */ |
493 |
map_item_t *item = map_real_item_at(map, x, y); |
map_item_t *item = map_item_at(map, x, y); |
494 |
if(item && (map_item_is_selected_way(map, item) || |
if(item && (map_item_is_selected_way(map, item) || |
495 |
map_item_is_selected_node(map, item))) { |
map_item_is_selected_node(map, item))) { |
496 |
gboolean cut_at_node = map_item_is_selected_node(map, item); |
gboolean cut_at_node = map_item_is_selected_node(map, item); |
504 |
printf(" cut at node\n"); |
printf(" cut at node\n"); |
505 |
|
|
506 |
/* node must not be first or last node of way */ |
/* node must not be first or last node of way */ |
507 |
g_assert(map->selected.type == MAP_TYPE_WAY); |
g_assert(map->selected.object.type == WAY); |
508 |
|
|
509 |
if((osm_way_get_first_node(map->selected.way) != item->node) && |
if((osm_way_get_first_node(map->selected.object.way) != |
510 |
(osm_way_get_last_node(map->selected.way) != item->node)) { |
item->object.node) && |
511 |
way = map->selected.way; |
(osm_way_get_last_node(map->selected.object.way) != |
512 |
|
item->object.node)) { |
513 |
|
way = map->selected.object.way; |
514 |
|
|
515 |
cut_at = 0; |
cut_at = 0; |
516 |
node_chain_t *chain = way->node_chain; |
node_chain_t *chain = way->node_chain; |
517 |
while(chain && chain->node != item->node) { |
while(chain && chain->node != item->object.node) { |
518 |
chain = chain->next; |
chain = chain->next; |
519 |
cut_at++; |
cut_at++; |
520 |
} |
} |
525 |
} else { |
} else { |
526 |
printf(" cut at segment\n"); |
printf(" cut at segment\n"); |
527 |
cut_at = canvas_item_get_segment(item->item, x, y); |
cut_at = canvas_item_get_segment(item->item, x, y); |
528 |
if(cut_at >= 0) way = item->way; |
if(cut_at >= 0) way = item->object.way; |
529 |
} |
} |
530 |
|
|
531 |
if(way) { |
if(way) { |
543 |
} |
} |
544 |
|
|
545 |
/* ------------ copy all tags ------------- */ |
/* ------------ copy all tags ------------- */ |
546 |
new->tag = osm_tags_copy(way->tag, TRUE); |
new->tag = osm_tags_copy(way->tag); |
547 |
|
|
548 |
/* ---- transfer relation membership from way to new ----- */ |
/* ---- transfer relation membership from way to new ----- */ |
549 |
transfer_relations(map->appdata->osm, new, way); |
transfer_relations(map->appdata->osm, new, way); |
581 |
map_item_deselect(map->appdata); |
map_item_deselect(map->appdata); |
582 |
|
|
583 |
/* remove prior version of this way */ |
/* remove prior version of this way */ |
584 |
printf("remove visible version of way #%ld\n", way->id); |
printf("remove visible version of way #"ITEM_ID_FORMAT"\n", way->id); |
585 |
map_item_chain_destroy(&way->map_item_chain); |
map_item_chain_destroy(&way->map_item_chain); |
586 |
|
|
587 |
/* swap chains of the old way is to be destroyed due to a lack */ |
/* swap chains of the old way is to be destroyed due to a lack */ |
640 |
map_t *map = appdata->map; |
map_t *map = appdata->map; |
641 |
osm_t *osm = appdata->osm; |
osm_t *osm = appdata->osm; |
642 |
|
|
643 |
g_assert(map_item->type == MAP_TYPE_NODE); |
g_assert(map_item->object.type == NODE); |
644 |
node_t *node = map_item->node; |
node_t *node = map_item->object.node; |
645 |
|
|
646 |
printf("released dragged node #%ld\n", node->id); |
printf("released dragged node #"ITEM_ID_FORMAT"\n", node->id); |
647 |
printf(" was at %d %d (%f %f)\n", |
printf(" was at %d %d (%f %f)\n", |
648 |
node->lpos.x, node->lpos.y, |
node->lpos.x, node->lpos.y, |
649 |
node->pos.lat, node->pos.lon); |
node->pos.lat, node->pos.lon); |
656 |
if(touchnode) { |
if(touchnode) { |
657 |
map_hl_touchnode_clear(map); |
map_hl_touchnode_clear(map); |
658 |
|
|
659 |
printf(" dropped onto node #%ld\n", touchnode->id); |
printf(" dropped onto node #"ITEM_ID_FORMAT"\n", touchnode->id); |
660 |
|
|
661 |
if(yes_no_f(GTK_WIDGET(appdata->window), |
if(yes_no_f(GTK_WIDGET(appdata->window), |
662 |
appdata, MISC_AGAIN_ID_JOIN_NODES, 0, |
appdata, MISC_AGAIN_ID_JOIN_NODES, 0, |
677 |
node_chain_t *chain = way->node_chain; |
node_chain_t *chain = way->node_chain; |
678 |
while(chain) { |
while(chain) { |
679 |
if(chain->node == touchnode) { |
if(chain->node == touchnode) { |
680 |
printf(" found node in way #%ld\n", way->id); |
printf(" found node in way #"ITEM_ID_FORMAT"\n", way->id); |
681 |
|
|
682 |
/* replace by node */ |
/* replace by node */ |
683 |
chain->node = node; |
chain->node = node; |
698 |
while(relation) { |
while(relation) { |
699 |
member_t *member = relation->member; |
member_t *member = relation->member; |
700 |
while(member) { |
while(member) { |
701 |
if(member->type == NODE && member->node == touchnode) { |
if(member->object.type == NODE && member->object.node == touchnode) { |
702 |
printf(" found node in relation #%ld\n", relation->id); |
printf(" found node in relation #"ITEM_ID_FORMAT"\n", |
703 |
|
relation->id); |
704 |
|
|
705 |
/* replace by node */ |
/* replace by node */ |
706 |
member->node = node; |
member->object.node = node; |
707 |
|
|
708 |
relation->flags |= OSM_FLAG_DIRTY; |
relation->flags |= OSM_FLAG_DIRTY; |
709 |
} |
} |
742 |
if(ways2join_cnt < 2) |
if(ways2join_cnt < 2) |
743 |
ways2join[ways2join_cnt] = way; |
ways2join[ways2join_cnt] = way; |
744 |
|
|
745 |
printf(" way #%ld ends with this node\n", way->id); |
printf(" way #"ITEM_ID_FORMAT" ends with this node\n", way->id); |
746 |
ways2join_cnt++; |
ways2join_cnt++; |
747 |
} |
} |
748 |
way = way->next; |
way = way->next; |
760 |
_("Do you want to join the dragged way with the one " |
_("Do you want to join the dragged way with the one " |
761 |
"you dropped it on?"))) { |
"you dropped it on?"))) { |
762 |
|
|
763 |
printf(" about to join ways #%ld and #%ld\n", |
printf(" about to join ways #" ITEM_ID_FORMAT " and #" |
764 |
ways2join[0]->id, ways2join[1]->id); |
ITEM_ID_FORMAT "\n", ways2join[0]->id, ways2join[1]->id); |
765 |
|
|
766 |
/* way[1] gets destroyed and attached to way[0] */ |
/* way[1] gets destroyed and attached to way[0] */ |
767 |
/* so check if way[1] is selected and exchainge ways then */ |
/* so check if way[1] is selected and exchainge ways then */ |
768 |
/* so that way may stay selected */ |
/* so that way may stay selected */ |
769 |
if((map->selected.type == MAP_TYPE_WAY) && |
if((map->selected.object.type == WAY) && |
770 |
(map->selected.way == ways2join[1])) { |
(map->selected.object.way == ways2join[1])) { |
771 |
printf(" swapping ways to keep selected one alive\n"); |
printf(" swapping ways to keep selected one alive\n"); |
772 |
way_t *tmp = ways2join[1]; |
way_t *tmp = ways2join[1]; |
773 |
ways2join[1] = ways2join[0]; |
ways2join[1] = ways2join[0]; |
818 |
|
|
819 |
while(rchain) { |
while(rchain) { |
820 |
relation_chain_t *next = rchain->next; |
relation_chain_t *next = rchain->next; |
821 |
printf("way[1] is part of relation #%ld\n", rchain->relation->id); |
printf("way[1] is part of relation #"ITEM_ID_FORMAT"\n", |
822 |
|
rchain->relation->id); |
823 |
|
|
824 |
/* make way[0] member of the same relation */ |
/* make way[0] member of the same relation */ |
825 |
|
|
829 |
member_t **member = &rchain->relation->member; |
member_t **member = &rchain->relation->member; |
830 |
char *role = NULL; |
char *role = NULL; |
831 |
while(*member && |
while(*member && |
832 |
!(((*member)->type == WAY) && |
!(((*member)->object.type == WAY) && |
833 |
((*member)->way == ways2join[0]))) { |
((*member)->object.way == ways2join[0]))) { |
834 |
|
|
835 |
/* save role of way[1] */ |
/* save role of way[1] */ |
836 |
if(((*member)->type == WAY) && ((*member)->way == ways2join[0])) |
if(((*member)->object.type == WAY) && |
837 |
|
((*member)->object.way == ways2join[0])) |
838 |
role = (*member)->role; |
role = (*member)->role; |
839 |
|
|
840 |
member = &(*member)->next; |
member = &(*member)->next; |
845 |
else { |
else { |
846 |
printf(" adding way[0] to relation\n"); |
printf(" adding way[0] to relation\n"); |
847 |
*member = g_new0(member_t, 1); |
*member = g_new0(member_t, 1); |
848 |
(*member)->type = WAY; |
(*member)->object.type = WAY; |
849 |
(*member)->way = ways2join[0]; |
(*member)->object.way = ways2join[0]; |
850 |
if(role) (*member)->role = g_strdup(role); |
if(role) (*member)->role = g_strdup(role); |
851 |
member = &(*member)->next; |
member = &(*member)->next; |
852 |
|
|
907 |
way_t *way = osm->way; |
way_t *way = osm->way; |
908 |
while(way) { |
while(way) { |
909 |
if(osm_node_in_way(way, node)) { |
if(osm_node_in_way(way, node)) { |
910 |
printf(" node is part of way #%ld, redraw!\n", way->id); |
printf(" node is part of way #"ITEM_ID_FORMAT", redraw!\n", way->id); |
911 |
|
|
912 |
/* remove prior version of this way */ |
/* remove prior version of this way */ |
913 |
map_item_chain_destroy(&way->map_item_chain); |
map_item_chain_destroy(&way->map_item_chain); |
937 |
/* deleting the selected item de-selects it ... */ |
/* deleting the selected item de-selects it ... */ |
938 |
map_item_deselect(appdata); |
map_item_deselect(appdata); |
939 |
|
|
940 |
g_assert(item.type == MAP_TYPE_WAY); |
g_assert(item.object.type == WAY); |
941 |
|
|
942 |
osm_way_reverse(item.way); |
osm_way_reverse(item.object.way); |
943 |
guint n_tags_flipped = osm_way_reverse_direction_sensitive_tags(item.way); |
guint n_tags_flipped = |
944 |
guint n_roles_flipped = osm_way_reverse_direction_sensitive_roles(appdata->osm, item.way); |
osm_way_reverse_direction_sensitive_tags(item.object.way); |
945 |
|
guint n_roles_flipped = |
946 |
|
osm_way_reverse_direction_sensitive_roles(appdata->osm, item.object.way); |
947 |
|
|
948 |
item.way->flags |= OSM_FLAG_DIRTY; |
item.object.way->flags |= OSM_FLAG_DIRTY; |
949 |
map_way_select(appdata, item.way); |
map_way_select(appdata, item.object.way); |
950 |
|
|
951 |
// Flash a message about any side-effects |
// Flash a message about any side-effects |
952 |
char *msg = NULL; |
char *msg = NULL; |