More conversions to gasmix

addStop, addGas and createSimpleDive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-06-01 18:18:29 -07:00
parent cfb93cb92c
commit 89f3532145
3 changed files with 28 additions and 45 deletions

View file

@ -62,19 +62,16 @@ void DivePlannerPointsModel::removeSelectedPoints(const QVector<int> &rows)
void DivePlannerPointsModel::createSimpleDive() void DivePlannerPointsModel::createSimpleDive()
{ {
int o2 = O2_IN_AIR; struct gasmix gas = { 0 };
int he = 0; if (isPlanner())
if (isPlanner()) {
// let's use the gas from the first cylinder // let's use the gas from the first cylinder
o2 = stagingDive->cylinder[0].gasmix.o2.permille; gas = stagingDive->cylinder[0].gasmix;
he = stagingDive->cylinder[0].gasmix.he.permille;
} plannerModel->addStop(M_OR_FT(15, 45), 1 * 60, gas, 0, true);
// plannerModel->addStop(0, 0, O2_IN_AIR, 0, 0); plannerModel->addStop(M_OR_FT(15, 45), 40 * 60, gas, 0, true);
plannerModel->addStop(M_OR_FT(15, 45), 1 * 60, o2, he, 0, true);
plannerModel->addStop(M_OR_FT(15, 45), 40 * 60, o2, he, 0, true);
if (!isPlanner()) { if (!isPlanner()) {
plannerModel->addStop(M_OR_FT(5, 15), 42 * 60, o2, he, 0, true); plannerModel->addStop(M_OR_FT(5, 15), 42 * 60, gas, 0, true);
plannerModel->addStop(M_OR_FT(5, 15), 45 * 60, o2, he, 0, true); plannerModel->addStop(M_OR_FT(5, 15), 45 * 60, gas, 0, true);
} }
} }
@ -95,7 +92,7 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
if (s.time.seconds == 0) if (s.time.seconds == 0)
continue; continue;
get_gas_from_events(&backupDive.dc, lasttime, &gas); get_gas_from_events(&backupDive.dc, lasttime, &gas);
plannerModel->addStop(s.depth.mm, s.time.seconds, get_o2(&gas), get_he(&gas), 0, true); plannerModel->addStop(s.depth.mm, s.time.seconds, gas, 0, true);
lasttime = s.time.seconds; lasttime = s.time.seconds;
} }
} }
@ -519,29 +516,20 @@ bool divePointsLessThan(const divedatapoint &p1, const divedatapoint &p2)
return p1.time <= p2.time; return p1.time <= p2.time;
} }
bool DivePlannerPointsModel::addGas(int o2, int he) bool DivePlannerPointsModel::addGas(struct gasmix mix)
{ {
struct gasmix mix;
mix.o2.permille = o2;
mix.he.permille = he;
sanitize_gasmix(&mix); sanitize_gasmix(&mix);
if (is_air(o2, he))
o2 = 0;
for (int i = 0; i < MAX_CYLINDERS; i++) { for (int i = 0; i < MAX_CYLINDERS; i++) {
cylinder_t *cyl = &stagingDive->cylinder[i]; cylinder_t *cyl = &stagingDive->cylinder[i];
if (cylinder_nodata(cyl)) { if (cylinder_nodata(cyl)) {
fill_default_cylinder(cyl); fill_default_cylinder(cyl);
cyl->gasmix.o2.permille = o2; cyl->gasmix = mix;
cyl->gasmix.he.permille = he;
sanitize_gasmix(&cyl->gasmix);
/* The depth to change to that gas is given by the depth where its pO2 is 1.6 bar. /* The depth to change to that gas is given by the depth where its pO2 is 1.6 bar.
* The user should be able to change this depth manually. */ * The user should be able to change this depth manually. */
pressure_t modppO2; pressure_t modppO2;
modppO2.mbar = 1600; modppO2.mbar = 1600;
cyl->depth = gas_mod(&cyl->gasmix, modppO2); cyl->depth = gas_mod(&mix, modppO2);
CylindersModel::instance()->setDive(stagingDive); CylindersModel::instance()->setDive(stagingDive);
return true; return true;
} }
@ -560,8 +548,9 @@ int DivePlannerPointsModel::lastEnteredPoint()
return -1; return -1;
} }
int DivePlannerPointsModel::addStop(int milimeters, int seconds, int o2, int he, int ccpoint, bool entered) int DivePlannerPointsModel::addStop(int milimeters, int seconds, struct gasmix gas, int ccpoint, bool entered, bool usePrevious)
{ {
struct gasmix air = { 0 };
if (recalcQ()) if (recalcQ())
removeDeco(); removeDeco();
@ -571,21 +560,18 @@ int DivePlannerPointsModel::addStop(int milimeters, int seconds, int o2, int he,
const divedatapoint t = divepoints.at(lastEnteredPoint()); const divedatapoint t = divepoints.at(lastEnteredPoint());
milimeters = t.depth; milimeters = t.depth;
seconds = t.time + 600; // 10 minutes. seconds = t.time + 600; // 10 minutes.
o2 = get_o2(&t.gasmix); gas = t.gasmix;
he = get_he(&t.gasmix);
ccpoint = t.po2; ccpoint = t.po2;
} else if (seconds == 0 && milimeters == 0 && row == 0) { } else if (seconds == 0 && milimeters == 0 && row == 0) {
milimeters = M_OR_FT(5, 15); // 5m / 15ft milimeters = M_OR_FT(5, 15); // 5m / 15ft
seconds = 600; // 10 min seconds = 600; // 10 min
//Default to the first defined gas, if we got one. //Default to the first defined gas, if we got one.
cylinder_t *cyl = &stagingDive->cylinder[0]; cylinder_t *cyl = &stagingDive->cylinder[0];
if (cyl) { if (cyl)
o2 = get_o2(&cyl->gasmix); gas = cyl->gasmix;
he = get_he(&cyl->gasmix);
}
} }
if (o2 != -1) if (!usePrevious)
if (!addGas(o2, he)) if (!addGas(gas))
qDebug("addGas failed"); // FIXME add error propagation qDebug("addGas failed"); // FIXME add error propagation
// check if there's already a new stop before this one: // check if there's already a new stop before this one:
@ -603,21 +589,18 @@ int DivePlannerPointsModel::addStop(int milimeters, int seconds, int o2, int he,
break; break;
} }
} }
if (o2 == -1) { if (usePrevious) {
if (row > 0) { if (row > 0) {
o2 = get_o2(&divepoints.at(row - 1).gasmix); gas = divepoints.at(row - 1).gasmix;
he = get_he(&divepoints.at(row - 1).gasmix);
} else { } else {
// when we add a first data point we need to make sure that there is a // when we add a first data point we need to make sure that there is a
// tank for it to use; // tank for it to use;
// first check to the right, then to the left, but if there's nothing, // first check to the right, then to the left, but if there's nothing,
// we simply default to AIR // we simply default to AIR
if (row < divepoints.count()) { if (row < divepoints.count()) {
o2 = get_o2(&divepoints.at(row).gasmix); gas = divepoints.at(row).gasmix;
he = get_he(&divepoints.at(row).gasmix);
} else { } else {
o2 = O2_IN_AIR; if (!addGas(air))
if (!addGas(o2, 0))
qDebug("addGas failed"); // FIXME add error propagation qDebug("addGas failed"); // FIXME add error propagation
} }
} }
@ -628,8 +611,7 @@ int DivePlannerPointsModel::addStop(int milimeters, int seconds, int o2, int he,
divedatapoint point; divedatapoint point;
point.depth = milimeters; point.depth = milimeters;
point.time = seconds; point.time = seconds;
point.gasmix.o2.permille = o2; point.gasmix = gas;
point.gasmix.he.permille = he;
point.po2 = ccpoint; point.po2 = ccpoint;
point.entered = entered; point.entered = entered;
divepoints.append(point); divepoints.append(point);

View file

@ -64,7 +64,7 @@ public:
public public
slots: slots:
int addStop(int millimeters = 0, int seconds = 0, int o2 = 0, int he = 0, int ccpoint = 0, bool entered = true); int addStop(int millimeters, int seconds, struct gasmix gas, int ccpoint, bool entered, bool usePrevious = false);
void addCylinder_clicked(); void addCylinder_clicked();
void setGFHigh(const int gfhigh); void setGFHigh(const int gfhigh);
void setGFLow(const int ghflow); void setGFLow(const int ghflow);
@ -88,7 +88,7 @@ signals:
private: private:
explicit DivePlannerPointsModel(QObject *parent = 0); explicit DivePlannerPointsModel(QObject *parent = 0);
bool addGas(int o2, int he); bool addGas(struct gasmix mix);
struct diveplan diveplan; struct diveplan diveplan;
Mode mode; Mode mode;
bool recalc; bool recalc;

View file

@ -605,7 +605,8 @@ void ProfileWidget2::mouseDoubleClickEvent(QMouseEvent *event)
int minutes = rint(timeAxis->valueAt(mappedPos) / 60); int minutes = rint(timeAxis->valueAt(mappedPos) / 60);
int milimeters = rint(profileYAxis->valueAt(mappedPos) / M_OR_FT(1, 1)) * M_OR_FT(1, 1); int milimeters = rint(profileYAxis->valueAt(mappedPos) / M_OR_FT(1, 1)) * M_OR_FT(1, 1);
plannerModel->addStop(milimeters, minutes * 60, -1, 0, 0, true); struct gasmix ignore = { 0 };
plannerModel->addStop(milimeters, minutes * 60, ignore, 0, true, true);
} }
} }