Changeset bb4bf63 in subsurface


Ignore:
Timestamp:
Jan 6, 2017, 8:43:23 PM (9 months ago)
Author:
Subsurface <dirk@…>
Branches:
master
Children:
9357341
Parents:
4e375f56
git-author:
Robert C. Helling <helling@…> (01/06/17 18:01:14)
git-committer:
Subsurface <dirk@…> (01/06/17 20:43:23)
Message:

Fix deco_mode confusion

We have two prefernces determining the deco_mode (BUEHLMANN vs VPMB
vs RECREATIONAL): One for the planner (deco_mode) and one for
displaying dives (display_deco_mode). The former is set in the planner
settings while the latter is set in the preferences.

This patch clears up a confusion which of the two to use by introducing
a helper function that selects the correct variable.

Signed-off-by: Robert C. Helling <helling@…>

Files:
8 edited

Legend:

Unmodified
Added
Removed
  • core/deco.c

    rf03acb9 rbb4bf63  
    2222#include <assert.h>
    2323#include "core/planner.h"
     24#include "qthelperfromc.h"
    2425
    2526#define cube(x) (x * x * x)
     
    259260        }
    260261
    261         if (prefs.deco_mode != VPMB) {
     262        if (decoMode() != VPMB) {
    262263                for (ci = 0; ci < 16; ci++) {
    263264
     
    382383double calc_surface_phase(double surface_pressure, double he_pressure, double n2_pressure, double he_time_constant, double n2_time_constant)
    383384{
    384         double inspired_n2 = (surface_pressure - ((in_planner() && (prefs.deco_mode == VPMB)) ? WV_PRESSURE_SCHREINER : WV_PRESSURE)) * NITROGEN_FRACTION;
     385        double inspired_n2 = (surface_pressure - ((in_planner() && (decoMode() == VPMB)) ? WV_PRESSURE_SCHREINER : WV_PRESSURE)) * NITROGEN_FRACTION;
    385386
    386387        if (n2_pressure > inspired_n2)
     
    523524        struct gas_pressures pressures;
    524525
    525         fill_pressures(&pressures, pressure - ((in_planner() && (prefs.deco_mode == VPMB)) ? WV_PRESSURE_SCHREINER : WV_PRESSURE),
     526        fill_pressures(&pressures, pressure - ((in_planner() && (decoMode() == VPMB)) ? WV_PRESSURE_SCHREINER : WV_PRESSURE),
    526527                       gasmix, (double) ccpo2 / 1000.0, dive->dc.divemode);
    527528
     
    542543
    543544        }
    544         if(prefs.deco_mode == VPMB)
     545        if(decoMode() == VPMB)
    545546                calc_crushing_pressure(pressure);
    546547        return;
     
    563564        int ci;
    564565        for (ci = 0; ci < 16; ci++) {
    565                 tissue_n2_sat[ci] = (surface_pressure - ((in_planner() && (prefs.deco_mode == VPMB)) ? WV_PRESSURE_SCHREINER : WV_PRESSURE)) * N2_IN_AIR / 1000;
     566                tissue_n2_sat[ci] = (surface_pressure - ((in_planner() && (decoMode() == VPMB)) ? WV_PRESSURE_SCHREINER : WV_PRESSURE)) * N2_IN_AIR / 1000;
    566567                tissue_he_sat[ci] = 0.0;
    567568                max_n2_crushing_pressure[ci] = 0.0;
  • core/planner.c

    r4359974 rbb4bf63  
    1515#include "gettext.h"
    1616#include "libdivecomputer/parser.h"
     17#include "qthelperfromc.h"
    1718
    1819#define TIMESTEP 2 /* second */
     
    174175                 * Remember the value for later.
    175176                 */
    176                 if ((prefs.deco_mode == VPMB) && (lastdepth.mm > sample->depth.mm)) {
     177                if ((decoMode() == VPMB) && (lastdepth.mm > sample->depth.mm)) {
    177178                        pressure_t ceiling_pressure;
    178179                        nuclear_regeneration(t0.seconds);
     
    549550        plan_display_transitions = prefs.display_transitions;
    550551
    551         if (prefs.deco_mode == VPMB) {
     552        if (decoMode() == VPMB) {
    552553                deco = "VPM-B";
    553554        } else {
     
    580581
    581582        len = show_disclaimer ? snprintf(buffer, sz_buffer, "<div><b>%s<b></div><br>", disclaimer) : 0;
    582         if (prefs.deco_mode == BUEHLMANN){
     583        if (decoMode() == BUEHLMANN){
    583584                snprintf(temp, sz_temp, translate("gettextFromC", "based on Bühlmann ZHL-16C with GFlow = %d and GFhigh = %d"),
    584585                        diveplan->gflow, diveplan->gfhigh);
    585         } else if (prefs.deco_mode == VPMB){
     586        } else if (decoMode() == VPMB){
    586587                int temp_len;
    587588                if (diveplan->vpmb_conservatism == 0)
     
    593594                                             , diveplan->eff_gfhigh);
    594595
    595         } else if (prefs.deco_mode == RECREATIONAL){
     596        } else if (decoMode() == RECREATIONAL){
    596597                snprintf(temp, sz_temp, translate("gettextFromC", "recreational mode based on Bühlmann ZHL-16B with GFlow = %d and GFhigh = %d"),
    597598                        diveplan->gflow, diveplan->gfhigh);
     
    939940        // deeper than the next stop (thus the offgasing during the ascent is ignored).
    940941        // However, we still need to make sure we don't break the ceiling due to on-gassing during ascent.
    941         if (prefs.deco_mode == VPMB && (deco_allowed_depth(tissue_tolerance_calc(&displayed_dive,
     942        if (decoMode() == VPMB && (deco_allowed_depth(tissue_tolerance_calc(&displayed_dive,
    942943                                                                                 depth_to_bar(stoplevel, &displayed_dive)),
    943944                                                           surface_pressure, &displayed_dive, 1) > stoplevel))
     
    10971098        vpmb_start_gradient();
    10981099
    1099         if(prefs.deco_mode == RECREATIONAL) {
     1100        if(decoMode() == RECREATIONAL) {
    11001101                bool safety_stop = prefs.safetystop && max_depth >= 10000;
    11011102                track_ascent_gas(depth, &displayed_dive.cylinder[current_cylinder], avg_depth, bottom_time, safety_stop);
     
    11731174        //CVA
    11741175        do {
    1175                 is_final_plan = (prefs.deco_mode == BUEHLMANN) || (previous_deco_time - deco_time < 10);  // CVA time converges
     1176                is_final_plan = (decoMode() == BUEHLMANN) || (previous_deco_time - deco_time < 10);  // CVA time converges
    11761177                if (deco_time != 10000000)
    11771178                        vpmb_next_gradient(deco_time, diveplan->surface_pressure / 1000.0);
     
    13731374
    13741375        plan_add_segment(diveplan, clock - previous_point_time, 0, current_cylinder, po2, false);
    1375         if(prefs.deco_mode == VPMB) {
     1376        if(decoMode() == VPMB) {
    13761377                diveplan->eff_gfhigh = rint(100.0 * regressionb());
    13771378                diveplan->eff_gflow = rint(100*(regressiona() * first_stop_depth + regressionb()));
  • core/profile.c

    rebddf95 rbb4bf63  
    1717#include "libdivecomputer/version.h"
    1818#include "membuffer.h"
     19#include "qthelperfromc.h"
    1920
    2021//#define DEBUG_GAS 1
     
    951952        char *cache_data_initial = NULL;
    952953        /* For VPM-B outside the planner, cache the initial deco state for CVA iterations */
    953         if (prefs.deco_mode == VPMB && !in_planner())
     954        if (decoMode() == VPMB && !in_planner())
    954955                cache_deco_state(&cache_data_initial);
    955956        /* For VPM-B outside the planner, iterate until deco time converges (usually one or two iterations after the initial)
     
    983984                        } else {
    984985                                /* Keep updating the VPM-B gradients until the start of the ascent phase of the dive. */
    985                                 if (prefs.deco_mode == VPMB && !in_planner() && (entry - 1)->ceiling >= first_ceiling && first_iteration == true) {
     986                                if (decoMode() == VPMB && !in_planner() && (entry - 1)->ceiling >= first_ceiling && first_iteration == true) {
    986987                                        nuclear_regeneration(t1);
    987988                                        vpmb_start_gradient();
     
    996997                                        current_ceiling = entry->ceiling;
    997998                                /* If using VPM-B outside the planner, take first_ceiling_pressure as the deepest ceiling */
    998                                 if (prefs.deco_mode == VPMB && !in_planner()) {
     999                                if (decoMode() == VPMB && !in_planner()) {
    9991000                                        if  (current_ceiling > first_ceiling) {
    10001001                                                time_deep_ceiling = t1;
     
    10281029                        * If the ceiling hasn't cleared by the last data point, we need tts for VPM-B CVA calculation
    10291030                        * It is not necessary to do these calculation on the first VPMB iteration, except for the last data point */
    1030                         if ((prefs.calcndltts && !print_mode && (prefs.deco_mode != VPMB || in_planner() || !first_iteration)) ||
    1031                             (prefs.deco_mode == VPMB && !in_planner() && i == pi->nr - 1)) {
     1031                        if ((prefs.calcndltts && !print_mode && (decoMode() != VPMB || in_planner() || !first_iteration)) ||
     1032                            (decoMode() == VPMB && !in_planner() && i == pi->nr - 1)) {
    10321033                                /* only calculate ndl/tts on every 30 seconds */
    10331034                                if ((entry->sec - last_ndl_tts_calc_time) < 30 && i != pi->nr - 1) {
     
    10451046                                cache_deco_state(&cache_data);
    10461047                                calculate_ndl_tts(entry, dive, surface_pressure);
    1047                                 if (prefs.deco_mode == VPMB && !in_planner() && i == pi->nr - 1)
     1048                                if (decoMode() == VPMB && !in_planner() && i == pi->nr - 1)
    10481049                                        final_tts = entry->tts_calc;
    10491050                                /* Restore "real" deco state for next real time step */
     
    10521053                        }
    10531054                }
    1054                 if (prefs.deco_mode == VPMB && !in_planner()) {
     1055                if (decoMode() == VPMB && !in_planner()) {
    10551056                        prev_deco_time = deco_time;
    10561057                        // Do we need to update deco_time?
  • core/qthelper.cpp

    r10b8bda rbb4bf63  
    14381438}
    14391439
     1440extern "C" enum deco_mode decoMode()
     1441{
     1442        return in_planner() ? prefs.deco_mode : prefs.display_deco_mode;
     1443}
     1444
    14401445void init_proxy()
    14411446{
  • core/qthelper.h

    r9b2404fc rbb4bf63  
    4141void setCurrentAppState(QByteArray state);
    4242extern "C" bool in_planner();
     43extern "C" enum deco_mode decoMode();
    4344extern "C" void subsurface_mkdir(const char *dir);
    4445void init_proxy();
  • core/qthelperfromc.h

    r7be962b rbb4bf63  
    1919char *picturedir_string();
    2020const char *subsurface_user_agent();
     21enum deco_mode decoMode();
    2122
    2223#endif // QTHELPERFROMC_H
  • profile-widget/divetooltipitem.cpp

    r37e3e7e6 rbb4bf63  
    99#include <QGraphicsView>
    1010#include <QStyleOptionGraphicsItem>
     11#include "core/qthelper.h"
    1112
    1213void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QPixmap& pixmap)
     
    268269
    269270                painter.setPen(QColor(0, 0, 0, 255));
    270                 if ((view->currentState == ProfileWidget2::PLAN && prefs.deco_mode == BUEHLMANN) || prefs.display_deco_mode == BUEHLMANN)
     271                if (decoMode() == BUEHLMANN)
    271272                        painter.drawLine(0, 60 - entry->gfline / 2, 16, 60 - entry->gfline / 2);
    272273                painter.drawLine(0, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure / 2,
  • profile-widget/profilewidget2.cpp

    r37e3e7e6 rbb4bf63  
    2020#include "desktop-widgets/simplewidgets.h"
    2121#include "desktop-widgets/divepicturewidget.h"
     22#include "core/qthelper.h"
    2223#endif
    2324
     
    559560                copy_dive(d, &displayed_dive);
    560561#ifndef SUBSURFACE_MOBILE
    561                 if ((currentState == PLAN && prefs.deco_mode == VPMB) || prefs.display_deco_mode == VPMB)
     562                if (decoMode() == VPMB)
    562563                        decoModelParameters->setText(QString("VPM-B +%1").arg(prefs.vpmb_conservatism));
    563564                else
     
    571572                        return;
    572573                }
    573                 if ((currentState == PLAN && prefs.deco_mode == VPMB) || prefs.display_deco_mode == VPMB)
     574                if (decoMode() == VPMB)
    574575                        decoModelParameters->setText(QString("VPM-B +%1").arg(diveplan.vpmb_conservatism));
    575576                else
Note: See TracChangeset for help on using the changeset viewer.