[PATCH] Fix the imperial cylinder size calculations in equipment handling

Linus Torvalds torvalds at linux-foundation.org
Wed Jun 19 19:42:43 PDT 2013


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Wed, 19 Jun 2013 16:33:49 -1000
Subject: [PATCH] Fix the imperial cylinder size calculations in equipment handling

This makes us use the same linear calculations as we did in the Gtk
branch.  We don't take compressibility into account, since tank
manufacturers don't seem to either.  A Luxfer AL80 is 11.1 liters, and
with the standard (non-compressibility) calculations, 80 cuft of air at
3000 psi is 11.094 liter, so that is the right model to use.

Also, stop with the horrible "units in edited numbers" stuff.  It uses
up precious space, and doesn't look any better.  If the user asked for
cuft, give him cuft without making a big deal about it.

Oh, and if the working pressure doesn't exist, sizes are always in
liters.  That's what we did in the Gtk branch, that's what we do here.
Again, no reason to even bother stating units, it's not helping.

Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---

This makes the Qt branch do the same thing the gtk branch did, which is 
not only less surprising, but also seems to be what cylinder manufacturers 
do.

Taking actual compressibility into account when calculating SAC rates is a 
good idea, but not when doing cylinder sizing, not when manufacturers 
don't do it, and not when a physical cylinder can obviously not know what 
gas it contains (not that we actually do compressibility differently for 
different gases, but technically we could).

Anyway, with this, I get the values I expect.

 qt-ui/models.cpp | 47 ++++++++++++++++++++++-------------------------
 1 file changed, 22 insertions(+), 25 deletions(-)

diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 489f91bb6eb7..4ef8bc6ca588 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -84,12 +84,16 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const
 			// we can't use get_volume_string because the idiotic imperial tank
 			// sizes take working pressure into account...
 			if (cyl->type.size.mliter) {
-				if (prefs.units.volume == prefs.units.CUFT) {
-					double cuft = ml_to_cuft(gas_volume(cyl, cyl->type.workingpressure));
-					ret = QString("%1cuft").arg(cuft, 0, 'f', 1);
+				double volume;
+				int mbar = cyl->type.workingpressure.mbar;
+
+				if (mbar && prefs.units.volume == prefs.units.CUFT) {
+					volume = ml_to_cuft(cyl->type.size.mliter);
+					volume *= bar_to_atm(mbar / 1000.0);
 				} else {
-					ret = QString("%1l").arg(cyl->type.size.mliter / 1000.0, 0, 'f', 1);
+					volume = cyl->type.size.mliter / 1000.0;
 				}
+				ret = QString("%1").arg(volume, 0, 'f', 1);
 			}
 			break;
 		case WORKINGPRESS:
@@ -164,28 +168,21 @@ bool CylindersModel::setData(const QModelIndex& index, const QVariant& value, in
 			if (value.toDouble() != 0.0) {
 				TankInfoModel *tanks = TankInfoModel::instance();
 				QModelIndexList matches = tanks->match(tanks->index(0,0), Qt::DisplayRole, cyl->type.description);
-				if (prefs.units.volume == prefs.units.CUFT) {
-					if (cyl->type.workingpressure.mbar == 0) {
-						// this is a hack as we can't store a wet size
-						// without working pressure in cuft mode
-						// so we assume it's an aluminum tank at 3000psi
-						cyl->type.workingpressure.mbar = psi_to_mbar(3000);
-						if (!matches.isEmpty())
-							tanks->setData(tanks->index(matches.first().row(), TankInfoModel::BAR), cyl->type.workingpressure.mbar / 1000.0);
-					}
-					if (cyl->type.size.mliter != wet_volume(value.toDouble(), cyl->type.workingpressure)) {
-						mark_divelist_changed(TRUE);
-						cyl->type.size.mliter = wet_volume(value.toDouble(), cyl->type.workingpressure);
-						if (!matches.isEmpty())
-							tanks->setData(tanks->index(matches.first().row(), TankInfoModel::ML), cyl->type.size.mliter);
-					}
+				int mbar = cyl->type.workingpressure.mbar;
+				int mliter;
+
+				if (mbar && prefs.units.volume == prefs.units.CUFT) {
+					double liters = cuft_to_l(value.toDouble());
+					liters /= bar_to_atm(mbar / 1000.0);
+					mliter = rint(liters * 1000);
 				} else {
-					if (cyl->type.size.mliter != value.toDouble() * 1000.0) {
-						mark_divelist_changed(TRUE);
-						cyl->type.size.mliter = value.toDouble() * 1000.0;
-						if (!matches.isEmpty())
-							tanks->setData(tanks->index(matches.first().row(), TankInfoModel::ML), cyl->type.size.mliter);
-					}
+					mliter = rint(value.toDouble() * 1000);
+				}
+				if (cyl->type.size.mliter != mliter) {
+					mark_divelist_changed(TRUE);
+					cyl->type.size.mliter = mliter;
+					if (!matches.isEmpty())
+						tanks->setData(tanks->index(matches.first().row(), TankInfoModel::ML), cyl->type.size.mliter);
 				}
 			}
 		}
-- 
1.8.3



More information about the subsurface mailing list