aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2019-03-20 16:29:27 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-03-29 06:51:12 -0700
commit5e494ce76106fe16f614e163c2bc6b8bf6903c86 (patch)
tree5162c2523e8a731eda22ce464e72c1d42124616d
parent7635ee3e776f7adb96dda70ea21920569368ae30 (diff)
downloadsubsurface-5e494ce76106fe16f614e163c2bc6b8bf6903c86.tar.gz
Show a bit of surface degassing in the planner
to display the deco parameters at the surface, in particular tissue saturation and heat map. Suggeted-by: Matthias Heinrichs <info@heinrichsweikamp.com> Signed-off-by: Robert C. Helling <helling@atdotde.de>
-rw-r--r--core/planner.c8
-rw-r--r--core/plannernotes.c8
-rw-r--r--core/profile.c2
-rw-r--r--profile-widget/diveeventitem.cpp20
-rw-r--r--profile-widget/diveeventitem.h1
5 files changed, 35 insertions, 4 deletions
diff --git a/core/planner.c b/core/planner.c
index 5bcbdab7e..0177b9691 100644
--- a/core/planner.c
+++ b/core/planner.c
@@ -1080,6 +1080,14 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
diveplan->eff_gflow = lrint(100.0 * (regressiona() * first_stop_depth + regressionb()));
}
+ for (int i = 0; i < MAX_CYLINDERS; i++)
+ if (cylinder_nodata(&dive->cylinder[i])) {
+ // Switch to an empty air cylinder for breathing air at the surface
+ // If no empty cylinder is found, keep using last deco gas
+ current_cylinder = i;
+ break;
+ }
+ plan_add_segment(diveplan, 600, 0, current_cylinder, 0, false, OC);
create_dive_from_plan(diveplan, dive, is_planner);
add_plan_to_notes(diveplan, dive, show_disclaimer, error);
fixup_dc_duration(&dive->dc);
diff --git a/core/plannernotes.c b/core/plannernotes.c
index 90f37add7..99f456393 100644
--- a/core/plannernotes.c
+++ b/core/plannernotes.c
@@ -24,9 +24,12 @@ static int diveplan_duration(struct diveplan *diveplan)
{
struct divedatapoint *dp = diveplan->dp;
int duration = 0;
+ int lastdepth = 0;
while(dp) {
- if (dp->time > duration)
+ if (dp->time > duration && (dp->depth.mm > SURFACE_THRESHOLD || lastdepth > SURFACE_THRESHOLD)) {
duration = dp->time;
+ lastdepth = dp->depth.mm;
+ }
dp = dp->next;
}
return (duration + 30) / 60;
@@ -193,6 +196,9 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
!rebreatherchange_before &&
!rebreatherchange_after)
continue;
+ // Ignore final surface segment for notes
+ if (lastdepth == 0 && dp->depth.mm == 0 && !dp->next)
+ continue;
if ((dp->time - lasttime < 10 && lastdepth == dp->depth.mm) && !(gaschange_after && dp->next && dp->depth.mm != dp->next->depth.mm))
continue;
diff --git a/core/profile.c b/core/profile.c
index 0d568a4fe..9cc072973 100644
--- a/core/profile.c
+++ b/core/profile.c
@@ -453,7 +453,7 @@ struct plot_info calculate_max_limits_new(struct dive *dive, struct divecomputer
if (depth > maxdepth)
maxdepth = s->depth.mm;
- if ((depth > SURFACE_THRESHOLD || lastdepth > SURFACE_THRESHOLD) &&
+ if ((depth > SURFACE_THRESHOLD || lastdepth > SURFACE_THRESHOLD || in_planner()) &&
s->time.seconds > maxtime)
maxtime = s->time.seconds;
lastdepth = depth;
diff --git a/profile-widget/diveeventitem.cpp b/profile-widget/diveeventitem.cpp
index 64de02436..afde2dc92 100644
--- a/profile-widget/diveeventitem.cpp
+++ b/profile-widget/diveeventitem.cpp
@@ -10,6 +10,8 @@
#include "core/membuffer.h"
#include "core/subsurface-string.h"
+#define DEPTH_NOT_FOUND (-2342)
+
extern struct ev_select *ev_namelist;
extern int evn_used;
@@ -234,7 +236,8 @@ bool DiveEventItem::shouldBeHidden()
struct sample *first_sample = &dc->sample[0];
if (!strcmp(event->name, "gaschange") &&
(event->time.seconds == 0 ||
- (first_sample && event->time.seconds == first_sample->time.seconds)))
+ (first_sample && event->time.seconds == first_sample->time.seconds) ||
+ depthAtTime(event->time.seconds) < SURFACE_THRESHOLD))
return true;
/*
@@ -254,6 +257,17 @@ bool DiveEventItem::shouldBeHidden()
return false;
}
+int DiveEventItem::depthAtTime(int time)
+{
+ QModelIndexList result = dataModel->match(dataModel->index(0, DivePlotDataModel::TIME), Qt::DisplayRole, time);
+ if (result.isEmpty()) {
+ Q_ASSERT("can't find a spot in the dataModel");
+ hide();
+ return DEPTH_NOT_FOUND;
+ }
+ return dataModel->data(dataModel->index(result.first().row(), DivePlotDataModel::DEPTH)).toInt();
+}
+
void DiveEventItem::recalculatePos(bool instant)
{
if (!vAxis || !hAxis || !internalEvent || !dataModel)
@@ -265,9 +279,11 @@ void DiveEventItem::recalculatePos(bool instant)
hide();
return;
}
+ int depth = depthAtTime(internalEvent->time.seconds);
+ if (depth == DEPTH_NOT_FOUND)
+ return;
if (!isVisible() && !shouldBeHidden())
show();
- int depth = dataModel->data(dataModel->index(result.first().row(), DivePlotDataModel::DEPTH)).toInt();
qreal x = hAxis->posAtValue(internalEvent->time.seconds);
qreal y = vAxis->posAtValue(depth);
if (!instant)
diff --git a/profile-widget/diveeventitem.h b/profile-widget/diveeventitem.h
index 6547fa716..2039da616 100644
--- a/profile-widget/diveeventitem.h
+++ b/profile-widget/diveeventitem.h
@@ -27,6 +27,7 @@ slots:
private:
void setupToolTipString(struct gasmix lastgasmix);
void setupPixmap(struct gasmix lastgasmix);
+ int depthAtTime(int time);
DiveCartesianAxis *vAxis;
DiveCartesianAxis *hAxis;
DivePlotDataModel *dataModel;