diff options
-rw-r--r-- | profile-widget/profilewidget2.cpp | 1 | ||||
-rw-r--r-- | qt-models/diveplannermodel.cpp | 49 | ||||
-rw-r--r-- | qt-models/diveplannermodel.h | 1 |
3 files changed, 28 insertions, 23 deletions
diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index d5cae62a4..d0c58c8ab 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -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(); diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp index ec83483f3..967ef3de7 100644 --- a/qt-models/diveplannermodel.cpp +++ b/qt-models/diveplannermodel.cpp @@ -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]; diff --git a/qt-models/diveplannermodel.h b/qt-models/diveplannermodel.h index 9b79232d6..70f06b7c6 100644 --- a/qt-models/diveplannermodel.h +++ b/qt-models/diveplannermodel.h @@ -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); |