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>
This commit is contained in:
Dirk Hohndel 2014-06-01 12:38:32 -07:00
parent 1a04013453
commit c539c8f861
6 changed files with 39 additions and 38 deletions

View file

@ -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;