undo: refine pasting of cylinders

When pasting cylinders, the destination dive got a verbatim copy
of the cylinders of the source dive. This is not what users want:
for example, the start and stop pressures from the dive computer
as well as the gas mix may be overwritten.

There seems to be no perfect solution, since some times users may
want to paste the gas-mix.

Therefore, let's choose a heuristic approach for now (in the future
we might implement a UI-flag):

When copying over existing cylinders, only copy type and maximum
pressure.

When adding new cylinders (i.e. from-dive has more cylinders than
to-dive), copy everything, but reset start- and top-pressure to 0,
which represents unkown.

Moroever, in the latter case, set "manually added" to true, since
obviously this wasn't added by a dive computer.

Fixes #2676

Reported-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-04-08 21:36:43 +02:00 committed by Dirk Hohndel
parent 3a74f65063
commit 4489389a01

View file

@ -660,8 +660,37 @@ PasteState::PasteState(dive *dIn, const dive *data, dive_components what) : d(dI
divesite = data->dive_site;
if (what.tags)
tags = taglist_copy(data->tag_list);
if (what.cylinders)
if (what.cylinders) {
copy_cylinders(&data->cylinders, &cylinders);
// Paste cylinders is "special":
// 1) For cylinders that exist in the destination dive we keep the gas-mix and pressures.
// 2) For cylinders that do not yet exist in the destination dive, we set the pressures to 0, i.e. unset.
// Moreover, for these we set the manually_added flag, because they weren't downloaded from a DC.
for (int i = 0; i < d->cylinders.nr && i < cylinders.nr; ++i) {
const cylinder_t &src = d->cylinders.cylinders[i];
cylinder_t &dst = cylinders.cylinders[i];
dst.gasmix = src.gasmix;
dst.start = src.start;
dst.end = src.end;
dst.sample_start = src.sample_start;
dst.sample_end = src.sample_end;
dst.depth = src.depth;
dst.manually_added = src.manually_added;
dst.gas_used = src.gas_used;
dst.deco_gas_used = src.deco_gas_used;
dst.cylinder_use = src.cylinder_use;
dst.bestmix_o2 = src.bestmix_o2;
dst.bestmix_he = src.bestmix_he;
}
for (int i = d->cylinders.nr; i < cylinders.nr; ++i) {
cylinder_t &cyl = cylinders.cylinders[i];
cyl.start.mbar = 0;
cyl.end.mbar = 0;
cyl.sample_start.mbar = 0;
cyl.sample_end.mbar = 0;
cyl.manually_added = true;
}
}
if (what.weights)
copy_weights(&data->weightsystems, &weightsystems);
}