Planner: Improve Gas Handling in CCR Mode.

This has become a bit of a catch-all overhaul of a large portion of the
planner - I started out wanting to improve the CCR mode, but then as I
started pulling all the other threads that needed addressing started to
come with it.

Improve how the gas selection is handled when planning dives in CCR
mode, by making the type (OC / CCR) of segments dependent on the gas use
type that was set for the selected gas.
Add a preference to allow the user to chose to use OC gases as diluent,
in a similar fashion to the original implementation.
Hide gases that cannot be used in the currently selected dive mode in
all drop downs.
Include usage type in gas names if this is needed.
Hide columns and disable elements in the 'Dive planner points' table if
they can they can not be edited in the curently selected dive mode.
Visually identify gases and usage types that are not appropriate for the
currently selected dive mode.
Move the 'Dive mode' selection to the top of the planner view, to
accommodate the fact that this is a property of the dive and not a
planner setting.
Show a warning instead of the dive plan if the plan contains gases that
are not usable in the selected dive mode.
Fix the data entry for the setpoint in the 'Dive planner points' table.
Fix problems with enabling / disabling planner settings when switching
between dive modes.
Refactor some names to make them more appropriate for their current
usage.

One point that is still open is to hide gas usage graphs in the planner
profile if the gas isn't used for OC, as there is no way to meaningfully
interpolate such usage.

Signed-off-by: Michael Keller <github@ike.ch>
This commit is contained in:
Michael Keller 2024-05-15 17:23:39 +12:00
parent 7106c4d5f0
commit 2d8e343221
63 changed files with 678 additions and 383 deletions

View file

