mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
planner: split createTemporaryPlan() function.
The DivePlannerPointsModel::createTemporaryPlan() function had two distinct and independent parts: 1) create the data points. 2) create the dive sample and calculate variations. The second part was only exectuted if the recalc flag was set. Out of the two callers, one was explicitly disabling and setting the recalc flag to avoid the second part. The much more logical thing is to simply split the function in two and only call the first part. To avoid any functional change, the second caller (the profile) still tests for the recalc flag. However, if it shouldn't replot a new plan, why calculate it in the first place!? And why does the display function change the plan at all? This appears all very ill-thought out and should be changed in due course. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
7b9c8e344a
commit
4b801f1f50
3 changed files with 27 additions and 22 deletions
|
@ -543,6 +543,7 @@ void ProfileWidget2::plotDive(const struct dive *dIn, int dcIn, bool force, bool
|
|||
#ifndef SUBSURFACE_MOBILE
|
||||
} else {
|
||||
plannerModel->createTemporaryPlan();
|
||||
plannerModel->recalcTemporaryPlan();
|
||||
struct diveplan &diveplan = plannerModel->getDiveplan();
|
||||
if (!diveplan.dp) {
|
||||
plannerModel->deleteTemporaryPlan();
|
||||
|
|
|
@ -1016,8 +1016,6 @@ void DivePlannerPointsModel::createTemporaryPlan()
|
|||
plan_add_segment(&diveplan, deltaT, p.depth.mm, p.cylinderid, p.setpoint, true, p.divemode);
|
||||
}
|
||||
|
||||
// what does the cache do???
|
||||
struct deco_state *cache = NULL;
|
||||
struct divedatapoint *dp = NULL;
|
||||
for (int i = 0; i < d->cylinders.nr; i++) {
|
||||
cylinder_t *cyl = get_cylinder(d, i);
|
||||
|
@ -1035,28 +1033,35 @@ void DivePlannerPointsModel::createTemporaryPlan()
|
|||
#if DEBUG_PLAN
|
||||
dump_plan(&diveplan);
|
||||
#endif
|
||||
if (recalcQ() && !diveplan_empty(&diveplan)) {
|
||||
struct decostop stoptable[60];
|
||||
struct deco_state plan_deco_state;
|
||||
struct diveplan *plan_copy;
|
||||
}
|
||||
|
||||
memset(&plan_deco_state, 0, sizeof(struct deco_state));
|
||||
plan(&plan_deco_state, &diveplan, d, DECOTIMESTEP, stoptable, &cache, isPlanner(), false);
|
||||
plan_copy = (struct diveplan *)malloc(sizeof(struct diveplan));
|
||||
lock_planner();
|
||||
cloneDiveplan(&diveplan, plan_copy);
|
||||
unlock_planner();
|
||||
void DivePlannerPointsModel::recalcTemporaryPlan()
|
||||
{
|
||||
if (diveplan_empty(&diveplan))
|
||||
return;
|
||||
|
||||
struct deco_state *cache = NULL;
|
||||
struct decostop stoptable[60];
|
||||
struct deco_state plan_deco_state;
|
||||
struct diveplan *plan_copy;
|
||||
|
||||
memset(&plan_deco_state, 0, sizeof(struct deco_state));
|
||||
plan(&plan_deco_state, &diveplan, d, DECOTIMESTEP, stoptable, &cache, isPlanner(), false);
|
||||
plan_copy = (struct diveplan *)malloc(sizeof(struct diveplan));
|
||||
lock_planner();
|
||||
cloneDiveplan(&diveplan, plan_copy);
|
||||
unlock_planner();
|
||||
#ifdef VARIATIONS_IN_BACKGROUND
|
||||
// Since we're calling computeVariations asynchronously and plan_deco_state is allocated
|
||||
// on the stack, it must be copied and freed by the worker-thread.
|
||||
struct deco_state *plan_deco_state_copy = new deco_state(plan_deco_state);
|
||||
QtConcurrent::run(this, &DivePlannerPointsModel::computeVariationsFreeDeco, plan_copy, plan_deco_state_copy);
|
||||
// Since we're calling computeVariations asynchronously and plan_deco_state is allocated
|
||||
// on the stack, it must be copied and freed by the worker-thread.
|
||||
struct deco_state *plan_deco_state_copy = new deco_state(plan_deco_state);
|
||||
QtConcurrent::run(this, &DivePlannerPointsModel::computeVariationsFreeDeco, plan_copy, plan_deco_state_copy);
|
||||
#else
|
||||
computeVariations(plan_copy, &plan_deco_state);
|
||||
computeVariations(plan_copy, &plan_deco_state);
|
||||
#endif
|
||||
final_deco_state = plan_deco_state;
|
||||
emit calculatedPlanNotes(QString(d->notes));
|
||||
}
|
||||
final_deco_state = plan_deco_state;
|
||||
emit calculatedPlanNotes(QString(d->notes));
|
||||
|
||||
// throw away the cache
|
||||
free(cache);
|
||||
#if DEBUG_PLAN
|
||||
|
@ -1246,10 +1251,8 @@ void DivePlannerPointsModel::createPlan(bool replanCopy)
|
|||
{
|
||||
// Ok, so, here the diveplan creates a dive
|
||||
struct deco_state *cache = NULL;
|
||||
bool oldrec = std::exchange(recalc, false);
|
||||
removeDeco();
|
||||
createTemporaryPlan();
|
||||
recalc = oldrec;
|
||||
|
||||
//TODO: C-based function here?
|
||||
struct decostop stoptable[60];
|
||||
|
|
|
@ -92,6 +92,7 @@ slots:
|
|||
void remove(const QModelIndex &index);
|
||||
void cancelPlan();
|
||||
void createTemporaryPlan();
|
||||
void recalcTemporaryPlan(); // Writes the plan into the dive.
|
||||
void deleteTemporaryPlan();
|
||||
void emitDataChanged();
|
||||
void setRebreatherMode(int mode);
|
||||
|
|
Loading…
Reference in a new issue