Offer to save to a copy in replan mode

When replannig a dive, offer another button that creates a new
dive rather than overwriting the old. This should help in creating
several versions of a planned dive (longer/shorter, deeper/shallower
etc). Note that this makes dives that start at the same time not
influcence each other's deco.

Also, only the first of a row of simultaneous dives contributes to
the tissue loadings of later dives.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Robert C. Helling 2014-11-04 12:15:27 +01:00 committed by Dirk Hohndel
parent 06ddfc0122
commit 20a9db779d
5 changed files with 66 additions and 7 deletions

View file

@ -347,7 +347,7 @@ double init_decompression(struct dive *dive)
{
int i, divenr = -1;
unsigned int surface_time;
timestamp_t when, lasttime = 0;
timestamp_t when, lasttime = 0, laststart = 0;
bool deco_init = false;
double tissue_tolerance, surface_pressure;
@ -370,8 +370,11 @@ double init_decompression(struct dive *dive)
* for how far back we need to go */
if (dive->divetrip && pdive->divetrip != dive->divetrip)
continue;
if (!pdive || pdive->when > when || pdive->when + pdive->duration.seconds + 48 * 60 * 60 < when)
if (!pdive || pdive->when >= when || pdive->when + pdive->duration.seconds + 48 * 60 * 60 < when)
break;
/* For simultaneous dives, only consider the first */
if (pdive->when == laststart)
continue;
when = pdive->when;
lasttime = when + pdive->duration.seconds;
}
@ -389,6 +392,7 @@ double init_decompression(struct dive *dive)
#endif
}
add_dive_to_deco(pdive);
laststart = pdive->when;
#if DECO_CALC_DEBUG & 2
printf("added dive #%d\n", pdive->number);
dump_tissues();

View file

@ -300,7 +300,9 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg
connect(DivePlannerPointsModel::instance(), SIGNAL(startTimeChanged(QDateTime)), this, SLOT(setupStartTime(QDateTime)));
// Creating (and canceling) the plan
connect(ui.buttonBox, SIGNAL(accepted()), plannerModel, SLOT(createPlan()));
replanButton = ui.buttonBox->addButton(tr("Save New"), QDialogButtonBox::ActionRole);
connect(replanButton, SIGNAL(clicked()), plannerModel, SLOT(saveDuplicatePlan()));
connect(ui.buttonBox, SIGNAL(accepted()), plannerModel, SLOT(savePlan()));
connect(ui.buttonBox, SIGNAL(rejected()), plannerModel, SLOT(cancelPlan()));
QShortcut *closeKey = new QShortcut(QKeySequence(Qt::Key_Escape), this);
connect(closeKey, SIGNAL(activated()), plannerModel, SLOT(cancelPlan()));
@ -319,6 +321,11 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg
setMinimumHeight(0);
}
void DivePlannerWidget::setReplanButton(bool replan)
{
replanButton->setVisible(replan);
}
void DivePlannerWidget::setupStartTime(QDateTime startTime)
{
ui.startTime->setTime(startTime.time());
@ -1168,7 +1175,17 @@ void DivePlannerPointsModel::deleteTemporaryPlan()
free_dps(&diveplan);
}
void DivePlannerPointsModel::createPlan()
void DivePlannerPointsModel::savePlan()
{
createPlan(false);
}
void DivePlannerPointsModel::saveDuplicatePlan()
{
createPlan(true);
}
void DivePlannerPointsModel::createPlan(bool replanCopy)
{
// Ok, so, here the diveplan creates a dive
char *cache = NULL;
@ -1188,6 +1205,15 @@ void DivePlannerPointsModel::createPlan()
displayed_dive.maxdepth.mm = 0;
displayed_dive.dc.maxdepth.mm = 0;
fixup_dive(&displayed_dive);
if (replanCopy) {
struct dive *copy = alloc_dive();
copy_dive(current_dive, copy);
copy->id = 0;
copy->divetrip = NULL;
if (current_dive->divetrip)
add_dive_to_trip(copy, current_dive->divetrip);
record_dive(copy);
}
copy_dive(&displayed_dive, current_dive);
}
mark_divelist_changed(true);

View file

@ -3,6 +3,7 @@
#include <QGraphicsPathItem>
#include <QAbstractTableModel>
#include <QAbstractButton>
#include <QDateTime>
#include "dive.h"
@ -80,7 +81,8 @@ slots:
void setDisplayRuntime(bool value);
void setDisplayDuration(bool value);
void setDisplayTransitions(bool value);
void createPlan();
void savePlan();
void saveDuplicatePlan();
void remove(const QModelIndex &index);
void cancelPlan();
void createTemporaryPlan();
@ -97,6 +99,7 @@ signals:
private:
explicit DivePlannerPointsModel(QObject *parent = 0);
bool addGas(struct gasmix mix);
void createPlan(bool replanCopy);
struct diveplan diveplan;
Mode mode;
bool recalc;
@ -136,6 +139,7 @@ class DivePlannerWidget : public QWidget {
Q_OBJECT
public:
explicit DivePlannerWidget(QWidget *parent = 0, Qt::WindowFlags f = 0);
void setReplanButton(bool replan);
public
slots:
void setupStartTime(QDateTime startTime);
@ -146,6 +150,7 @@ slots:
private:
Ui::DivePlanner ui;
QAbstractButton *replanButton;
};
#include "ui_plannerSettings.h"

View file

@ -100,7 +100,10 @@
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred"/>
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Planned dive time</string>
@ -109,6 +112,12 @@
</item>
<item row="1" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
</property>
@ -118,13 +127,26 @@
<layout class="QHBoxLayout" name="dateAndTime">
<item>
<widget class="QDateEdit" name="dateEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="calendarPopup">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QTimeEdit" name="startTime"/>
<widget class="QTimeEdit" name="startTime">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>

View file

@ -466,6 +466,7 @@ void MainWindow::on_actionReplanDive_triggered()
ui.newProfile->setPlanState();
ui.newProfile->clearHandlers();
ui.infoPane->setCurrentIndex(PLANNERWIDGET);
ui.divePlannerWidget->setReplanButton(true);
DivePlannerPointsModel::instance()->loadFromDive(current_dive);
reset_cylinders(&displayed_dive, true);
ui.diveListPane->setCurrentIndex(1); // switch to the plan output
@ -491,6 +492,7 @@ void MainWindow::on_actionDivePlanner_triggered()
DivePlannerPointsModel::instance()->setupStartTime();
DivePlannerPointsModel::instance()->createSimpleDive();
DivePictureModel::instance()->updateDivePictures();
ui.divePlannerWidget->setReplanButton(false);
ui.diveListPane->setCurrentIndex(1); // switch to the plan output
ui.globePane->setCurrentIndex(1);