269 |
} |
} |
270 |
|
|
271 |
/* attach to existing way if the user requested so */ |
/* attach to existing way if the user requested so */ |
272 |
gboolean revert = FALSE; |
gboolean reverse = FALSE; |
273 |
if(map->action.extending) { |
if(map->action.extending) { |
274 |
node_t *nfirst = map->action.way->node_chain->node; |
node_t *nfirst = map->action.way->node_chain->node; |
275 |
|
|
277 |
|
|
278 |
if(osm_way_get_first_node(map->action.extending) == nfirst) { |
if(osm_way_get_first_node(map->action.extending) == nfirst) { |
279 |
printf(" need to prepend\n"); |
printf(" need to prepend\n"); |
280 |
osm_way_revert(map->action.extending); |
osm_way_reverse(map->action.extending); |
281 |
revert = TRUE; |
reverse = TRUE; |
282 |
} else if(osm_way_get_last_node(map->action.extending) == nfirst) |
} else if(osm_way_get_last_node(map->action.extending) == nfirst) |
283 |
printf(" need to append\n"); |
printf(" need to append\n"); |
284 |
|
|
302 |
map->action.way->flags |= OSM_FLAG_DIRTY; |
map->action.way->flags |= OSM_FLAG_DIRTY; |
303 |
|
|
304 |
/* and undo reversion of required */ |
/* and undo reversion of required */ |
305 |
if(revert) |
if(reverse) |
306 |
osm_way_revert(map->action.way); |
osm_way_reverse(map->action.way); |
307 |
|
|
308 |
} else { |
} else { |
309 |
/* now move the way itself into the main data structure */ |
/* now move the way itself into the main data structure */ |
327 |
if(map->action.ends_on) { |
if(map->action.ends_on) { |
328 |
printf(" this new way ends on another way\n"); |
printf(" this new way ends on another way\n"); |
329 |
|
|
330 |
/* if revert is true the node in question is the first one */ |
/* If reverse is true the node in question is the first one */ |
331 |
/* of the newly created way. thus is it revertes again before */ |
/* of the newly created way. Thus it is reversed again before */ |
332 |
/* attaching and the result is finally reverted once more */ |
/* attaching and the result is finally reversed once more */ |
333 |
|
|
334 |
/* this is slightly more complex as this time two full tagged */ |
/* this is slightly more complex as this time two full tagged */ |
335 |
/* ways may be involved as the new way may be an extended existing */ |
/* ways may be involved as the new way may be an extended existing */ |
336 |
/* way being connected to another way. This happens if you connect */ |
/* way being connected to another way. This happens if you connect */ |
337 |
/* two existing ways using a new way between them */ |
/* two existing ways using a new way between them */ |
338 |
|
|
339 |
if(revert) osm_way_revert(map->action.way); |
if (reverse) osm_way_reverse(map->action.way); |
340 |
|
|
341 |
/* and open dialog to resolve tag collisions if necessary */ |
/* and open dialog to resolve tag collisions if necessary */ |
342 |
if(combine_tags(&map->action.way->tag, map->action.ends_on->tag)) |
if(combine_tags(&map->action.way->tag, map->action.ends_on->tag)) |
349 |
/* make way member of all relations ends_on already is */ |
/* make way member of all relations ends_on already is */ |
350 |
transfer_relations(map->appdata->osm, map->action.way, map->action.ends_on); |
transfer_relations(map->appdata->osm, map->action.way, map->action.ends_on); |
351 |
|
|
352 |
/* check if we have to revert (again?) to match the way order */ |
/* check if we have to reverse (again?) to match the way order */ |
353 |
if(osm_way_get_last_node(map->action.ends_on) == |
if(osm_way_get_last_node(map->action.ends_on) == |
354 |
osm_way_get_last_node(map->action.way)) { |
osm_way_get_last_node(map->action.way)) { |
355 |
|
|
356 |
printf(" need to prepend ends_on\n"); |
printf(" need to prepend ends_on\n"); |
357 |
|
|
358 |
/* need to revert ends_on way */ |
/* need to reverse ends_on way */ |
359 |
osm_way_revert(map->action.ends_on); |
osm_way_reverse(map->action.ends_on); |
360 |
revert = !revert; |
reverse = !reverse; |
361 |
} |
} |
362 |
|
|
363 |
/* search end of node chain */ |
/* search end of node chain */ |
372 |
/* erase and free ends_on (now only containing the first node anymore) */ |
/* erase and free ends_on (now only containing the first node anymore) */ |
373 |
map_way_delete(map->appdata, map->action.ends_on); |
map_way_delete(map->appdata, map->action.ends_on); |
374 |
|
|
375 |
if(revert) osm_way_revert(map->action.way); |
if(reverse) osm_way_reverse(map->action.way); |
376 |
} |
} |
377 |
|
|
378 |
/* remove prior version of this way */ |
/* remove prior version of this way */ |
396 |
if(map_item_is_selected_way(map, item)) { |
if(map_item_is_selected_way(map, item)) { |
397 |
gint nx, ny; |
gint nx, ny; |
398 |
canvas_window2world(map->canvas, x, y, &nx, &ny); |
canvas_window2world(map->canvas, x, y, &nx, &ny); |
399 |
if(canvas_item_get_segment(item->item, nx, ny) >= 0) |
if(canvas_item_get_segment(item->item, nx, ny) >= 0) |
400 |
map_hl_cursor_draw(map, x, y, FALSE, map->style->node.radius); |
map_hl_cursor_draw(map, x, y, FALSE, map->style->node.radius); |
401 |
} |
} |
402 |
} |
} |
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_item_at(map, x, y); |
map_item_t *item = map_real_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); |
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_item_at(map, x, y); |
map_item_t *item = map_real_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); |
645 |
|
|
646 |
/* check if it was dropped onto another node */ |
/* check if it was dropped onto another node */ |
647 |
node_t *touchnode = map_hl_touchnode_get_node(map); |
node_t *touchnode = map_hl_touchnode_get_node(map); |
648 |
|
gboolean joined_with_touchnode = FALSE; |
649 |
|
|
650 |
if(touchnode) { |
if(touchnode) { |
651 |
map_hl_touchnode_clear(map); |
map_hl_touchnode_clear(map); |
652 |
|
|
660 |
|
|
661 |
/* the touchnode vanishes and is replaced by the node the */ |
/* the touchnode vanishes and is replaced by the node the */ |
662 |
/* user dropped onto it */ |
/* user dropped onto it */ |
663 |
|
joined_with_touchnode = TRUE; |
664 |
|
|
665 |
/* use touchnodes position */ |
/* use touchnodes position */ |
666 |
node->lpos = touchnode->lpos; |
node->lpos = touchnode->lpos; |
769 |
|
|
770 |
/* take all nodes from way[1] and append them to way[0] */ |
/* take all nodes from way[1] and append them to way[0] */ |
771 |
/* check if we have to append or prepend to way[0] */ |
/* check if we have to append or prepend to way[0] */ |
772 |
gboolean revert = FALSE; |
gboolean reverse = FALSE; |
773 |
if(ways2join[0]->node_chain->node == node) { |
if(ways2join[0]->node_chain->node == node) { |
774 |
/* make "prepend" to be "append" by reverting way[0] */ |
/* make "prepend" to be "append" by reversing way[0] */ |
775 |
printf(" target prepend -> revert\n"); |
printf(" target prepend -> reverse\n"); |
776 |
revert = TRUE; |
reverse = TRUE; |
777 |
osm_way_revert(ways2join[0]); |
osm_way_reverse(ways2join[0]); |
778 |
} |
} |
779 |
|
|
780 |
/* verify the common node is last in the target way */ |
/* verify the common node is last in the target way */ |
785 |
|
|
786 |
/* common node must be first in the chain to attach */ |
/* common node must be first in the chain to attach */ |
787 |
if(ways2join[1]->node_chain->node != node) { |
if(ways2join[1]->node_chain->node != node) { |
788 |
printf(" source revert\n"); |
printf(" source reverse\n"); |
789 |
osm_way_revert(ways2join[1]); |
osm_way_reverse(ways2join[1]); |
790 |
} |
} |
791 |
|
|
792 |
/* verify the common node is first in the source way */ |
/* verify the common node is first in the source way */ |
860 |
} |
} |
861 |
} |
} |
862 |
} |
} |
863 |
} else { |
} |
864 |
|
|
865 |
|
/* the node either wasn't dropped into another one (touchnode) or */ |
866 |
|
/* the user didn't want to join the nodes */ |
867 |
|
if(!joined_with_touchnode) { |
868 |
|
|
869 |
/* finally update dragged nodes position */ |
/* finally update dragged nodes position */ |
870 |
|
|
879 |
node->lpos.x = x; |
node->lpos.x = x; |
880 |
node->lpos.y = y; |
node->lpos.y = y; |
881 |
|
|
882 |
/* convert screen position back to ll */ |
/* convert screen position to lat/lon */ |
883 |
lpos2pos(osm->bounds, &node->lpos, &node->pos); |
lpos2pos(osm->bounds, &node->lpos, &node->pos); |
884 |
|
|
885 |
|
/* convert pos back to lpos to see rounding errors */ |
886 |
|
pos2lpos(osm->bounds, &node->pos, &node->lpos); |
887 |
|
|
888 |
printf(" now at %d %d (%f %f)\n", |
printf(" now at %d %d (%f %f)\n", |
889 |
node->lpos.x, node->lpos.y, node->pos.lat, node->pos.lon); |
node->lpos.x, node->lpos.y, node->pos.lat, node->pos.lon); |
890 |
} |
} |
930 |
|
|
931 |
g_assert(item.type == MAP_TYPE_WAY); |
g_assert(item.type == MAP_TYPE_WAY); |
932 |
|
|
933 |
osm_way_revert(item.way); |
osm_way_reverse(item.way); |
934 |
item.way->flags |= OSM_FLAG_DIRTY; |
guint n_tags_flipped = osm_way_reverse_direction_sensitive_tags(item.way); |
935 |
|
guint n_roles_flipped = osm_way_reverse_direction_sensitive_roles(appdata->osm, item.way); |
936 |
|
|
937 |
|
item.way->flags |= OSM_FLAG_DIRTY; |
938 |
map_way_select(appdata, item.way); |
map_way_select(appdata, item.way); |
939 |
|
|
940 |
|
// Flash a message about any side-effects |
941 |
|
char *msg = NULL; |
942 |
|
if (n_tags_flipped && !n_roles_flipped) { |
943 |
|
msg = g_strdup_printf(ngettext("%d tag updated", "%d tags updated", |
944 |
|
n_tags_flipped), |
945 |
|
n_tags_flipped); |
946 |
|
} |
947 |
|
else if (!n_tags_flipped && n_roles_flipped) { |
948 |
|
msg = g_strdup_printf(ngettext("%d relation updated", |
949 |
|
"%d relations updated", |
950 |
|
n_roles_flipped), |
951 |
|
n_roles_flipped); |
952 |
|
} |
953 |
|
else if (n_tags_flipped && n_roles_flipped) { |
954 |
|
char *msg1 = g_strdup_printf(ngettext("%d tag", "%d tags", |
955 |
|
n_tags_flipped), |
956 |
|
n_tags_flipped); |
957 |
|
char *msg2 = g_strdup_printf(ngettext("%d relation", "%d relations", |
958 |
|
n_roles_flipped), |
959 |
|
n_roles_flipped); |
960 |
|
msg = g_strdup_printf(_("%s & %s updated"), msg1, msg2); |
961 |
|
g_free(msg1); |
962 |
|
g_free(msg2); |
963 |
|
} |
964 |
|
if (msg) { |
965 |
|
banner_show_info(appdata, msg); |
966 |
|
g_free(msg); |
967 |
|
} |
968 |
} |
} |
969 |
|
|
970 |
|
// vim:et:ts=8:sw=2:sts=2:ai |