[PATCH 1/1] Add cylinder equipment tooltips with gas volume

Linus Torvalds torvalds at linux-foundation.org
Tue Jan 10 14:57:27 PST 2017


This adds tooltips for the equipment tab for each cylinder, showing the 
amount of gas used.

When you mouse over the size and working pressure fields, the tooltip will 
show the amount of gas used (along with start and end gas volumes). And 
when you mouse over the start and end pressures, it will show the start 
and end gas volumes, and the Z factor used.

I started doing this because of the gas volume questions in the last day 
or two (and a few from a few weeks ago). When even Robert Helling starts 
wondering about the effects of compressibility on the SAC calculation, our 
numbers are clearly too opaque.

With these tooltips, at least you can see what went into the used gas 
calculations, instead of having to add debugging options to print out Z 
factors.

[ This patch also adds a "rint()" to get the rounding right in the  
  gas_volume() function.  Although rounding to the nearst milliliter
  really doesn't matter, it's the right thing to do after doing FP 
  calculations ;^]

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

NOTE! This will *not* help the planner stage, which is where I'm assuming 
Robert is actually seeing the problems. I'm not sure what the exact issue 
Robert had, so I suspect this is just one part of something that we 
should clarify.

Robert? Can you give me more background on what SAC issue you were looking 
at? Because it is also entirely possible that we get something wrong 
somewhere - and hopefully having these kinds of tooltips will also make it 
more obvious when we screw up.

 core/dive.c                 |  2 +-
 qt-models/cylindermodel.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/core/dive.c b/core/dive.c
index 0ad728ae..a05f0529 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -872,7 +872,7 @@ int gas_volume(cylinder_t *cyl, pressure_t p)
 {
 	double bar = p.mbar / 1000.0;
 	double z_factor = gas_compressibility_factor(&cyl->gasmix, bar);
-	return cyl->type.size.mliter * bar_to_atm(bar) / z_factor;
+	return rint(cyl->type.size.mliter * bar_to_atm(bar) / z_factor);
 }
 
 /*
diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp
index 4a9b0386..c2c94f76 100644
--- a/qt-models/cylindermodel.cpp
+++ b/qt-models/cylindermodel.cpp
@@ -51,6 +51,58 @@ static QString get_cylinder_string(cylinder_t *cyl)
 	return QString("%1").arg(value, 0, 'f', decimals) + unit;
 }
 
+static QString gas_volume_string(int ml, const char *tail)
+{
+	double vol;
+	const char *unit;
+	int decimals;
+
+	vol = get_volume_units(ml, NULL, &unit);
+	decimals = (vol > 20.0) ? 0 : (vol > 2.0) ? 1 : 2;
+
+	return QString("%1 %2 %3").arg(vol, 0, 'f', decimals).arg(unit).arg(tail);
+}
+
+static QVariant gas_usage_tooltip(cylinder_t *cyl)
+{
+	pressure_t startp = cyl->start.mbar ? cyl->start : cyl->sample_start;
+	pressure_t endp = cyl->end.mbar ? cyl->end : cyl->sample_end;
+
+	int start, end, used;
+
+	start = gas_volume(cyl, startp);
+	end = gas_volume(cyl, endp);
+	used = (end && start > end) ? start - end : 0;
+
+	if (!used)
+		return QVariant();
+
+	return gas_volume_string(used, "(") +
+		gas_volume_string(start, " -> ") +
+		gas_volume_string(end, ")");
+}
+
+static QVariant gas_volume_tooltip(cylinder_t *cyl, pressure_t p)
+{
+	int vol = gas_volume(cyl, p);
+	double Z;
+
+	if (!vol)
+		return QVariant();
+
+	Z = gas_compressibility_factor(&cyl->gasmix, p.mbar / 1000.0);
+	return gas_volume_string(vol, "(Z=") + QString("%1)").arg(Z, 0, 'f', 3);
+}
+
+static QVariant gas_start_tooltip(cylinder_t *cyl)
+{
+	return gas_volume_tooltip(cyl, cyl->start.mbar ? cyl->start : cyl->sample_start);
+}
+
+static QVariant gas_end_tooltip(cylinder_t *cyl)
+{
+	return gas_volume_tooltip(cyl, cyl->end.mbar ? cyl->end : cyl->sample_end);
+}
 
 static QVariant percent_string(fraction_t fraction)
 {
@@ -176,6 +228,13 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
 		case REMOVE:
 			ret = tr("Clicking here will remove this cylinder.");
 			break;
+		case SIZE:
+		case WORKINGPRESS:
+			return gas_usage_tooltip(cyl);
+		case START:
+			return gas_start_tooltip(cyl);
+		case END:
+			return gas_end_tooltip(cyl);
 		case DEPTH:
 			ret = tr("Switch depth for deco gas. Calculated using Deco pO₂ preference, unless set manually.");
 			break;


More information about the subsurface mailing list