diff options
author | Robert C. Helling <helling@atdotde.de> | 2015-05-07 22:59:12 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-05-08 10:02:45 -0700 |
commit | 9d8eb1042125e4e33b593f37aec2d5bab13f1ac6 (patch) | |
tree | 3064a137d3181f889d69e31d67679d3c8469ce5f /qt-ui/diveplanner.cpp | |
parent | 69b4a404b9961bc9b3b2f3cbbf7e0bc634f3a5dd (diff) | |
download | subsurface-9d8eb1042125e4e33b593f37aec2d5bab13f1ac6.tar.gz |
Only warn when trying to replan a logged dive
If there are more than 100 samples, average some of them so we end up with no more than 100.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/diveplanner.cpp')
-rw-r--r-- | qt-ui/diveplanner.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index a5b6e1e40..42570dac6 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -92,10 +92,13 @@ void DivePlannerPointsModel::setupStartTime() void DivePlannerPointsModel::loadFromDive(dive *d) { + int depthsum = 0; + int samplecount = 0; bool oldRec = recalc; recalc = false; CylindersModel::instance()->updateDive(); duration_t lasttime = {}; + duration_t newtime = {}; struct gasmix gas; free_dps(&diveplan); diveplan.when = d->when; @@ -104,13 +107,27 @@ void DivePlannerPointsModel::loadFromDive(dive *d) // if it is we only add the manually entered samples as waypoints to the diveplan // otherwise we have to add all of them bool hasMarkedSamples = d->dc.sample[0].manually_entered; - for (int i = 0; i < d->dc.samples - 1; i++) { - const sample &s = d->dc.sample[i]; - if (s.time.seconds == 0 || (hasMarkedSamples && !s.manually_entered)) - continue; - get_gas_at_time(d, &d->dc, lasttime, &gas); - plannerModel->addStop(s.depth.mm, s.time.seconds, &gas, 0, true); - lasttime = s.time; + // if this dive has more than 100 samples (so it is probably a logged dive), + // average samples so we end up with a total of 100 samples. + int plansamples = d->dc.samples <= 100 ? d->dc.samples : 100; + int j = 0; + for (int i = 0; i < plansamples - 1; i++) { + while (j * plansamples <= i * d->dc.samples) { + const sample &s = d->dc.sample[j]; + if (s.time.seconds != 0 && (!hasMarkedSamples || s.manually_entered)) { + depthsum += s.depth.mm; + ++samplecount; + newtime = s.time; + } + j++; + } + if (samplecount) { + get_gas_at_time(d, &d->dc, lasttime, &gas); + plannerModel->addStop(depthsum / samplecount, newtime.seconds, &gas, 0, true); + lasttime = newtime; + depthsum = 0; + samplecount = 0; + } } recalc = oldRec; emitDataChanged(); |