Sanity check on gas percentages

O2 + He + N2 = 100%
(well, there are some other gases, but this is close enough)

Since N2 can't be negative that means we should refuse any change where
O2 + He > 100% (or o2.permille + he.permille > 1000).

Fixes #280

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2013-11-19 05:00:09 -08:00
parent 4619bfd9ca
commit 1a5e94006c

View file

@ -284,14 +284,20 @@ bool CylindersModel::setData(const QModelIndex& index, const QVariant& value, in
break;
case O2:
if (CHANGED(toDouble, "%", "%")) {
cyl->gasmix.o2.permille = value.toString().remove('%').toDouble() * 10 + 0.5;
changed = true;
int o2 = value.toString().remove('%').toDouble() * 10 + 0.5;
if (cyl->gasmix.he.permille + o2 <= 1000) {
cyl->gasmix.o2.permille = o2;
changed = true;
}
}
break;
case HE:
if (CHANGED(toDouble, "%", "%")) {
cyl->gasmix.he.permille = value.toString().remove('%').toDouble() * 10 + 0.5;
changed = true;
int he = value.toString().remove('%').toDouble() * 10 + 0.5;
if (cyl->gasmix.o2.permille + he <= 1000) {
cyl->gasmix.he.permille = he;
changed = true;
}
}
break;
case DEPTH: