subsurface/qt-ui/diveplanner.cpp

1091 lines
31 KiB
C++
Raw Normal View History

#include "diveplanner.h"
#include "graphicsview-common.h"
#include "models.h"
#include "modeldelegates.h"
#include "mainwindow.h"
#include "maintab.h"
#include "tableview.h"
#include "dive.h"
#include "divelist.h"
#include "planner.h"
#include "display.h"
#include "helpers.h"
#include <QMouseEvent>
#include <QDebug>
#include <QGraphicsSceneMouseEvent>
#include <QMessageBox>
#include <QListView>
#include <QModelIndex>
#include <QSettings>
#include <QTableView>
#include <QColor>
#include <QShortcut>
#include <algorithm>
#include <string.h>
#define TIME_INITIAL_MAX 30
#define MAX_DEPTH M_OR_FT(150, 450)
#define MIN_DEPTH M_OR_FT(20, 60)
#define UNIT_FACTOR ((prefs.units.length == units::METERS) ? 1000.0 / 60.0 : feet_to_mm(1.0) / 60.0)
QString gasToStr(struct gasmix gas)
{
uint o2 = (gas.o2.permille + 5) / 10, he = (gas.he.permille + 5) / 10;
QString result = gasmix_is_air(&gas) ? QObject::tr("AIR") : he == 0 ? QString("EAN%1").arg(o2, 2, 10, QChar('0')) : QString("%1/%2").arg(o2).arg(he);
return result;
}
QString dpGasToStr(const divedatapoint &p)
{
return gasToStr(p.gasmix);
}
static DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
bool intLessThan(int a, int b)
{
return a <= b;
}
void DivePlannerPointsModel::removeSelectedPoints(const QVector<int> &rows)
{
int firstRow = rowCount() - rows.count();
QVector<int> v2 = rows;
std::sort(v2.begin(), v2.end(), intLessThan);
beginRemoveRows(QModelIndex(), firstRow, rowCount() - 1);
for (int i = v2.count() - 1; i >= 0; i--) {
divepoints.remove(v2[i]);
}
endRemoveRows();
}
void DivePlannerPointsModel::createSimpleDive()
{
struct gasmix gas = { 0 };
// set the start time of the plan
diveplan.when = displayed_dive.when;
if (isPlanner())
// let's use the gas from the first cylinder
gas = displayed_dive.cylinder[0].gasmix;
// If we're in drop_stone_mode, don't add a first point.
// It will be added implicit.
if (!drop_stone_mode)
plannerModel->addStop(M_OR_FT(15, 45), 1 * 60, &gas, 0, true);
plannerModel->addStop(M_OR_FT(15, 45), 40 * 60, &gas, 0, true);
if (!isPlanner()) {
plannerModel->addStop(M_OR_FT(5, 15), 42 * 60, &gas, 0, true);
plannerModel->addStop(M_OR_FT(5, 15), 45 * 60, &gas, 0, true);
}
}
void DivePlannerPointsModel::setupStartTime()
{
// if the latest dive is in the future, then start an hour after it ends
// otherwise start an hour from now
startTime = QDateTime::currentDateTimeUtc().addSecs(3600 + gettimezoneoffset());
if (dive_table.nr) {
struct dive *d = get_dive(dive_table.nr - 1);
time_t ends = d->when + d->duration.seconds;
time_t diff = ends - startTime.toTime_t();
if (diff > 0) {
startTime = startTime.addSecs(diff + 3600);
}
}
emit startTimeChanged(startTime);
}
void DivePlannerPointsModel::loadFromDive(dive *d)
{
// We need to make a copy, because as soon as the model is modified, it will
// remove all samples from the dive.
memcpy(&backupDive, d, sizeof(struct dive));
// this code is just adjusted for the new API, it continues to just copy the first
// DC (which here is almost certainly sufficient)
// but it should most likely use copy_dive() instead
// but this whole section needs to be rewritten, anyway
copy_samples(&d->dc, &backupDive.dc);
copy_events(&d->dc, &backupDive.dc);
CylindersModel::instance()->updateDive();
int lasttime = 0;
// we start with the first gas and see if it was changed
struct gasmix gas = backupDive.cylinder[0].gasmix;
for (int i = 0; i < backupDive.dc.samples - 1; i++) {
const sample &s = backupDive.dc.sample[i];
if (s.time.seconds == 0)
continue;
get_gas_from_events(&backupDive.dc, lasttime, &gas);
plannerModel->addStop(s.depth.mm, s.time.seconds, &gas, 0, true);
lasttime = s.time.seconds;
}
}
void DivePlannerPointsModel::restoreBackupDive()
{
memcpy(current_dive, &backupDive, sizeof(struct dive));
}
// copy the tanks from the current dive, or the default cylinder
// or an unknown cylinder
// setup the cylinder widget accordingly
void DivePlannerPointsModel::setupCylinders()
{
if (mode == PLAN && current_dive) {
// take the used cylinders from the selected dive as starting point
CylindersModel::instance()->copyFromDive(current_dive);
copy_cylinders(current_dive, &displayed_dive, true);
reset_cylinders(&displayed_dive);
return;
}
if (!same_string(prefs.default_cylinder, "")) {
fill_default_cylinder(&displayed_dive.cylinder[0]);
} else {
// roughly an AL80
displayed_dive.cylinder[0].type.description = strdup(tr("unknown").toUtf8().constData());
displayed_dive.cylinder[0].type.size.mliter = 11100;
displayed_dive.cylinder[0].type.workingpressure.mbar = 207000;
}
reset_cylinders(&displayed_dive);
CylindersModel::instance()->copyFromDive(&displayed_dive);
}
QStringList &DivePlannerPointsModel::getGasList()
{
static QStringList list;
list.clear();
for (int i = 0; i < MAX_CYLINDERS; i++) {
cylinder_t *cyl = &displayed_dive.cylinder[i];
if (cylinder_nodata(cyl))
break;
list.push_back(gasToStr(cyl->gasmix));
}
return list;
}
void DivePlannerPointsModel::removeDeco()
{
bool oldrec = setRecalc(false);
QVector<int> computedPoints;
for (int i = 0; i < plannerModel->rowCount(); i++)
if (!plannerModel->at(i).entered)
computedPoints.push_back(i);
removeSelectedPoints(computedPoints);
setRecalc(oldrec);
}
#if 0
void DivePlannerGraphics::drawProfile()
{
// Code ported to the new profile is deleted. This part that I left here
// is because I didn't fully understood the reason of the magic with
// the plannerModel.
Improvement for various bits of the planner Rewrite of the actual planner logic. Now ascend to the next potential stop depth. There the state is cached and we try to ascend to the next stop depth. If we hit the ceiling while doing that we go back to the cached state and wait there for a minute. Then we try again. Then loop. Converted all depth related variables from unsigned int to int. During planning, in a time step the current depth can temporarily be negative and comparisons of a negative int with an unsigned it have not the result I expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we don’t really need the 32nd bit that unsigned buys us for depths. Deco stops are now shown in the same table as manually entered stops in boldface (I removed the second table to save screen estate). The gas shown in the table is still misleading as it means the gas used on the segment leading up to that event. The update of the profile only works partially upon changes in the list of available gases. Treatment of various gases is basically there but needs some more love. The ascent velocity is now provided by a function that takes the current depth as argument. Currently it always returns 10m/min but that will later be variable (and hopefully user configurable). The profile is not redrawn while deco is computed (avoiding an infinite recursion). The table got a new column for the duration of a segment while the old “duration” column was renamed “Runtime” to reflect what it actually shows. Currently, only the run time but not the duration are editable. All deco gases are used from the depth where their pO2 is 1.4bar. This should become more flexible. Calculation of the pressure drop in cylinders without configured volumes is suppressed. This solves a problem with the planner crashing when saving a dive where not all cylinders had been manually given a volume. [Short rant break: Treating 0/0 as air bites back at so many places. E.g. Cylinder data is initialized with memsetting the whole structures to 0. Then later suddenly this totally unconfigured cylinder is being treated as it would contain air. Maybe at some point this was a feature. But it lead to a naughty bug which took me over an hour to resolve. We should seriously reconsider this choice and better move to 209/0 being air if changing this everywhere is not too much trouble] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:54:55 +00:00
bool oldRecalc = plannerModel->setRecalc(false);
plannerModel->removeDeco();
// Here we plotted the old planner profile. why there's the magic with the plannerModel here?
Improvement for various bits of the planner Rewrite of the actual planner logic. Now ascend to the next potential stop depth. There the state is cached and we try to ascend to the next stop depth. If we hit the ceiling while doing that we go back to the cached state and wait there for a minute. Then we try again. Then loop. Converted all depth related variables from unsigned int to int. During planning, in a time step the current depth can temporarily be negative and comparisons of a negative int with an unsigned it have not the result I expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we don’t really need the 32nd bit that unsigned buys us for depths. Deco stops are now shown in the same table as manually entered stops in boldface (I removed the second table to save screen estate). The gas shown in the table is still misleading as it means the gas used on the segment leading up to that event. The update of the profile only works partially upon changes in the list of available gases. Treatment of various gases is basically there but needs some more love. The ascent velocity is now provided by a function that takes the current depth as argument. Currently it always returns 10m/min but that will later be variable (and hopefully user configurable). The profile is not redrawn while deco is computed (avoiding an infinite recursion). The table got a new column for the duration of a segment while the old “duration” column was renamed “Runtime” to reflect what it actually shows. Currently, only the run time but not the duration are editable. All deco gases are used from the depth where their pO2 is 1.4bar. This should become more flexible. Calculation of the pressure drop in cylinders without configured volumes is suppressed. This solves a problem with the planner crashing when saving a dive where not all cylinders had been manually given a volume. [Short rant break: Treating 0/0 as air bites back at so many places. E.g. Cylinder data is initialized with memsetting the whole structures to 0. Then later suddenly this totally unconfigured cylinder is being treated as it would contain air. Maybe at some point this was a feature. But it lead to a naughty bug which took me over an hour to resolve. We should seriously reconsider this choice and better move to 209/0 being air if changing this everywhere is not too much trouble] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:54:55 +00:00
plannerModel->setRecalc(oldRecalc);
plannerModel->deleteTemporaryPlan();
}
#endif
DiveHandler::DiveHandler() : QGraphicsEllipseItem()
{
setRect(-5, -5, 10, 10);
setFlags(ItemIgnoresTransformations | ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges);
setBrush(Qt::white);
setZValue(2);
}
int DiveHandler::parentIndex()
{
ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
return view->handles.indexOf(this);
}
void DiveHandler::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
QMenu m;
GasSelectionModel *model = GasSelectionModel::instance();
model->repopulate();
int rowCount = model->rowCount();
for (int i = 0; i < rowCount; i++) {
QAction *action = new QAction(&m);
action->setText(model->data(model->index(i, 0), Qt::DisplayRole).toString());
connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas()));
m.addAction(action);
}
m.addSeparator();
m.addAction(QObject::tr("Remove this Point"), this, SLOT(selfRemove()));
m.exec(event->screenPos());
}
void DiveHandler::selfRemove()
{
setSelected(true);
ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
view->keyDeleteAction();
}
void DiveHandler::changeGas()
{
QAction *action = qobject_cast<QAction *>(sender());
QModelIndex index = plannerModel->index(parentIndex(), DivePlannerPointsModel::GAS);
plannerModel->setData(index, action->text());
}
void DiveHandler::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
ProfileWidget2 *view = qobject_cast<ProfileWidget2*>(scene()->views().first());
if(view->isPointOutOfBoundaries(event->scenePos()))
return;
QGraphicsEllipseItem::mouseMoveEvent(event);
emit moved();
}
void DiveHandler::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mousePressEvent(event);
emit clicked();
}
void DiveHandler::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mouseReleaseEvent(event);
emit released();
}
DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
{
ui.setupUi(this);
ui.tableWidget->setTitle(tr("Dive Planner Points"));
ui.tableWidget->setModel(DivePlannerPointsModel::instance());
Improvement for various bits of the planner Rewrite of the actual planner logic. Now ascend to the next potential stop depth. There the state is cached and we try to ascend to the next stop depth. If we hit the ceiling while doing that we go back to the cached state and wait there for a minute. Then we try again. Then loop. Converted all depth related variables from unsigned int to int. During planning, in a time step the current depth can temporarily be negative and comparisons of a negative int with an unsigned it have not the result I expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we don’t really need the 32nd bit that unsigned buys us for depths. Deco stops are now shown in the same table as manually entered stops in boldface (I removed the second table to save screen estate). The gas shown in the table is still misleading as it means the gas used on the segment leading up to that event. The update of the profile only works partially upon changes in the list of available gases. Treatment of various gases is basically there but needs some more love. The ascent velocity is now provided by a function that takes the current depth as argument. Currently it always returns 10m/min but that will later be variable (and hopefully user configurable). The profile is not redrawn while deco is computed (avoiding an infinite recursion). The table got a new column for the duration of a segment while the old “duration” column was renamed “Runtime” to reflect what it actually shows. Currently, only the run time but not the duration are editable. All deco gases are used from the depth where their pO2 is 1.4bar. This should become more flexible. Calculation of the pressure drop in cylinders without configured volumes is suppressed. This solves a problem with the planner crashing when saving a dive where not all cylinders had been manually given a volume. [Short rant break: Treating 0/0 as air bites back at so many places. E.g. Cylinder data is initialized with memsetting the whole structures to 0. Then later suddenly this totally unconfigured cylinder is being treated as it would contain air. Maybe at some point this was a feature. But it lead to a naughty bug which took me over an hour to resolve. We should seriously reconsider this choice and better move to 209/0 being air if changing this everywhere is not too much trouble] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:54:55 +00:00
DivePlannerPointsModel::instance()->setRecalc(true);
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::GAS, new AirTypesDelegate(this));
ui.cylinderTableWidget->setTitle(tr("Available Gases"));
ui.cylinderTableWidget->setModel(CylindersModel::instance());
QTableView *view = ui.cylinderTableWidget->view();
view->setColumnHidden(CylindersModel::START, true);
view->setColumnHidden(CylindersModel::END, true);
view->setColumnHidden(CylindersModel::DEPTH, false);
view->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate(this));
connect(ui.cylinderTableWidget, SIGNAL(addButtonClicked()), DivePlannerPointsModel::instance(), SLOT(addCylinder_clicked()));
connect(ui.tableWidget, SIGNAL(addButtonClicked()), DivePlannerPointsModel::instance(), SLOT(addStop()));
connect(CylindersModel::instance(), SIGNAL(dataChanged(QModelIndex, QModelIndex)),
GasSelectionModel::instance(), SLOT(repopulate()));
connect(CylindersModel::instance(), SIGNAL(rowsInserted(QModelIndex, int, int)),
GasSelectionModel::instance(), SLOT(repopulate()));
connect(CylindersModel::instance(), SIGNAL(rowsRemoved(QModelIndex, int, int)),
GasSelectionModel::instance(), SLOT(repopulate()));
connect(CylindersModel::instance(), SIGNAL(dataChanged(QModelIndex, QModelIndex)),
plannerModel, SIGNAL(cylinderModelEdited()));
Improvement for various bits of the planner Rewrite of the actual planner logic. Now ascend to the next potential stop depth. There the state is cached and we try to ascend to the next stop depth. If we hit the ceiling while doing that we go back to the cached state and wait there for a minute. Then we try again. Then loop. Converted all depth related variables from unsigned int to int. During planning, in a time step the current depth can temporarily be negative and comparisons of a negative int with an unsigned it have not the result I expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we don’t really need the 32nd bit that unsigned buys us for depths. Deco stops are now shown in the same table as manually entered stops in boldface (I removed the second table to save screen estate). The gas shown in the table is still misleading as it means the gas used on the segment leading up to that event. The update of the profile only works partially upon changes in the list of available gases. Treatment of various gases is basically there but needs some more love. The ascent velocity is now provided by a function that takes the current depth as argument. Currently it always returns 10m/min but that will later be variable (and hopefully user configurable). The profile is not redrawn while deco is computed (avoiding an infinite recursion). The table got a new column for the duration of a segment while the old “duration” column was renamed “Runtime” to reflect what it actually shows. Currently, only the run time but not the duration are editable. All deco gases are used from the depth where their pO2 is 1.4bar. This should become more flexible. Calculation of the pressure drop in cylinders without configured volumes is suppressed. This solves a problem with the planner crashing when saving a dive where not all cylinders had been manually given a volume. [Short rant break: Treating 0/0 as air bites back at so many places. E.g. Cylinder data is initialized with memsetting the whole structures to 0. Then later suddenly this totally unconfigured cylinder is being treated as it would contain air. Maybe at some point this was a feature. But it lead to a naughty bug which took me over an hour to resolve. We should seriously reconsider this choice and better move to 209/0 being air if changing this everywhere is not too much trouble] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:54:55 +00:00
connect(CylindersModel::instance(), SIGNAL(rowsInserted(QModelIndex, int, int)),
plannerModel, SIGNAL(cylinderModelEdited()));
Improvement for various bits of the planner Rewrite of the actual planner logic. Now ascend to the next potential stop depth. There the state is cached and we try to ascend to the next stop depth. If we hit the ceiling while doing that we go back to the cached state and wait there for a minute. Then we try again. Then loop. Converted all depth related variables from unsigned int to int. During planning, in a time step the current depth can temporarily be negative and comparisons of a negative int with an unsigned it have not the result I expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we don’t really need the 32nd bit that unsigned buys us for depths. Deco stops are now shown in the same table as manually entered stops in boldface (I removed the second table to save screen estate). The gas shown in the table is still misleading as it means the gas used on the segment leading up to that event. The update of the profile only works partially upon changes in the list of available gases. Treatment of various gases is basically there but needs some more love. The ascent velocity is now provided by a function that takes the current depth as argument. Currently it always returns 10m/min but that will later be variable (and hopefully user configurable). The profile is not redrawn while deco is computed (avoiding an infinite recursion). The table got a new column for the duration of a segment while the old “duration” column was renamed “Runtime” to reflect what it actually shows. Currently, only the run time but not the duration are editable. All deco gases are used from the depth where their pO2 is 1.4bar. This should become more flexible. Calculation of the pressure drop in cylinders without configured volumes is suppressed. This solves a problem with the planner crashing when saving a dive where not all cylinders had been manually given a volume. [Short rant break: Treating 0/0 as air bites back at so many places. E.g. Cylinder data is initialized with memsetting the whole structures to 0. Then later suddenly this totally unconfigured cylinder is being treated as it would contain air. Maybe at some point this was a feature. But it lead to a naughty bug which took me over an hour to resolve. We should seriously reconsider this choice and better move to 209/0 being air if changing this everywhere is not too much trouble] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:54:55 +00:00
connect(CylindersModel::instance(), SIGNAL(rowsRemoved(QModelIndex, int, int)),
plannerModel, SIGNAL(cylinderModelEdited()));
ui.tableWidget->setBtnToolTip(tr("add dive data point"));
connect(ui.startTime, SIGNAL(timeChanged(QTime)), plannerModel, SLOT(setStartTime(QTime)));
connect(ui.dateEdit, SIGNAL(dateChanged(QDate)), plannerModel, SLOT(setStartDate(QDate)));
connect(ui.ATMPressure, SIGNAL(valueChanged(int)), this, SLOT(atmPressureChanged(int)));
connect(ui.atmHeight, SIGNAL(valueChanged(int)), this, SLOT(heightChanged(int)));
connect(DivePlannerPointsModel::instance(), SIGNAL(startTimeChanged(QDateTime)), this, SLOT(setupStartTime(QDateTime)));
// Creating (and canceling) the plan
connect(ui.buttonBox, SIGNAL(accepted()), plannerModel, SLOT(createPlan()));
connect(ui.buttonBox, SIGNAL(rejected()), plannerModel, SLOT(cancelPlan()));
QShortcut *closeKey = new QShortcut(QKeySequence(Qt::Key_Escape), this);
connect(closeKey, SIGNAL(activated()), plannerModel, SLOT(cancelPlan()));
/* set defaults. */
ui.ATMPressure->setValue(1013);
ui.atmHeight->setValue(0);
setMinimumWidth(0);
setMinimumHeight(0);
}
void DivePlannerWidget::setupStartTime(QDateTime startTime)
{
ui.startTime->setTime(startTime.time());
ui.dateEdit->setDate(startTime.date());
}
void DivePlannerWidget::settingsChanged()
{
// Adopt units
if (get_units()->length == units::FEET) {
ui.atmHeight->setSuffix("ft");
} else {
ui.atmHeight->setSuffix(("m"));
}
}
void DivePlannerPointsModel::addCylinder_clicked()
{
CylindersModel::instance()->add();
}
void DivePlannerWidget::atmPressureChanged(const int pressure)
{
plannerModel->setSurfacePressure(pressure);
ui.atmHeight->blockSignals(true);
ui.atmHeight->setValue((int) get_depth_units((int)(log(1013.0 / pressure) * 7800000), NULL,NULL));
ui.atmHeight->blockSignals(false);
}
void DivePlannerWidget::heightChanged(const int height)
{
int pressure = (int) (1013.0 * exp(- (double) units_to_depth((double) height) / 7800000.0));
ui.ATMPressure->blockSignals(true);
ui.ATMPressure->setValue(pressure);
ui.ATMPressure->blockSignals(false);
plannerModel->setSurfacePressure(pressure);
}
void PlannerSettingsWidget::bottomSacChanged(const int bottomSac)
{
plannerModel->setBottomSac(bottomSac);
}
void PlannerSettingsWidget::decoSacChanged(const int decosac)
{
plannerModel->setDecoSac(decosac);
}
void DivePlannerWidget::printDecoPlan()
{
MainWindow::instance()->printPlan();
}
PlannerSettingsWidget::PlannerSettingsWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
{
ui.setupUi(this);
ui.ascRate75->setValue(prefs.ascrate75 / UNIT_FACTOR);
ui.ascRate50->setValue(prefs.ascrate50 / UNIT_FACTOR);
ui.ascRateStops->setValue(prefs.ascratestops / UNIT_FACTOR);
ui.ascRateLast6m->setValue(prefs.ascratelast6m / UNIT_FACTOR);
ui.descRate->setValue(prefs.descrate / UNIT_FACTOR);
ui.bottompo2->setValue(prefs.bottompo2 / 1000.0);
ui.decopo2->setValue(prefs.decopo2 / 1000.0);
ui.backgasBreaks->setChecked(prefs.doo2breaks);
connect(ui.lastStop, SIGNAL(toggled(bool)), plannerModel, SLOT(setLastStop6m(bool)));
connect(ui.verbatim_plan, SIGNAL(toggled(bool)), plannerModel, SLOT(setVerbatim(bool)));
connect(ui.display_duration, SIGNAL(toggled(bool)), plannerModel, SLOT(setDisplayDuration(bool)));
connect(ui.display_runtime, SIGNAL(toggled(bool)), plannerModel, SLOT(setDisplayRuntime(bool)));
connect(ui.display_transitions, SIGNAL(toggled(bool)), plannerModel, SLOT(setDisplayTransitions(bool)));
connect(ui.ascRate75, SIGNAL(valueChanged(int)), this, SLOT(setAscRate75(int)));
connect(ui.ascRate75, SIGNAL(valueChanged(int)), plannerModel, SLOT(emitDataChanged()));
connect(ui.ascRate50, SIGNAL(valueChanged(int)), this, SLOT(setAscRate50(int)));
connect(ui.ascRate50, SIGNAL(valueChanged(int)), plannerModel, SLOT(emitDataChanged()));
connect(ui.ascRateStops, SIGNAL(valueChanged(int)), this, SLOT(setAscRateStops(int)));
connect(ui.ascRateStops, SIGNAL(valueChanged(int)), plannerModel, SLOT(emitDataChanged()));
connect(ui.ascRateLast6m, SIGNAL(valueChanged(int)), this, SLOT(setAscRateLast6m(int)));
connect(ui.ascRateLast6m, SIGNAL(valueChanged(int)), plannerModel, SLOT(emitDataChanged()));
connect(ui.descRate, SIGNAL(valueChanged(int)), this, SLOT(setDescRate(int)));
connect(ui.descRate, SIGNAL(valueChanged(int)), plannerModel, SLOT(emitDataChanged()));
connect(ui.bottompo2, SIGNAL(valueChanged(double)), this, SLOT(setBottomPo2(double)));
connect(ui.decopo2, SIGNAL(valueChanged(double)), this, SLOT(setDecoPo2(double)));
connect(ui.drop_stone_mode, SIGNAL(toggled(bool)), plannerModel, SLOT(setDropStoneMode(bool)));
connect(ui.bottomSAC, SIGNAL(valueChanged(int)), this, SLOT(bottomSacChanged(int)));
connect(ui.decoStopSAC, SIGNAL(valueChanged(int)), this, SLOT(decoSacChanged(int)));
connect(ui.gfhigh, SIGNAL(valueChanged(int)), plannerModel, SLOT(setGFHigh(int)));
connect(ui.gflow, SIGNAL(valueChanged(int)), plannerModel, SLOT(setGFLow(int)));
connect(ui.backgasBreaks, SIGNAL(toggled(bool)), this, SLOT(setBackgasBreaks(bool)));
ui.bottomSAC->setValue(20);
ui.decoStopSAC->setValue(17);
ui.gflow->setValue(prefs.gflow);
ui.gfhigh->setValue(prefs.gfhigh);
setMinimumWidth(0);
setMinimumHeight(0);
}
void PlannerSettingsWidget::settingsChanged()
{
if (get_units()->length == units::FEET) {
ui.ascRate75->setSuffix("ft/min");
ui.ascRate50->setSuffix("ft/min");
ui.ascRateStops->setSuffix("ft/min");
ui.ascRateLast6m->setSuffix("ft/min");
ui.descRate->setSuffix("ft/min");
ui.lastStop->setText(tr("Last stop at 20ft"));
} else {
ui.ascRate75->setSuffix("m/min");
ui.ascRate50->setSuffix("m/min");
ui.ascRateStops->setSuffix("m/min");
ui.ascRateLast6m->setSuffix("m/min");
ui.descRate->setSuffix("m/min");
ui.lastStop->setText(tr("Last stop at 6m"));
}
}
void PlannerSettingsWidget::atmPressureChanged(const QString &pressure)
{
}
void PlannerSettingsWidget::printDecoPlan()
{
}
void PlannerSettingsWidget::setAscRate75(int rate)
{
prefs.ascrate75 = rate * UNIT_FACTOR;
}
void PlannerSettingsWidget::setAscRate50(int rate)
{
prefs.ascrate50 = rate * UNIT_FACTOR;
}
void PlannerSettingsWidget::setAscRateStops(int rate)
{
prefs.ascratestops = rate * UNIT_FACTOR;
}
void PlannerSettingsWidget::setAscRateLast6m(int rate)
{
prefs.ascratelast6m = rate * UNIT_FACTOR;
}
void PlannerSettingsWidget::setDescRate(int rate)
{
prefs.descrate = rate * UNIT_FACTOR;
}
void PlannerSettingsWidget::setBottomPo2(double po2)
{
prefs.bottompo2 = (int) (po2 * 1000.0);
}
void PlannerSettingsWidget::setDecoPo2(double po2)
{
prefs.decopo2 = (int) (po2 * 1000.0);
}
void PlannerSettingsWidget::setBackgasBreaks(bool dobreaks)
{
prefs.doo2breaks = dobreaks;
}
void DivePlannerPointsModel::setPlanMode(Mode m)
{
mode = m;
// the planner may reset our GF settings that are used to show deco
// reset them to what's in the preferences
if (m != PLAN)
set_gf(prefs.gflow, prefs.gfhigh, prefs.gf_low_at_maxdepth);
}
bool DivePlannerPointsModel::isPlanner()
{
return mode == PLAN;
}
/* When the planner adds deco stops to the model, adding those should not trigger a new deco calculation.
* We thus start the planner only when recalc is true. */
Improvement for various bits of the planner Rewrite of the actual planner logic. Now ascend to the next potential stop depth. There the state is cached and we try to ascend to the next stop depth. If we hit the ceiling while doing that we go back to the cached state and wait there for a minute. Then we try again. Then loop. Converted all depth related variables from unsigned int to int. During planning, in a time step the current depth can temporarily be negative and comparisons of a negative int with an unsigned it have not the result I expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we don’t really need the 32nd bit that unsigned buys us for depths. Deco stops are now shown in the same table as manually entered stops in boldface (I removed the second table to save screen estate). The gas shown in the table is still misleading as it means the gas used on the segment leading up to that event. The update of the profile only works partially upon changes in the list of available gases. Treatment of various gases is basically there but needs some more love. The ascent velocity is now provided by a function that takes the current depth as argument. Currently it always returns 10m/min but that will later be variable (and hopefully user configurable). The profile is not redrawn while deco is computed (avoiding an infinite recursion). The table got a new column for the duration of a segment while the old “duration” column was renamed “Runtime” to reflect what it actually shows. Currently, only the run time but not the duration are editable. All deco gases are used from the depth where their pO2 is 1.4bar. This should become more flexible. Calculation of the pressure drop in cylinders without configured volumes is suppressed. This solves a problem with the planner crashing when saving a dive where not all cylinders had been manually given a volume. [Short rant break: Treating 0/0 as air bites back at so many places. E.g. Cylinder data is initialized with memsetting the whole structures to 0. Then later suddenly this totally unconfigured cylinder is being treated as it would contain air. Maybe at some point this was a feature. But it lead to a naughty bug which took me over an hour to resolve. We should seriously reconsider this choice and better move to 209/0 being air if changing this everywhere is not too much trouble] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:54:55 +00:00
bool DivePlannerPointsModel::setRecalc(bool rec)
{
bool old = recalc;
recalc = rec;
return old;
}
bool DivePlannerPointsModel::recalcQ()
{
return recalc;
}
int DivePlannerPointsModel::columnCount(const QModelIndex &parent) const
{
return COLUMNS;
}
QVariant DivePlannerPointsModel::data(const QModelIndex &index, int role) const
{
divedatapoint p = divepoints.at(index.row());
if (role == Qt::DisplayRole || role == Qt::EditRole) {
switch (index.column()) {
case CCSETPOINT:
return (double)p.po2 / 1000;
case DEPTH:
return rint(get_depth_units(p.depth, NULL, NULL));
Improvement for various bits of the planner Rewrite of the actual planner logic. Now ascend to the next potential stop depth. There the state is cached and we try to ascend to the next stop depth. If we hit the ceiling while doing that we go back to the cached state and wait there for a minute. Then we try again. Then loop. Converted all depth related variables from unsigned int to int. During planning, in a time step the current depth can temporarily be negative and comparisons of a negative int with an unsigned it have not the result I expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we don’t really need the 32nd bit that unsigned buys us for depths. Deco stops are now shown in the same table as manually entered stops in boldface (I removed the second table to save screen estate). The gas shown in the table is still misleading as it means the gas used on the segment leading up to that event. The update of the profile only works partially upon changes in the list of available gases. Treatment of various gases is basically there but needs some more love. The ascent velocity is now provided by a function that takes the current depth as argument. Currently it always returns 10m/min but that will later be variable (and hopefully user configurable). The profile is not redrawn while deco is computed (avoiding an infinite recursion). The table got a new column for the duration of a segment while the old “duration” column was renamed “Runtime” to reflect what it actually shows. Currently, only the run time but not the duration are editable. All deco gases are used from the depth where their pO2 is 1.4bar. This should become more flexible. Calculation of the pressure drop in cylinders without configured volumes is suppressed. This solves a problem with the planner crashing when saving a dive where not all cylinders had been manually given a volume. [Short rant break: Treating 0/0 as air bites back at so many places. E.g. Cylinder data is initialized with memsetting the whole structures to 0. Then later suddenly this totally unconfigured cylinder is being treated as it would contain air. Maybe at some point this was a feature. But it lead to a naughty bug which took me over an hour to resolve. We should seriously reconsider this choice and better move to 209/0 being air if changing this everywhere is not too much trouble] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:54:55 +00:00
case RUNTIME:
return p.time / 60;
Improvement for various bits of the planner Rewrite of the actual planner logic. Now ascend to the next potential stop depth. There the state is cached and we try to ascend to the next stop depth. If we hit the ceiling while doing that we go back to the cached state and wait there for a minute. Then we try again. Then loop. Converted all depth related variables from unsigned int to int. During planning, in a time step the current depth can temporarily be negative and comparisons of a negative int with an unsigned it have not the result I expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we don’t really need the 32nd bit that unsigned buys us for depths. Deco stops are now shown in the same table as manually entered stops in boldface (I removed the second table to save screen estate). The gas shown in the table is still misleading as it means the gas used on the segment leading up to that event. The update of the profile only works partially upon changes in the list of available gases. Treatment of various gases is basically there but needs some more love. The ascent velocity is now provided by a function that takes the current depth as argument. Currently it always returns 10m/min but that will later be variable (and hopefully user configurable). The profile is not redrawn while deco is computed (avoiding an infinite recursion). The table got a new column for the duration of a segment while the old “duration” column was renamed “Runtime” to reflect what it actually shows. Currently, only the run time but not the duration are editable. All deco gases are used from the depth where their pO2 is 1.4bar. This should become more flexible. Calculation of the pressure drop in cylinders without configured volumes is suppressed. This solves a problem with the planner crashing when saving a dive where not all cylinders had been manually given a volume. [Short rant break: Treating 0/0 as air bites back at so many places. E.g. Cylinder data is initialized with memsetting the whole structures to 0. Then later suddenly this totally unconfigured cylinder is being treated as it would contain air. Maybe at some point this was a feature. But it lead to a naughty bug which took me over an hour to resolve. We should seriously reconsider this choice and better move to 209/0 being air if changing this everywhere is not too much trouble] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:54:55 +00:00
case DURATION:
if (index.row())
return (p.time - divepoints.at(index.row() - 1).time) / 60;
Improvement for various bits of the planner Rewrite of the actual planner logic. Now ascend to the next potential stop depth. There the state is cached and we try to ascend to the next stop depth. If we hit the ceiling while doing that we go back to the cached state and wait there for a minute. Then we try again. Then loop. Converted all depth related variables from unsigned int to int. During planning, in a time step the current depth can temporarily be negative and comparisons of a negative int with an unsigned it have not the result I expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we don’t really need the 32nd bit that unsigned buys us for depths. Deco stops are now shown in the same table as manually entered stops in boldface (I removed the second table to save screen estate). The gas shown in the table is still misleading as it means the gas used on the segment leading up to that event. The update of the profile only works partially upon changes in the list of available gases. Treatment of various gases is basically there but needs some more love. The ascent velocity is now provided by a function that takes the current depth as argument. Currently it always returns 10m/min but that will later be variable (and hopefully user configurable). The profile is not redrawn while deco is computed (avoiding an infinite recursion). The table got a new column for the duration of a segment while the old “duration” column was renamed “Runtime” to reflect what it actually shows. Currently, only the run time but not the duration are editable. All deco gases are used from the depth where their pO2 is 1.4bar. This should become more flexible. Calculation of the pressure drop in cylinders without configured volumes is suppressed. This solves a problem with the planner crashing when saving a dive where not all cylinders had been manually given a volume. [Short rant break: Treating 0/0 as air bites back at so many places. E.g. Cylinder data is initialized with memsetting the whole structures to 0. Then later suddenly this totally unconfigured cylinder is being treated as it would contain air. Maybe at some point this was a feature. But it lead to a naughty bug which took me over an hour to resolve. We should seriously reconsider this choice and better move to 209/0 being air if changing this everywhere is not too much trouble] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:54:55 +00:00
else
return p.time / 60;
case GAS:
return dpGasToStr(p);
}
} else if (role == Qt::DecorationRole) {
switch (index.column()) {
case REMOVE:
return p.entered ? QIcon(":trash") : QVariant();
}
} else if (role == Qt::FontRole) {
Improvement for various bits of the planner Rewrite of the actual planner logic. Now ascend to the next potential stop depth. There the state is cached and we try to ascend to the next stop depth. If we hit the ceiling while doing that we go back to the cached state and wait there for a minute. Then we try again. Then loop. Converted all depth related variables from unsigned int to int. During planning, in a time step the current depth can temporarily be negative and comparisons of a negative int with an unsigned it have not the result I expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we don’t really need the 32nd bit that unsigned buys us for depths. Deco stops are now shown in the same table as manually entered stops in boldface (I removed the second table to save screen estate). The gas shown in the table is still misleading as it means the gas used on the segment leading up to that event. The update of the profile only works partially upon changes in the list of available gases. Treatment of various gases is basically there but needs some more love. The ascent velocity is now provided by a function that takes the current depth as argument. Currently it always returns 10m/min but that will later be variable (and hopefully user configurable). The profile is not redrawn while deco is computed (avoiding an infinite recursion). The table got a new column for the duration of a segment while the old “duration” column was renamed “Runtime” to reflect what it actually shows. Currently, only the run time but not the duration are editable. All deco gases are used from the depth where their pO2 is 1.4bar. This should become more flexible. Calculation of the pressure drop in cylinders without configured volumes is suppressed. This solves a problem with the planner crashing when saving a dive where not all cylinders had been manually given a volume. [Short rant break: Treating 0/0 as air bites back at so many places. E.g. Cylinder data is initialized with memsetting the whole structures to 0. Then later suddenly this totally unconfigured cylinder is being treated as it would contain air. Maybe at some point this was a feature. But it lead to a naughty bug which took me over an hour to resolve. We should seriously reconsider this choice and better move to 209/0 being air if changing this everywhere is not too much trouble] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:54:55 +00:00
if (divepoints.at(index.row()).entered) {
return defaultModelFont();
} else {
QFont font = defaultModelFont();
font.setBold(true);
return font;
}
}
return QVariant();
}
bool DivePlannerPointsModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
struct gasmix gas = { 0 };
int i, shift;
if (role == Qt::EditRole) {
divedatapoint &p = divepoints[index.row()];
switch (index.column()) {
case DEPTH:
p.depth = units_to_depth(value.toInt());
break;
Improvement for various bits of the planner Rewrite of the actual planner logic. Now ascend to the next potential stop depth. There the state is cached and we try to ascend to the next stop depth. If we hit the ceiling while doing that we go back to the cached state and wait there for a minute. Then we try again. Then loop. Converted all depth related variables from unsigned int to int. During planning, in a time step the current depth can temporarily be negative and comparisons of a negative int with an unsigned it have not the result I expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we don’t really need the 32nd bit that unsigned buys us for depths. Deco stops are now shown in the same table as manually entered stops in boldface (I removed the second table to save screen estate). The gas shown in the table is still misleading as it means the gas used on the segment leading up to that event. The update of the profile only works partially upon changes in the list of available gases. Treatment of various gases is basically there but needs some more love. The ascent velocity is now provided by a function that takes the current depth as argument. Currently it always returns 10m/min but that will later be variable (and hopefully user configurable). The profile is not redrawn while deco is computed (avoiding an infinite recursion). The table got a new column for the duration of a segment while the old “duration” column was renamed “Runtime” to reflect what it actually shows. Currently, only the run time but not the duration are editable. All deco gases are used from the depth where their pO2 is 1.4bar. This should become more flexible. Calculation of the pressure drop in cylinders without configured volumes is suppressed. This solves a problem with the planner crashing when saving a dive where not all cylinders had been manually given a volume. [Short rant break: Treating 0/0 as air bites back at so many places. E.g. Cylinder data is initialized with memsetting the whole structures to 0. Then later suddenly this totally unconfigured cylinder is being treated as it would contain air. Maybe at some point this was a feature. But it lead to a naughty bug which took me over an hour to resolve. We should seriously reconsider this choice and better move to 209/0 being air if changing this everywhere is not too much trouble] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:54:55 +00:00
case RUNTIME:
p.time = value.toInt() * 60;
break;
Improvement for various bits of the planner Rewrite of the actual planner logic. Now ascend to the next potential stop depth. There the state is cached and we try to ascend to the next stop depth. If we hit the ceiling while doing that we go back to the cached state and wait there for a minute. Then we try again. Then loop. Converted all depth related variables from unsigned int to int. During planning, in a time step the current depth can temporarily be negative and comparisons of a negative int with an unsigned it have not the result I expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we don’t really need the 32nd bit that unsigned buys us for depths. Deco stops are now shown in the same table as manually entered stops in boldface (I removed the second table to save screen estate). The gas shown in the table is still misleading as it means the gas used on the segment leading up to that event. The update of the profile only works partially upon changes in the list of available gases. Treatment of various gases is basically there but needs some more love. The ascent velocity is now provided by a function that takes the current depth as argument. Currently it always returns 10m/min but that will later be variable (and hopefully user configurable). The profile is not redrawn while deco is computed (avoiding an infinite recursion). The table got a new column for the duration of a segment while the old “duration” column was renamed “Runtime” to reflect what it actually shows. Currently, only the run time but not the duration are editable. All deco gases are used from the depth where their pO2 is 1.4bar. This should become more flexible. Calculation of the pressure drop in cylinders without configured volumes is suppressed. This solves a problem with the planner crashing when saving a dive where not all cylinders had been manually given a volume. [Short rant break: Treating 0/0 as air bites back at so many places. E.g. Cylinder data is initialized with memsetting the whole structures to 0. Then later suddenly this totally unconfigured cylinder is being treated as it would contain air. Maybe at some point this was a feature. But it lead to a naughty bug which took me over an hour to resolve. We should seriously reconsider this choice and better move to 209/0 being air if changing this everywhere is not too much trouble] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:54:55 +00:00
case DURATION:
i = index.row();
if (i)
shift = divepoints[i].time - divepoints[i - 1].time - value.toInt() * 60;
Improvement for various bits of the planner Rewrite of the actual planner logic. Now ascend to the next potential stop depth. There the state is cached and we try to ascend to the next stop depth. If we hit the ceiling while doing that we go back to the cached state and wait there for a minute. Then we try again. Then loop. Converted all depth related variables from unsigned int to int. During planning, in a time step the current depth can temporarily be negative and comparisons of a negative int with an unsigned it have not the result I expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we don’t really need the 32nd bit that unsigned buys us for depths. Deco stops are now shown in the same table as manually entered stops in boldface (I removed the second table to save screen estate). The gas shown in the table is still misleading as it means the gas used on the segment leading up to that event. The update of the profile only works partially upon changes in the list of available gases. Treatment of various gases is basically there but needs some more love. The ascent velocity is now provided by a function that takes the current depth as argument. Currently it always returns 10m/min but that will later be variable (and hopefully user configurable). The profile is not redrawn while deco is computed (avoiding an infinite recursion). The table got a new column for the duration of a segment while the old “duration” column was renamed “Runtime” to reflect what it actually shows. Currently, only the run time but not the duration are editable. All deco gases are used from the depth where their pO2 is 1.4bar. This should become more flexible. Calculation of the pressure drop in cylinders without configured volumes is suppressed. This solves a problem with the planner crashing when saving a dive where not all cylinders had been manually given a volume. [Short rant break: Treating 0/0 as air bites back at so many places. E.g. Cylinder data is initialized with memsetting the whole structures to 0. Then later suddenly this totally unconfigured cylinder is being treated as it would contain air. Maybe at some point this was a feature. But it lead to a naughty bug which took me over an hour to resolve. We should seriously reconsider this choice and better move to 209/0 being air if changing this everywhere is not too much trouble] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:54:55 +00:00
else
shift = divepoints[i].time - value.toInt() * 60;
while (i < divepoints.size())
divepoints[i++].time -= shift;
Improvement for various bits of the planner Rewrite of the actual planner logic. Now ascend to the next potential stop depth. There the state is cached and we try to ascend to the next stop depth. If we hit the ceiling while doing that we go back to the cached state and wait there for a minute. Then we try again. Then loop. Converted all depth related variables from unsigned int to int. During planning, in a time step the current depth can temporarily be negative and comparisons of a negative int with an unsigned it have not the result I expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we don’t really need the 32nd bit that unsigned buys us for depths. Deco stops are now shown in the same table as manually entered stops in boldface (I removed the second table to save screen estate). The gas shown in the table is still misleading as it means the gas used on the segment leading up to that event. The update of the profile only works partially upon changes in the list of available gases. Treatment of various gases is basically there but needs some more love. The ascent velocity is now provided by a function that takes the current depth as argument. Currently it always returns 10m/min but that will later be variable (and hopefully user configurable). The profile is not redrawn while deco is computed (avoiding an infinite recursion). The table got a new column for the duration of a segment while the old “duration” column was renamed “Runtime” to reflect what it actually shows. Currently, only the run time but not the duration are editable. All deco gases are used from the depth where their pO2 is 1.4bar. This should become more flexible. Calculation of the pressure drop in cylinders without configured volumes is suppressed. This solves a problem with the planner crashing when saving a dive where not all cylinders had been manually given a volume. [Short rant break: Treating 0/0 as air bites back at so many places. E.g. Cylinder data is initialized with memsetting the whole structures to 0. Then later suddenly this totally unconfigured cylinder is being treated as it would contain air. Maybe at some point this was a feature. But it lead to a naughty bug which took me over an hour to resolve. We should seriously reconsider this choice and better move to 209/0 being air if changing this everywhere is not too much trouble] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:54:55 +00:00
break;
case CCSETPOINT: {
int po2 = 0;
QByteArray gasv = value.toByteArray();
if (validate_po2(gasv.data(), &po2))
p.po2 = po2;
} break;
case GAS:
QByteArray gasv = value.toByteArray();
if (validate_gas(gasv.data(), &gas))
p.gasmix = gas;
break;
}
editStop(index.row(), p);
}
return QAbstractItemModel::setData(index, value, role);
}
QVariant DivePlannerPointsModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
switch (section) {
case DEPTH:
return tr("Final Depth");
Improvement for various bits of the planner Rewrite of the actual planner logic. Now ascend to the next potential stop depth. There the state is cached and we try to ascend to the next stop depth. If we hit the ceiling while doing that we go back to the cached state and wait there for a minute. Then we try again. Then loop. Converted all depth related variables from unsigned int to int. During planning, in a time step the current depth can temporarily be negative and comparisons of a negative int with an unsigned it have not the result I expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we don’t really need the 32nd bit that unsigned buys us for depths. Deco stops are now shown in the same table as manually entered stops in boldface (I removed the second table to save screen estate). The gas shown in the table is still misleading as it means the gas used on the segment leading up to that event. The update of the profile only works partially upon changes in the list of available gases. Treatment of various gases is basically there but needs some more love. The ascent velocity is now provided by a function that takes the current depth as argument. Currently it always returns 10m/min but that will later be variable (and hopefully user configurable). The profile is not redrawn while deco is computed (avoiding an infinite recursion). The table got a new column for the duration of a segment while the old “duration” column was renamed “Runtime” to reflect what it actually shows. Currently, only the run time but not the duration are editable. All deco gases are used from the depth where their pO2 is 1.4bar. This should become more flexible. Calculation of the pressure drop in cylinders without configured volumes is suppressed. This solves a problem with the planner crashing when saving a dive where not all cylinders had been manually given a volume. [Short rant break: Treating 0/0 as air bites back at so many places. E.g. Cylinder data is initialized with memsetting the whole structures to 0. Then later suddenly this totally unconfigured cylinder is being treated as it would contain air. Maybe at some point this was a feature. But it lead to a naughty bug which took me over an hour to resolve. We should seriously reconsider this choice and better move to 209/0 being air if changing this everywhere is not too much trouble] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:54:55 +00:00
case RUNTIME:
return tr("Run time");
case DURATION:
return tr("Duration");
case GAS:
return tr("Used Gas");
case CCSETPOINT:
return tr("CC Set Point");
}
} else if (role == Qt::FontRole) {
return defaultModelFont();
}
return QVariant();
}
Qt::ItemFlags DivePlannerPointsModel::flags(const QModelIndex &index) const
{
if (index.column() != REMOVE)
Improvement for various bits of the planner Rewrite of the actual planner logic. Now ascend to the next potential stop depth. There the state is cached and we try to ascend to the next stop depth. If we hit the ceiling while doing that we go back to the cached state and wait there for a minute. Then we try again. Then loop. Converted all depth related variables from unsigned int to int. During planning, in a time step the current depth can temporarily be negative and comparisons of a negative int with an unsigned it have not the result I expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we don’t really need the 32nd bit that unsigned buys us for depths. Deco stops are now shown in the same table as manually entered stops in boldface (I removed the second table to save screen estate). The gas shown in the table is still misleading as it means the gas used on the segment leading up to that event. The update of the profile only works partially upon changes in the list of available gases. Treatment of various gases is basically there but needs some more love. The ascent velocity is now provided by a function that takes the current depth as argument. Currently it always returns 10m/min but that will later be variable (and hopefully user configurable). The profile is not redrawn while deco is computed (avoiding an infinite recursion). The table got a new column for the duration of a segment while the old “duration” column was renamed “Runtime” to reflect what it actually shows. Currently, only the run time but not the duration are editable. All deco gases are used from the depth where their pO2 is 1.4bar. This should become more flexible. Calculation of the pressure drop in cylinders without configured volumes is suppressed. This solves a problem with the planner crashing when saving a dive where not all cylinders had been manually given a volume. [Short rant break: Treating 0/0 as air bites back at so many places. E.g. Cylinder data is initialized with memsetting the whole structures to 0. Then later suddenly this totally unconfigured cylinder is being treated as it would contain air. Maybe at some point this was a feature. But it lead to a naughty bug which took me over an hour to resolve. We should seriously reconsider this choice and better move to 209/0 being air if changing this everywhere is not too much trouble] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:54:55 +00:00
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
else
return QAbstractItemModel::flags(index);
}
int DivePlannerPointsModel::rowCount(const QModelIndex &parent) const
{
return divepoints.count();
}
DivePlannerPointsModel::DivePlannerPointsModel(QObject *parent) : QAbstractTableModel(parent), mode(NOTHING), drop_stone_mode(false)
{
memset(&diveplan, 0, sizeof(diveplan));
memset(&backupDive, 0, sizeof(backupDive));
startTime = QDateTime::currentDateTimeUtc();
}
DivePlannerPointsModel *DivePlannerPointsModel::instance()
{
static QScopedPointer<DivePlannerPointsModel> self(new DivePlannerPointsModel());
return self.data();
}
void DivePlannerPointsModel::emitDataChanged()
{
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
}
void DivePlannerPointsModel::setBottomSac(int sac)
{
diveplan.bottomsac = sac * 1000;
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
}
void DivePlannerPointsModel::setDecoSac(int sac)
{
diveplan.decosac = sac * 1000;
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
}
void DivePlannerPointsModel::setGFHigh(const int gfhigh)
{
diveplan.gfhigh = gfhigh;
plannerModel->emitDataChanged();
}
void DivePlannerPointsModel::setGFLow(const int ghflow)
{
diveplan.gflow = ghflow;
plannerModel->emitDataChanged();
}
void DivePlannerPointsModel::setSurfacePressure(int pressure)
{
diveplan.surface_pressure = pressure;
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
}
void DivePlannerPointsModel::setLastStop6m(bool value)
{
set_last_stop(value);
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
}
void DivePlannerPointsModel::setVerbatim(bool value)
{
set_verbatim(value);
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
}
void DivePlannerPointsModel::setDisplayRuntime(bool value)
{
set_display_runtime(value);
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
}
void DivePlannerPointsModel::setDisplayDuration(bool value)
{
set_display_duration(value);
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
}
void DivePlannerPointsModel::setDisplayTransitions(bool value)
{
set_display_transitions(value);
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
}
void DivePlannerPointsModel::setDropStoneMode(bool value)
{
drop_stone_mode = value;
if (drop_stone_mode) {
/* Remove the first entry if we enable drop_stone_mode */
if (rowCount() >= 2) {
beginRemoveRows(QModelIndex(), 0, 0);
divepoints.remove(0);
endRemoveRows();
}
} else {
/* Add a first entry if we disable drop_stone_mode */
beginInsertRows(QModelIndex(), 0, 0);
/* Copy the first current point */
divedatapoint p = divepoints.at(0);
p.time = p.depth / prefs.descrate;
divepoints.push_front(p);
endInsertRows();
}
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
}
void DivePlannerPointsModel::setStartDate(const QDate &date)
{
startTime.setDate(date);
diveplan.when = startTime.toTime_t();
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
}
void DivePlannerPointsModel::setStartTime(const QTime &t)
{
startTime.setTime(t);
diveplan.when = startTime.toTime_t();
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
}
bool divePointsLessThan(const divedatapoint &p1, const divedatapoint &p2)
{
return p1.time <= p2.time;
}
bool DivePlannerPointsModel::addGas(struct gasmix mix)
{
sanitize_gasmix(&mix);
for (int i = 0; i < MAX_CYLINDERS; i++) {
cylinder_t *cyl = &displayed_dive.cylinder[i];
if (cylinder_nodata(cyl)) {
fill_default_cylinder(cyl);
cyl->gasmix = mix;
/* The depth to change to that gas is given by the depth where its pO₂ is 1.6 bar.
* The user should be able to change this depth manually. */
pressure_t modpO2;
modpO2.mbar = prefs.decopo2;
cyl->depth = gas_mod(&mix, modpO2, M_OR_FT(3,10));
// FIXME -- need to get rid of stagingDIve
// the following now uses displayed_dive !!!!
CylindersModel::instance()->updateDive();
return true;
}
if (!gasmix_distance(&cyl->gasmix, &mix))
return true;
}
qDebug("too many gases");
return false;
}
Improvement for various bits of the planner Rewrite of the actual planner logic. Now ascend to the next potential stop depth. There the state is cached and we try to ascend to the next stop depth. If we hit the ceiling while doing that we go back to the cached state and wait there for a minute. Then we try again. Then loop. Converted all depth related variables from unsigned int to int. During planning, in a time step the current depth can temporarily be negative and comparisons of a negative int with an unsigned it have not the result I expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we don’t really need the 32nd bit that unsigned buys us for depths. Deco stops are now shown in the same table as manually entered stops in boldface (I removed the second table to save screen estate). The gas shown in the table is still misleading as it means the gas used on the segment leading up to that event. The update of the profile only works partially upon changes in the list of available gases. Treatment of various gases is basically there but needs some more love. The ascent velocity is now provided by a function that takes the current depth as argument. Currently it always returns 10m/min but that will later be variable (and hopefully user configurable). The profile is not redrawn while deco is computed (avoiding an infinite recursion). The table got a new column for the duration of a segment while the old “duration” column was renamed “Runtime” to reflect what it actually shows. Currently, only the run time but not the duration are editable. All deco gases are used from the depth where their pO2 is 1.4bar. This should become more flexible. Calculation of the pressure drop in cylinders without configured volumes is suppressed. This solves a problem with the planner crashing when saving a dive where not all cylinders had been manually given a volume. [Short rant break: Treating 0/0 as air bites back at so many places. E.g. Cylinder data is initialized with memsetting the whole structures to 0. Then later suddenly this totally unconfigured cylinder is being treated as it would contain air. Maybe at some point this was a feature. But it lead to a naughty bug which took me over an hour to resolve. We should seriously reconsider this choice and better move to 209/0 being air if changing this everywhere is not too much trouble] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:54:55 +00:00
int DivePlannerPointsModel::lastEnteredPoint()
{
for (int i = divepoints.count() - 1; i >= 0; i--)
Improvement for various bits of the planner Rewrite of the actual planner logic. Now ascend to the next potential stop depth. There the state is cached and we try to ascend to the next stop depth. If we hit the ceiling while doing that we go back to the cached state and wait there for a minute. Then we try again. Then loop. Converted all depth related variables from unsigned int to int. During planning, in a time step the current depth can temporarily be negative and comparisons of a negative int with an unsigned it have not the result I expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we don’t really need the 32nd bit that unsigned buys us for depths. Deco stops are now shown in the same table as manually entered stops in boldface (I removed the second table to save screen estate). The gas shown in the table is still misleading as it means the gas used on the segment leading up to that event. The update of the profile only works partially upon changes in the list of available gases. Treatment of various gases is basically there but needs some more love. The ascent velocity is now provided by a function that takes the current depth as argument. Currently it always returns 10m/min but that will later be variable (and hopefully user configurable). The profile is not redrawn while deco is computed (avoiding an infinite recursion). The table got a new column for the duration of a segment while the old “duration” column was renamed “Runtime” to reflect what it actually shows. Currently, only the run time but not the duration are editable. All deco gases are used from the depth where their pO2 is 1.4bar. This should become more flexible. Calculation of the pressure drop in cylinders without configured volumes is suppressed. This solves a problem with the planner crashing when saving a dive where not all cylinders had been manually given a volume. [Short rant break: Treating 0/0 as air bites back at so many places. E.g. Cylinder data is initialized with memsetting the whole structures to 0. Then later suddenly this totally unconfigured cylinder is being treated as it would contain air. Maybe at some point this was a feature. But it lead to a naughty bug which took me over an hour to resolve. We should seriously reconsider this choice and better move to 209/0 being air if changing this everywhere is not too much trouble] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:54:55 +00:00
if (divepoints.at(i).entered)
return i;
return -1;
}
int DivePlannerPointsModel::addStop(int milimeters, int seconds, gasmix *gas_in, int ccpoint, bool entered)
{
struct gasmix air = { 0 };
struct gasmix gas = { 0 };
bool usePrevious = false;
if (gas_in)
gas = *gas_in;
else
usePrevious = true;
if (recalcQ())
removeDeco();
int row = divepoints.count();
if (seconds == 0 && milimeters == 0 && row != 0) {
/* this is only possible if the user clicked on the 'plus' sign on the DivePoints Table */
Improvement for various bits of the planner Rewrite of the actual planner logic. Now ascend to the next potential stop depth. There the state is cached and we try to ascend to the next stop depth. If we hit the ceiling while doing that we go back to the cached state and wait there for a minute. Then we try again. Then loop. Converted all depth related variables from unsigned int to int. During planning, in a time step the current depth can temporarily be negative and comparisons of a negative int with an unsigned it have not the result I expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we don’t really need the 32nd bit that unsigned buys us for depths. Deco stops are now shown in the same table as manually entered stops in boldface (I removed the second table to save screen estate). The gas shown in the table is still misleading as it means the gas used on the segment leading up to that event. The update of the profile only works partially upon changes in the list of available gases. Treatment of various gases is basically there but needs some more love. The ascent velocity is now provided by a function that takes the current depth as argument. Currently it always returns 10m/min but that will later be variable (and hopefully user configurable). The profile is not redrawn while deco is computed (avoiding an infinite recursion). The table got a new column for the duration of a segment while the old “duration” column was renamed “Runtime” to reflect what it actually shows. Currently, only the run time but not the duration are editable. All deco gases are used from the depth where their pO2 is 1.4bar. This should become more flexible. Calculation of the pressure drop in cylinders without configured volumes is suppressed. This solves a problem with the planner crashing when saving a dive where not all cylinders had been manually given a volume. [Short rant break: Treating 0/0 as air bites back at so many places. E.g. Cylinder data is initialized with memsetting the whole structures to 0. Then later suddenly this totally unconfigured cylinder is being treated as it would contain air. Maybe at some point this was a feature. But it lead to a naughty bug which took me over an hour to resolve. We should seriously reconsider this choice and better move to 209/0 being air if changing this everywhere is not too much trouble] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:54:55 +00:00
const divedatapoint t = divepoints.at(lastEnteredPoint());
milimeters = t.depth;
seconds = t.time + 600; // 10 minutes.
gas = t.gasmix;
ccpoint = t.po2;
} else if (seconds == 0 && milimeters == 0 && row == 0) {
milimeters = M_OR_FT(5, 15); // 5m / 15ft
seconds = 600; // 10 min
//Default to the first defined gas, if we got one.
cylinder_t *cyl = &displayed_dive.cylinder[0];
if (cyl)
gas = cyl->gasmix;
}
if (!usePrevious)
if (!addGas(gas))
qDebug("addGas failed"); // FIXME add error propagation
// check if there's already a new stop before this one:
for (int i = 0; i < row; i++) {
const divedatapoint &dp = divepoints.at(i);
if (dp.time == seconds) {
row = i;
beginRemoveRows(QModelIndex(), row, row);
divepoints.remove(row);
endRemoveRows();
break;
}
if (dp.time > seconds) {
row = i;
break;
}
}
if (usePrevious) {
if (row > 0) {
gas = divepoints.at(row - 1).gasmix;
} else {
// when we add a first data point we need to make sure that there is a
// tank for it to use;
// first check to the right, then to the left, but if there's nothing,
// we simply default to AIR
if (row < divepoints.count()) {
gas = divepoints.at(row).gasmix;
} else {
if (!addGas(air))
qDebug("addGas failed"); // FIXME add error propagation
}
}
}
// add the new stop
beginInsertRows(QModelIndex(), row, row);
divedatapoint point;
point.depth = milimeters;
point.time = seconds;
point.gasmix = gas;
point.po2 = ccpoint;
point.entered = entered;
point.next = NULL;
divepoints.append(point);
std::sort(divepoints.begin(), divepoints.end(), divePointsLessThan);
endInsertRows();
return row;
}
void DivePlannerPointsModel::editStop(int row, divedatapoint newData)
{
divepoints[row] = newData;
std::sort(divepoints.begin(), divepoints.end(), divePointsLessThan);
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
}
int DivePlannerPointsModel::size()
{
return divepoints.size();
}
divedatapoint DivePlannerPointsModel::at(int row)
{
return divepoints.at(row);
}
void DivePlannerPointsModel::remove(const QModelIndex &index)
{
if (index.column() != REMOVE)
return;
divedatapoint dp = at(index.row());
if (!dp.entered)
return;
beginRemoveRows(QModelIndex(), index.row(), index.row());
divepoints.remove(index.row());
endRemoveRows();
}
struct diveplan &DivePlannerPointsModel::getDiveplan()
{
return diveplan;
}
void DivePlannerPointsModel::cancelPlan()
{
if (mode == PLAN && rowCount()) {
if (QMessageBox::warning(MainWindow::instance(), TITLE_OR_TEXT(tr("Discard the Plan?"),
tr("You are about to discard your plan.")),
QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard) != QMessageBox::Discard) {
return;
}
}
setPlanMode(NOTHING);
diveplan.dp = NULL;
// somewhere, somehow we need to make sure that the current_dive is displayed again
emit planCanceled();
}
DivePlannerPointsModel::Mode DivePlannerPointsModel::currentMode() const
{
return mode;
}
QVector<QPair<int, int> > DivePlannerPointsModel::collectGases(struct dive *d)
{
QVector<QPair<int, int> > l;
for (int i = 0; i < MAX_CYLINDERS; i++) {
cylinder_t *cyl = &d->cylinder[i];
if (!cylinder_nodata(cyl))
l.push_back(qMakePair(get_o2(&cyl->gasmix), get_he(&cyl->gasmix)));
}
return l;
}
void DivePlannerPointsModel::rememberTanks()
{
oldGases = collectGases(&displayed_dive);
}
bool DivePlannerPointsModel::tankInUse(struct gasmix gasmix)
{
for (int j = 0; j < rowCount(); j++) {
divedatapoint &p = divepoints[j];
if (p.time == 0) // special entries that hold the available gases
continue;
Improvement for various bits of the planner Rewrite of the actual planner logic. Now ascend to the next potential stop depth. There the state is cached and we try to ascend to the next stop depth. If we hit the ceiling while doing that we go back to the cached state and wait there for a minute. Then we try again. Then loop. Converted all depth related variables from unsigned int to int. During planning, in a time step the current depth can temporarily be negative and comparisons of a negative int with an unsigned it have not the result I expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we don’t really need the 32nd bit that unsigned buys us for depths. Deco stops are now shown in the same table as manually entered stops in boldface (I removed the second table to save screen estate). The gas shown in the table is still misleading as it means the gas used on the segment leading up to that event. The update of the profile only works partially upon changes in the list of available gases. Treatment of various gases is basically there but needs some more love. The ascent velocity is now provided by a function that takes the current depth as argument. Currently it always returns 10m/min but that will later be variable (and hopefully user configurable). The profile is not redrawn while deco is computed (avoiding an infinite recursion). The table got a new column for the duration of a segment while the old “duration” column was renamed “Runtime” to reflect what it actually shows. Currently, only the run time but not the duration are editable. All deco gases are used from the depth where their pO2 is 1.4bar. This should become more flexible. Calculation of the pressure drop in cylinders without configured volumes is suppressed. This solves a problem with the planner crashing when saving a dive where not all cylinders had been manually given a volume. [Short rant break: Treating 0/0 as air bites back at so many places. E.g. Cylinder data is initialized with memsetting the whole structures to 0. Then later suddenly this totally unconfigured cylinder is being treated as it would contain air. Maybe at some point this was a feature. But it lead to a naughty bug which took me over an hour to resolve. We should seriously reconsider this choice and better move to 209/0 being air if changing this everywhere is not too much trouble] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:54:55 +00:00
if (!p.entered) // removing deco gases is ok
continue;
if (gasmix_distance(&p.gasmix, &gasmix) < 200)
return true;
}
return false;
}
void DivePlannerPointsModel::tanksUpdated()
{
// we don't know exactly what changed - what we care about is
// "did a gas change on us". So we look through the diveplan to
// see if there is a gas that is now missing and if there is, we
// replace it with the matching new gas.
QVector<QPair<int, int> > gases = collectGases(&displayed_dive);
if (gases.count() == oldGases.count()) {
// either nothing relevant changed, or exactly ONE gasmix changed
for (int i = 0; i < gases.count(); i++) {
if (gases.at(i) != oldGases.at(i)) {
if (oldGases.count(oldGases.at(i)) > 1) {
// we had this gas more than once, so don't
// change segments that used this gas as it still exists
break;
}
for (int j = 0; j < rowCount(); j++) {
divedatapoint &p = divepoints[j];
struct gasmix gas;
gas.o2.permille = oldGases.at(i).first;
gas.he.permille = oldGases.at(i).second;
if (gasmix_distance(&gas, &p.gasmix) < 200) {
p.gasmix.o2.permille = gases.at(i).first;
p.gasmix.he.permille = gases.at(i).second;
}
}
break;
}
}
}
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
}
void DivePlannerPointsModel::clear()
{
bool oldRecalc = setRecalc(false);
CylindersModel::instance()->updateDive();
if (rowCount() > 0) {
beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
divepoints.clear();
endRemoveRows();
}
CylindersModel::instance()->clear();
setRecalc(oldRecalc);
}
void DivePlannerPointsModel::createTemporaryPlan()
{
// Get the user-input and calculate the dive info
diveplan.dp = NULL;
int lastIndex = -1;
for (int i = 0; i < rowCount(); i++) {
divedatapoint p = at(i);
int deltaT = lastIndex != -1 ? p.time - at(lastIndex).time : p.time;
lastIndex = i;
if (i == 0 && drop_stone_mode) {
/* Okay, we add a fist segment where we go down to depth */
plan_add_segment(&diveplan, p.depth / prefs.descrate, p.depth, p.gasmix, p.po2, false);
deltaT -= p.depth / prefs.descrate;
}
Improvement for various bits of the planner Rewrite of the actual planner logic. Now ascend to the next potential stop depth. There the state is cached and we try to ascend to the next stop depth. If we hit the ceiling while doing that we go back to the cached state and wait there for a minute. Then we try again. Then loop. Converted all depth related variables from unsigned int to int. During planning, in a time step the current depth can temporarily be negative and comparisons of a negative int with an unsigned it have not the result I expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we don’t really need the 32nd bit that unsigned buys us for depths. Deco stops are now shown in the same table as manually entered stops in boldface (I removed the second table to save screen estate). The gas shown in the table is still misleading as it means the gas used on the segment leading up to that event. The update of the profile only works partially upon changes in the list of available gases. Treatment of various gases is basically there but needs some more love. The ascent velocity is now provided by a function that takes the current depth as argument. Currently it always returns 10m/min but that will later be variable (and hopefully user configurable). The profile is not redrawn while deco is computed (avoiding an infinite recursion). The table got a new column for the duration of a segment while the old “duration” column was renamed “Runtime” to reflect what it actually shows. Currently, only the run time but not the duration are editable. All deco gases are used from the depth where their pO2 is 1.4bar. This should become more flexible. Calculation of the pressure drop in cylinders without configured volumes is suppressed. This solves a problem with the planner crashing when saving a dive where not all cylinders had been manually given a volume. [Short rant break: Treating 0/0 as air bites back at so many places. E.g. Cylinder data is initialized with memsetting the whole structures to 0. Then later suddenly this totally unconfigured cylinder is being treated as it would contain air. Maybe at some point this was a feature. But it lead to a naughty bug which took me over an hour to resolve. We should seriously reconsider this choice and better move to 209/0 being air if changing this everywhere is not too much trouble] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:54:55 +00:00
if (p.entered)
plan_add_segment(&diveplan, deltaT, p.depth, p.gasmix, p.po2, true);
}
// what does the cache do???
char *cache = NULL;
struct divedatapoint *dp = NULL;
for (int i = 0; i < MAX_CYLINDERS; i++) {
cylinder_t *cyl = &displayed_dive.cylinder[i];
if (cyl->depth.mm) {
dp = create_dp(0, cyl->depth.mm, cyl->gasmix, 0);
if (diveplan.dp) {
dp->next = diveplan.dp->next;
diveplan.dp->next = dp;
} else {
dp->next = NULL;
diveplan.dp = dp;
}
}
}
#if DEBUG_PLAN
dump_plan(&diveplan);
#endif
if (plannerModel->recalcQ() && !diveplan_empty(&diveplan)) {
plan(&diveplan, &cache, isPlanner(), false);
MainWindow::instance()->setPlanNotes(displayed_dive.notes);
}
// throw away the cache
free(cache);
#if DEBUG_PLAN
save_dive(stderr, &displayed_dive);
dump_plan(&diveplan);
#endif
}
void DivePlannerPointsModel::deleteTemporaryPlan()
{
deleteTemporaryPlan(diveplan.dp);
diveplan.dp = NULL;
}
void DivePlannerPointsModel::deleteTemporaryPlan(struct divedatapoint *dp)
{
if (!dp)
return;
deleteTemporaryPlan(dp->next);
free(dp);
}
void DivePlannerPointsModel::createPlan()
{
// Ok, so, here the diveplan creates a dive
char *cache = NULL;
bool oldRecalc = plannerModel->setRecalc(false);
removeDeco();
createTemporaryPlan();
plannerModel->setRecalc(oldRecalc);
//TODO: C-based function here?
plan(&diveplan, &cache, isPlanner(), true);
record_dive(clone_dive(&displayed_dive));
mark_divelist_changed(true);
// Remove and clean the diveplan, so we don't delete
// the dive by mistake.
diveplan.dp = NULL;
setPlanMode(NOTHING);
planCreated();
}