summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-04-08 21:36:43 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-04-10 09:43:32 -0700
commit4489389a018d7099e6fd0019e4717dcf95bc08b5 (patch)
tree1e1316048f90d55bab967f57b74397c512e86278 /commands
parent3a74f650637e5e8e1ae71933cbfb6373147c0456 (diff)
downloadsubsurface-4489389a018d7099e6fd0019e4717dcf95bc08b5.tar.gz
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>
Diffstat (limited to 'commands')
-rw-r--r--commands/command_edit.cpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/commands/command_edit.cpp b/commands/command_edit.cpp
index 46c206c98..a5eb46bc1 100644
--- a/commands/command_edit.cpp
+++ b/commands/command_edit.cpp
@@ -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);
}