summaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/diveplannermodel.cpp37
-rw-r--r--qt-models/diveplannermodel.h3
-rw-r--r--qt-models/diveplotdatamodel.cpp4
-rw-r--r--qt-models/diveplotdatamodel.h2
4 files changed, 27 insertions, 19 deletions
diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp
index acf2d9c6f..153771c08 100644
--- a/qt-models/diveplannermodel.cpp
+++ b/qt-models/diveplannermodel.cpp
@@ -6,6 +6,7 @@
#include "core/planner.h"
#include "qt-models/models.h"
#include "core/device.h"
+#include "core/qthelper.h"
#include "core/subsurface-qt/SettingsObjectWrapper.h"
#include <QApplication>
#include <QTextDocument>
@@ -920,8 +921,9 @@ void DivePlannerPointsModel::createTemporaryPlan()
#endif
if (recalcQ() && !diveplan_empty(&diveplan)) {
struct decostop stoptable[60];
- plan(&diveplan, &displayed_dive, DECOTIMESTEP, stoptable, &cache, isPlanner(), false);
- QtConcurrent::run(this, &DivePlannerPointsModel::computeVariations);
+ struct deco_state plan_deco_state;
+ plan(&plan_deco_state, &diveplan, &displayed_dive, DECOTIMESTEP, stoptable, &cache, isPlanner(), false);
+ //QtConcurrent::run(this, &DivePlannerPointsModel::computeVariations, &ds_after_previous_dives);
emit calculatedPlanNotes();
}
// throw away the cache
@@ -952,6 +954,7 @@ struct divedatapoint * DivePlannerPointsModel::cloneDiveplan(struct diveplan *pl
divedatapoint *src, *last_segment;
divedatapoint **dp;
+ lock_planner();
src = diveplan.dp;
*plan_copy = diveplan;
dp = &plan_copy->dp;
@@ -964,8 +967,9 @@ struct divedatapoint * DivePlannerPointsModel::cloneDiveplan(struct diveplan *pl
(*dp) = NULL;
last_segment = plan_copy->dp;
- while (last_segment->next->next)
+ while (last_segment && last_segment->next && last_segment->next->next)
last_segment = last_segment->next;
+ unlock_planner();
return last_segment;
}
@@ -1003,8 +1007,9 @@ int DivePlannerPointsModel::analyzeVariations(struct decostop *min, struct decos
return (leftsum + rightsum) / 2;
}
-void DivePlannerPointsModel::computeVariations()
+void DivePlannerPointsModel::computeVariations(struct deco_state *ds)
{
+ return;
bool oldRecalc = setRecalc(false);
struct dive *dive = alloc_dive();
copy_dive(&displayed_dive, dive);
@@ -1015,47 +1020,47 @@ void DivePlannerPointsModel::computeVariations()
if(in_planner() && prefs.display_variations) {
int my_instance = ++instanceCounter;
- cache_deco_state(&save);
+ cache_deco_state(ds, &save);
cloneDiveplan(&plan_copy);
if (my_instance != instanceCounter)
return;
- plan(&plan_copy, dive, 1, original, &cache, true, false);
+ plan(ds, &plan_copy, dive, 1, original, &cache, true, false);
free_dps(&plan_copy);
- restore_deco_state(save, false);
+ restore_deco_state(save, ds, false);
last_segment = cloneDiveplan(&plan_copy);
last_segment->depth.mm += 1000;
last_segment->next->depth.mm += 1000;
if (my_instance != instanceCounter)
return;
- plan(&plan_copy, dive, 1, deeper, &cache, true, false);
+ plan(ds, &plan_copy, dive, 1, deeper, &cache, true, false);
free_dps(&plan_copy);
- restore_deco_state(save, false);
+ restore_deco_state(save, ds, false);
last_segment = cloneDiveplan(&plan_copy);
last_segment->depth.mm -= 1000;
last_segment->next->depth.mm -= 1000;
if (my_instance != instanceCounter)
return;
- plan(&plan_copy, dive, 1, shallower, &cache, true, false);
+ plan(ds, &plan_copy, dive, 1, shallower, &cache, true, false);
free_dps(&plan_copy);
- restore_deco_state(save, false);
+ restore_deco_state(save, ds, false);
last_segment = cloneDiveplan(&plan_copy);
last_segment->next->time += 60;
if (my_instance != instanceCounter)
return;
- plan(&plan_copy, dive, 1, longer, &cache, true, false);
+ plan(ds, &plan_copy, dive, 1, longer, &cache, true, false);
free_dps(&plan_copy);
- restore_deco_state(save, false);
+ restore_deco_state(save, ds, false);
last_segment = cloneDiveplan(&plan_copy);
last_segment->next->time -= 60;
if (my_instance != instanceCounter)
return;
- plan(&plan_copy, dive, 1, shorter, &cache, true, false);
+ plan(ds, &plan_copy, dive, 1, shorter, &cache, true, false);
free_dps(&plan_copy);
- restore_deco_state(save, false);
+ restore_deco_state(save, ds, false);
#ifdef SHOWSTOPVARIATIONS
printf("\n\n");
#endif
@@ -1083,7 +1088,7 @@ void DivePlannerPointsModel::createPlan(bool replanCopy)
//TODO: C-based function here?
struct decostop stoptable[60];
- plan(&diveplan, &displayed_dive, DECOTIMESTEP, stoptable, &cache, isPlanner(), true);
+ plan(&ds_after_previous_dives, &diveplan, &displayed_dive, DECOTIMESTEP, stoptable, &cache, isPlanner(), true);
free(cache);
if (!current_dive || displayed_dive.id != current_dive->id) {
// we were planning a new dive, not re-planning an existing on
diff --git a/qt-models/diveplannermodel.h b/qt-models/diveplannermodel.h
index a4fe35a65..0b714e608 100644
--- a/qt-models/diveplannermodel.h
+++ b/qt-models/diveplannermodel.h
@@ -115,7 +115,7 @@ private:
void createPlan(bool replanCopy);
struct diveplan diveplan;
struct divedatapoint *cloneDiveplan(struct diveplan *plan_copy);
- void computeVariations();
+ void computeVariations(struct deco_state *ds);
int analyzeVariations(struct decostop *min, struct decostop *mid, struct decostop *max, const char *unit);
Mode mode;
bool recalc;
@@ -124,6 +124,7 @@ private:
int tempGFHigh;
int tempGFLow;
int instanceCounter = 0;
+ struct deco_state ds_after_previous_dives;
};
#endif
diff --git a/qt-models/diveplotdatamodel.cpp b/qt-models/diveplotdatamodel.cpp
index 8cabd833e..ac6cf7cd8 100644
--- a/qt-models/diveplotdatamodel.cpp
+++ b/qt-models/diveplotdatamodel.cpp
@@ -231,8 +231,8 @@ void DivePlotDataModel::emitDataChanged()
void DivePlotDataModel::calculateDecompression()
{
struct divecomputer *dc = select_dc(&displayed_dive);
- init_decompression(&displayed_dive);
- calculate_deco_information(&displayed_dive, dc, &pInfo, false);
+ init_decompression(&plot_deco_state, &displayed_dive);
+ calculate_deco_information(&plot_deco_state, &displayed_dive, dc, &pInfo, false);
dataChanged(index(0, CEILING), index(pInfo.nr - 1, TISSUE_16));
}
#endif
diff --git a/qt-models/diveplotdatamodel.h b/qt-models/diveplotdatamodel.h
index b28dce685..4e0c63c2e 100644
--- a/qt-models/diveplotdatamodel.h
+++ b/qt-models/diveplotdatamodel.h
@@ -5,6 +5,7 @@
#include <QAbstractTableModel>
#include "core/display.h"
+#include "core/dive.h"
struct dive;
struct plot_data;
@@ -91,6 +92,7 @@ private:
struct plot_info pInfo;
int diveId;
unsigned int dcNr;
+ struct deco_state plot_deco_state;
};
#endif // DIVEPLOTDATAMODEL_H