aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/display.h1
-rw-r--r--core/profile.c18
-rw-r--r--profile-widget/diveprofileitem.cpp38
3 files changed, 21 insertions, 36 deletions
diff --git a/core/display.h b/core/display.h
index 8fbe34261..a8ceb1484 100644
--- a/core/display.h
+++ b/core/display.h
@@ -21,6 +21,7 @@ struct plot_info {
enum {AIR, NITROX, TRIMIX, FREEDIVING} dive_type;
double endtempcoord;
double maxpp;
+ bool waypoint_above_ceiling;
struct plot_data *entry;
struct plot_pressure_data *pressures; /* cylinders.nr blocks of nr entries. */
};
diff --git a/core/profile.c b/core/profile.c
index 997b4bb57..3ddd2300b 100644
--- a/core/profile.c
+++ b/core/profile.c
@@ -1026,7 +1026,7 @@ static void calculate_deco_information(struct deco_state *ds, const struct deco_
for (i = 1; i < pi->nr; i++) {
struct plot_data *entry = pi->entry + i;
int j, t0 = (entry - 1)->sec, t1 = entry->sec;
- int time_stepsize = 20;
+ int time_stepsize = 20, max_ceiling = -1;
current_divemode = get_current_divemode(dc, entry->sec, &evd, &current_divemode);
gasmix = get_gasmix(dive, dc, t1, &ev, gasmix);
@@ -1096,6 +1096,8 @@ static void calculate_deco_information(struct deco_state *ds, const struct deco_
double m_value = ds->buehlmann_inertgas_a[j] + entry->ambpressure / ds->buehlmann_inertgas_b[j];
double surface_m_value = ds->buehlmann_inertgas_a[j] + surface_pressure / ds->buehlmann_inertgas_b[j];
entry->ceilings[j] = deco_allowed_depth(ds->tolerated_by_tissue[j], surface_pressure, dive, 1);
+ if (entry->ceilings[j] > max_ceiling)
+ max_ceiling = entry->ceilings[j];
double current_gf = (ds->tissue_inertgas_saturation[j] - entry->ambpressure) / (m_value - entry->ambpressure);
entry->percentages[j] = ds->tissue_inertgas_saturation[j] < entry->ambpressure ?
lrint(ds->tissue_inertgas_saturation[j] / entry->ambpressure * AMB_PERCENTAGE) :
@@ -1107,6 +1109,20 @@ static void calculate_deco_information(struct deco_state *ds, const struct deco_
entry->surface_gf = surface_gf;
}
+ // In the planner, if the ceiling is violated, add an event.
+ // TODO: This *really* shouldn't be done here. This is a contract
+ // between the planner and the profile that the planner uses a dive
+ // that can be trampled upon. But ultimately, the ceiling-violation
+ // marker should be handled differently!
+ // Don't scream if we violate the ceiling by a few cm.
+ if (planner_ds && !pi->waypoint_above_ceiling &&
+ entry->depth < max_ceiling - 100 && entry->sec > 0) {
+ struct dive *non_const_dive = (struct dive *)dive; // cast away const!
+ add_event(&non_const_dive->dc, entry->sec, SAMPLE_EVENT_CEILING, -1, max_ceiling / 1000,
+ translate("gettextFromC", "planned waypoint above ceiling"));
+ pi->waypoint_above_ceiling = true;
+ }
+
/* should we do more calculations?
* We don't for print-mode because this info doesn't show up there
* If the ceiling hasn't cleared by the last data point, we need tts for VPM-B CVA calculation
diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp
index 48f7dd380..eb343cc5e 100644
--- a/profile-widget/diveprofileitem.cpp
+++ b/profile-widget/diveprofileitem.cpp
@@ -85,49 +85,17 @@ void DiveProfileItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
painter->restore();
}
-int DiveProfileItem::maxCeiling(int row)
-{
- int max = -1;
- plot_data *entry = dataModel.data().entry + row;
- for (int tissue = 0; tissue < 16; tissue++) {
- if (max < entry->ceilings[tissue])
- max = entry->ceilings[tissue];
- }
- return max;
-}
-
void DiveProfileItem::replot()
{
- bool eventAdded = false;
-
AbstractProfilePolygonItem::replot();
if (polygon().isEmpty())
return;
show_reported_ceiling = prefs.dcceiling;
reported_ceiling_in_red = prefs.redceiling;
- profileColor = getColor(DEPTH_BOTTOM);
-
-#ifdef SUBSURFACE_MOBILE
- Q_UNUSED(eventAdded);
-#else
- int currState = qobject_cast<ProfileWidget2 *>(scene()->views().first())->currentState;
- if (currState == ProfileWidget2::PLAN) {
- plot_data *entry = dataModel.data().entry;
- for (int i = 0; i < dataModel.rowCount(); i++, entry++) {
- int max = maxCeiling(i);
- // Don't scream if we violate the ceiling by a few cm
- if (entry->depth < max - 100 && entry->sec > 0) {
- profileColor = QColor(Qt::red);
- if (!eventAdded) {
- add_event(&displayed_dive.dc, entry->sec, SAMPLE_EVENT_CEILING, -1, max / 1000,
- QT_TRANSLATE_NOOP("gettextFromC", "planned waypoint above ceiling"));
- eventAdded = true;
- }
- }
- }
- }
-#endif
+ profileColor = dataModel.data().waypoint_above_ceiling ? QColor(Qt::red)
+ : getColor(DEPTH_BOTTOM);
+
/* Show any ceiling we may have encountered */
if (prefs.dcceiling && !prefs.redceiling) {
QPolygonF p = polygon();