55 |
static void diff_save_nodes(node_t *node, xmlNodePtr root_node) { |
static void diff_save_nodes(node_t *node, xmlNodePtr root_node) { |
56 |
/* store all modfied nodes */ |
/* store all modfied nodes */ |
57 |
while(node) { |
while(node) { |
58 |
if(node->flags) { |
if(OSM_FLAGS(node)) { |
59 |
xmlNodePtr node_node = xmlNewChild(root_node, NULL, |
xmlNodePtr node_node = xmlNewChild(root_node, NULL, |
60 |
BAD_CAST "node", NULL); |
BAD_CAST "node", NULL); |
61 |
|
|
62 |
diff_save_state_n_id(node->flags, node_node, OSM_ID(node)); |
diff_save_state_n_id(OSM_FLAGS(node), node_node, OSM_ID(node)); |
63 |
|
|
64 |
if(!(node->flags & OSM_FLAG_DELETED)) { |
if(!(OSM_FLAGS(node) & OSM_FLAG_DELETED)) { |
65 |
char str[32]; |
char str[32]; |
66 |
|
|
67 |
/* additional info is only required if the node hasn't been deleted */ |
/* additional info is only required if the node hasn't been deleted */ |
72 |
snprintf(str, sizeof(str), "%lu", OSM_TIME(node)); |
snprintf(str, sizeof(str), "%lu", OSM_TIME(node)); |
73 |
xmlNewProp(node_node, BAD_CAST "time", BAD_CAST str); |
xmlNewProp(node_node, BAD_CAST "time", BAD_CAST str); |
74 |
|
|
75 |
diff_save_tags(node->tag, node_node); |
diff_save_tags(OSM_TAG(node), node_node); |
76 |
} |
} |
77 |
} |
} |
78 |
node = node->next; |
node = node->next; |
83 |
|
|
84 |
/* store all modfied ways */ |
/* store all modfied ways */ |
85 |
while(way) { |
while(way) { |
86 |
if(way->flags) { |
if(OSM_FLAGS(way)) { |
87 |
xmlNodePtr node_way = xmlNewChild(root_node, NULL, |
xmlNodePtr node_way = xmlNewChild(root_node, NULL, |
88 |
BAD_CAST "way", NULL); |
BAD_CAST "way", NULL); |
89 |
|
|
90 |
diff_save_state_n_id(way->flags, node_way, OSM_ID(way)); |
diff_save_state_n_id(OSM_FLAGS(way), node_way, OSM_ID(way)); |
91 |
|
|
92 |
if(way->flags & OSM_FLAG_HIDDEN) |
if(OSM_FLAGS(way) & OSM_FLAG_HIDDEN) |
93 |
xmlNewProp(node_way, BAD_CAST "hidden", BAD_CAST "true"); |
xmlNewProp(node_way, BAD_CAST "hidden", BAD_CAST "true"); |
94 |
|
|
95 |
/* additional info is only required if the way hasn't been deleted */ |
/* additional info is only required if the way hasn't been deleted */ |
96 |
/* and of the dirty or new flags are set. (otherwise e.g. only */ |
/* and of the dirty or new flags are set. (otherwise e.g. only */ |
97 |
/* the hidden flag may be set) */ |
/* the hidden flag may be set) */ |
98 |
if((!(way->flags & OSM_FLAG_DELETED)) && |
if((!(OSM_FLAGS(way) & OSM_FLAG_DELETED)) && |
99 |
(way->flags & (OSM_FLAG_DIRTY | OSM_FLAG_NEW))) { |
(OSM_FLAGS(way) & (OSM_FLAG_DIRTY | OSM_FLAG_NEW))) { |
100 |
node_chain_t *node_chain = way->node_chain; |
node_chain_t *node_chain = way->node_chain; |
101 |
while(node_chain) { |
while(node_chain) { |
102 |
xmlNodePtr node_node = xmlNewChild(node_way, NULL, |
xmlNodePtr node_node = xmlNewChild(node_way, NULL, |
106 |
g_free(id); |
g_free(id); |
107 |
node_chain = node_chain->next; |
node_chain = node_chain->next; |
108 |
} |
} |
109 |
diff_save_tags(way->tag, node_way); |
diff_save_tags(OSM_TAG(way), node_way); |
110 |
} |
} |
111 |
} |
} |
112 |
way = way->next; |
way = way->next; |
117 |
|
|
118 |
/* store all modfied relations */ |
/* store all modfied relations */ |
119 |
while(relation) { |
while(relation) { |
120 |
if(relation->flags) { |
if(OSM_FLAGS(relation)) { |
121 |
xmlNodePtr node_rel = xmlNewChild(root_node, NULL, |
xmlNodePtr node_rel = xmlNewChild(root_node, NULL, |
122 |
BAD_CAST "relation", NULL); |
BAD_CAST "relation", NULL); |
123 |
|
|
124 |
diff_save_state_n_id(relation->flags, node_rel, OSM_ID(relation)); |
diff_save_state_n_id(OSM_FLAGS(relation), node_rel, OSM_ID(relation)); |
125 |
|
|
126 |
if(!(relation->flags & OSM_FLAG_DELETED)) { |
if(!(OSM_FLAGS(relation) & OSM_FLAG_DELETED)) { |
127 |
/* additional info is only required if the relation */ |
/* additional info is only required if the relation */ |
128 |
/* hasn't been deleted */ |
/* hasn't been deleted */ |
129 |
member_t *member = relation->member; |
member_t *member = relation->member; |
175 |
|
|
176 |
member = member->next; |
member = member->next; |
177 |
} |
} |
178 |
diff_save_tags(relation->tag, node_rel); |
diff_save_tags(OSM_TAG(relation), node_rel); |
179 |
} |
} |
180 |
} |
} |
181 |
relation = relation->next; |
relation = relation->next; |
190 |
/* check if a diff is necessary */ |
/* check if a diff is necessary */ |
191 |
node_t *node = osm->node; |
node_t *node = osm->node; |
192 |
while(node && clean) { |
while(node && clean) { |
193 |
if(node->flags) clean = FALSE; |
if(OSM_FLAGS(node)) clean = FALSE; |
194 |
node = node->next; |
node = node->next; |
195 |
} |
} |
196 |
|
|
197 |
way_t *way = osm->way; |
way_t *way = osm->way; |
198 |
while(way && clean) { |
while(way && clean) { |
199 |
if(honor_hidden_flags) { |
if(honor_hidden_flags) { |
200 |
if(way->flags) clean = FALSE; |
if(OSM_FLAGS(way)) clean = FALSE; |
201 |
} else |
} else |
202 |
if(way->flags & ~OSM_FLAG_HIDDEN) |
if(OSM_FLAGS(way) & ~OSM_FLAG_HIDDEN) |
203 |
clean = FALSE; |
clean = FALSE; |
204 |
|
|
205 |
way = way->next; |
way = way->next; |
207 |
|
|
208 |
relation_t *relation = osm->relation; |
relation_t *relation = osm->relation; |
209 |
while(relation && clean) { |
while(relation && clean) { |
210 |
if(relation->flags) clean = FALSE; |
if(OSM_FLAGS(relation)) clean = FALSE; |
211 |
relation = relation->next; |
relation = relation->next; |
212 |
} |
} |
213 |
|
|
343 |
printf(" Restoring NEW node\n"); |
printf(" Restoring NEW node\n"); |
344 |
|
|
345 |
node = g_new0(node_t, 1); |
node = g_new0(node_t, 1); |
346 |
node->visible = TRUE; |
OSM_VISIBLE(node) = TRUE; |
347 |
node->flags = OSM_FLAG_NEW; |
OSM_FLAGS(node) = OSM_FLAG_NEW; |
348 |
OSM_TIME(node) = xml_get_prop_int(node_node, "time", 0); |
OSM_TIME(node) = xml_get_prop_int(node_node, "time", 0); |
349 |
if(!OSM_TIME(node)) OSM_TIME(node) = time(NULL); |
if(!OSM_TIME(node)) OSM_TIME(node) = time(NULL); |
350 |
|
|
358 |
printf(" Restoring DELETE flag\n"); |
printf(" Restoring DELETE flag\n"); |
359 |
|
|
360 |
if((node = osm_get_node_by_id(osm, id))) |
if((node = osm_get_node_by_id(osm, id))) |
361 |
node->flags |= OSM_FLAG_DELETED; |
OSM_FLAGS(node) |= OSM_FLAG_DELETED; |
362 |
else |
else |
363 |
printf(" WARNING: no node with that id found\n"); |
printf(" WARNING: no node with that id found\n"); |
364 |
break; |
break; |
367 |
printf(" Valid id/position (DIRTY)\n"); |
printf(" Valid id/position (DIRTY)\n"); |
368 |
|
|
369 |
if((node = osm_get_node_by_id(osm, id))) |
if((node = osm_get_node_by_id(osm, id))) |
370 |
node->flags |= OSM_FLAG_DIRTY; |
OSM_FLAGS(node) |= OSM_FLAG_DIRTY; |
371 |
else |
else |
372 |
printf(" WARNING: no node with that id found\n"); |
printf(" WARNING: no node with that id found\n"); |
373 |
break; |
break; |
396 |
|
|
397 |
/* node may be an existing node, so remove tags to */ |
/* node may be an existing node, so remove tags to */ |
398 |
/* make space for new ones */ |
/* make space for new ones */ |
399 |
if(node->tag) { |
if(OSM_TAG(node)) { |
400 |
printf(" removing existing tags for diff tags\n"); |
printf(" removing existing tags for diff tags\n"); |
401 |
osm_tag_free(node->tag); |
osm_tag_free(OSM_TAG(node)); |
402 |
node->tag = NULL; |
OSM_TAG(node) = NULL; |
403 |
} |
} |
404 |
|
|
405 |
node->tag = xml_scan_tags(doc, node_node->children, osm); |
OSM_TAG(node) = xml_scan_tags(doc, node_node->children, osm); |
406 |
} |
} |
407 |
|
|
408 |
void diff_restore_way(xmlDoc *doc, xmlNodePtr node_node, osm_t *osm) { |
void diff_restore_way(xmlDoc *doc, xmlNodePtr node_node, osm_t *osm) { |
434 |
printf(" Restoring NEW way\n"); |
printf(" Restoring NEW way\n"); |
435 |
|
|
436 |
way = g_new0(way_t, 1); |
way = g_new0(way_t, 1); |
437 |
way->visible = TRUE; |
OSM_VISIBLE(way) = TRUE; |
438 |
way->flags = OSM_FLAG_NEW; |
OSM_FLAGS(way) = OSM_FLAG_NEW; |
439 |
OSM_TIME(way) = xml_get_prop_int(node_node, "time", 0); |
OSM_TIME(way) = xml_get_prop_int(node_node, "time", 0); |
440 |
if(!OSM_TIME(way)) OSM_TIME(way) = time(NULL); |
if(!OSM_TIME(way)) OSM_TIME(way) = time(NULL); |
441 |
|
|
449 |
printf(" Restoring DELETE flag\n"); |
printf(" Restoring DELETE flag\n"); |
450 |
|
|
451 |
if((way = osm_get_way_by_id(osm, id))) |
if((way = osm_get_way_by_id(osm, id))) |
452 |
way->flags |= OSM_FLAG_DELETED; |
OSM_FLAGS(way) |= OSM_FLAG_DELETED; |
453 |
else |
else |
454 |
printf(" WARNING: no way with that id found\n"); |
printf(" WARNING: no way with that id found\n"); |
455 |
break; |
break; |
458 |
printf(" Valid id (DIRTY)\n"); |
printf(" Valid id (DIRTY)\n"); |
459 |
|
|
460 |
if((way = osm_get_way_by_id(osm, id))) |
if((way = osm_get_way_by_id(osm, id))) |
461 |
way->flags |= OSM_FLAG_DIRTY; |
OSM_FLAGS(way) |= OSM_FLAG_DIRTY; |
462 |
else |
else |
463 |
printf(" WARNING: no way with that id found\n"); |
printf(" WARNING: no way with that id found\n"); |
464 |
break; |
break; |
478 |
|
|
479 |
/* update node_chain */ |
/* update node_chain */ |
480 |
if(hidden) |
if(hidden) |
481 |
way->flags |= OSM_FLAG_HIDDEN; |
OSM_FLAGS(way) |= OSM_FLAG_HIDDEN; |
482 |
|
|
483 |
gboolean installed_new_nodes = FALSE; |
gboolean installed_new_nodes = FALSE; |
484 |
|
|
518 |
|
|
519 |
/* node may be an existing node, so remove tags to */ |
/* node may be an existing node, so remove tags to */ |
520 |
/* make space for new ones */ |
/* make space for new ones */ |
521 |
if(way->tag) { |
if(OSM_TAG(way)) { |
522 |
printf(" removing existing tags for diff tags\n"); |
printf(" removing existing tags for diff tags\n"); |
523 |
osm_tag_free(way->tag); |
osm_tag_free(OSM_TAG(way)); |
524 |
way->tag = NULL; |
OSM_TAG(way) = NULL; |
525 |
} |
} |
526 |
|
|
527 |
way->tag = xml_scan_tags(doc, node_node->children, osm); |
OSM_TAG(way) = xml_scan_tags(doc, node_node->children, osm); |
528 |
} else { |
} else { |
529 |
printf(" no nodes restored, way isn't dirty!\n"); |
printf(" no nodes restored, way isn't dirty!\n"); |
530 |
way->flags &= ~OSM_FLAG_DIRTY; |
OSM_FLAGS(way) &= ~OSM_FLAG_DIRTY; |
531 |
} |
} |
532 |
} |
} |
533 |
|
|
549 |
printf(" Restoring NEW relation\n"); |
printf(" Restoring NEW relation\n"); |
550 |
|
|
551 |
relation = g_new0(relation_t, 1); |
relation = g_new0(relation_t, 1); |
552 |
relation->visible = TRUE; |
OSM_VISIBLE(relation) = TRUE; |
553 |
relation->flags = OSM_FLAG_NEW; |
OSM_FLAGS(relation) = OSM_FLAG_NEW; |
554 |
OSM_TIME(relation) = xml_get_prop_int(node_rel, "time", 0); |
OSM_TIME(relation) = xml_get_prop_int(node_rel, "time", 0); |
555 |
if(!OSM_TIME(relation)) OSM_TIME(relation) = time(NULL); |
if(!OSM_TIME(relation)) OSM_TIME(relation) = time(NULL); |
556 |
|
|
564 |
printf(" Restoring DELETE flag\n"); |
printf(" Restoring DELETE flag\n"); |
565 |
|
|
566 |
if((relation = osm_get_relation_by_id(osm, id))) |
if((relation = osm_get_relation_by_id(osm, id))) |
567 |
relation->flags |= OSM_FLAG_DELETED; |
OSM_FLAGS(relation) |= OSM_FLAG_DELETED; |
568 |
else |
else |
569 |
printf(" WARNING: no relation with that id found\n"); |
printf(" WARNING: no relation with that id found\n"); |
570 |
break; |
break; |
573 |
printf(" Valid id (DIRTY)\n"); |
printf(" Valid id (DIRTY)\n"); |
574 |
|
|
575 |
if((relation = osm_get_relation_by_id(osm, id))) |
if((relation = osm_get_relation_by_id(osm, id))) |
576 |
relation->flags |= OSM_FLAG_DIRTY; |
OSM_FLAGS(relation) |= OSM_FLAG_DIRTY; |
577 |
else |
else |
578 |
printf(" WARNING: no relation with that id found\n"); |
printf(" WARNING: no relation with that id found\n"); |
579 |
break; |
break; |
618 |
|
|
619 |
/* node may be an existing node, so remove tags to */ |
/* node may be an existing node, so remove tags to */ |
620 |
/* make space for new ones */ |
/* make space for new ones */ |
621 |
if(relation->tag) { |
if(OSM_TAG(relation)) { |
622 |
printf(" removing existing tags for diff tags\n"); |
printf(" removing existing tags for diff tags\n"); |
623 |
osm_tag_free(relation->tag); |
osm_tag_free(OSM_TAG(relation)); |
624 |
relation->tag = NULL; |
OSM_TAG(relation) = NULL; |
625 |
} |
} |
626 |
|
|
627 |
relation->tag = xml_scan_tags(doc, node_rel->children, osm); |
OSM_TAG(relation) = xml_scan_tags(doc, node_rel->children, osm); |
628 |
} |
} |
629 |
|
|
630 |
void diff_restore(appdata_t *appdata, project_t *project, osm_t *osm) { |
void diff_restore(appdata_t *appdata, project_t *project, osm_t *osm) { |
700 |
gboolean something_is_hidden = FALSE; |
gboolean something_is_hidden = FALSE; |
701 |
way_t *way = osm->way; |
way_t *way = osm->way; |
702 |
while(!something_is_hidden && way) { |
while(!something_is_hidden && way) { |
703 |
if(way->flags & OSM_FLAG_HIDDEN) |
if(OSM_FLAGS(way) & OSM_FLAG_HIDDEN) |
704 |
something_is_hidden = TRUE; |
something_is_hidden = TRUE; |
705 |
|
|
706 |
way = way->next; |
way = way->next; |