Hi,
From ec79ffdefd466d1e4a07fddfab04cdd8d3334892 Mon Sep 17 00:00:00 2001
From: "Robert C. Helling" <hell...@atdotde.de>
Date: Thu, 7 May 2015 22:59:12 +0200
Subject: [PATCH 1/2] 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 <hell...@atdotde.de>
---
planner.c | 2 +-
qt-ui/diveplanner.cpp | 31 ++++++++++++++++++++++++-------
qt-ui/mainwindow.cpp | 5 +++--
3 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/planner.c b/planner.c
index 9de6a21..af1db50 100644
--- a/planner.c
+++ b/planner.c
@@ -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)
{
- char buffer[20000], temp[1000];
+ char buffer[2000000], temp[100000];
int len, lastdepth = 0, lasttime = 0, lastsetpoint = -1, newdepth = 0,
lastprintdepth = 0;
struct divedatapoint *dp = diveplan->dp;
bool gaschange = !plan_verbatim, postponed = plan_verbatim;
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index a5b6e1e..42570da 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();
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 23f9551..970c0f7 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -596,8 +596,9 @@ void MainWindow::on_actionReplanDive_triggered()
if (!plannerStateClean() || !current_dive || !current_dive->dc.model)
return;
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."));
- return;
+ if (QMessageBox::warning(this, tr("Warning"), tr("trying to
replan a dive that's not a planned dive."),
+ QMessageBox::Ok | QMessageBox::Cancel) ==
QMessageBox::Cancel)
+ return;
}
// put us in PLAN mode
DivePlannerPointsModel::instance()->clear();
--
1.9.5 (Apple Git-50.3)
From a29a39f4bf83be397f72cb870d1baa27da52a258 Mon Sep 17 00:00:00 2001
From: "Robert C. Helling" <hell...@atdotde.de>
Date: Thu, 7 May 2015 23:40:34 +0200
Subject: [PATCH 2/2] Only print gasname for a segment in planner if it differs
from the previous one
This is to avoid visual clutter when replanning logged dives.
Signed-off-by: Robert C. Helling <hell...@atdotde.de>
---
qt-ui/profile/profilewidget2.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 2d1b727..a426cee 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -1537,6 +1537,7 @@ void ProfileWidget2::repositionDiveHandlers()
{
DivePlannerPointsModel *plannerModel =
DivePlannerPointsModel::instance();
// Re-position the user generated dive handlers
+ struct gasmix mix, lastmix;
for (int i = 0; i < plannerModel->rowCount(); i++) {
struct divedatapoint datapoint = plannerModel->at(i);
if (datapoint.time == 0) // those are the magic entries for
tanks
@@ -1561,8 +1562,9 @@ void ProfileWidget2::repositionDiveHandlers()
QLineF line(p1, p2);
QPointF pos = line.pointAt(0.5);
gases[i]->setPos(pos);
- gases[i]->setVisible(datapoint.entered);
- gases[i]->setText(dpGasToStr(plannerModel->at(i)));
+ gases[i]->setText(dpGasToStr(datapoint));
+ gases[i]->setVisible(datapoint.entered &&
+ (i == 0 || gases[i]->text() !=
gases[i-1]->text()));
}
}
--
1.9.5 (Apple Git-50.3)
these two patches allow opening a logged dive in the planner via „replan“. This
can be useful to see how much more deco would have been needed according to
the planner. This is inspired by a suggestion by Davide.
Best
Robert
_______________________________________________
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface