mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Geo taxonomy: save and load the taxonomy data with XML
If taxonomy data are available we are switching a dive site entry from single item with attributes to an item that has children. This is backwards compatible and older versions will simply ignore the children. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
6e81677d89
commit
f7b7d4c2df
2 changed files with 33 additions and 6 deletions
24
parse-xml.c
24
parse-xml.c
|
@ -1431,6 +1431,8 @@ static void try_to_fill_dive_site(struct dive_site **ds_p, const char *name, cha
|
||||||
start_match("divesite", name, buf);
|
start_match("divesite", name, buf);
|
||||||
|
|
||||||
struct dive_site *ds = *ds_p;
|
struct dive_site *ds = *ds_p;
|
||||||
|
if (ds->taxonomy.category == NULL)
|
||||||
|
ds->taxonomy.category = alloc_taxonomy();
|
||||||
|
|
||||||
if (MATCH("uuid", hex_value, &ds->uuid))
|
if (MATCH("uuid", hex_value, &ds->uuid))
|
||||||
return;
|
return;
|
||||||
|
@ -1442,6 +1444,15 @@ static void try_to_fill_dive_site(struct dive_site **ds_p, const char *name, cha
|
||||||
return;
|
return;
|
||||||
if (MATCH("gps", gps_location, ds))
|
if (MATCH("gps", gps_location, ds))
|
||||||
return;
|
return;
|
||||||
|
if (MATCH("cat.geo", get_index, (int *)&ds->taxonomy.category[ds->taxonomy.nr].category))
|
||||||
|
return;
|
||||||
|
if (MATCH("origin.geo", get_index, (int *)&ds->taxonomy.category[ds->taxonomy.nr].origin))
|
||||||
|
return;
|
||||||
|
if (MATCH("value.geo", utf8_string, &ds->taxonomy.category[ds->taxonomy.nr].value)) {
|
||||||
|
if (ds->taxonomy.nr < NR_CATEGORIES)
|
||||||
|
ds->taxonomy.nr++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
nonmatch("divesite", name, buf);
|
nonmatch("divesite", name, buf);
|
||||||
}
|
}
|
||||||
|
@ -1517,14 +1528,17 @@ static void dive_site_end(void)
|
||||||
if (!cur_dive_site)
|
if (!cur_dive_site)
|
||||||
return;
|
return;
|
||||||
if (cur_dive_site->uuid) {
|
if (cur_dive_site->uuid) {
|
||||||
uint32_t tmp = create_dive_site_with_gps(cur_dive_site->name, cur_dive_site->latitude, cur_dive_site->longitude);
|
struct dive_site *ds = alloc_dive_site();
|
||||||
struct dive_site *ds = get_dive_site_by_uuid(tmp);
|
if (cur_dive_site->taxonomy.nr == 0) {
|
||||||
ds->uuid = cur_dive_site->uuid;
|
free(cur_dive_site->taxonomy.category);
|
||||||
ds->notes = cur_dive_site->notes;
|
cur_dive_site->taxonomy.category = NULL;
|
||||||
ds->description = cur_dive_site->description;
|
}
|
||||||
|
copy_dive_site(cur_dive_site, ds);
|
||||||
|
|
||||||
if (verbose > 3)
|
if (verbose > 3)
|
||||||
printf("completed dive site uuid %x8 name {%s}\n", ds->uuid, ds->name);
|
printf("completed dive site uuid %x8 name {%s}\n", ds->uuid, ds->name);
|
||||||
}
|
}
|
||||||
|
free_taxonomy(cur_dive_site->taxonomy.category);
|
||||||
free(cur_dive_site);
|
free(cur_dive_site);
|
||||||
cur_dive_site = NULL;
|
cur_dive_site = NULL;
|
||||||
}
|
}
|
||||||
|
|
15
save-xml.c
15
save-xml.c
|
@ -539,7 +539,20 @@ void save_dives_buffer(struct membuffer *b, const bool select_only)
|
||||||
}
|
}
|
||||||
show_utf8(b, ds->description, " description='", "'", 1);
|
show_utf8(b, ds->description, " description='", "'", 1);
|
||||||
show_utf8(b, ds->notes, " notes='", "'", 1);
|
show_utf8(b, ds->notes, " notes='", "'", 1);
|
||||||
put_format(b, "/>\n");
|
if (prefs.geocoding.enable_geocoding && ds->taxonomy.nr) {
|
||||||
|
put_format(b, ">\n");
|
||||||
|
for (int j = 0; j < ds->taxonomy.nr; j++) {
|
||||||
|
struct taxonomy *t = &ds->taxonomy.category[j];
|
||||||
|
if (t->category != NONE) {
|
||||||
|
put_format(b, "<geo cat='%d'", t->category);
|
||||||
|
put_format(b, " origin='%d'", t->origin);
|
||||||
|
show_utf8(b, t->value, " value='", "'/>\n", 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
put_format(b, "</site>\n");
|
||||||
|
} else {
|
||||||
|
put_format(b, "/>\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
put_format(b, "</divesites>\n<dives>\n");
|
put_format(b, "</divesites>\n<dives>\n");
|
||||||
for (trip = dive_trip_list; trip != NULL; trip = trip->next)
|
for (trip = dive_trip_list; trip != NULL; trip = trip->next)
|
||||||
|
|
Loading…
Reference in a new issue