2013-06-20 15:33:26 +00:00
|
|
|
#include "diveplanner.h"
|
2013-07-02 13:13:06 +00:00
|
|
|
#include "graphicsview-common.h"
|
2013-08-28 10:48:46 +00:00
|
|
|
#include "models.h"
|
2013-08-30 10:14:30 +00:00
|
|
|
#include "modeldelegates.h"
|
2013-08-30 19:43:10 +00:00
|
|
|
#include "mainwindow.h"
|
2013-09-19 04:02:53 +00:00
|
|
|
#include "maintab.h"
|
2013-09-02 19:21:08 +00:00
|
|
|
#include "tableview.h"
|
2013-07-02 13:13:06 +00:00
|
|
|
|
2014-05-29 00:01:18 +00:00
|
|
|
#include "dive.h"
|
|
|
|
#include "divelist.h"
|
|
|
|
#include "planner.h"
|
2014-03-07 15:42:13 +00:00
|
|
|
#include "display.h"
|
2013-09-20 23:41:42 +00:00
|
|
|
#include "helpers.h"
|
2013-08-30 10:14:30 +00:00
|
|
|
|
2013-06-20 15:37:41 +00:00
|
|
|
#include <QMouseEvent>
|
2013-06-20 16:39:41 +00:00
|
|
|
#include <QDebug>
|
2013-07-02 17:36:52 +00:00
|
|
|
#include <QGraphicsSceneMouseEvent>
|
2013-07-04 15:58:11 +00:00
|
|
|
#include <QMessageBox>
|
2013-07-21 16:54:21 +00:00
|
|
|
#include <QListView>
|
|
|
|
#include <QModelIndex>
|
2013-08-28 10:48:46 +00:00
|
|
|
#include <QSettings>
|
2013-09-02 19:21:08 +00:00
|
|
|
#include <QTableView>
|
2013-09-16 22:21:13 +00:00
|
|
|
#include <QColor>
|
2014-06-03 22:26:06 +00:00
|
|
|
#include <QShortcut>
|
2013-06-20 15:33:26 +00:00
|
|
|
|
2013-10-03 20:34:50 +00:00
|
|
|
#include <algorithm>
|
2014-05-29 00:01:18 +00:00
|
|
|
#include <string.h>
|
2013-10-03 20:34:50 +00:00
|
|
|
|
2013-06-27 14:10:03 +00:00
|
|
|
#define TIME_INITIAL_MAX 30
|
|
|
|
|
2013-09-22 19:37:49 +00:00
|
|
|
#define MAX_DEPTH M_OR_FT(150, 450)
|
|
|
|
#define MIN_DEPTH M_OR_FT(20, 60)
|
2013-07-02 17:14:09 +00:00
|
|
|
|
2014-06-24 22:08:36 +00:00
|
|
|
#define UNIT_FACTOR ((prefs.units.length == units::METERS) ? 1000.0 / 60.0 : feet_to_mm(1.0) / 60.0)
|
|
|
|
|
2014-06-01 22:25:19 +00:00
|
|
|
QString gasToStr(struct gasmix gas)
|
2014-02-28 04:09:57 +00:00
|
|
|
{
|
2014-06-01 22:25:19 +00:00
|
|
|
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);
|
2013-11-11 08:09:19 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
QString dpGasToStr(const divedatapoint &p)
|
2013-11-11 08:09:19 +00:00
|
|
|
{
|
2014-06-01 22:25:19 +00:00
|
|
|
return gasToStr(p.gasmix);
|
2013-08-30 18:06:26 +00:00
|
|
|
}
|
|
|
|
|
2013-08-26 19:34:06 +00:00
|
|
|
static DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
|
2013-07-04 13:06:52 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
bool intLessThan(int a, int b)
|
|
|
|
{
|
2013-08-30 18:53:10 +00:00
|
|
|
return a <= b;
|
|
|
|
}
|
2014-02-28 04:09:57 +00:00
|
|
|
void DivePlannerPointsModel::removeSelectedPoints(const QVector<int> &rows)
|
2013-08-30 18:53:10 +00:00
|
|
|
{
|
|
|
|
int firstRow = rowCount() - rows.count();
|
|
|
|
QVector<int> v2 = rows;
|
|
|
|
std::sort(v2.begin(), v2.end(), intLessThan);
|
2014-02-28 04:09:57 +00:00
|
|
|
beginRemoveRows(QModelIndex(), firstRow, rowCount() - 1);
|
|
|
|
for (int i = v2.count() - 1; i >= 0; i--) {
|
2013-08-30 18:53:10 +00:00
|
|
|
divepoints.remove(v2[i]);
|
|
|
|
}
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
|
2014-05-27 18:28:42 +00:00
|
|
|
void DivePlannerPointsModel::createSimpleDive()
|
2013-09-20 12:36:14 +00:00
|
|
|
{
|
2014-06-02 01:18:29 +00:00
|
|
|
struct gasmix gas = { 0 };
|
|
|
|
if (isPlanner())
|
2014-05-27 18:28:42 +00:00
|
|
|
// let's use the gas from the first cylinder
|
2014-06-02 01:18:29 +00:00
|
|
|
gas = stagingDive->cylinder[0].gasmix;
|
|
|
|
|
2014-06-02 19:36:05 +00:00
|
|
|
plannerModel->addStop(M_OR_FT(15, 45), 1 * 60, &gas, 0, true);
|
|
|
|
plannerModel->addStop(M_OR_FT(15, 45), 40 * 60, &gas, 0, true);
|
2014-05-27 18:28:42 +00:00
|
|
|
if (!isPlanner()) {
|
2014-06-02 19:36:05 +00:00
|
|
|
plannerModel->addStop(M_OR_FT(5, 15), 42 * 60, &gas, 0, true);
|
|
|
|
plannerModel->addStop(M_OR_FT(5, 15), 45 * 60, &gas, 0, true);
|
2014-05-25 22:28:55 +00:00
|
|
|
}
|
2013-09-20 12:36:14 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void DivePlannerPointsModel::loadFromDive(dive *d)
|
2013-11-01 15:48:34 +00:00
|
|
|
{
|
2014-02-12 13:37:18 +00:00
|
|
|
// 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));
|
|
|
|
copy_samples(d, &backupDive);
|
|
|
|
copy_events(d, &backupDive);
|
2014-06-04 06:09:12 +00:00
|
|
|
copy_cylinders(d, stagingDive, false); // this way the correct cylinder data is shown
|
2013-11-14 09:36:21 +00:00
|
|
|
CylindersModel::instance()->setDive(stagingDive);
|
2013-11-13 13:39:05 +00:00
|
|
|
int lasttime = 0;
|
2013-11-18 19:55:56 +00:00
|
|
|
// we start with the first gas and see if it was changed
|
2014-06-01 21:17:06 +00:00
|
|
|
struct gasmix gas = backupDive.cylinder[0].gasmix;
|
2013-12-04 04:52:28 +00:00
|
|
|
for (int i = 0; i < backupDive.dc.samples - 1; i++) {
|
2013-11-18 19:55:56 +00:00
|
|
|
const sample &s = backupDive.dc.sample[i];
|
2013-11-15 20:41:00 +00:00
|
|
|
if (s.time.seconds == 0)
|
|
|
|
continue;
|
2014-06-01 21:17:06 +00:00
|
|
|
get_gas_from_events(&backupDive.dc, lasttime, &gas);
|
2014-06-02 19:36:05 +00:00
|
|
|
plannerModel->addStop(s.depth.mm, s.time.seconds, &gas, 0, true);
|
2013-11-13 13:39:05 +00:00
|
|
|
lasttime = s.time.seconds;
|
2013-11-01 15:48:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-18 19:55:56 +00:00
|
|
|
void DivePlannerPointsModel::restoreBackupDive()
|
|
|
|
{
|
|
|
|
memcpy(current_dive, &backupDive, sizeof(struct dive));
|
|
|
|
}
|
|
|
|
|
2013-11-14 09:36:21 +00:00
|
|
|
void DivePlannerPointsModel::copyCylinders(dive *d)
|
|
|
|
{
|
2014-06-04 06:09:12 +00:00
|
|
|
copy_cylinders(stagingDive, d, false);
|
2013-11-14 09:36:21 +00:00
|
|
|
}
|
|
|
|
|
2014-05-29 00:01:18 +00:00
|
|
|
// copy the tanks from the current dive, or the default cylinder
|
|
|
|
// or an unknown cylinder
|
|
|
|
// setup the cylinder widget accordingly
|
|
|
|
void DivePlannerPointsModel::setupCylinders()
|
2014-05-08 21:36:45 +00:00
|
|
|
{
|
2014-05-29 21:36:14 +00:00
|
|
|
if (!stagingDive)
|
2014-05-29 00:01:18 +00:00
|
|
|
return;
|
|
|
|
|
2014-05-29 21:36:14 +00:00
|
|
|
if (stagingDive != current_dive) {
|
2014-06-01 19:38:32 +00:00
|
|
|
// we are planning a dive
|
2014-05-29 21:36:14 +00:00
|
|
|
if (current_dive) {
|
2014-06-04 06:09:12 +00:00
|
|
|
// take the used cylinders from the selected dive as starting point
|
2014-06-01 19:38:32 +00:00
|
|
|
CylindersModel::instance()->copyFromDive(current_dive);
|
2014-06-04 06:09:12 +00:00
|
|
|
copy_cylinders(current_dive, stagingDive, true);
|
2014-06-01 19:38:32 +00:00
|
|
|
reset_cylinders(stagingDive);
|
|
|
|
return;
|
2014-05-29 00:01:18 +00:00
|
|
|
} else {
|
2014-05-29 21:36:14 +00:00
|
|
|
if (!same_string(prefs.default_cylinder, "")) {
|
|
|
|
fill_default_cylinder(&stagingDive->cylinder[0]);
|
|
|
|
} else {
|
|
|
|
// roughly an AL80
|
|
|
|
stagingDive->cylinder[0].type.description = strdup(tr("unknown").toUtf8().constData());
|
|
|
|
stagingDive->cylinder[0].type.size.mliter = 11100;
|
|
|
|
stagingDive->cylinder[0].type.workingpressure.mbar = 207000;
|
|
|
|
}
|
2014-05-29 00:01:18 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-29 21:36:14 +00:00
|
|
|
reset_cylinders(stagingDive);
|
2014-05-29 00:01:18 +00:00
|
|
|
CylindersModel::instance()->copyFromDive(stagingDive);
|
2014-05-08 21:36:45 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
QStringList &DivePlannerPointsModel::getGasList()
|
2013-11-11 08:09:19 +00:00
|
|
|
{
|
2013-11-20 02:23:14 +00:00
|
|
|
struct dive *activeDive = isPlanner() ? stagingDive : current_dive;
|
2013-11-11 08:09:19 +00:00
|
|
|
static QStringList list;
|
|
|
|
list.clear();
|
2013-11-20 02:23:14 +00:00
|
|
|
if (!activeDive) {
|
2013-11-11 08:09:19 +00:00
|
|
|
list.push_back(tr("AIR"));
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
2013-11-20 02:23:14 +00:00
|
|
|
cylinder_t *cyl = &activeDive->cylinder[i];
|
2013-11-11 08:09:19 +00:00
|
|
|
if (cylinder_nodata(cyl))
|
|
|
|
break;
|
2014-06-01 22:25:19 +00:00
|
|
|
list.push_back(gasToStr(cyl->gasmix));
|
2013-11-11 08:09:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2014-04-24 14:42:10 +00:00
|
|
|
void DivePlannerPointsModel::removeDeco()
|
|
|
|
{
|
2014-05-06 13:28:32 +00:00
|
|
|
bool oldrec = setRecalc(false);
|
2014-04-24 14:42:10 +00:00
|
|
|
QVector<int> computedPoints;
|
|
|
|
for (int i = 0; i < plannerModel->rowCount(); i++)
|
|
|
|
if (!plannerModel->at(i).entered)
|
|
|
|
computedPoints.push_back(i);
|
|
|
|
removeSelectedPoints(computedPoints);
|
2014-05-06 13:28:32 +00:00
|
|
|
setRecalc(oldrec);
|
2014-04-24 14:42:10 +00:00
|
|
|
}
|
2014-05-25 03:51:05 +00:00
|
|
|
|
2014-05-24 01:39:51 +00:00
|
|
|
#if 0
|
2013-09-19 03:19:49 +00:00
|
|
|
void DivePlannerGraphics::drawProfile()
|
2013-06-20 16:20:41 +00:00
|
|
|
{
|
2014-05-22 02:49:17 +00:00
|
|
|
// 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.
|
2014-04-17 08:54:55 +00:00
|
|
|
bool oldRecalc = plannerModel->setRecalc(false);
|
2014-04-24 14:42:10 +00:00
|
|
|
plannerModel->removeDeco();
|
2014-05-22 02:49:17 +00:00
|
|
|
// Here we plotted the old planner profile. why there's the magic with the plannerModel here?
|
2014-04-17 08:54:55 +00:00
|
|
|
plannerModel->setRecalc(oldRecalc);
|
2013-09-16 15:11:06 +00:00
|
|
|
plannerModel->deleteTemporaryPlan();
|
2013-06-20 15:37:41 +00:00
|
|
|
}
|
2014-05-24 01:39:51 +00:00
|
|
|
#endif
|
2013-06-20 15:37:41 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
DiveHandler::DiveHandler() : QGraphicsEllipseItem()
|
2013-06-20 17:29:32 +00:00
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
setRect(-5, -5, 10, 10);
|
2014-05-23 22:50:09 +00:00
|
|
|
setFlags(ItemIgnoresTransformations | ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges);
|
2013-06-27 22:52:58 +00:00
|
|
|
setBrush(Qt::white);
|
|
|
|
setZValue(2);
|
2013-06-20 17:29:32 +00:00
|
|
|
}
|
2013-07-04 14:01:59 +00:00
|
|
|
|
2013-11-19 22:42:05 +00:00
|
|
|
int DiveHandler::parentIndex()
|
|
|
|
{
|
2014-05-24 01:39:51 +00:00
|
|
|
ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
|
2013-11-19 22:42:05 +00:00
|
|
|
return view->handles.indexOf(this);
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void DiveHandler::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
2013-11-15 01:29:36 +00:00
|
|
|
{
|
|
|
|
QMenu m;
|
2013-11-19 22:42:05 +00:00
|
|
|
GasSelectionModel *model = GasSelectionModel::instance();
|
|
|
|
model->repopulate();
|
|
|
|
int rowCount = model->rowCount();
|
2014-02-28 04:09:57 +00:00
|
|
|
for (int i = 0; i < rowCount; i++) {
|
2013-11-19 22:42:05 +00:00
|
|
|
QAction *action = new QAction(&m);
|
2014-02-28 04:09:57 +00:00
|
|
|
action->setText(model->data(model->index(i, 0), Qt::DisplayRole).toString());
|
2013-11-19 22:42:05 +00:00
|
|
|
connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas()));
|
|
|
|
m.addAction(action);
|
|
|
|
}
|
|
|
|
m.addSeparator();
|
2013-11-15 01:29:36 +00:00
|
|
|
m.addAction(QObject::tr("Remove this Point"), this, SLOT(selfRemove()));
|
|
|
|
m.exec(event->screenPos());
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiveHandler::selfRemove()
|
|
|
|
{
|
|
|
|
setSelected(true);
|
2014-05-24 01:39:51 +00:00
|
|
|
ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
|
2013-11-15 01:29:36 +00:00
|
|
|
view->keyDeleteAction();
|
|
|
|
}
|
|
|
|
|
2013-11-19 22:42:05 +00:00
|
|
|
void DiveHandler::changeGas()
|
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
QAction *action = qobject_cast<QAction *>(sender());
|
2013-11-19 22:42:05 +00:00
|
|
|
QModelIndex index = plannerModel->index(parentIndex(), DivePlannerPointsModel::GAS);
|
|
|
|
plannerModel->setData(index, action->text());
|
|
|
|
}
|
|
|
|
|
2014-05-23 23:51:30 +00:00
|
|
|
void DiveHandler::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
2013-07-04 14:01:59 +00:00
|
|
|
{
|
2014-05-23 23:51:30 +00:00
|
|
|
ProfileWidget2 *view = qobject_cast<ProfileWidget2*>(scene()->views().first());
|
|
|
|
if(view->isPointOutOfBoundaries(event->scenePos()))
|
|
|
|
return;
|
|
|
|
QGraphicsEllipseItem::mouseMoveEvent(event);
|
|
|
|
emit moved();
|
2013-07-04 14:01:59 +00:00
|
|
|
}
|
2013-06-20 18:52:27 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
|
2013-10-03 18:54:25 +00:00
|
|
|
{
|
|
|
|
ui.setupUi(this);
|
|
|
|
ui.tableWidget->setTitle(tr("Dive Planner Points"));
|
|
|
|
ui.tableWidget->setModel(DivePlannerPointsModel::instance());
|
2014-04-17 08:54:55 +00:00
|
|
|
DivePlannerPointsModel::instance()->setRecalc(true);
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::GAS, new AirTypesDelegate(this));
|
2013-11-09 22:06:26 +00:00
|
|
|
ui.cylinderTableWidget->setTitle(tr("Available Gases"));
|
|
|
|
ui.cylinderTableWidget->setModel(CylindersModel::instance());
|
2013-11-12 19:57:33 +00:00
|
|
|
QTableView *view = ui.cylinderTableWidget->view();
|
|
|
|
view->setColumnHidden(CylindersModel::START, true);
|
|
|
|
view->setColumnHidden(CylindersModel::END, true);
|
2014-03-22 14:13:58 +00:00
|
|
|
view->setColumnHidden(CylindersModel::DEPTH, false);
|
2014-01-15 17:52:42 +00:00
|
|
|
view->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate(this));
|
2013-11-10 12:02:53 +00:00
|
|
|
connect(ui.cylinderTableWidget, SIGNAL(addButtonClicked()), DivePlannerPointsModel::instance(), SLOT(addCylinder_clicked()));
|
2013-10-03 18:54:25 +00:00
|
|
|
connect(ui.tableWidget, SIGNAL(addButtonClicked()), DivePlannerPointsModel::instance(), SLOT(addStop()));
|
2013-11-14 19:39:35 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
connect(CylindersModel::instance(), SIGNAL(dataChanged(QModelIndex, QModelIndex)),
|
2013-11-14 19:39:35 +00:00
|
|
|
GasSelectionModel::instance(), SLOT(repopulate()));
|
2014-02-28 04:09:57 +00:00
|
|
|
connect(CylindersModel::instance(), SIGNAL(rowsInserted(QModelIndex, int, int)),
|
2013-11-14 19:39:35 +00:00
|
|
|
GasSelectionModel::instance(), SLOT(repopulate()));
|
2014-02-28 04:09:57 +00:00
|
|
|
connect(CylindersModel::instance(), SIGNAL(rowsRemoved(QModelIndex, int, int)),
|
2013-11-14 19:39:35 +00:00
|
|
|
GasSelectionModel::instance(), SLOT(repopulate()));
|
2014-04-18 02:48:00 +00:00
|
|
|
connect(CylindersModel::instance(), SIGNAL(dataChanged(QModelIndex, QModelIndex)),
|
2014-05-22 00:38:26 +00:00
|
|
|
plannerModel, SIGNAL(cylinderModelEdited()));
|
2014-04-17 08:54:55 +00:00
|
|
|
connect(CylindersModel::instance(), SIGNAL(rowsInserted(QModelIndex, int, int)),
|
2014-05-22 00:38:26 +00:00
|
|
|
plannerModel, SIGNAL(cylinderModelEdited()));
|
2014-04-17 08:54:55 +00:00
|
|
|
connect(CylindersModel::instance(), SIGNAL(rowsRemoved(QModelIndex, int, int)),
|
2014-05-22 00:38:26 +00:00
|
|
|
plannerModel, SIGNAL(cylinderModelEdited()));
|
2013-11-14 19:39:35 +00:00
|
|
|
|
2013-11-10 12:02:53 +00:00
|
|
|
ui.tableWidget->setBtnToolTip(tr("add dive data point"));
|
2013-11-14 18:55:35 +00:00
|
|
|
connect(ui.startTime, SIGNAL(timeChanged(QTime)), plannerModel, SLOT(setStartTime(QTime)));
|
2013-10-03 18:54:25 +00:00
|
|
|
connect(ui.ATMPressure, SIGNAL(textChanged(QString)), this, SLOT(atmPressureChanged(QString)));
|
2014-06-20 11:43:09 +00:00
|
|
|
connect(ui.bottomSAC, SIGNAL(valueChanged(int)), this, SLOT(bottomSacChanged(int)));
|
|
|
|
connect(ui.decoStopSAC, SIGNAL(valueChanged(int)), this, SLOT(decoSacChanged(int)));
|
2013-11-14 18:55:33 +00:00
|
|
|
connect(ui.gfhigh, SIGNAL(valueChanged(int)), plannerModel, SLOT(setGFHigh(int)));
|
2014-06-04 16:34:08 +00:00
|
|
|
connect(ui.gfhigh, SIGNAL(editingFinished()), plannerModel, SLOT(emitDataChanged()));
|
2013-11-14 18:55:33 +00:00
|
|
|
connect(ui.gflow, SIGNAL(valueChanged(int)), plannerModel, SLOT(setGFLow(int)));
|
2014-06-04 16:34:08 +00:00
|
|
|
connect(ui.gflow, SIGNAL(editingFinished()), plannerModel, SLOT(emitDataChanged()));
|
2014-06-03 08:06:18 +00:00
|
|
|
connect(ui.printPlan, SIGNAL(pressed()), this, SLOT(printDecoPlan()));
|
2014-06-23 17:21:29 +00:00
|
|
|
connect(ui.drop_stone_mode, SIGNAL(toggled(bool)), plannerModel, SLOT(setDropStoneMode(bool)));
|
2014-06-23 13:43:51 +00:00
|
|
|
#ifdef NO_PRINTING
|
|
|
|
ui.printPlan->hide();
|
|
|
|
#endif
|
2013-09-09 10:18:22 +00:00
|
|
|
|
2014-05-27 22:27:53 +00:00
|
|
|
// Creating (and canceling) the plan
|
2013-10-03 18:54:25 +00:00
|
|
|
connect(ui.buttonBox, SIGNAL(accepted()), plannerModel, SLOT(createPlan()));
|
|
|
|
connect(ui.buttonBox, SIGNAL(rejected()), plannerModel, SLOT(cancelPlan()));
|
2014-06-03 22:26:06 +00:00
|
|
|
QShortcut *closeKey = new QShortcut(QKeySequence(Qt::Key_Escape), this);
|
|
|
|
connect(closeKey, SIGNAL(activated()), plannerModel, SLOT(cancelPlan()));
|
2013-09-16 14:38:41 +00:00
|
|
|
|
2013-09-09 10:18:22 +00:00
|
|
|
/* set defaults. */
|
2014-02-28 04:09:57 +00:00
|
|
|
ui.startTime->setTime(QTime(1, 0));
|
|
|
|
ui.ATMPressure->setText("1013");
|
2014-06-20 11:43:09 +00:00
|
|
|
ui.bottomSAC->setValue(20);
|
|
|
|
ui.decoStopSAC->setValue(17);
|
2013-11-14 18:55:34 +00:00
|
|
|
ui.gflow->setValue(prefs.gflow);
|
|
|
|
ui.gfhigh->setValue(prefs.gfhigh);
|
2013-09-26 21:14:09 +00:00
|
|
|
|
|
|
|
setMinimumWidth(0);
|
|
|
|
setMinimumHeight(0);
|
2013-08-28 10:48:46 +00:00
|
|
|
}
|
|
|
|
|
2013-12-09 06:43:00 +00:00
|
|
|
void DivePlannerWidget::settingsChanged()
|
|
|
|
{
|
2014-06-10 16:28:17 +00:00
|
|
|
// right now there's nothing special we do when settings change
|
2013-12-09 06:43:00 +00:00
|
|
|
}
|
|
|
|
|
2013-11-10 12:02:53 +00:00
|
|
|
void DivePlannerPointsModel::addCylinder_clicked()
|
|
|
|
{
|
|
|
|
CylindersModel::instance()->add();
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void DivePlannerWidget::atmPressureChanged(const QString &pressure)
|
2013-08-26 16:18:21 +00:00
|
|
|
{
|
2013-08-26 19:34:06 +00:00
|
|
|
plannerModel->setSurfacePressure(pressure.toInt());
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
2014-06-20 11:43:09 +00:00
|
|
|
void DivePlannerWidget::bottomSacChanged(const int bottomSac)
|
2013-08-26 16:18:21 +00:00
|
|
|
{
|
2014-06-20 11:43:09 +00:00
|
|
|
plannerModel->setBottomSac(bottomSac);
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
2014-06-20 11:43:09 +00:00
|
|
|
void DivePlannerWidget::decoSacChanged(const int decosac)
|
2013-08-26 16:18:21 +00:00
|
|
|
{
|
2014-06-20 11:43:09 +00:00
|
|
|
plannerModel->setDecoSac(decosac);
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
2014-06-03 08:06:18 +00:00
|
|
|
void DivePlannerWidget::printDecoPlan()
|
|
|
|
{
|
|
|
|
MainWindow::instance()->printPlan();
|
|
|
|
}
|
|
|
|
|
2014-06-10 15:40:02 +00:00
|
|
|
PlannerSettingsWidget::PlannerSettingsWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
|
|
|
|
{
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
2014-06-24 22:08:36 +00:00
|
|
|
if (prefs.units.METERS == 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.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);
|
|
|
|
|
2014-06-10 15:40:02 +00:00
|
|
|
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)));
|
2014-06-24 22:08:36 +00:00
|
|
|
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()));
|
2014-06-25 12:33:03 +00:00
|
|
|
connect(ui.descRate, SIGNAL(valueChanged(int)), this, SLOT(setDescRate(int)));
|
2014-06-24 22:08:36 +00:00
|
|
|
connect(ui.descRate, SIGNAL(valueChanged(int)), plannerModel, SLOT(emitDataChanged()));
|
2014-06-10 15:40:02 +00:00
|
|
|
|
|
|
|
setMinimumWidth(0);
|
|
|
|
setMinimumHeight(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlannerSettingsWidget::settingsChanged()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlannerSettingsWidget::atmPressureChanged(const QString &pressure)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-06-20 11:43:09 +00:00
|
|
|
void PlannerSettingsWidget::bottomSacChanged(const int bottomSac)
|
2014-06-10 15:40:02 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-06-20 11:43:09 +00:00
|
|
|
void PlannerSettingsWidget::decoSacChanged(const int decosac)
|
2014-06-10 15:40:02 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlannerSettingsWidget::printDecoPlan()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-06-24 22:08:36 +00:00
|
|
|
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;
|
|
|
|
}
|
2014-06-10 15:40:02 +00:00
|
|
|
|
2013-11-09 00:09:46 +00:00
|
|
|
void DivePlannerPointsModel::setPlanMode(Mode m)
|
2013-09-19 02:33:53 +00:00
|
|
|
{
|
2013-11-09 00:09:46 +00:00
|
|
|
mode = m;
|
2014-05-29 04:34:10 +00:00
|
|
|
if (m == NOTHING)
|
|
|
|
stagingDive = NULL;
|
2014-06-10 16:11:34 +00:00
|
|
|
// 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);
|
2013-09-19 02:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DivePlannerPointsModel::isPlanner()
|
|
|
|
{
|
|
|
|
return mode == PLAN;
|
|
|
|
}
|
|
|
|
|
2014-04-18 14:08:33 +00:00
|
|
|
/* 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. */
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
int DivePlannerPointsModel::columnCount(const QModelIndex &parent) const
|
2013-08-26 12:14:19 +00:00
|
|
|
{
|
|
|
|
return COLUMNS;
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
QVariant DivePlannerPointsModel::data(const QModelIndex &index, int role) const
|
2013-08-26 12:14:19 +00:00
|
|
|
{
|
2014-05-30 02:51:25 +00:00
|
|
|
divedatapoint p = divepoints.at(index.row());
|
2014-06-03 18:44:05 +00:00
|
|
|
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
2014-01-16 04:50:56 +00:00
|
|
|
switch (index.column()) {
|
2014-02-28 04:09:57 +00:00
|
|
|
case CCSETPOINT:
|
|
|
|
return (double)p.po2 / 1000;
|
|
|
|
case DEPTH:
|
|
|
|
return rint(get_depth_units(p.depth, NULL, NULL));
|
2014-04-17 08:54:55 +00:00
|
|
|
case RUNTIME:
|
2014-02-28 04:09:57 +00:00
|
|
|
return p.time / 60;
|
2014-04-17 08:54:55 +00:00
|
|
|
case DURATION:
|
|
|
|
if (index.row())
|
2014-04-17 15:06:11 +00:00
|
|
|
return (p.time - divepoints.at(index.row() - 1).time) / 60;
|
2014-04-17 08:54:55 +00:00
|
|
|
else
|
|
|
|
return p.time / 60;
|
2014-02-28 04:09:57 +00:00
|
|
|
case GAS:
|
|
|
|
return dpGasToStr(p);
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
2013-09-22 19:34:50 +00:00
|
|
|
} else if (role == Qt::DecorationRole) {
|
2014-01-16 04:50:56 +00:00
|
|
|
switch (index.column()) {
|
2014-02-28 04:09:57 +00:00
|
|
|
case REMOVE:
|
2014-05-30 02:51:25 +00:00
|
|
|
return p.entered ? QIcon(":trash") : QVariant();
|
2013-08-28 10:27:59 +00:00
|
|
|
}
|
2013-09-22 19:34:50 +00:00
|
|
|
} else if (role == Qt::FontRole) {
|
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;
|
|
|
|
}
|
2013-09-02 19:21:08 +00:00
|
|
|
}
|
2013-08-26 12:14:19 +00:00
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
bool DivePlannerPointsModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
2013-08-30 10:14:30 +00:00
|
|
|
{
|
2014-06-01 21:17:06 +00:00
|
|
|
struct gasmix gas = { 0 };
|
2014-05-31 11:53:18 +00:00
|
|
|
int i, shift;
|
2014-01-16 04:50:56 +00:00
|
|
|
if (role == Qt::EditRole) {
|
2014-02-28 04:09:57 +00:00
|
|
|
divedatapoint &p = divepoints[index.row()];
|
2014-01-16 04:50:56 +00:00
|
|
|
switch (index.column()) {
|
2014-02-28 04:09:57 +00:00
|
|
|
case DEPTH:
|
|
|
|
p.depth = units_to_depth(value.toInt());
|
|
|
|
break;
|
2014-04-17 08:54:55 +00:00
|
|
|
case RUNTIME:
|
2014-02-28 04:09:57 +00:00
|
|
|
p.time = value.toInt() * 60;
|
|
|
|
break;
|
2014-04-17 08:54:55 +00:00
|
|
|
case DURATION:
|
2014-05-31 11:53:18 +00:00
|
|
|
i = index.row();
|
|
|
|
if (i)
|
|
|
|
shift = divepoints[i].time - divepoints[i - 1].time - value.toInt() * 60;
|
2014-04-17 08:54:55 +00:00
|
|
|
else
|
2014-05-31 11:53:18 +00:00
|
|
|
shift = divepoints[i].time - value.toInt() * 60;
|
|
|
|
while (i < divepoints.size())
|
|
|
|
divepoints[i++].time -= shift;
|
2014-04-17 08:54:55 +00:00
|
|
|
break;
|
2013-11-08 12:22:59 +00:00
|
|
|
case CCSETPOINT: {
|
|
|
|
int po2 = 0;
|
|
|
|
QByteArray gasv = value.toByteArray();
|
|
|
|
if (validate_po2(gasv.data(), &po2))
|
|
|
|
p.po2 = po2;
|
2014-02-28 04:09:57 +00:00
|
|
|
} break;
|
2013-11-12 02:19:04 +00:00
|
|
|
case GAS:
|
2013-11-08 12:22:59 +00:00
|
|
|
QByteArray gasv = value.toByteArray();
|
2014-06-01 22:25:19 +00:00
|
|
|
if (validate_gas(gasv.data(), &gas))
|
|
|
|
p.gasmix = gas;
|
2013-11-08 12:22:59 +00:00
|
|
|
break;
|
2013-08-30 16:27:15 +00:00
|
|
|
}
|
|
|
|
editStop(index.row(), p);
|
|
|
|
}
|
2013-08-30 18:06:26 +00:00
|
|
|
return QAbstractItemModel::setData(index, value, role);
|
2013-08-30 10:14:30 +00:00
|
|
|
}
|
|
|
|
|
2013-08-26 12:14:19 +00:00
|
|
|
QVariant DivePlannerPointsModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
2013-09-22 19:34:50 +00:00
|
|
|
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
2014-01-16 04:50:56 +00:00
|
|
|
switch (section) {
|
2014-02-28 04:09:57 +00:00
|
|
|
case DEPTH:
|
|
|
|
return tr("Final Depth");
|
2014-04-17 08:54:55 +00:00
|
|
|
case RUNTIME:
|
|
|
|
return tr("Run time");
|
2014-02-28 04:09:57 +00:00
|
|
|
case DURATION:
|
|
|
|
return tr("Duration");
|
|
|
|
case GAS:
|
|
|
|
return tr("Used Gas");
|
|
|
|
case CCSETPOINT:
|
|
|
|
return tr("CC Set Point");
|
2013-08-26 12:14:19 +00:00
|
|
|
}
|
2013-09-22 19:34:50 +00:00
|
|
|
} else if (role == Qt::FontRole) {
|
2014-02-28 04:09:57 +00:00
|
|
|
return defaultModelFont();
|
2013-09-02 19:21:08 +00:00
|
|
|
}
|
2013-08-26 12:14:19 +00:00
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
Qt::ItemFlags DivePlannerPointsModel::flags(const QModelIndex &index) const
|
2013-08-30 10:14:30 +00:00
|
|
|
{
|
2014-05-31 11:53:18 +00:00
|
|
|
if (index.column() != REMOVE)
|
2014-04-17 08:54:55 +00:00
|
|
|
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
|
|
|
|
else
|
|
|
|
return QAbstractItemModel::flags(index);
|
2013-08-30 10:14:30 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
int DivePlannerPointsModel::rowCount(const QModelIndex &parent) const
|
2013-08-26 12:14:19 +00:00
|
|
|
{
|
2013-08-26 16:18:21 +00:00
|
|
|
return divepoints.count();
|
2013-08-26 12:14:19 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
DivePlannerPointsModel::DivePlannerPointsModel(QObject *parent) : QAbstractTableModel(parent), mode(NOTHING), tempDive(NULL), stagingDive(NULL)
|
2013-08-26 12:14:19 +00:00
|
|
|
{
|
2014-02-09 18:30:52 +00:00
|
|
|
memset(&diveplan, 0, sizeof(diveplan));
|
|
|
|
memset(&backupDive, 0, sizeof(backupDive));
|
2013-08-26 12:14:19 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
DivePlannerPointsModel *DivePlannerPointsModel::instance()
|
2013-08-26 12:14:19 +00:00
|
|
|
{
|
2013-11-30 17:18:04 +00:00
|
|
|
static QScopedPointer<DivePlannerPointsModel> self(new DivePlannerPointsModel());
|
|
|
|
return self.data();
|
2013-08-26 12:14:19 +00:00
|
|
|
}
|
|
|
|
|
2014-06-04 16:34:08 +00:00
|
|
|
void DivePlannerPointsModel::emitDataChanged()
|
|
|
|
{
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
|
|
|
}
|
|
|
|
|
2013-08-26 16:18:21 +00:00
|
|
|
void DivePlannerPointsModel::setBottomSac(int sac)
|
|
|
|
{
|
2014-05-18 20:18:46 +00:00
|
|
|
diveplan.bottomsac = sac * 1000;
|
2014-02-28 04:09:57 +00:00
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::setDecoSac(int sac)
|
|
|
|
{
|
2014-05-18 20:18:46 +00:00
|
|
|
diveplan.decosac = sac * 1000;
|
2014-02-28 04:09:57 +00:00
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
2013-11-14 18:55:33 +00:00
|
|
|
void DivePlannerPointsModel::setGFHigh(const int gfhigh)
|
2013-08-26 16:18:21 +00:00
|
|
|
{
|
|
|
|
diveplan.gfhigh = gfhigh;
|
|
|
|
}
|
|
|
|
|
2013-11-14 18:55:33 +00:00
|
|
|
void DivePlannerPointsModel::setGFLow(const int ghflow)
|
2013-08-26 16:18:21 +00:00
|
|
|
{
|
|
|
|
diveplan.gflow = ghflow;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::setSurfacePressure(int pressure)
|
|
|
|
{
|
|
|
|
diveplan.surface_pressure = pressure;
|
2014-02-28 04:09:57 +00:00
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::setLastStop6m(bool value)
|
|
|
|
{
|
2013-11-09 21:08:42 +00:00
|
|
|
set_last_stop(value);
|
2014-02-28 04:09:57 +00:00
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
2014-06-02 14:25:58 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2014-06-23 17:21:29 +00:00
|
|
|
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 / 300;
|
|
|
|
divepoints.push_front(p);
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void DivePlannerPointsModel::setStartTime(const QTime &t)
|
2013-08-26 16:18:21 +00:00
|
|
|
{
|
2013-09-20 23:41:42 +00:00
|
|
|
diveplan.when = (t.msec() + QDateTime::currentMSecsSinceEpoch()) / 1000 - gettimezoneoffset();
|
2014-02-28 04:09:57 +00:00
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
bool divePointsLessThan(const divedatapoint &p1, const divedatapoint &p2)
|
2013-09-22 19:34:50 +00:00
|
|
|
{
|
2013-08-26 20:02:34 +00:00
|
|
|
return p1.time <= p2.time;
|
|
|
|
}
|
2013-09-22 19:34:50 +00:00
|
|
|
|
2014-06-02 01:18:29 +00:00
|
|
|
bool DivePlannerPointsModel::addGas(struct gasmix mix)
|
2013-11-12 02:19:04 +00:00
|
|
|
{
|
2014-05-25 16:01:16 +00:00
|
|
|
sanitize_gasmix(&mix);
|
|
|
|
|
2013-11-12 02:19:04 +00:00
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
2013-11-13 13:38:14 +00:00
|
|
|
cylinder_t *cyl = &stagingDive->cylinder[i];
|
2013-11-12 02:19:04 +00:00
|
|
|
if (cylinder_nodata(cyl)) {
|
2013-11-13 12:44:18 +00:00
|
|
|
fill_default_cylinder(cyl);
|
2014-06-02 01:18:29 +00:00
|
|
|
cyl->gasmix = mix;
|
2014-06-22 14:41:44 +00:00
|
|
|
/* The depth to change to that gas is given by the depth where its pO₂ is 1.6 bar.
|
2014-04-18 14:08:33 +00:00
|
|
|
* The user should be able to change this depth manually. */
|
2014-06-22 14:41:44 +00:00
|
|
|
pressure_t modpO2;
|
|
|
|
modpO2.mbar = 1600;
|
|
|
|
cyl->depth = gas_mod(&mix, modpO2);
|
2013-11-12 02:19:04 +00:00
|
|
|
CylindersModel::instance()->setDive(stagingDive);
|
|
|
|
return true;
|
|
|
|
}
|
2014-05-25 16:01:16 +00:00
|
|
|
if (!gasmix_distance(&cyl->gasmix, &mix))
|
2013-11-12 02:19:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
qDebug("too many gases");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-17 08:54:55 +00:00
|
|
|
int DivePlannerPointsModel::lastEnteredPoint()
|
|
|
|
{
|
2014-04-17 15:06:11 +00:00
|
|
|
for (int i = divepoints.count() - 1; i >= 0; i--)
|
2014-04-17 08:54:55 +00:00
|
|
|
if (divepoints.at(i).entered)
|
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-06-02 19:36:05 +00:00
|
|
|
int DivePlannerPointsModel::addStop(int milimeters, int seconds, gasmix *gas_in, int ccpoint, bool entered)
|
2013-08-26 16:18:21 +00:00
|
|
|
{
|
2014-06-02 01:18:29 +00:00
|
|
|
struct gasmix air = { 0 };
|
2014-06-02 19:36:05 +00:00
|
|
|
struct gasmix gas = { 0 };
|
|
|
|
bool usePrevious = false;
|
|
|
|
if (gas_in)
|
|
|
|
gas = *gas_in;
|
|
|
|
else
|
|
|
|
usePrevious = true;
|
2014-05-06 13:28:32 +00:00
|
|
|
if (recalcQ())
|
|
|
|
removeDeco();
|
|
|
|
|
2013-08-26 16:18:21 +00:00
|
|
|
int row = divepoints.count();
|
2014-01-16 04:50:56 +00:00
|
|
|
if (seconds == 0 && milimeters == 0 && row != 0) {
|
2013-11-15 02:54:13 +00:00
|
|
|
/* this is only possible if the user clicked on the 'plus' sign on the DivePoints Table */
|
2014-04-17 08:54:55 +00:00
|
|
|
const divedatapoint t = divepoints.at(lastEnteredPoint());
|
2013-11-15 02:54:13 +00:00
|
|
|
milimeters = t.depth;
|
2013-12-04 04:55:00 +00:00
|
|
|
seconds = t.time + 600; // 10 minutes.
|
2014-06-02 01:18:29 +00:00
|
|
|
gas = t.gasmix;
|
2013-12-07 15:25:41 +00:00
|
|
|
ccpoint = t.po2;
|
2013-12-04 04:55:00 +00:00
|
|
|
} else if (seconds == 0 && milimeters == 0 && row == 0) {
|
2013-11-15 02:54:13 +00:00
|
|
|
milimeters = M_OR_FT(5, 15); // 5m / 15ft
|
2014-02-28 04:09:57 +00:00
|
|
|
seconds = 600; // 10 min
|
2013-12-07 22:54:19 +00:00
|
|
|
//Default to the first defined gas, if we got one.
|
|
|
|
cylinder_t *cyl = &stagingDive->cylinder[0];
|
2014-06-02 01:18:29 +00:00
|
|
|
if (cyl)
|
|
|
|
gas = cyl->gasmix;
|
2013-11-14 20:06:08 +00:00
|
|
|
}
|
2014-06-02 01:18:29 +00:00
|
|
|
if (!usePrevious)
|
|
|
|
if (!addGas(gas))
|
2013-11-12 02:19:04 +00:00
|
|
|
qDebug("addGas failed"); // FIXME add error propagation
|
2013-09-09 22:57:22 +00:00
|
|
|
|
2013-08-26 19:55:30 +00:00
|
|
|
// check if there's already a new stop before this one:
|
2013-11-09 11:33:33 +00:00
|
|
|
for (int i = 0; i < row; i++) {
|
2014-02-28 04:09:57 +00:00
|
|
|
const divedatapoint &dp = divepoints.at(i);
|
2013-12-04 04:55:00 +00:00
|
|
|
if (dp.time == seconds) {
|
2013-11-08 12:22:59 +00:00
|
|
|
row = i;
|
|
|
|
beginRemoveRows(QModelIndex(), row, row);
|
|
|
|
divepoints.remove(row);
|
|
|
|
endRemoveRows();
|
|
|
|
break;
|
|
|
|
}
|
2014-02-28 04:09:57 +00:00
|
|
|
if (dp.time > seconds) {
|
2013-08-26 20:02:34 +00:00
|
|
|
row = i;
|
|
|
|
break;
|
2013-08-26 19:55:30 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-02 01:18:29 +00:00
|
|
|
if (usePrevious) {
|
2013-11-15 02:54:13 +00:00
|
|
|
if (row > 0) {
|
2014-06-02 01:18:29 +00:00
|
|
|
gas = divepoints.at(row - 1).gasmix;
|
2013-11-15 02:54:13 +00:00
|
|
|
} 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()) {
|
2014-06-02 01:18:29 +00:00
|
|
|
gas = divepoints.at(row).gasmix;
|
2013-11-15 02:54:13 +00:00
|
|
|
} else {
|
2014-06-02 01:18:29 +00:00
|
|
|
if (!addGas(air))
|
2013-11-15 02:54:13 +00:00
|
|
|
qDebug("addGas failed"); // FIXME add error propagation
|
|
|
|
}
|
|
|
|
}
|
2013-11-11 09:13:55 +00:00
|
|
|
}
|
2014-04-18 14:08:33 +00:00
|
|
|
|
2013-08-26 19:55:30 +00:00
|
|
|
// add the new stop
|
2013-08-26 16:18:21 +00:00
|
|
|
beginInsertRows(QModelIndex(), row, row);
|
|
|
|
divedatapoint point;
|
2013-09-22 19:37:49 +00:00
|
|
|
point.depth = milimeters;
|
2013-12-04 04:55:00 +00:00
|
|
|
point.time = seconds;
|
2014-06-02 01:18:29 +00:00
|
|
|
point.gasmix = gas;
|
2013-11-08 09:15:04 +00:00
|
|
|
point.po2 = ccpoint;
|
2014-03-12 15:49:42 +00:00
|
|
|
point.entered = entered;
|
2014-06-11 21:07:57 +00:00
|
|
|
point.next = NULL;
|
2014-02-28 04:09:57 +00:00
|
|
|
divepoints.append(point);
|
2013-08-26 20:02:34 +00:00
|
|
|
std::sort(divepoints.begin(), divepoints.end(), divePointsLessThan);
|
2013-08-26 16:18:21 +00:00
|
|
|
endInsertRows();
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
2013-08-26 17:54:07 +00:00
|
|
|
void DivePlannerPointsModel::editStop(int row, divedatapoint newData)
|
|
|
|
{
|
|
|
|
divepoints[row] = newData;
|
2013-08-26 20:15:48 +00:00
|
|
|
std::sort(divepoints.begin(), divepoints.end(), divePointsLessThan);
|
2014-02-28 04:09:57 +00:00
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
2013-08-26 17:54:07 +00:00
|
|
|
}
|
|
|
|
|
2013-09-22 18:01:18 +00:00
|
|
|
int DivePlannerPointsModel::size()
|
|
|
|
{
|
|
|
|
return divepoints.size();
|
|
|
|
}
|
|
|
|
|
2013-08-26 17:17:39 +00:00
|
|
|
divedatapoint DivePlannerPointsModel::at(int row)
|
|
|
|
{
|
|
|
|
return divepoints.at(row);
|
|
|
|
}
|
2013-08-30 19:08:55 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void DivePlannerPointsModel::remove(const QModelIndex &index)
|
2013-08-30 19:08:55 +00:00
|
|
|
{
|
|
|
|
if (index.column() != REMOVE)
|
|
|
|
return;
|
|
|
|
|
2014-05-30 02:49:43 +00:00
|
|
|
divedatapoint dp = at(index.row());
|
|
|
|
if (!dp.entered)
|
|
|
|
return;
|
|
|
|
|
2013-08-30 19:08:55 +00:00
|
|
|
beginRemoveRows(QModelIndex(), index.row(), index.row());
|
|
|
|
divepoints.remove(index.row());
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
2013-09-09 10:18:22 +00:00
|
|
|
|
2014-05-22 18:40:22 +00:00
|
|
|
struct diveplan &DivePlannerPointsModel::getDiveplan()
|
2013-09-09 10:18:22 +00:00
|
|
|
{
|
|
|
|
return diveplan;
|
|
|
|
}
|
2013-09-16 14:38:41 +00:00
|
|
|
|
|
|
|
void DivePlannerPointsModel::cancelPlan()
|
|
|
|
{
|
2013-09-22 19:34:50 +00:00
|
|
|
if (mode == PLAN && rowCount()) {
|
2014-02-12 14:22:54 +00:00
|
|
|
if (QMessageBox::warning(MainWindow::instance(), TITLE_OR_TEXT(tr("Discard the Plan?"),
|
2014-02-28 04:09:57 +00:00
|
|
|
tr("You are about to discard your plan.")),
|
|
|
|
QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard) != QMessageBox::Discard) {
|
2013-10-05 20:55:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-09-16 14:38:41 +00:00
|
|
|
}
|
2014-05-28 18:43:32 +00:00
|
|
|
|
2014-05-29 04:34:10 +00:00
|
|
|
if (mode != ADD) // for ADD stagingDive points at current_dive
|
2013-11-12 05:21:50 +00:00
|
|
|
free(stagingDive);
|
2014-05-29 04:34:10 +00:00
|
|
|
stagingDive = NULL; // always reset the stagingDive to NULL
|
2013-11-09 00:09:46 +00:00
|
|
|
setPlanMode(NOTHING);
|
2014-04-18 17:21:58 +00:00
|
|
|
diveplan.dp = NULL;
|
2014-05-28 18:43:32 +00:00
|
|
|
emit planCanceled();
|
2013-11-09 00:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DivePlannerPointsModel::Mode DivePlannerPointsModel::currentMode() const
|
|
|
|
{
|
|
|
|
return mode;
|
|
|
|
}
|
2013-09-16 14:38:41 +00:00
|
|
|
|
2013-12-24 12:18:56 +00:00
|
|
|
QVector<QPair<int, int> > DivePlannerPointsModel::collectGases(struct dive *d)
|
2013-11-13 12:45:54 +00:00
|
|
|
{
|
2013-12-24 12:18:56 +00:00
|
|
|
QVector<QPair<int, int> > l;
|
2013-11-13 12:45:54 +00:00
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
|
|
|
cylinder_t *cyl = &d->cylinder[i];
|
|
|
|
if (!cylinder_nodata(cyl))
|
2014-05-25 16:01:16 +00:00
|
|
|
l.push_back(qMakePair(get_o2(&cyl->gasmix), get_he(&cyl->gasmix)));
|
2013-11-13 12:45:54 +00:00
|
|
|
}
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
void DivePlannerPointsModel::rememberTanks()
|
|
|
|
{
|
|
|
|
oldGases = collectGases(stagingDive);
|
|
|
|
}
|
|
|
|
|
2014-06-01 22:25:19 +00:00
|
|
|
bool DivePlannerPointsModel::tankInUse(struct gasmix gasmix)
|
2013-11-13 12:45:54 +00:00
|
|
|
{
|
|
|
|
for (int j = 0; j < rowCount(); j++) {
|
2014-02-28 04:09:57 +00:00
|
|
|
divedatapoint &p = divepoints[j];
|
2013-11-13 12:45:54 +00:00
|
|
|
if (p.time == 0) // special entries that hold the available gases
|
|
|
|
continue;
|
2014-04-17 08:54:55 +00:00
|
|
|
if (!p.entered) // removing deco gases is ok
|
|
|
|
continue;
|
2014-06-01 22:25:19 +00:00
|
|
|
if (gasmix_distance(&p.gasmix, &gasmix) < 200)
|
2013-11-13 12:45:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::tanksUpdated()
|
|
|
|
{
|
2013-11-14 12:58:04 +00:00
|
|
|
// 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.
|
2014-02-28 04:09:57 +00:00
|
|
|
QVector<QPair<int, int> > gases = collectGases(stagingDive);
|
2013-12-24 12:18:56 +00:00
|
|
|
if (gases.count() == oldGases.count()) {
|
2013-11-14 12:58:04 +00:00
|
|
|
// either nothing relevant changed, or exactly ONE gasmix changed
|
2013-12-24 12:18:56 +00:00
|
|
|
for (int i = 0; i < gases.count(); i++) {
|
2013-11-14 12:58:04 +00:00
|
|
|
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
|
2013-11-13 12:45:54 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-11-14 12:58:04 +00:00
|
|
|
for (int j = 0; j < rowCount(); j++) {
|
2014-02-28 04:09:57 +00:00
|
|
|
divedatapoint &p = divepoints[j];
|
2014-06-01 22:25:19 +00:00
|
|
|
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;
|
2013-11-14 12:58:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2013-11-13 12:45:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-28 04:09:57 +00:00
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
2013-11-13 12:45:54 +00:00
|
|
|
}
|
|
|
|
|
2013-11-09 00:09:46 +00:00
|
|
|
void DivePlannerPointsModel::clear()
|
|
|
|
{
|
2014-05-29 05:12:53 +00:00
|
|
|
Q_ASSERT(stagingDive == 0);
|
2013-11-12 05:21:50 +00:00
|
|
|
if (mode == ADD) {
|
|
|
|
stagingDive = current_dive;
|
|
|
|
} else {
|
2014-05-29 05:12:53 +00:00
|
|
|
stagingDive = alloc_dive();
|
2013-11-12 05:21:50 +00:00
|
|
|
}
|
2014-05-30 23:12:35 +00:00
|
|
|
bool oldRecalc = setRecalc(false);
|
2013-11-12 02:19:04 +00:00
|
|
|
CylindersModel::instance()->setDive(stagingDive);
|
2013-12-09 23:02:06 +00:00
|
|
|
if (rowCount() > 0) {
|
|
|
|
beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
|
|
|
|
divepoints.clear();
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
2013-11-10 12:02:53 +00:00
|
|
|
CylindersModel::instance()->clear();
|
2014-05-30 23:12:35 +00:00
|
|
|
setRecalc(oldRecalc);
|
2013-09-16 14:38:41 +00:00
|
|
|
}
|
2013-09-16 15:11:06 +00:00
|
|
|
|
|
|
|
void DivePlannerPointsModel::createTemporaryPlan()
|
|
|
|
{
|
|
|
|
// This needs to be done in the following steps:
|
|
|
|
// Get the user-input and calculate the dive info
|
|
|
|
// Not sure if this is the place to create the diveplan...
|
|
|
|
// We just start with a surface node at time = 0
|
2013-12-09 06:43:00 +00:00
|
|
|
if (!stagingDive)
|
|
|
|
return;
|
2014-04-17 02:56:42 +00:00
|
|
|
//TODO: this thingy looks like it could be a good C-based function
|
2013-12-07 22:54:15 +00:00
|
|
|
diveplan.dp = NULL;
|
2013-09-16 15:11:06 +00:00
|
|
|
int lastIndex = -1;
|
2013-09-22 19:34:50 +00:00
|
|
|
for (int i = 0; i < rowCount(); i++) {
|
2013-09-16 15:11:06 +00:00
|
|
|
divedatapoint p = at(i);
|
|
|
|
int deltaT = lastIndex != -1 ? p.time - at(lastIndex).time : p.time;
|
|
|
|
lastIndex = i;
|
2014-06-23 17:21:29 +00:00
|
|
|
if (i == 0 && drop_stone_mode) {
|
|
|
|
/* Okay, we add a fist segment where we go down to depth */
|
|
|
|
/* FIXME: make this configurable, now hard-coded to 18 m/s */
|
|
|
|
plan_add_segment(&diveplan, p.depth / 300, p.depth, p.gasmix, p.po2, false);
|
|
|
|
deltaT -= p.depth / 300;
|
|
|
|
}
|
2014-04-17 08:54:55 +00:00
|
|
|
if (p.entered)
|
2014-06-01 22:25:19 +00:00
|
|
|
plan_add_segment(&diveplan, deltaT, p.depth, p.gasmix, p.po2, true);
|
2013-09-16 15:11:06 +00:00
|
|
|
}
|
|
|
|
char *cache = NULL;
|
|
|
|
tempDive = NULL;
|
2013-12-07 22:54:15 +00:00
|
|
|
struct divedatapoint *dp = NULL;
|
2013-11-12 02:19:04 +00:00
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
|
|
|
cylinder_t *cyl = &stagingDive->cylinder[i];
|
|
|
|
if (cyl->depth.mm) {
|
2014-06-01 22:25:19 +00:00
|
|
|
dp = create_dp(0, cyl->depth.mm, cyl->gasmix, 0);
|
2014-01-26 15:22:02 +00:00
|
|
|
if (diveplan.dp) {
|
2013-12-19 21:11:31 +00:00
|
|
|
dp->next = diveplan.dp->next;
|
2014-01-26 15:22:02 +00:00
|
|
|
diveplan.dp->next = dp;
|
|
|
|
} else {
|
2013-12-19 21:11:31 +00:00
|
|
|
dp->next = NULL;
|
2014-01-26 15:22:02 +00:00
|
|
|
diveplan.dp = dp;
|
|
|
|
}
|
2013-11-12 02:19:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#if DEBUG_PLAN
|
|
|
|
dump_plan(&diveplan);
|
|
|
|
#endif
|
2014-05-30 22:40:13 +00:00
|
|
|
if (plannerModel->recalcQ() && !diveplan_empty(&diveplan)) {
|
2014-06-01 04:24:27 +00:00
|
|
|
plan(&diveplan, &cache, &tempDive, stagingDive, isPlanner(), false);
|
2014-06-01 04:14:44 +00:00
|
|
|
MainWindow::instance()->setPlanNotes(tempDive->notes);
|
2014-05-29 21:36:14 +00:00
|
|
|
if (mode == ADD || mode == PLAN) {
|
|
|
|
// copy the samples and events, but don't overwrite the cylinders
|
|
|
|
copy_samples(tempDive, current_dive);
|
|
|
|
copy_events(tempDive, current_dive);
|
2014-06-04 06:09:12 +00:00
|
|
|
copy_cylinders(tempDive, current_dive, false);
|
2014-05-29 21:36:14 +00:00
|
|
|
}
|
2013-11-07 08:25:42 +00:00
|
|
|
}
|
2014-03-06 22:26:33 +00:00
|
|
|
// throw away the cache
|
|
|
|
free(cache);
|
2013-09-16 15:11:06 +00:00
|
|
|
#if DEBUG_PLAN
|
|
|
|
dump_plan(&diveplan);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::deleteTemporaryPlan()
|
|
|
|
{
|
|
|
|
deleteTemporaryPlan(diveplan.dp);
|
2014-05-30 18:01:37 +00:00
|
|
|
diveplan.dp = NULL;
|
2013-09-16 15:11:06 +00:00
|
|
|
delete_single_dive(get_divenr(tempDive));
|
|
|
|
tempDive = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::deleteTemporaryPlan(struct divedatapoint *dp)
|
|
|
|
{
|
2013-09-22 19:34:50 +00:00
|
|
|
if (!dp)
|
2013-09-16 15:11:06 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
deleteTemporaryPlan(dp->next);
|
|
|
|
free(dp);
|
|
|
|
}
|
2013-09-16 15:30:58 +00:00
|
|
|
|
|
|
|
void DivePlannerPointsModel::createPlan()
|
|
|
|
{
|
|
|
|
// Ok, so, here the diveplan creates a dive,
|
|
|
|
// puts it on the dive list, and we need to remember
|
|
|
|
// to not delete it later. mumble. ;p
|
2013-09-22 19:34:50 +00:00
|
|
|
char *cache = NULL;
|
2013-09-16 15:30:58 +00:00
|
|
|
tempDive = NULL;
|
|
|
|
|
2014-04-24 14:42:10 +00:00
|
|
|
bool oldRecalc = plannerModel->setRecalc(false);
|
|
|
|
removeDeco();
|
2013-09-16 15:30:58 +00:00
|
|
|
createTemporaryPlan();
|
2014-04-24 14:42:10 +00:00
|
|
|
plannerModel->setRecalc(oldRecalc);
|
|
|
|
|
2014-04-17 02:56:42 +00:00
|
|
|
//TODO: C-based function here?
|
2014-06-01 04:24:27 +00:00
|
|
|
plan(&diveplan, &cache, &tempDive, stagingDive, isPlanner(), true);
|
2014-05-29 05:16:15 +00:00
|
|
|
record_dive(tempDive);
|
2014-01-15 08:30:42 +00:00
|
|
|
mark_divelist_changed(true);
|
2013-09-16 15:30:58 +00:00
|
|
|
|
2013-09-16 22:21:13 +00:00
|
|
|
// Remove and clean the diveplan, so we don't delete
|
|
|
|
// the dive by mistake.
|
|
|
|
diveplan.dp = NULL;
|
2013-11-09 00:09:46 +00:00
|
|
|
setPlanMode(NOTHING);
|
2013-11-10 12:02:53 +00:00
|
|
|
free(stagingDive);
|
|
|
|
stagingDive = NULL;
|
2014-05-28 18:54:04 +00:00
|
|
|
planCreated();
|
2013-09-16 15:30:58 +00:00
|
|
|
}
|