@ -23,27 +23,32 @@
#include <QBuffer>
#endif
DivePlannerWidget::DivePlannerWidget(dive &planned_dive, int dcNr, PlannerWidgets *parent)
DivePlannerWidget::DivePlannerWidget(const dive &planned_dive, int &dcNr, PlannerWidgets *parent)
{
DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
CylindersModel *cylinders = DivePlannerPointsModel::instance()->cylindersModel();
ui.setupUi(this);
// should be the same order as in dive_comp_type!
QStringList divemodes = QStringList();
for (int i = 0; i < FREEDIVE; i++)
divemodes.append(gettextFromC::tr(divemode_text_ui[i]));
ui.divemode->insertItems(0, divemodes);
ui.tableWidget->setTitle(tr("Dive planner points"));
ui.tableWidget->setBtnToolTip(tr("Add dive data point"));
ui.tableWidget->setModel(plannerModel);
connect(ui.tableWidget, &TableView::itemClicked, plannerModel, &DivePlannerPointsModel::remove);
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::GAS, new AirTypesDelegate(planned_dive, this));
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DIVEMODE, new DiveTypesDelegate(this));
connect(ui.tableWidget, &TableView::addButtonClicked, plannerModel, &DivePlannerPointsModel::addDefaultStop);
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::GAS, new GasTypesDelegate(planned_dive, dcNr, this));
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DIVEMODE, new DiveTypesDelegate(planned_dive, dcNr, this));
ui.cylinderTableWidget->setTitle(tr("Available gases"));
ui.cylinderTableWidget->setBtnToolTip(tr("Add cylinder"));
ui.cylinderTableWidget->setModel(cylinders);
connect(ui.cylinderTableWidget, &TableView::itemClicked, cylinders, &CylindersModel::remove);
ui.waterType->setItemData(0, FRESHWATER_SALINITY);
ui.waterType->setItemData(1, SEAWATER_SALINITY);
ui.waterType->setItemData(2, EN13319_SALINITY);
waterTypeUpdateTexts();
QTableView *view = ui.cylinderTableWidget->view();
connect(ui.cylinderTableWidget, &TableView::itemClicked, cylinders, &CylindersModel::remove);
view->setColumnHidden(CylindersModel::START, true);
view->setColumnHidden(CylindersModel::END, true);
view->setColumnHidden(CylindersModel::DEPTH, false);
@ -52,18 +57,22 @@ DivePlannerWidget::DivePlannerWidget(dive &planned_dive, int dcNr, PlannerWidget
view->setColumnHidden(CylindersModel::SENSORS, true);
view->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate(this));
auto tankUseDelegate = new TankUseDelegate(this);
tankUseDelegate->setCurrentDC(planned_dive.get_dc(dcNr));
tankUseDelegate->setDiveDc(planned_dive, dcNr);
view->setItemDelegateForColumn(CylindersModel::USE, tankUseDelegate);
connect(ui.cylinderTableWidget, &TableView::addButtonClicked, plannerModel, &DivePlannerPointsModel::addCylinder_clicked);
connect(ui.tableWidget, &TableView::addButtonClicked, plannerModel, &DivePlannerPointsModel::addDefaultStop);
connect(cylinders, &CylindersModel::dataChanged, plannerModel, &DivePlannerPointsModel::emitDataChanged);
connect(cylinders, &CylindersModel::dataChanged, plannerModel, &DivePlannerPointsModel::cylinderModelEdited);
connect(cylinders, &CylindersModel::rowsInserted, plannerModel, &DivePlannerPointsModel::cylinderModelEdited);
connect(cylinders, &CylindersModel::rowsRemoved, plannerModel, &DivePlannerPointsModel::cylinderModelEdited);
ui.tableWidget->setBtnToolTip(tr("Add dive data point"));
ui.waterType->setItemData(0, FRESHWATER_SALINITY);
ui.waterType->setItemData(1, SEAWATER_SALINITY);
ui.waterType->setItemData(2, EN13319_SALINITY);
waterTypeUpdateTexts();
connect(ui.startTime, &QDateEdit::timeChanged, plannerModel, &DivePlannerPointsModel::setStartTime);
connect(ui.dateEdit, &QDateEdit::dateChanged, plannerModel, &DivePlannerPointsModel::setStartDate);
connect(ui.divemode, QOverload<int>::of(&QComboBox::currentIndexChanged), parent, &PlannerWidgets::setDiveMode);
connect(ui.ATMPressure, QOverload<int>::of(&QSpinBox::valueChanged), this, &DivePlannerWidget::atmPressureChanged);
connect(ui.atmHeight, QOverload<int>::of(&QSpinBox::valueChanged), this, &DivePlannerWidget::heightChanged);
connect(ui.waterType, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DivePlannerWidget::waterTypeChanged);
@ -77,14 +86,14 @@ DivePlannerWidget::DivePlannerWidget(dive &planned_dive, int dcNr, PlannerWidget
QShortcut *closeKey = new QShortcut(QKeySequence(Qt::Key_Escape), this);
connect(closeKey, &QShortcut::activated, plannerModel, &DivePlannerPointsModel::cancelPlan);
// This makes shure the spinbox gets a setMinimum(0) on it so we can't have negative time or depth.
// This makes sure the spinbox gets a setMinimum(0) on it so we can't have negative time or depth.
// Limit segments to a depth of 1000 m/3300 ft and a duration of 100 h. Setting the limit for
// the depth will be done in settingChanged() since this depends on the chosen units.
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::RUNTIME, new SpinBoxDelegate(0, INT_MAX, 1, this));
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DURATION, new SpinBoxDelegate(0, 6000, 1, this));
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::CCSETPOINT, new DoubleSpinBoxDelegate(0, 2, 0.01, this));
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &DivePlannerWidget::settingsChanged);
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, parent, &PlannerWidgets::settingsChanged);
/* set defaults. */
ui.ATMPressure->setValue(1013);
@ -116,11 +125,6 @@ void DivePlannerWidget::setSurfacePressure(int surface_pressure)
ui.ATMPressure->setValue(surface_pressure);
}
void PlannerSettingsWidget::setDiveMode(int mode)
{
ui.rebreathermode->setCurrentIndex(mode);
}
void DivePlannerWidget::setSalinity(int salinity)
{
bool mapped = false;
@ -212,7 +216,23 @@ void DivePlannerWidget::customSalinityChanged(double density)
}
}
void PlannerSettingsWidget::disableDecoElements(int mode, divemode_t rebreathermode)
void DivePlannerWidget::setDiveMode(int mode)
{
ui.divemode->setCurrentIndex(mode);
}
void DivePlannerWidget::setColumnVisibility(int mode)
{
ui.tableWidget->view()->setColumnHidden(DivePlannerPointsModel::CCSETPOINT, mode != CCR);
ui.tableWidget->view()->setColumnHidden(DivePlannerPointsModel::DIVEMODE, mode == OC || (mode == CCR && !prefs.allowOcGasAsDiluent));
// This is needed as Qt sets the column width to 0 when hiding a column
ui.tableWidget->view()->setVisible(false); // This will cause the resize to include rows outside the current viewport
ui.tableWidget->view()->resizeColumnsToContents();
ui.tableWidget->view()->setVisible(true);
}
void PlannerSettingsWidget::disableDecoElements(int mode, divemode_t divemode)
{
if (mode == RECREATIONAL) {
ui.label_gflow->setDisabled(false);
@ -265,7 +285,7 @@ void PlannerSettingsWidget::disableDecoElements(int mode, divemode_t rebreatherm
ui.backgasBreaks->setChecked(false);
ui.backgasBreaks->blockSignals(false);
}
ui.bailout->setDisabled(!(rebreathermode == CCR || rebreathermode == PSCR));
ui.bailout->setDisabled(!IS_REBREATHER_MODE(divemode));
ui.bottompo2->setDisabled(false);
ui.decopo2->setDisabled(false);
ui.safetystop->setDisabled(true);
@ -277,7 +297,7 @@ void PlannerSettingsWidget::disableDecoElements(int mode, divemode_t rebreatherm
ui.min_switch_duration->setDisabled(false);
ui.surface_segment->setDisabled(false);
ui.label_min_switch_duration->setDisabled(false);
ui.sacfactor->setDisabled(false);
ui.sacfactor->setDisabled(IS_REBREATHER_MODE(divemode));
ui.problemsolvingtime->setDisabled(false);
ui.sacfactor->setValue(PlannerShared::sacfactor());
ui.problemsolvingtime->setValue(prefs.problemsolvingtime);
@ -299,7 +319,7 @@ void PlannerSettingsWidget::disableDecoElements(int mode, divemode_t rebreatherm
ui.backgasBreaks->setChecked(false);
ui.backgasBreaks->blockSignals(false);
}
ui.bailout->setDisabled(!(rebreathermode == CCR || rebreathermode == PSCR));
ui.bailout->setDisabled(!IS_REBREATHER_MODE(divemode));
ui.bottompo2->setDisabled(false);
ui.decopo2->setDisabled(false);
ui.safetystop->setDisabled(true);
@ -311,7 +331,7 @@ void PlannerSettingsWidget::disableDecoElements(int mode, divemode_t rebreatherm
ui.min_switch_duration->setDisabled(false);
ui.surface_segment->setDisabled(false);
ui.label_min_switch_duration->setDisabled(false);
ui.sacfactor->setDisabled(false);
ui.sacfactor->setDisabled(IS_REBREATHER_MODE(divemode));
ui.problemsolvingtime->setDisabled(false);
ui.sacfactor->setValue(PlannerShared::sacfactor());
ui.problemsolvingtime->setValue(prefs.problemsolvingtime);
@ -359,7 +379,6 @@ PlannerSettingsWidget::PlannerSettingsWidget(PlannerWidgets *parent)
ui.decopo2->setValue(PlannerShared::decopo2());
ui.backgasBreaks->setChecked(prefs.doo2breaks);
PlannerShared::set_dobailout(false);
setBailoutVisibility(false);
ui.o2narcotic->setChecked(prefs.o2narcotic);
ui.drop_stone_mode->setChecked(prefs.drop_stone_mode);
ui.switch_at_req_stop->setChecked(prefs.switch_at_req_stop);
@ -370,12 +389,6 @@ PlannerSettingsWidget::PlannerSettingsWidget(PlannerWidgets *parent)
ui.vpmb_deco->setChecked(prefs.planner_deco_mode == VPMB);
disableDecoElements((int) prefs.planner_deco_mode, OC);
// should be the same order as in dive_comp_type!
QStringList rebreather_modes = QStringList();
for (int i = 0; i < FREEDIVE; i++)
rebreather_modes.append(gettextFromC::tr(divemode_text_ui[i]));
ui.rebreathermode->insertItems(0, rebreather_modes);
connect(ui.recreational_deco, &QAbstractButton::clicked, [] { PlannerShared::set_planner_deco_mode(RECREATIONAL); });
connect(ui.buehlmann_deco, &QAbstractButton::clicked, [] { PlannerShared::set_planner_deco_mode(BUEHLMANN); });
connect(ui.vpmb_deco, &QAbstractButton::clicked, [] { PlannerShared::set_planner_deco_mode(VPMB); });
@ -404,12 +417,10 @@ PlannerSettingsWidget::PlannerSettingsWidget(PlannerWidgets *parent)
connect(ui.switch_at_req_stop, &QAbstractButton::toggled, plannerModel, &DivePlannerPointsModel::setSwitchAtReqStop);
connect(ui.min_switch_duration, QOverload<int>::of(&QSpinBox::valueChanged), &PlannerShared::set_min_switch_duration);
connect(ui.surface_segment, QOverload<int>::of(&QSpinBox::valueChanged), &PlannerShared::set_surface_segment);
connect(ui.rebreathermode, QOverload<int>::of(&QComboBox::currentIndexChanged), plannerModel, &DivePlannerPointsModel::setRebreatherMode);
connect(ui.rebreathermode, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &PlannerSettingsWidget::setBailoutVisibility);
connect(ui.recreational_deco, &QAbstractButton::clicked, [this, parent] { disableDecoElements(RECREATIONAL, parent->getRebreatherMode()); });
connect(ui.buehlmann_deco, &QAbstractButton::clicked, [this, parent] { disableDecoElements(BUEHLMANN, parent->getRebreatherMode()); });
connect(ui.vpmb_deco, &QAbstractButton::clicked, [this, parent] { disableDecoElements(VPMB, parent->getRebreatherMode()); });
connect(ui.recreational_deco, &QAbstractButton::clicked, [this, parent] { disableDecoElements(RECREATIONAL, parent->getDiveMode()); });
connect(ui.buehlmann_deco, &QAbstractButton::clicked, [this, parent] { disableDecoElements(BUEHLMANN, parent->getDiveMode()); });
connect(ui.vpmb_deco, &QAbstractButton::clicked, [this, parent] { disableDecoElements(VPMB, parent->getDiveMode()); });
connect(ui.sacfactor, QOverload<double>::of(&QDoubleSpinBox::valueChanged), &PlannerShared::set_sacfactor);
connect(ui.problemsolvingtime, QOverload<int>::of(&QSpinBox::valueChanged), plannerModel, &DivePlannerPointsModel::setProblemSolvingTime);
@ -519,8 +530,9 @@ void PlannerSettingsWidget::setBackgasBreaks(bool dobreaks)
void PlannerSettingsWidget::setBailoutVisibility(int mode)
{
ui.bailout->setDisabled(!(mode == CCR || mode == PSCR));
ui.sacFactor->setDisabled(mode == CCR);
bool isRebreatherMode = IS_REBREATHER_MODE(mode);
ui.bailout->setDisabled(!isRebreatherMode);
ui.sacfactor->setDisabled(isRebreatherMode);
}
PlannerDetails::PlannerDetails(QWidget *parent) : QWidget(parent)
@ -561,7 +573,7 @@ int PlannerWidgets::getDcNr()
return dcNr;
}
divemode_t PlannerWidgets::getRebreatherMode() const
divemode_t PlannerWidgets::getDiveMode() const
{
return planned_dive->get_dc(dcNr)->divemode;
}
@ -575,13 +587,14 @@ void PlannerWidgets::preparePlanDive(const dive *currentDive, int currentDcNr)
// plan the dive in the same mode as the currently selected one
if (currentDive) {
plannerSettingsWidget.setDiveMode(currentDive->get_dc(currentDcNr)->divemode);
plannerSettingsWidget.setBailoutVisibility(currentDive->get_dc(currentDcNr)->divemode);
planned_dive->get_dc(dcNr)->divemode = currentDive->get_dc(currentDcNr)->divemode;
if (currentDive->salinity)
plannerWidget.setSalinity(currentDive->salinity);
else // No salinity means salt water
plannerWidget.setSalinity(SEAWATER_SALINITY);
}
setDiveMode(getDiveMode());
}
void PlannerWidgets::planDive()
@ -589,6 +602,7 @@ void PlannerWidgets::planDive()
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN);
plannerWidget.setReplanButton(false);
plannerWidget.setupStartTime(timestampToDateTime(planned_dive->when)); // This will reload the profile!
}
@ -596,6 +610,8 @@ void PlannerWidgets::prepareReplanDive(const dive *currentDive, int currentDcNr)
{
copy_dive(currentDive, planned_dive.get());
dcNr = currentDcNr;
setDiveMode(getDiveMode());
}
void PlannerWidgets::replanDive()
@ -609,6 +625,7 @@ void PlannerWidgets::replanDive()
plannerWidget.setSurfacePressure(planned_dive->surface_pressure.mbar);
if (planned_dive->salinity)
plannerWidget.setSalinity(planned_dive->salinity);
reset_cylinders(planned_dive.get(), true);
DivePlannerPointsModel::instance()->cylindersModel()->updateDive(planned_dive.get(), dcNr);
}
@ -657,3 +674,16 @@ void PlannerWidgets::printDecoPlan()
plannerDetails.divePlanOutput()->setHtml(origPlan); // restore original plan
#endif
}
void PlannerWidgets::setDiveMode(int mode)
{
DivePlannerPointsModel::instance()->setDiveMode(mode);
plannerWidget.setColumnVisibility(mode);
plannerSettingsWidget.setBailoutVisibility(mode);
}
void PlannerWidgets::settingsChanged()
{
plannerWidget.settingsChanged();
setDiveMode(getDiveMode());
}