planner: fix calculations of variations

In 8704a8b6f9 the code in
cloneDiveplan() was replaced by a simple assignement statement.

Alas, the original code was more complex: it copied only up
to a certain point (it stopped at automatically generated
steps).

The new behavior made the calculations of variations fail.

Therefore, readd a function that copies a dive plan, but
"forgets" the automatically added stops.

Fixes #4368

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-11-14 23:24:24 +01:00
parent beb352d47c
commit 69d1be999a
3 changed files with 16 additions and 2 deletions

View file

@ -1127,7 +1127,7 @@ void DivePlannerPointsModel::updateDiveProfile()
if (isPlanner() && shouldComputeVariations()) {
auto plan_copy = std::make_unique<struct diveplan>();
lock_planner();
*plan_copy = diveplan;
*plan_copy = diveplan.copy_planned_segments();
unlock_planner();
#ifdef VARIATIONS_IN_BACKGROUND
// Since we're calling computeVariations asynchronously and plan_deco_state is allocated
@ -1252,6 +1252,7 @@ void DivePlannerPointsModel::computeVariations(std::unique_ptr<struct diveplan>
auto deeper = plan(&ds, plan_copy, dive.get(), dcNr, 1, cache, true, false);
save.restore(&ds, false);
plan_copy = *original_plan;
second_to_last(plan_copy.dp).depth.mm -= delta_depth.mm;
plan_copy.dp.back().depth.mm -= delta_depth.mm;
if (my_instance != instanceCounter)
@ -1266,6 +1267,7 @@ void DivePlannerPointsModel::computeVariations(std::unique_ptr<struct diveplan>
auto longer = plan(&ds, plan_copy, dive.get(), dcNr, 1, cache, true, false);
save.restore(&ds, false);
plan_copy = *original_plan;
plan_copy.dp.back().time -= delta_time.seconds;
if (my_instance != instanceCounter)
return;
@ -1313,7 +1315,7 @@ void DivePlannerPointsModel::createPlan(bool saveAsNew)
if (shouldComputeVariations()) {
auto plan_copy = std::make_unique<struct diveplan>();
lock_planner();
*plan_copy = diveplan;
*plan_copy = diveplan.copy_planned_segments();
unlock_planner();
computeVariations(std::move(plan_copy), &ds_after_previous_dives);
}