When merging planned dives keep all cylinders

When merging a real dive with a planned dive (for comparison),
we should not try to be clever in merging similar cylinders,
rather keep the union of both cylinder sets as the two versions
of the dive might differ in exctly which gas and how much of it
was used.

Increase MAX_CYLINDERS to 20 to make room for this.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
This commit is contained in:
Robert C. Helling 2017-02-02 15:31:52 +01:00 committed by Dirk Hohndel
parent 99595542ec
commit a031dbbbd8
2 changed files with 40 additions and 15 deletions

View file

@ -2028,23 +2028,43 @@ static void merge_cylinders(struct dive *res, struct dive *a, struct dive *b)
memcpy(res->cylinder, a->cylinder, sizeof(res->cylinder));
memset(a->cylinder, 0, sizeof(a->cylinder));
for (i = 0; i < MAX_CYLINDERS; i++) {
int j;
cylinder_t *cyl = b->cylinder + i;
if (strcmp(b->dc.model, "planned dive")) {
// We merge two actual dive
for (i = 0; i < MAX_CYLINDERS; i++) {
int j;
cylinder_t *cyl = b->cylinder + i;
j = find_cylinder_match(cyl, res->cylinder, used);
mapping[i] = j;
if (j < 0)
continue;
used |= 1 << j;
merge_cylinder_info(cyl, res->cylinder + j);
j = find_cylinder_match(cyl, res->cylinder, used);
mapping[i] = j;
if (j < 0)
continue;
used |= 1 << j;
merge_cylinder_info(cyl, res->cylinder + j);
/* If that renumbered the cylinders, fix it up! */
if (i != j)
renumber = 1;
}
if (renumber)
/* If that renumbered the cylinders, fix it up! */
if (i != j)
renumber = 1;
}
if (renumber)
cylinder_renumber(b, mapping);
} else {
int j=0;
for (i = 0; i < MAX_CYLINDERS && j < MAX_CYLINDERS; i++) {
if (is_cylinder_used(res, i))
continue;
while (!is_cylinder_used(b, j) && j < MAX_CYLINDERS - 1) {
mapping[j] = 0;
++j;
}
memcpy(&res->cylinder[i], &b->cylinder[j], sizeof (b->cylinder[j]));
mapping[j] = i;
++j;
}
while (j < MAX_CYLINDERS)
mapping[j++] = 0;
cylinder_renumber(b, mapping);
}
}
static void merge_equipment(struct dive *res, struct dive *a, struct dive *b)
@ -3000,6 +3020,11 @@ struct dive *merge_dives(struct dive *a, struct dive *b, int offset, bool prefer
dl = b;
}
if (!strcmp(a->dc.model, "planneed dive")) {
struct dive *tmp = a;
a = b;
b = tmp;
}
res->when = dl ? dl->when : a->when;
res->selected = a->selected || b->selected;
merge_trip(res, a, b);

View file

@ -290,7 +290,7 @@ struct divecomputer {
struct divecomputer *next;
};
#define MAX_CYLINDERS (8)
#define MAX_CYLINDERS (20)
#define MAX_WEIGHTSYSTEMS (6)
#define W_IDX_PRIMARY 0
#define W_IDX_SECONDARY 1