diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-06-01 12:38:32 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-06-01 12:43:40 -0700 |
commit | c539c8f861928c637f6b3e790b05e89914e2be8f (patch) | |
tree | 9728f8d08279bbe98fa8afdec73de9de1d55b66a /equipment.c | |
parent | 1a040134538b7733f3088ea34f101cfedecc2c64 (diff) | |
download | subsurface-c539c8f861928c637f6b3e790b05e89914e2be8f.tar.gz |
Remove the .used member of the cylinder structure
Instead calculate this information on the fly, taking into account all
dive computers on the dive in questions.
There is one wrinkle to this - previously we abused the '.used' member to
make sure that a manually added cylinder didn't disappear the moment it
was added (think of the workflow: you add a cylinder, then you add a gas
change to that cylinder -> right after you add it it is unused and would
not be shown).
I am thinking that we might have to add the "manually_added" property to
the properties that we store in XML / git.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'equipment.c')
-rw-r--r-- | equipment.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/equipment.c b/equipment.c index b69155629..a67df68a4 100644 --- a/equipment.c +++ b/equipment.c @@ -72,6 +72,31 @@ bool cylinder_none(void *_data) return cylinder_nodata(cyl) && cylinder_nosamples(cyl); } +/* look at all dive computers and figure out if this cylinder is used anywhere + * d has to be a valid dive (test before calling) + * cyl does not have to be a cylinder that is part of this dive structure */ +bool cylinder_is_used(struct dive *d, cylinder_t *cyl) +{ + struct divecomputer *dc = &d->dc; + bool same_as_first = gasmix_distance(&cyl->gasmix, &d->cylinder[0].gasmix) < 200; + while (dc) { + struct event *ev = get_next_event(dc->events, "gaschange"); + if (same_as_first && (!ev || ev->time.seconds > 30)) { + // unless there is a gas change in the first 30 seconds we can + // always mark the first cylinder as used + return true; + } + while (ev) { + if (gasmix_distance(&cyl->gasmix, get_gasmix_from_event(ev)) < 200) + return true; + + ev = get_next_event(ev->next, "gaschange"); + } + dc = dc->next; + } + return false; +} + bool weightsystem_none(void *_data) { weightsystem_t *ws = _data; |