Changeset 638e7fb in subsurface


Ignore:
Timestamp:
Jan 12, 2017, 2:17:09 PM (4 months ago)
Author:
Subsurface <dirk@…>
Branches:
master
Children:
56575b84
Parents:
6637aee1
git-author:
Linus Torvalds <torvalds@…> (01/11/17 09:22:41)
git-committer:
Subsurface <dirk@…> (01/12/17 14:17:09)
Message:

Add cylinder equipment tooltips with gas volume

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@…>

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • core/dive.c

    rb5de08b7 r638e7fb  
    873873        double bar = p.mbar / 1000.0;
    874874        double z_factor = gas_compressibility_factor(&cyl->gasmix, bar);
    875         return cyl->type.size.mliter * bar_to_atm(bar) / z_factor;
     875        return rint(cyl->type.size.mliter * bar_to_atm(bar) / z_factor);
    876876}
    877877
  • qt-models/cylindermodel.cpp

    r9710ac89 r638e7fb  
    5252}
    5353
     54static QString gas_volume_string(int ml, const char *tail)
     55{
     56        double vol;
     57        const char *unit;
     58        int decimals;
     59
     60        vol = get_volume_units(ml, NULL, &unit);
     61        decimals = (vol > 20.0) ? 0 : (vol > 2.0) ? 1 : 2;
     62
     63        return QString("%1 %2 %3").arg(vol, 0, 'f', decimals).arg(unit).arg(tail);
     64}
     65
     66static QVariant gas_usage_tooltip(cylinder_t *cyl)
     67{
     68        pressure_t startp = cyl->start.mbar ? cyl->start : cyl->sample_start;
     69        pressure_t endp = cyl->end.mbar ? cyl->end : cyl->sample_end;
     70
     71        int start, end, used;
     72
     73        start = gas_volume(cyl, startp);
     74        end = gas_volume(cyl, endp);
     75        used = (end && start > end) ? start - end : 0;
     76
     77        if (!used)
     78                return QVariant();
     79
     80        return gas_volume_string(used, "(") +
     81                gas_volume_string(start, " -> ") +
     82                gas_volume_string(end, ")");
     83}
     84
     85static QVariant gas_volume_tooltip(cylinder_t *cyl, pressure_t p)
     86{
     87        int vol = gas_volume(cyl, p);
     88        double Z;
     89
     90        if (!vol)
     91                return QVariant();
     92
     93        Z = gas_compressibility_factor(&cyl->gasmix, p.mbar / 1000.0);
     94        return gas_volume_string(vol, "(Z=") + QString("%1)").arg(Z, 0, 'f', 3);
     95}
     96
     97static QVariant gas_start_tooltip(cylinder_t *cyl)
     98{
     99        return gas_volume_tooltip(cyl, cyl->start.mbar ? cyl->start : cyl->sample_start);
     100}
     101
     102static QVariant gas_end_tooltip(cylinder_t *cyl)
     103{
     104        return gas_volume_tooltip(cyl, cyl->end.mbar ? cyl->end : cyl->sample_end);
     105}
    54106
    55107static QVariant percent_string(fraction_t fraction)
     
    177229                        ret = tr("Clicking here will remove this cylinder.");
    178230                        break;
     231                case SIZE:
     232                case WORKINGPRESS:
     233                        return gas_usage_tooltip(cyl);
     234                case START:
     235                        return gas_start_tooltip(cyl);
     236                case END:
     237                        return gas_end_tooltip(cyl);
    179238                case DEPTH:
    180239                        ret = tr("Switch depth for deco gas. Calculated using Deco pO₂ preference, unless set manually.");
Note: See TracChangeset for help on using the changeset viewer.