mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-27 20:58:47 +00:00
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:
parent
beb352d47c
commit
69d1be999a
3 changed files with 16 additions and 2 deletions
|
@ -74,6 +74,17 @@ diveplan::~diveplan()
|
|||
{
|
||||
}
|
||||
|
||||
diveplan diveplan::copy_planned_segments() const
|
||||
{
|
||||
diveplan res = *this;
|
||||
|
||||
// Remove non manually added entries
|
||||
auto it = std::find_if(res.dp.begin(), res.dp.end(),
|
||||
[] (const divedatapoint &dp) { return dp.time && !dp.entered; });
|
||||
res.dp.erase(it, res.dp.end());
|
||||
return res;
|
||||
}
|
||||
|
||||
bool diveplan::is_empty() const
|
||||
{
|
||||
return std::none_of(dp.begin(), dp.end(), [](const divedatapoint &dp) { return dp.time != 0; });
|
||||
|
|
|
@ -53,6 +53,7 @@ struct diveplan {
|
|||
bool is_empty() const;
|
||||
void add_plan_to_notes(struct dive &dive, bool show_disclaimer, planner_error_t error);
|
||||
int duration() const;
|
||||
diveplan copy_planned_segments() const; // copy diveplan, but ignore automatically added stops
|
||||
};
|
||||
|
||||
struct deco_state_cache;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue