From c539c8f861928c637f6b3e790b05e89914e2be8f Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 1 Jun 2014 12:38:32 -0700 Subject: 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 --- equipment.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'equipment.c') 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; -- cgit v1.2.3-70-g09d2