mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
69b4a404b9
commit
9d8eb10421
3 changed files with 28 additions and 10 deletions
|
@ -520,7 +520,7 @@ static unsigned int *sort_stops(int *dstops, int dnr, struct gaschanges *gstops,
|
||||||
|
|
||||||
static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer, int error)
|
static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer, int error)
|
||||||
{
|
{
|
||||||
char buffer[20000], temp[1000];
|
char buffer[2000000], temp[100000];
|
||||||
int len, lastdepth = 0, lasttime = 0, lastsetpoint = -1, newdepth = 0, lastprintdepth = 0;
|
int len, lastdepth = 0, lasttime = 0, lastsetpoint = -1, newdepth = 0, lastprintdepth = 0;
|
||||||
struct divedatapoint *dp = diveplan->dp;
|
struct divedatapoint *dp = diveplan->dp;
|
||||||
bool gaschange = !plan_verbatim, postponed = plan_verbatim;
|
bool gaschange = !plan_verbatim, postponed = plan_verbatim;
|
||||||
|
|
|
@ -92,10 +92,13 @@ void DivePlannerPointsModel::setupStartTime()
|
||||||
|
|
||||||
void DivePlannerPointsModel::loadFromDive(dive *d)
|
void DivePlannerPointsModel::loadFromDive(dive *d)
|
||||||
{
|
{
|
||||||
|
int depthsum = 0;
|
||||||
|
int samplecount = 0;
|
||||||
bool oldRec = recalc;
|
bool oldRec = recalc;
|
||||||
recalc = false;
|
recalc = false;
|
||||||
CylindersModel::instance()->updateDive();
|
CylindersModel::instance()->updateDive();
|
||||||
duration_t lasttime = {};
|
duration_t lasttime = {};
|
||||||
|
duration_t newtime = {};
|
||||||
struct gasmix gas;
|
struct gasmix gas;
|
||||||
free_dps(&diveplan);
|
free_dps(&diveplan);
|
||||||
diveplan.when = d->when;
|
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
|
// if it is we only add the manually entered samples as waypoints to the diveplan
|
||||||
// otherwise we have to add all of them
|
// otherwise we have to add all of them
|
||||||
bool hasMarkedSamples = d->dc.sample[0].manually_entered;
|
bool hasMarkedSamples = d->dc.sample[0].manually_entered;
|
||||||
for (int i = 0; i < d->dc.samples - 1; i++) {
|
// if this dive has more than 100 samples (so it is probably a logged dive),
|
||||||
const sample &s = d->dc.sample[i];
|
// average samples so we end up with a total of 100 samples.
|
||||||
if (s.time.seconds == 0 || (hasMarkedSamples && !s.manually_entered))
|
int plansamples = d->dc.samples <= 100 ? d->dc.samples : 100;
|
||||||
continue;
|
int j = 0;
|
||||||
get_gas_at_time(d, &d->dc, lasttime, &gas);
|
for (int i = 0; i < plansamples - 1; i++) {
|
||||||
plannerModel->addStop(s.depth.mm, s.time.seconds, &gas, 0, true);
|
while (j * plansamples <= i * d->dc.samples) {
|
||||||
lasttime = s.time;
|
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;
|
recalc = oldRec;
|
||||||
emitDataChanged();
|
emitDataChanged();
|
||||||
|
|
|
@ -596,8 +596,9 @@ void MainWindow::on_actionReplanDive_triggered()
|
||||||
if (!plannerStateClean() || !current_dive || !current_dive->dc.model)
|
if (!plannerStateClean() || !current_dive || !current_dive->dc.model)
|
||||||
return;
|
return;
|
||||||
else if (strcmp(current_dive->dc.model, "planned dive")) {
|
else if (strcmp(current_dive->dc.model, "planned dive")) {
|
||||||
QMessageBox::warning(this, tr("Warning"), tr("trying to replan a dive that's not a planned dive."));
|
if (QMessageBox::warning(this, tr("Warning"), tr("trying to replan a dive that's not a planned dive."),
|
||||||
return;
|
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
// put us in PLAN mode
|
// put us in PLAN mode
|
||||||
DivePlannerPointsModel::instance()->clear();
|
DivePlannerPointsModel::instance()->clear();
|
||||||
|
|
Loading…
Add table
Reference in a new issue