diff options
author | willemferguson <willemferguson@zoology.up.ac.za> | 2019-04-30 12:42:33 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-05-15 07:37:14 -0700 |
commit | 1bdf00b2b472078a0b24f1c269782d822cb96e02 (patch) | |
tree | 13a5e784118d9abb0a1bc1dfa9cbe4a9f457de80 /core/dive.c | |
parent | ca6aa3813956b5e8be68b86ed36a5786b3ee746f (diff) | |
download | subsurface-1bdf00b2b472078a0b24f1c269782d822cb96e02.tar.gz |
Convert the atmospheric pressure in the Information Tab to an editable field
The Information tab shows the atmospheric pressure. Make this value editable
and also ensure that changes to it are undo-able.
Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Diffstat (limited to 'core/dive.c')
-rw-r--r-- | core/dive.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/core/dive.c b/core/dive.c index 0f67ebe61..d20350a80 100644 --- a/core/dive.c +++ b/core/dive.c @@ -1317,9 +1317,10 @@ static struct event *find_previous_event(struct divecomputer *dc, struct event * return previous; } -static void fixup_surface_pressure(struct dive *dive) +pressure_t calculate_surface_pressure(const struct dive *dive) { - struct divecomputer *dc; + const struct divecomputer *dc; + pressure_t res; int sum = 0, nr = 0; for_each_dc (dive, dc) { @@ -1328,8 +1329,24 @@ static void fixup_surface_pressure(struct dive *dive) nr++; } } - if (nr) - dive->surface_pressure.mbar = (sum + nr / 2) / nr; + res.mbar = nr ? (sum + nr / 2) / nr : 0; + return res; +} + +static void fixup_surface_pressure(struct dive *dive) +{ + dive->surface_pressure = calculate_surface_pressure(dive); +} + +/* if the surface pressure in the dive data is redundant to the calculated + * value (i.e., it was added by running fixup on the dive) return 0, + * otherwise return the air temperature given in the dive */ +pressure_t un_fixup_surface_pressure(const struct dive *d) +{ + pressure_t res = d->surface_pressure; + if (res.mbar && res.mbar == calculate_surface_pressure(d).mbar) + res.mbar = 0; + return res; } static void fixup_water_salinity(struct dive *dive) @@ -1823,7 +1840,8 @@ struct dive *fixup_dive(struct dive *dive) fixup_dive_dc(dive, dc); fixup_water_salinity(dive); - fixup_surface_pressure(dive); + if (!dive->surface_pressure.mbar) + fixup_surface_pressure(dive); fixup_meandepth(dive); fixup_duration(dive); fixup_watertemp(dive); |