profile: move adding of ceiling-violation-event

The profile item that shows the ceilings adds a warning event
if the ceiling is violated. This is very unfortunate.

Improve this situation by adding the event up to the function
that calculates the ceiling. This is still not how it should
be - the display layer should not modify the dive that it
displays.

To make this clear, add a comment that details that this
is a contract between planner and display layer: The planner
uses a dive that can be trampled upon by the profile.
Still, this should be solved differently.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-01-09 17:28:23 +01:00 committed by Dirk Hohndel
parent 9bfc6d2520
commit 09287809eb
3 changed files with 20 additions and 35 deletions

View file

@ -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. */
};

View file

@ -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

View file

@ -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);
profileColor = dataModel.data().waypoint_above_ceiling ? QColor(Qt::red)
: 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
/* Show any ceiling we may have encountered */
if (prefs.dcceiling && !prefs.redceiling) {
QPolygonF p = polygon();