2017-04-27 18:24:53 +00:00
|
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-03-11 20:08:31 +00:00
|
|
|
|
#ifdef __clang__
|
2016-03-09 18:17:17 +00:00
|
|
|
|
// Clang has a bug on zero-initialization of C structs.
|
|
|
|
|
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
|
2017-03-11 20:08:31 +00:00
|
|
|
|
#endif
|
2016-03-09 18:17:17 +00:00
|
|
|
|
|
2024-04-05 15:15:04 +00:00
|
|
|
|
/* equipment.cpp */
|
2011-09-09 15:38:48 +00:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include <time.h>
|
2019-06-04 11:52:48 +00:00
|
|
|
|
#include <limits.h>
|
2019-05-30 18:51:30 +00:00
|
|
|
|
#include "equipment.h"
|
2013-10-06 15:55:58 +00:00
|
|
|
|
#include "gettext.h"
|
2011-09-09 15:38:48 +00:00
|
|
|
|
#include "dive.h"
|
|
|
|
|
#include "divelist.h"
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
|
#include "divelog.h"
|
2024-03-24 20:03:08 +00:00
|
|
|
|
#include "errorhelper.h"
|
2020-10-25 18:13:42 +00:00
|
|
|
|
#include "pref.h"
|
2024-05-28 19:31:11 +00:00
|
|
|
|
#include "range.h"
|
2019-07-15 20:16:56 +00:00
|
|
|
|
#include "subsurface-string.h"
|
2019-06-26 15:21:03 +00:00
|
|
|
|
|
2024-05-28 19:31:11 +00:00
|
|
|
|
cylinder_t::cylinder_t() = default;
|
|
|
|
|
cylinder_t::~cylinder_t() = default;
|
|
|
|
|
|
|
|
|
|
static cylinder_t make_surface_air_cylinder()
|
|
|
|
|
{
|
|
|
|
|
cylinder_t res;
|
|
|
|
|
res.cylinder_use = NOT_USED;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
static const cylinder_t surface_air_cylinder = make_surface_air_cylinder();
|
|
|
|
|
|
|
|
|
|
static void warn_index(size_t i, size_t max)
|
|
|
|
|
{
|
|
|
|
|
if (i >= max + 1) {
|
|
|
|
|
report_info("Warning: accessing invalid cylinder %lu (%lu existing)",
|
|
|
|
|
static_cast<unsigned long>(i), static_cast<unsigned long>(max));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cylinder_t &cylinder_table::operator[](size_t i)
|
|
|
|
|
{
|
|
|
|
|
warn_index(i, size());
|
|
|
|
|
return i < size() ? std::vector<cylinder_t>::operator[](i)
|
|
|
|
|
: const_cast<cylinder_t &>(surface_air_cylinder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const cylinder_t &cylinder_table::operator[](size_t i) const
|
|
|
|
|
{
|
|
|
|
|
warn_index(i, size());
|
|
|
|
|
return i < size() ? std::vector<cylinder_t>::operator[](i)
|
|
|
|
|
: surface_air_cylinder;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-29 05:03:03 +00:00
|
|
|
|
weightsystem_t::weightsystem_t() = default;
|
|
|
|
|
weightsystem_t::~weightsystem_t() = default;
|
|
|
|
|
weightsystem_t::weightsystem_t(weight_t w, std::string desc, bool auto_filled)
|
|
|
|
|
: weight(w), description(std::move(desc)), auto_filled(auto_filled)
|
2019-06-26 15:21:03 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-15 20:16:56 +00:00
|
|
|
|
const char *cylinderuse_text[NUM_GAS_USE] = {
|
|
|
|
|
QT_TRANSLATE_NOOP("gettextFromC", "OC-gas"), QT_TRANSLATE_NOOP("gettextFromC", "diluent"), QT_TRANSLATE_NOOP("gettextFromC", "oxygen"), QT_TRANSLATE_NOOP("gettextFromC", "not used")
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-04 16:45:55 +00:00
|
|
|
|
enum cylinderuse cylinderuse_from_text(const char *text)
|
2019-07-15 20:16:56 +00:00
|
|
|
|
{
|
2024-04-05 15:15:04 +00:00
|
|
|
|
for (int i = 0; i < static_cast<int>(NUM_GAS_USE); i++) {
|
2019-07-15 20:16:56 +00:00
|
|
|
|
if (same_string(text, cylinderuse_text[i]) || same_string(text, translate("gettextFromC", cylinderuse_text[i])))
|
2024-04-05 15:15:04 +00:00
|
|
|
|
return static_cast<enum cylinderuse>(i);
|
2019-07-15 20:16:56 +00:00
|
|
|
|
}
|
2024-04-05 15:15:04 +00:00
|
|
|
|
return static_cast<enum cylinderuse>(-1);
|
2019-07-15 20:16:56 +00:00
|
|
|
|
}
|
2011-09-09 15:38:48 +00:00
|
|
|
|
|
2020-12-11 21:34:35 +00:00
|
|
|
|
/* Add a metric or an imperial tank info structure. Copies the passed-in string. */
|
2024-05-03 21:18:45 +00:00
|
|
|
|
static void add_tank_info_metric(std::vector<tank_info> &table, const std::string &name, int ml, int bar)
|
2020-12-11 21:34:35 +00:00
|
|
|
|
{
|
2024-05-03 21:18:45 +00:00
|
|
|
|
table.push_back(tank_info{ name, .ml = ml, .bar = bar });
|
2020-12-11 21:34:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 21:18:45 +00:00
|
|
|
|
static void add_tank_info_imperial(std::vector<tank_info> &table, const std::string &name, int cuft, int psi)
|
2020-12-11 21:34:35 +00:00
|
|
|
|
{
|
2024-05-03 21:18:45 +00:00
|
|
|
|
table.push_back(tank_info{ name, .cuft = cuft, .psi = psi });
|
2020-12-11 21:34:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 21:18:45 +00:00
|
|
|
|
struct tank_info *get_tank_info(std::vector<tank_info> &table, const std::string &name)
|
2024-03-30 12:40:00 +00:00
|
|
|
|
{
|
2024-05-03 21:18:45 +00:00
|
|
|
|
auto it = std::find_if(table.begin(), table.end(), [&name](const tank_info &info)
|
|
|
|
|
{ return info.name == name; });
|
|
|
|
|
return it != table.end() ? &*it : nullptr;
|
2024-03-30 12:40:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 21:18:45 +00:00
|
|
|
|
void set_tank_info_data(std::vector<tank_info> &table, const std::string &name, volume_t size, pressure_t working_pressure)
|
2024-03-30 12:40:00 +00:00
|
|
|
|
{
|
|
|
|
|
struct tank_info *info = get_tank_info(table, name);
|
|
|
|
|
if (info) {
|
2024-06-09 04:16:26 +00:00
|
|
|
|
if (info->ml != 0 || info->bar != 0) {
|
|
|
|
|
info->bar = working_pressure.mbar / 1000;
|
2024-03-30 12:40:00 +00:00
|
|
|
|
info->ml = size.mliter;
|
2024-06-09 04:16:26 +00:00
|
|
|
|
} else {
|
|
|
|
|
info->psi = lrint(to_PSI(working_pressure));
|
|
|
|
|
info->cuft = lrint(ml_to_cuft(size.mliter) * mbar_to_atm(working_pressure.mbar));
|
|
|
|
|
}
|
2024-03-30 12:40:00 +00:00
|
|
|
|
} else {
|
2024-06-09 04:16:26 +00:00
|
|
|
|
// Metric is a better choice as the volume is independent of the working pressure
|
|
|
|
|
add_tank_info_metric(table, name, size.mliter, working_pressure.mbar / 1000);
|
2024-03-30 12:40:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 21:18:45 +00:00
|
|
|
|
std::pair<volume_t, pressure_t> extract_tank_info(const struct tank_info &info)
|
2024-06-09 04:16:26 +00:00
|
|
|
|
{
|
2024-05-03 21:18:45 +00:00
|
|
|
|
pressure_t working_pressure {
|
|
|
|
|
static_cast<int32_t>(info.bar != 0 ? info.bar * 1000 : psi_to_mbar(info.psi))
|
|
|
|
|
};
|
|
|
|
|
volume_t size { 0 };
|
|
|
|
|
if (info.ml != 0)
|
|
|
|
|
size.mliter = info.ml;
|
|
|
|
|
else if (working_pressure.mbar != 0)
|
|
|
|
|
size.mliter = lrint(cuft_to_l(info.cuft) * 1000 / mbar_to_atm(working_pressure.mbar));
|
|
|
|
|
return std::make_pair(size, working_pressure);
|
2024-06-09 04:16:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 21:18:45 +00:00
|
|
|
|
std::pair<volume_t, pressure_t> get_tank_info_data(const std::vector<tank_info> &table, const std::string &name)
|
2024-03-30 12:40:00 +00:00
|
|
|
|
{
|
2024-05-03 21:18:45 +00:00
|
|
|
|
// Here, we would need a const version of get_tank_info().
|
|
|
|
|
auto it = std::find_if(table.begin(), table.end(), [&name](const tank_info &info)
|
|
|
|
|
{ return info.name == name; });
|
|
|
|
|
return it != table.end() ? extract_tank_info(*it)
|
|
|
|
|
: std::make_pair(volume_t{0}, pressure_t{0});
|
2024-03-30 12:40:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 21:18:45 +00:00
|
|
|
|
void add_cylinder_description(const cylinder_type_t &type)
|
2013-05-03 18:04:51 +00:00
|
|
|
|
{
|
2024-05-28 19:31:11 +00:00
|
|
|
|
const std::string &desc = type.description;
|
2024-05-03 21:18:45 +00:00
|
|
|
|
if (desc.empty())
|
2013-05-03 18:04:51 +00:00
|
|
|
|
return;
|
2024-05-03 21:18:45 +00:00
|
|
|
|
if (std::any_of(tank_info_table.begin(), tank_info_table.end(),
|
2024-05-28 19:31:11 +00:00
|
|
|
|
[&desc](const tank_info &info) { return info.name == desc; }))
|
2024-05-03 21:18:45 +00:00
|
|
|
|
return;
|
|
|
|
|
add_tank_info_metric(tank_info_table, desc, type.size.mliter,
|
|
|
|
|
type.workingpressure.mbar / 1000);
|
2013-05-03 18:04:51 +00:00
|
|
|
|
}
|
2019-06-26 15:21:03 +00:00
|
|
|
|
|
2024-04-17 09:31:50 +00:00
|
|
|
|
void add_weightsystem_description(const weightsystem_t &weightsystem)
|
2013-05-03 18:04:51 +00:00
|
|
|
|
{
|
2024-05-29 05:03:03 +00:00
|
|
|
|
if (weightsystem.description.empty())
|
2024-04-17 09:31:50 +00:00
|
|
|
|
return;
|
2013-05-03 18:04:51 +00:00
|
|
|
|
|
2024-04-17 09:31:50 +00:00
|
|
|
|
auto it = std::find_if(ws_info_table.begin(), ws_info_table.end(),
|
|
|
|
|
[&weightsystem](const ws_info &info)
|
|
|
|
|
{ return info.name == weightsystem.description; });
|
|
|
|
|
if (it != ws_info_table.end()) {
|
|
|
|
|
it->weight = weightsystem.weight;
|
2013-05-03 18:04:51 +00:00
|
|
|
|
return;
|
2013-09-10 18:42:26 +00:00
|
|
|
|
}
|
2024-04-17 09:31:50 +00:00
|
|
|
|
ws_info_table.push_back(ws_info { std::string(weightsystem.description), weightsystem.weight });
|
2013-05-03 18:04:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-17 09:31:50 +00:00
|
|
|
|
weight_t get_weightsystem_weight(const std::string &name)
|
2024-03-30 12:40:00 +00:00
|
|
|
|
{
|
2024-04-17 09:31:50 +00:00
|
|
|
|
// Also finds translated names (TODO: should only consider non-user items).
|
|
|
|
|
auto it = std::find_if(ws_info_table.begin(), ws_info_table.end(),
|
|
|
|
|
[&name](const ws_info &info)
|
|
|
|
|
{ return info.name == name || translate("gettextFromC", info.name.c_str()) == name; });
|
|
|
|
|
return it != ws_info_table.end() ? it->weight : weight_t();
|
2024-03-30 12:40:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 12:49:25 +00:00
|
|
|
|
void cylinder_table::add(int idx, cylinder_t cyl)
|
2020-04-28 12:50:40 +00:00
|
|
|
|
{
|
2024-07-02 12:49:25 +00:00
|
|
|
|
insert(begin() + idx, std::move(cyl));
|
2011-10-02 20:13:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-30 20:12:25 +00:00
|
|
|
|
bool weightsystem_t::operator==(const weightsystem_t &w2) const
|
Fix missing save of (almost empty) cylinder information
If we have no explicit cylinder info at all (it's normal air, no size or
working pressure information, and no beginning/end pressure information),
we don't save the cylinders in question because that would be redundant.
Such non-saved cylinders may still show up in the equipment list because
there may be implicit mention of them elsewhere, notably due to sample
data, so not saving them is the right thing to do - there is nothing to
save.
However, we missed one case: if there were other cylinders that *did* have
explicit information in it following such an uninteresting cylinder, we do
need to save the cylinder information for the useless case - if only in
order to be able to save the non-useless information for subsequent
cylinders.
This patch does that. Now, if you had an air-filled cylinder with no
information as your first cylinder, and a 51% nitrox as your second one,
it will save that information as
<cylinder />
<cylinder o2='51.0%' />
rather than dropping the cylinder information entirely.
This bug has been there for a long time, and was hidden by the fact that
normally you'd fill in cylinder descriptions etc after importing new
dives. It also used to be that we saved the cylinder beginning/end
pressure even if that was generated from the sample data, so if you
imported from a air-integrated computer and had samples for that cylinder,
we used to save it even though it was technically redundant.
We stopped saving redundant air sample information in commit 0089dd8819b7
("Don't save cylinder start/end pressures unless set by hand").
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Removed start and end in save_cylinder_info(). These two variables are no
longer used.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-21 21:06:57 +00:00
|
|
|
|
{
|
2024-06-30 20:12:25 +00:00
|
|
|
|
return std::tie(weight.grams, description) ==
|
|
|
|
|
std::tie(w2.weight.grams, w2.description);
|
Fix missing save of (almost empty) cylinder information
If we have no explicit cylinder info at all (it's normal air, no size or
working pressure information, and no beginning/end pressure information),
we don't save the cylinders in question because that would be redundant.
Such non-saved cylinders may still show up in the equipment list because
there may be implicit mention of them elsewhere, notably due to sample
data, so not saving them is the right thing to do - there is nothing to
save.
However, we missed one case: if there were other cylinders that *did* have
explicit information in it following such an uninteresting cylinder, we do
need to save the cylinder information for the useless case - if only in
order to be able to save the non-useless information for subsequent
cylinders.
This patch does that. Now, if you had an air-filled cylinder with no
information as your first cylinder, and a 51% nitrox as your second one,
it will save that information as
<cylinder />
<cylinder o2='51.0%' />
rather than dropping the cylinder information entirely.
This bug has been there for a long time, and was hidden by the fact that
normally you'd fill in cylinder descriptions etc after importing new
dives. It also used to be that we saved the cylinder beginning/end
pressure even if that was generated from the sample data, so if you
imported from a air-integrated computer and had samples for that cylinder,
we used to save it even though it was technically redundant.
We stopped saving redundant air sample information in commit 0089dd8819b7
("Don't save cylinder start/end pressures unless set by hand").
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Removed start and end in save_cylinder_info(). These two variables are no
longer used.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-21 21:06:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 09:12:27 +00:00
|
|
|
|
volume_t cylinder_t::gas_volume(pressure_t p) const
|
2019-06-04 11:52:48 +00:00
|
|
|
|
{
|
|
|
|
|
double bar = p.mbar / 1000.0;
|
2024-07-02 09:12:27 +00:00
|
|
|
|
double z_factor = gas_compressibility_factor(gasmix, bar);
|
|
|
|
|
return volume_t { static_cast<int>(lrint(type.size.mliter * bar_to_atm(bar) / z_factor)) };
|
2019-06-04 11:52:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 19:31:11 +00:00
|
|
|
|
int find_best_gasmix_match(struct gasmix mix, const struct cylinder_table &cylinders)
|
2019-06-04 11:52:48 +00:00
|
|
|
|
{
|
|
|
|
|
int best = -1, score = INT_MAX;
|
|
|
|
|
|
2024-05-28 19:31:11 +00:00
|
|
|
|
for (auto [i, match]: enumerated_range(cylinders)) {
|
|
|
|
|
int distance = gasmix_distance(mix, match.gasmix);
|
2019-06-04 11:52:48 +00:00
|
|
|
|
if (distance >= score)
|
|
|
|
|
continue;
|
|
|
|
|
best = i;
|
|
|
|
|
score = distance;
|
|
|
|
|
}
|
|
|
|
|
return best;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-11 00:14:07 +00:00
|
|
|
|
/*
|
|
|
|
|
* We hardcode the most common standard cylinders,
|
|
|
|
|
* we should pick up any other names from the dive
|
|
|
|
|
* logs directly.
|
|
|
|
|
*/
|
2024-05-03 21:18:45 +00:00
|
|
|
|
static void add_default_tank_infos(std::vector<tank_info> &table)
|
2020-12-11 21:34:35 +00:00
|
|
|
|
{
|
2011-09-11 00:14:07 +00:00
|
|
|
|
/* Size-only metric cylinders */
|
2020-12-11 21:34:35 +00:00
|
|
|
|
add_tank_info_metric(table, "10.0ℓ", 10000, 0);
|
|
|
|
|
add_tank_info_metric(table, "11.1ℓ", 11100, 0);
|
2011-09-11 00:14:07 +00:00
|
|
|
|
|
|
|
|
|
/* Most common AL cylinders */
|
2020-12-17 08:09:49 +00:00
|
|
|
|
add_tank_info_imperial(table, "AL40", 40, 3000);
|
|
|
|
|
add_tank_info_imperial(table, "AL50", 50, 3000);
|
|
|
|
|
add_tank_info_imperial(table, "AL63", 63, 3000);
|
|
|
|
|
add_tank_info_imperial(table, "AL72", 72, 3000);
|
|
|
|
|
add_tank_info_imperial(table, "AL80", 80, 3000);
|
|
|
|
|
add_tank_info_imperial(table, "AL100", 100, 3300);
|
2011-09-11 00:14:07 +00:00
|
|
|
|
|
2014-06-25 08:43:03 +00:00
|
|
|
|
/* Metric AL cylinders */
|
2020-12-11 21:34:35 +00:00
|
|
|
|
add_tank_info_metric(table, "ALU7", 7000, 200);
|
2014-06-25 08:43:03 +00:00
|
|
|
|
|
2011-09-11 00:14:07 +00:00
|
|
|
|
/* Somewhat common LP steel cylinders */
|
2020-12-11 21:34:35 +00:00
|
|
|
|
add_tank_info_imperial(table, "LP85", 85, 2640);
|
|
|
|
|
add_tank_info_imperial(table, "LP95", 95, 2640);
|
|
|
|
|
add_tank_info_imperial(table, "LP108", 108, 2640);
|
|
|
|
|
add_tank_info_imperial(table, "LP121", 121, 2640);
|
2011-09-11 00:14:07 +00:00
|
|
|
|
|
|
|
|
|
/* Somewhat common HP steel cylinders */
|
2020-12-11 21:34:35 +00:00
|
|
|
|
add_tank_info_imperial(table, "HP65", 65, 3442);
|
|
|
|
|
add_tank_info_imperial(table, "HP80", 80, 3442);
|
|
|
|
|
add_tank_info_imperial(table, "HP100", 100, 3442);
|
|
|
|
|
add_tank_info_imperial(table, "HP117", 117, 3442);
|
|
|
|
|
add_tank_info_imperial(table, "HP119", 119, 3442);
|
|
|
|
|
add_tank_info_imperial(table, "HP130", 130, 3442);
|
2011-09-11 00:14:07 +00:00
|
|
|
|
|
2011-12-11 20:03:55 +00:00
|
|
|
|
/* Common European steel cylinders */
|
2020-12-11 21:34:35 +00:00
|
|
|
|
add_tank_info_metric(table, "3ℓ 232 bar", 3000, 232);
|
|
|
|
|
add_tank_info_metric(table, "3ℓ 300 bar", 3000, 300);
|
|
|
|
|
add_tank_info_metric(table, "10ℓ 200 bar", 10000, 200);
|
|
|
|
|
add_tank_info_metric(table, "10ℓ 232 bar", 10000, 232);
|
|
|
|
|
add_tank_info_metric(table, "10ℓ 300 bar", 10000, 300);
|
|
|
|
|
add_tank_info_metric(table, "12ℓ 200 bar", 12000, 200);
|
|
|
|
|
add_tank_info_metric(table, "12ℓ 232 bar", 12000, 232);
|
|
|
|
|
add_tank_info_metric(table, "12ℓ 300 bar", 12000, 300);
|
|
|
|
|
add_tank_info_metric(table, "15ℓ 200 bar", 15000, 200);
|
|
|
|
|
add_tank_info_metric(table, "15ℓ 232 bar", 15000, 232);
|
|
|
|
|
add_tank_info_metric(table, "D7 300 bar", 14000, 300);
|
|
|
|
|
add_tank_info_metric(table, "D8.5 232 bar", 17000, 232);
|
|
|
|
|
add_tank_info_metric(table, "D12 232 bar", 24000, 232);
|
|
|
|
|
add_tank_info_metric(table, "D13 232 bar", 26000, 232);
|
|
|
|
|
add_tank_info_metric(table, "D15 232 bar", 30000, 232);
|
|
|
|
|
add_tank_info_metric(table, "D16 232 bar", 32000, 232);
|
|
|
|
|
add_tank_info_metric(table, "D18 232 bar", 36000, 232);
|
|
|
|
|
add_tank_info_metric(table, "D20 232 bar", 40000, 232);
|
|
|
|
|
}
|
2011-09-09 15:38:48 +00:00
|
|
|
|
|
2024-05-03 21:18:45 +00:00
|
|
|
|
std::vector<tank_info> tank_info_table;
|
|
|
|
|
void reset_tank_info_table(std::vector<tank_info> &table)
|
2020-12-11 22:55:18 +00:00
|
|
|
|
{
|
2024-05-03 21:18:45 +00:00
|
|
|
|
table.clear();
|
2020-12-11 22:55:18 +00:00
|
|
|
|
if (prefs.display_default_tank_infos)
|
|
|
|
|
add_default_tank_infos(table);
|
|
|
|
|
|
|
|
|
|
/* Add cylinders from dive list */
|
2024-06-07 08:25:09 +00:00
|
|
|
|
for (auto &dive: divelog.dives) {
|
2024-05-28 19:31:11 +00:00
|
|
|
|
for (auto &cyl: dive->cylinders)
|
|
|
|
|
add_cylinder_description(cyl.type);
|
2020-12-11 22:55:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-24 03:41:16 +00:00
|
|
|
|
/*
|
|
|
|
|
* We hardcode the most common weight system types
|
|
|
|
|
* This is a bit odd as the weight system types don't usually encode weight
|
|
|
|
|
*/
|
2024-04-17 09:31:50 +00:00
|
|
|
|
struct std::vector<ws_info> ws_info_table = {
|
|
|
|
|
{ QT_TRANSLATE_NOOP("gettextFromC", "integrated"), weight_t() },
|
|
|
|
|
{ QT_TRANSLATE_NOOP("gettextFromC", "belt"), weight_t() },
|
|
|
|
|
{ QT_TRANSLATE_NOOP("gettextFromC", "ankle"), weight_t() },
|
|
|
|
|
{ QT_TRANSLATE_NOOP("gettextFromC", "backplate"), weight_t() },
|
|
|
|
|
{ QT_TRANSLATE_NOOP("gettextFromC", "clip-on"), weight_t() },
|
2011-12-24 03:41:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
2024-05-04 16:45:55 +00:00
|
|
|
|
void remove_cylinder(struct dive *dive, int idx)
|
2013-05-22 17:02:28 +00:00
|
|
|
|
{
|
2024-05-28 19:31:11 +00:00
|
|
|
|
dive->cylinders.erase(dive->cylinders.begin() + idx);
|
2013-05-22 17:02:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 08:21:14 +00:00
|
|
|
|
void weightsystem_table::remove(int idx)
|
2013-05-22 17:02:28 +00:00
|
|
|
|
{
|
2024-07-02 08:21:14 +00:00
|
|
|
|
erase(begin() + idx);
|
2024-05-29 05:03:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 19:54:59 +00:00
|
|
|
|
void weightsystem_table::add(int idx, weightsystem_t ws)
|
2024-05-29 05:03:03 +00:00
|
|
|
|
{
|
2024-07-01 19:54:59 +00:00
|
|
|
|
idx = std::clamp(idx, 0, static_cast<int>(size()));
|
|
|
|
|
insert(begin() + idx, std::move(ws));
|
2013-05-22 17:02:28 +00:00
|
|
|
|
}
|
2014-05-29 21:36:14 +00:00
|
|
|
|
|
2024-07-01 20:55:39 +00:00
|
|
|
|
void weightsystem_table::set(int idx, weightsystem_t ws)
|
2019-11-08 21:47:38 +00:00
|
|
|
|
{
|
2024-07-01 20:55:39 +00:00
|
|
|
|
if (idx < 0 || static_cast<size_t>(idx) >= size())
|
2019-11-08 21:47:38 +00:00
|
|
|
|
return;
|
2024-07-01 20:55:39 +00:00
|
|
|
|
(*this)[idx] = std::move(ws);
|
2019-11-08 21:47:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-30 16:10:35 +00:00
|
|
|
|
/* when planning a dive we need to make sure that all cylinders have a sane depth assigned
|
2014-07-04 18:40:02 +00:00
|
|
|
|
* and if we are tracking gas consumption the pressures need to be reset to start = end = workingpressure */
|
2024-05-04 16:45:55 +00:00
|
|
|
|
void reset_cylinders(struct dive *dive, bool track_gas)
|
2014-05-29 21:36:14 +00:00
|
|
|
|
{
|
2014-12-04 19:56:17 +00:00
|
|
|
|
pressure_t decopo2 = {.mbar = prefs.decopo2};
|
2014-05-30 16:10:35 +00:00
|
|
|
|
|
2024-05-28 19:31:11 +00:00
|
|
|
|
for (cylinder_t &cyl: dive->cylinders) {
|
|
|
|
|
if (cyl.depth.mm == 0) /* if the gas doesn't give a mod, calculate based on prefs */
|
2024-06-30 14:17:20 +00:00
|
|
|
|
cyl.depth = dive->gas_mod(cyl.gasmix, decopo2, M_OR_FT(3,10));
|
2014-07-17 06:04:30 +00:00
|
|
|
|
if (track_gas)
|
2024-05-28 19:31:11 +00:00
|
|
|
|
cyl.start.mbar = cyl.end.mbar = cyl.type.workingpressure.mbar;
|
|
|
|
|
cyl.gas_used.mliter = 0;
|
|
|
|
|
cyl.deco_gas_used.mliter = 0;
|
2014-05-29 21:36:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-27 11:36:20 +00:00
|
|
|
|
|
2024-05-28 19:31:11 +00:00
|
|
|
|
static void copy_cylinder_type(const cylinder_t &s, cylinder_t &d)
|
2019-08-04 12:42:21 +00:00
|
|
|
|
{
|
2024-05-28 19:31:11 +00:00
|
|
|
|
d.type = s.type;
|
|
|
|
|
d.gasmix = s.gasmix;
|
|
|
|
|
d.depth = s.depth;
|
|
|
|
|
d.cylinder_use = s.cylinder_use;
|
|
|
|
|
d.manually_added = true;
|
2019-08-04 12:42:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* copy the equipment data part of the cylinders but keep pressures */
|
2024-05-04 16:45:55 +00:00
|
|
|
|
void copy_cylinder_types(const struct dive *s, struct dive *d)
|
2019-08-04 12:42:21 +00:00
|
|
|
|
{
|
|
|
|
|
if (!s || !d)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-05-28 19:31:11 +00:00
|
|
|
|
for (size_t i = 0; i < s->cylinders.size() && i < d->cylinders.size(); i++)
|
|
|
|
|
copy_cylinder_type(s->cylinders[i], d->cylinders[i]);
|
2019-08-04 16:44:57 +00:00
|
|
|
|
|
2024-05-28 19:31:11 +00:00
|
|
|
|
for (size_t i = d->cylinders.size(); i < s->cylinders.size(); i++)
|
|
|
|
|
d->cylinders.push_back(s->cylinders[i]);
|
2019-08-04 16:44:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-02 14:34:56 +00:00
|
|
|
|
/* if a default cylinder is set, use that */
|
2024-05-04 16:45:55 +00:00
|
|
|
|
void fill_default_cylinder(const struct dive *dive, cylinder_t *cyl)
|
2020-03-02 14:34:56 +00:00
|
|
|
|
{
|
2024-06-13 20:59:32 +00:00
|
|
|
|
const std::string &cyl_name = prefs.default_cylinder;
|
2024-04-05 15:15:04 +00:00
|
|
|
|
pressure_t pO2 = {.mbar = static_cast<int>(lrint(prefs.modpO2 * 1000.0))};
|
2020-03-02 14:34:56 +00:00
|
|
|
|
|
2024-06-13 20:59:32 +00:00
|
|
|
|
if (cyl_name.empty())
|
2020-03-02 14:34:56 +00:00
|
|
|
|
return;
|
2024-05-03 21:18:45 +00:00
|
|
|
|
for (auto &ti: tank_info_table) {
|
|
|
|
|
if (ti.name == cyl_name) {
|
2024-05-28 19:31:11 +00:00
|
|
|
|
cyl->type.description = ti.name;
|
2024-05-03 21:18:45 +00:00
|
|
|
|
if (ti.ml) {
|
|
|
|
|
cyl->type.size.mliter = ti.ml;
|
|
|
|
|
cyl->type.workingpressure.mbar = ti.bar * 1000;
|
2020-12-11 21:34:35 +00:00
|
|
|
|
} else {
|
2024-05-03 21:18:45 +00:00
|
|
|
|
cyl->type.workingpressure.mbar = psi_to_mbar(ti.psi);
|
|
|
|
|
if (ti.psi)
|
|
|
|
|
cyl->type.size.mliter = lrint(cuft_to_l(ti.cuft) * 1000 / bar_to_atm(psi_to_bar(ti.psi)));
|
2020-12-11 21:34:35 +00:00
|
|
|
|
}
|
|
|
|
|
// MOD of air
|
2024-06-30 14:17:20 +00:00
|
|
|
|
cyl->depth = dive->gas_mod(cyl->gasmix, pO2, 1);
|
2020-12-11 21:34:35 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2020-03-02 14:34:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 19:31:11 +00:00
|
|
|
|
cylinder_t default_cylinder(const struct dive *d)
|
|
|
|
|
{
|
|
|
|
|
cylinder_t res;
|
|
|
|
|
fill_default_cylinder(d, &res);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-04 16:45:55 +00:00
|
|
|
|
cylinder_t create_new_cylinder(const struct dive *d)
|
2020-03-01 15:26:47 +00:00
|
|
|
|
{
|
2024-05-28 19:31:11 +00:00
|
|
|
|
cylinder_t cyl = default_cylinder(d);
|
2020-03-01 15:26:47 +00:00
|
|
|
|
cyl.start = cyl.type.workingpressure;
|
|
|
|
|
cyl.cylinder_use = OC_GAS;
|
|
|
|
|
return cyl;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 07:03:39 +00:00
|
|
|
|
cylinder_t create_new_manual_cylinder(const struct dive *d)
|
|
|
|
|
{
|
|
|
|
|
cylinder_t cyl = create_new_cylinder(d);
|
|
|
|
|
cyl.manually_added = true;
|
|
|
|
|
return cyl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void add_default_cylinder(struct dive *d)
|
|
|
|
|
{
|
|
|
|
|
// Only add if there are no cylinders yet
|
2024-05-28 19:31:11 +00:00
|
|
|
|
if (!d->cylinders.empty())
|
2024-05-25 07:03:39 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
cylinder_t cyl;
|
2024-06-13 20:59:32 +00:00
|
|
|
|
if (!prefs.default_cylinder.empty()) {
|
2024-05-25 07:03:39 +00:00
|
|
|
|
cyl = create_new_cylinder(d);
|
|
|
|
|
} else {
|
|
|
|
|
// roughly an AL80
|
2024-05-28 19:31:11 +00:00
|
|
|
|
cyl.type.description = translate("gettextFromC", "unknown");
|
2024-05-25 07:03:39 +00:00
|
|
|
|
cyl.type.size.mliter = 11100;
|
|
|
|
|
cyl.type.workingpressure.mbar = 207000;
|
|
|
|
|
}
|
2024-07-02 12:49:25 +00:00
|
|
|
|
d->cylinders.add(0, cyl);
|
2024-05-25 07:03:39 +00:00
|
|
|
|
reset_cylinders(d, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool show_cylinder(const struct dive *d, int i)
|
2021-11-21 10:39:02 +00:00
|
|
|
|
{
|
2024-06-25 05:43:32 +00:00
|
|
|
|
if (d->is_cylinder_used(i))
|
2021-11-21 10:39:02 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
2024-05-28 19:31:11 +00:00
|
|
|
|
const cylinder_t &cyl = d->cylinders[i];
|
|
|
|
|
if (cyl.start.mbar || cyl.sample_start.mbar ||
|
|
|
|
|
cyl.end.mbar || cyl.sample_end.mbar)
|
2021-11-21 10:39:02 +00:00
|
|
|
|
return true;
|
2024-05-28 19:31:11 +00:00
|
|
|
|
if (cyl.manually_added)
|
2021-11-21 10:39:02 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The cylinder has some data, but none of it is very interesting,
|
|
|
|
|
* it has no pressures and no gas switches. Do we want to show it?
|
|
|
|
|
*/
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The unused cylinders at the end of the cylinder list are hidden. */
|
2024-05-04 16:45:55 +00:00
|
|
|
|
int first_hidden_cylinder(const struct dive *d)
|
2021-11-21 10:39:02 +00:00
|
|
|
|
{
|
2024-05-28 19:31:11 +00:00
|
|
|
|
size_t res = d->cylinders.size();
|
2021-11-21 10:39:02 +00:00
|
|
|
|
while (res > 0 && !show_cylinder(d, res - 1))
|
|
|
|
|
--res;
|
2024-05-28 19:31:11 +00:00
|
|
|
|
return static_cast<int>(res);
|
2021-11-21 10:39:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-27 11:36:20 +00:00
|
|
|
|
#ifdef DEBUG_CYL
|
2024-05-04 16:45:55 +00:00
|
|
|
|
void dump_cylinders(struct dive *dive, bool verbose)
|
2017-11-27 11:36:20 +00:00
|
|
|
|
{
|
|
|
|
|
printf("Cylinder list:\n");
|
2019-08-04 16:44:57 +00:00
|
|
|
|
for (int i = 0; i < dive->cylinders; i++) {
|
2024-06-25 05:43:32 +00:00
|
|
|
|
cylinder_t *cyl = dive->get_cylinder(i);
|
2017-11-27 11:36:20 +00:00
|
|
|
|
|
2024-05-28 19:31:11 +00:00
|
|
|
|
printf("%02d: Type %s, %3.1fl, %3.0fbar\n", i, cyl->type.description.c_str(), cyl->type.size.mliter / 1000.0, cyl->type.workingpressure.mbar / 1000.0);
|
2017-11-27 11:36:20 +00:00
|
|
|
|
printf(" Gasmix O2 %2.0f%% He %2.0f%%\n", cyl->gasmix.o2.permille / 10.0, cyl->gasmix.he.permille / 10.0);
|
|
|
|
|
printf(" Pressure Start %3.0fbar End %3.0fbar Sample start %3.0fbar Sample end %3.0fbar\n", cyl->start.mbar / 1000.0, cyl->end.mbar / 1000.0, cyl->sample_start.mbar / 1000.0, cyl->sample_end.mbar / 1000.0);
|
|
|
|
|
if (verbose) {
|
|
|
|
|
printf(" Depth %3.0fm\n", cyl->depth.mm / 1000.0);
|
|
|
|
|
printf(" Added %s\n", (cyl->manually_added ? "manually" : ""));
|
|
|
|
|
printf(" Gas used Bottom %5.0fl Deco %5.0fl\n", cyl->gas_used.mliter / 1000.0, cyl->deco_gas_used.mliter / 1000.0);
|
|
|
|
|
printf(" Use %d\n", cyl->cylinder_use);
|
|
|
|
|
printf(" Bestmix %s %s\n", (cyl->bestmix_o2 ? "O2" : " "), (cyl->bestmix_he ? "He" : " "));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|