2017-04-27 18:24:53 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2011-08-31 01:23:59 +00:00
|
|
|
#ifndef DIVE_H
|
|
|
|
#define DIVE_H
|
|
|
|
|
2018-05-11 15:25:41 +00:00
|
|
|
// dive and dive computer related structures and helpers
|
|
|
|
|
2019-08-05 18:43:06 +00:00
|
|
|
#include "divemode.h"
|
2020-10-25 12:28:55 +00:00
|
|
|
#include "divecomputer.h"
|
2024-05-29 05:03:03 +00:00
|
|
|
#include "equipment.h"
|
2024-05-25 06:16:57 +00:00
|
|
|
#include "picture.h" // TODO: remove
|
2024-05-29 15:57:48 +00:00
|
|
|
#include "tag.h"
|
2011-09-05 20:14:53 +00:00
|
|
|
|
2024-06-03 19:50:08 +00:00
|
|
|
#include <array>
|
2024-06-03 17:09:43 +00:00
|
|
|
#include <memory>
|
2024-05-04 11:39:04 +00:00
|
|
|
#include <string>
|
2024-05-27 15:09:48 +00:00
|
|
|
#include <vector>
|
2024-05-04 15:55:50 +00:00
|
|
|
|
2015-02-13 07:35:52 +00:00
|
|
|
extern int last_xml_version;
|
|
|
|
|
2018-05-17 08:04:41 +00:00
|
|
|
extern const char *divemode_text_ui[];
|
2015-01-10 23:01:15 +00:00
|
|
|
extern const char *divemode_text[];
|
2014-06-11 17:48:48 +00:00
|
|
|
|
2019-03-04 22:20:29 +00:00
|
|
|
struct dive_site;
|
2020-05-01 11:43:52 +00:00
|
|
|
struct dive_table;
|
2019-05-31 14:09:14 +00:00
|
|
|
struct dive_trip;
|
2020-02-16 21:26:47 +00:00
|
|
|
struct full_text_cache;
|
2020-10-25 12:28:55 +00:00
|
|
|
struct event;
|
|
|
|
struct trip_table;
|
2024-05-27 15:09:48 +00:00
|
|
|
|
2024-06-03 17:09:43 +00:00
|
|
|
/* A unique_ptr that will not be copied if the parent class is copied.
|
|
|
|
* This is used to keep a pointer to the fulltext cache and avoid
|
|
|
|
* having it copied when the dive is copied, since the new dive is
|
|
|
|
* not (yet) registered in the fulltext system. Quite hackish.
|
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
struct non_copying_unique_ptr : public std::unique_ptr<T> {
|
|
|
|
using std::unique_ptr<T>::unique_ptr;
|
|
|
|
using std::unique_ptr<T>::operator=;
|
|
|
|
non_copying_unique_ptr(const non_copying_unique_ptr<T> &) { }
|
|
|
|
void operator=(const non_copying_unique_ptr<T> &) { }
|
|
|
|
};
|
|
|
|
|
2011-08-31 01:23:59 +00:00
|
|
|
struct dive {
|
2024-05-16 18:11:21 +00:00
|
|
|
struct dive_trip *divetrip = nullptr;
|
|
|
|
timestamp_t when = 0;
|
|
|
|
struct dive_site *dive_site = nullptr;
|
2024-05-29 18:40:18 +00:00
|
|
|
std::string notes;
|
|
|
|
std::string diveguide, buddy;
|
|
|
|
std::string suit;
|
2024-05-29 05:03:03 +00:00
|
|
|
cylinder_table cylinders;
|
|
|
|
weightsystem_table weightsystems;
|
2024-05-16 18:11:21 +00:00
|
|
|
int number = 0;
|
|
|
|
int rating = 0;
|
|
|
|
int wavesize = 0, current = 0, visibility = 0, surge = 0, chill = 0; /* 0 - 5 star ratings */
|
|
|
|
int sac = 0, otu = 0, cns = 0, maxcns = 0;
|
2013-02-09 00:15:18 +00:00
|
|
|
|
|
|
|
/* Calculated based on dive computer data */
|
2013-02-09 15:41:15 +00:00
|
|
|
temperature_t mintemp, maxtemp, watertemp, airtemp;
|
2013-02-09 14:50:53 +00:00
|
|
|
depth_t maxdepth, meandepth;
|
2013-02-09 00:15:18 +00:00
|
|
|
pressure_t surface_pressure;
|
2013-02-09 15:12:30 +00:00
|
|
|
duration_t duration;
|
2024-05-16 18:11:21 +00:00
|
|
|
int salinity = 0; // kg per 10000 l
|
|
|
|
int user_salinity = 0; // water density reflecting a user-specified type
|
2012-11-24 02:51:27 +00:00
|
|
|
|
2024-05-29 15:57:48 +00:00
|
|
|
tag_list tags;
|
2024-05-27 15:09:48 +00:00
|
|
|
std::vector<divecomputer> dcs; // Attn: pointers to divecomputers are not stable!
|
2024-05-16 18:11:21 +00:00
|
|
|
int id = 0; // unique ID for this dive
|
2024-05-30 13:00:28 +00:00
|
|
|
picture_table pictures;
|
2024-05-16 18:11:21 +00:00
|
|
|
unsigned char git_id[20] = {};
|
|
|
|
bool notrip = false; /* Don't autogroup this dive to a trip */
|
|
|
|
bool selected = false;
|
|
|
|
bool hidden_by_filter = false;
|
2024-06-03 17:09:43 +00:00
|
|
|
non_copying_unique_ptr<full_text_cache> full_text; /* word cache for full text search */
|
2024-05-16 18:11:21 +00:00
|
|
|
bool invalid = false;
|
|
|
|
|
|
|
|
dive();
|
|
|
|
~dive();
|
2024-06-03 19:50:08 +00:00
|
|
|
dive(const dive &);
|
2024-05-19 10:38:38 +00:00
|
|
|
dive(dive &&);
|
|
|
|
dive &operator=(const dive &);
|
2024-06-21 14:43:27 +00:00
|
|
|
static std::unique_ptr<dive> default_dive();
|
2024-06-05 15:02:40 +00:00
|
|
|
|
|
|
|
timestamp_t endtime() const; /* maximum over divecomputers (with samples) */
|
|
|
|
duration_t totaltime() const; /* maximum over divecomputers (with samples) */
|
|
|
|
temperature_t dc_airtemp() const; /* average over divecomputers */
|
|
|
|
temperature_t dc_watertemp() const; /* average over divecomputers */
|
|
|
|
|
|
|
|
bool is_planned() const;
|
|
|
|
bool is_logged() const;
|
|
|
|
|
2024-06-20 20:09:47 +00:00
|
|
|
int depth_to_mbar(int depth) const;
|
|
|
|
double depth_to_mbarf(int depth) const;
|
|
|
|
double depth_to_bar(int depth) const;
|
|
|
|
double depth_to_atm(int depth) const;
|
2024-06-20 20:47:16 +00:00
|
|
|
int rel_mbar_to_depth(int mbar) const;
|
|
|
|
int mbar_to_depth(int mbar) const;
|
2024-06-22 18:08:47 +00:00
|
|
|
|
|
|
|
pressure_t calculate_surface_pressure() const;
|
|
|
|
pressure_t un_fixup_surface_pressure() const;
|
2014-06-02 19:56:02 +00:00
|
|
|
};
|
|
|
|
|
2018-11-10 08:07:42 +00:00
|
|
|
/* For the top-level list: an entry is either a dive or a trip */
|
|
|
|
struct dive_or_trip {
|
|
|
|
struct dive *dive;
|
|
|
|
struct dive_trip *trip;
|
|
|
|
};
|
|
|
|
|
2018-07-18 18:47:19 +00:00
|
|
|
extern void invalidate_dive_cache(struct dive *dive);
|
|
|
|
extern bool dive_cache_is_valid(const struct dive *dive);
|
2016-04-03 22:31:59 +00:00
|
|
|
|
2018-08-16 22:58:30 +00:00
|
|
|
extern int get_cylinder_idx_by_use(const struct dive *dive, enum cylinderuse cylinder_use_type);
|
2024-06-04 11:22:25 +00:00
|
|
|
extern void cylinder_renumber(struct dive &dive, int mapping[]);
|
2024-05-28 19:31:11 +00:00
|
|
|
extern int same_gasmix_cylinder(const cylinder_t &cyl, int cylid, const struct dive *dive, bool check_unused);
|
Calculate nitrogen and helium gas pressures for CCR after import from CSV
Currently the gas pressures stored in structures of pressure are
calculated using the gasmix composition of the currently selected
cylinder. But with CCR dives the default cylinder is the oxygen
cylinder (here, index 0). However, the gas pressures need to
be calculated using gasmix data from cylinder 1 (the diluent
cylinder). This patch allows setting the appropriate cylinder
for calculating the values in the structures of pressure. It
also allows for correctly calculating gas pressures for any
open circuit cylinders (e.g. bailout) that a CCR diver may
use. This is performed as follows:
1) In dive.h create an enum variable {oxygen, diluent, bailout}
2) Within the definition of cylinder_t, add a member: cylinder_use_type
This stores an enum variable, one of the above.
3) In file.c where the Poseidon CSV data are read in, assign
the appropriate enum values to each of the cylinders.
4) Within the definition of structure dive, add two members:
int oxygen_cylinder_index
int diluent_cylinder_index
This will keep the indices of the two main CCR cylinders.
5) In dive.c create a function get_cylinder_use(). This scans the
cylinders for that dive, looking for a cylinder that has a
particular cylinder_use_type and returns that cylinder index.
6) In dive.c create a function fixup_cylinder_use() that stores the
indices of the oxygen and diluent cylinders in the variables
dive->oxygen_cylinder_index and dive->diluent_cylinder_index,
making use of the function in 4) above.
7) In profile.c, modify function calculate_gas_information_new()
to use the above functions for CCR dives to find the oxygen and
diluent cylinders and to calculate partail gas pressures based
on the diluent cylinder gas mix.
This results in the correct calculation of gas partial pressures
in the case of CCR dives, displaying the correct partial pressure
graphs in the dive profile widget.
Signed-off-by: willem ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-03 20:11:00 +00:00
|
|
|
|
2014-08-16 13:55:31 +00:00
|
|
|
/* when selectively copying dive information, which parts should be copied? */
|
|
|
|
struct dive_components {
|
2015-02-13 04:58:03 +00:00
|
|
|
unsigned int divesite : 1;
|
2014-08-16 13:55:31 +00:00
|
|
|
unsigned int notes : 1;
|
2022-02-12 13:03:18 +00:00
|
|
|
unsigned int diveguide : 1;
|
2014-08-16 13:55:31 +00:00
|
|
|
unsigned int buddy : 1;
|
|
|
|
unsigned int suit : 1;
|
|
|
|
unsigned int rating : 1;
|
|
|
|
unsigned int visibility : 1;
|
2019-11-28 19:04:52 +00:00
|
|
|
unsigned int wavesize : 1;
|
|
|
|
unsigned int current : 1;
|
|
|
|
unsigned int surge : 1;
|
|
|
|
unsigned int chill : 1;
|
2014-08-16 13:55:31 +00:00
|
|
|
unsigned int tags : 1;
|
|
|
|
unsigned int cylinders : 1;
|
|
|
|
unsigned int weights : 1;
|
2021-05-16 03:39:47 +00:00
|
|
|
unsigned int number : 1;
|
|
|
|
unsigned int when : 1;
|
2014-08-16 13:55:31 +00:00
|
|
|
};
|
|
|
|
|
2018-08-16 22:58:30 +00:00
|
|
|
extern bool has_gaschange_event(const struct dive *dive, const struct divecomputer *dc, int idx);
|
|
|
|
extern int explicit_first_cylinder(const struct dive *dive, const struct divecomputer *dc);
|
2014-06-02 19:56:02 +00:00
|
|
|
|
2020-10-27 22:04:24 +00:00
|
|
|
extern fraction_t best_o2(depth_t depth, const struct dive *dive, bool in_planner);
|
2019-10-29 16:57:34 +00:00
|
|
|
extern fraction_t best_he(depth_t depth, const struct dive *dive, bool o2narcotic, fraction_t fo2);
|
2016-05-21 09:32:07 +00:00
|
|
|
|
2018-07-18 18:47:19 +00:00
|
|
|
extern int get_surface_pressure_in_mbar(const struct dive *dive, bool non_null);
|
2018-08-16 22:36:51 +00:00
|
|
|
extern depth_t gas_mod(struct gasmix mix, pressure_t po2_limit, const struct dive *dive, int roundto);
|
|
|
|
extern depth_t gas_mnd(struct gasmix mix, depth_t end, const struct dive *dive, int roundto);
|
2016-07-06 12:40:31 +00:00
|
|
|
|
2018-08-16 22:36:51 +00:00
|
|
|
extern struct dive_site *get_dive_site_for_dive(const struct dive *dive);
|
2024-05-04 11:39:04 +00:00
|
|
|
extern std::string get_dive_country(const struct dive *dive);
|
2024-05-04 15:18:08 +00:00
|
|
|
extern std::string get_dive_location(const struct dive *dive);
|
2018-08-16 22:36:51 +00:00
|
|
|
extern unsigned int number_of_computers(const struct dive *dive);
|
2018-07-18 18:47:19 +00:00
|
|
|
extern struct divecomputer *get_dive_dc(struct dive *dive, int nr);
|
2024-05-27 15:09:48 +00:00
|
|
|
extern const struct divecomputer *get_dive_dc(const struct dive *dive, int nr);
|
2015-09-22 19:32:27 +00:00
|
|
|
|
2024-06-04 05:10:22 +00:00
|
|
|
extern std::unique_ptr<dive> clone_make_first_dc(const struct dive &d, int dc_number);
|
|
|
|
extern std::unique_ptr<dive> clone_delete_divecomputer(const struct dive &d, int dc_number);
|
2024-06-03 19:50:08 +00:00
|
|
|
extern std::array<std::unique_ptr<dive>, 2> split_divecomputer(const struct dive &src, int num);
|
2014-05-19 05:39:34 +00:00
|
|
|
|
2018-08-16 22:36:51 +00:00
|
|
|
extern bool dive_site_has_gps_location(const struct dive_site *ds);
|
|
|
|
extern int dive_has_gps_location(const struct dive *dive);
|
2019-04-24 21:59:59 +00:00
|
|
|
extern location_t dive_get_gps_location(const struct dive *d);
|
2018-07-18 18:47:19 +00:00
|
|
|
|
2020-05-22 20:14:24 +00:00
|
|
|
extern bool time_during_dive_with_offset(const struct dive *dive, timestamp_t when, timestamp_t offset);
|
2013-01-29 22:25:09 +00:00
|
|
|
|
2014-03-14 17:11:26 +00:00
|
|
|
extern int save_dives(const char *filename);
|
2018-09-10 12:47:56 +00:00
|
|
|
extern int save_dives_logic(const char *filename, bool select_only, bool anonymize);
|
2024-06-07 08:25:09 +00:00
|
|
|
extern int save_dive(FILE *f, const struct dive &dive, bool anonymize);
|
2020-02-06 21:56:10 +00:00
|
|
|
extern int export_dives_xslt(const char *filename, bool selected, const int units, const char *export_xslt, bool anonymize);
|
2014-03-12 21:12:58 +00:00
|
|
|
|
2019-09-21 12:10:53 +00:00
|
|
|
extern int save_dive_sites_logic(const char *filename, const struct dive_site *sites[], int nr_sites, bool anonymize);
|
2019-04-06 19:05:18 +00:00
|
|
|
|
2015-04-28 18:27:36 +00:00
|
|
|
struct membuffer;
|
2024-06-07 08:25:09 +00:00
|
|
|
extern void save_one_dive_to_mb(struct membuffer *b, const struct dive &dive, bool anonymize);
|
2015-04-28 18:27:36 +00:00
|
|
|
|
2024-05-04 16:53:41 +00:00
|
|
|
extern void subsurface_console_init();
|
|
|
|
extern void subsurface_console_exit();
|
|
|
|
extern bool subsurface_user_is_root();
|
2013-12-19 13:00:50 +00:00
|
|
|
|
2014-07-02 22:29:02 +00:00
|
|
|
extern void clear_dive(struct dive *dive);
|
2018-08-23 17:18:43 +00:00
|
|
|
extern void copy_dive(const struct dive *s, struct dive *d);
|
|
|
|
extern void selective_copy_dive(const struct dive *s, struct dive *d, struct dive_components what, bool clear);
|
2011-09-12 19:56:34 +00:00
|
|
|
|
2018-08-23 17:18:43 +00:00
|
|
|
extern int legacy_format_o2pressures(const struct dive *dive, const struct divecomputer *dc);
|
2011-09-12 19:56:34 +00:00
|
|
|
|
2024-06-07 08:25:09 +00:00
|
|
|
extern bool dive_less_than(const struct dive &a, const struct dive &b);
|
|
|
|
extern bool dive_less_than_ptr(const struct dive *a, const struct dive *b);
|
2018-11-10 08:07:42 +00:00
|
|
|
extern bool dive_or_trip_less_than(struct dive_or_trip a, struct dive_or_trip b);
|
2011-09-03 20:19:26 +00:00
|
|
|
extern struct dive *fixup_dive(struct dive *dive);
|
2020-05-04 13:54:58 +00:00
|
|
|
extern int get_dive_salinity(const struct dive *dive);
|
2018-07-17 21:05:03 +00:00
|
|
|
extern int dive_getUniqID();
|
2024-06-03 19:50:08 +00:00
|
|
|
extern std::array<std::unique_ptr<dive>, 2> split_dive(const struct dive &dive);
|
|
|
|
extern std::array<std::unique_ptr<dive>, 2> split_dive_at_time(const struct dive &dive, duration_t time);
|
2024-06-04 11:22:25 +00:00
|
|
|
|
|
|
|
struct merge_result {
|
|
|
|
std::unique_ptr<struct dive> dive;
|
|
|
|
dive_trip *trip;
|
|
|
|
dive_site *site;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern merge_result merge_dives(const struct dive &a, const struct dive &b, int offset, bool prefer_downloaded);
|
|
|
|
extern std::unique_ptr<dive> try_to_merge(const struct dive &a, const struct dive &b, bool prefer_downloaded);
|
2024-04-25 20:16:08 +00:00
|
|
|
extern void copy_events_until(const struct dive *sd, struct dive *dd, int dcNr, int time);
|
2019-08-04 16:44:57 +00:00
|
|
|
extern void copy_used_cylinders(const struct dive *s, struct dive *d, bool used_only);
|
2018-08-23 17:18:43 +00:00
|
|
|
extern bool is_cylinder_used(const struct dive *dive, int idx);
|
|
|
|
extern bool is_cylinder_prot(const struct dive *dive, int idx);
|
First step in cleaning up cylinder pressure sensor logic
This clarifies/changes the meaning of our "cylinderindex" entry in our
samples. It has been rather confused, because different dive computers
have done things differently, and the naming really hasn't helped.
There are two totally different - and independent - cylinder "indexes":
- the pressure sensor index, which indicates which cylinder the sensor
data is from.
- the "active cylinder" index, which indicates which cylinder we actually
breathe from.
These two values really are totally independent, and have nothing
what-so-ever to do with each other. The sensor index may well be fixed:
many dive computers only support a single pressure sensor (whether
wireless or wired), and the sensor index is thus always zero.
Other dive computers may support multiple pressure sensors, and the gas
switch event may - or may not - indicate that the sensor changed too. A
dive computer might give the sensor data for *all* cylinders it can read,
regardless of which one is the one we're actively breathing. In fact, some
dive computers might give sensor data for not just *your* cylinder, but
your buddies.
This patch renames "cylinderindex" in the samples as "sensor", making it
quite clear that it's about which sensor index the pressure data in the
sample is about.
The way we figure out which is the currently active gas is with an
explicit has change event. If a computer (like the Uemis Zurich) joins the
two concepts together, then a sensor change should also create a gas
switch event. This patch also changes the Uemis importer to do that.
Finally, it should be noted that the plot info works totally separately
from the sample data, and is about what we actually *display*, not about
the sample pressures etc. In the plot info, the "cylinderindex" does in
fact mean the currently active cylinder, and while it is initially set to
match the sensor information from the samples, we then walk the gas change
events and fix it up - and if the active cylinder differs from the sensor
cylinder, we clear the sensor data.
[Dirk Hohndel: this conflicted with some of my recent changes - I think
I merged things correctly...]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-31 04:00:51 +00:00
|
|
|
extern void add_gas_switch_event(struct dive *dive, struct divecomputer *dc, int time, int idx);
|
2024-05-25 06:16:57 +00:00
|
|
|
extern struct event create_gas_switch_event(struct dive *dive, struct divecomputer *dc, int seconds, int idx);
|
2018-08-23 17:18:43 +00:00
|
|
|
extern void per_cylinder_mean_depth(const struct dive *dive, struct divecomputer *dc, int *mean, int *duration);
|
2024-05-25 06:16:57 +00:00
|
|
|
extern int get_cylinder_index(const struct dive *dive, const struct event &ev);
|
|
|
|
extern struct gasmix get_gasmix_from_event(const struct dive *, const struct event &ev);
|
2021-09-02 16:39:17 +00:00
|
|
|
extern bool cylinder_with_sensor_sample(const struct dive *dive, int cylinder_id);
|
2011-09-23 01:02:54 +00:00
|
|
|
|
2011-09-20 19:40:34 +00:00
|
|
|
/* UI related protopypes */
|
|
|
|
|
2016-04-03 22:31:59 +00:00
|
|
|
extern void invalidate_dive_cache(struct dive *dc);
|
2013-10-09 07:14:39 +00:00
|
|
|
|
2018-08-23 17:18:43 +00:00
|
|
|
extern int total_weight(const struct dive *);
|
2012-12-13 06:26:29 +00:00
|
|
|
|
2018-08-16 15:11:51 +00:00
|
|
|
/* Get gasmix at a given time */
|
2024-05-25 06:16:57 +00:00
|
|
|
extern struct gasmix get_gasmix_at_time(const struct dive &dive, const struct divecomputer &dc, duration_t time);
|
2018-08-16 15:11:51 +00:00
|
|
|
|
2018-08-16 22:58:30 +00:00
|
|
|
extern void update_setpoint_events(const struct dive *dive, struct divecomputer *dc);
|
2018-11-22 07:06:07 +00:00
|
|
|
|
2019-09-25 19:28:46 +00:00
|
|
|
/* Make pointers to dive and dive_trip "Qt metatypes" so that they can be passed through
|
|
|
|
* QVariants and through QML.
|
|
|
|
*/
|
2019-03-04 22:20:29 +00:00
|
|
|
#include <QObject>
|
2018-11-22 07:06:07 +00:00
|
|
|
Q_DECLARE_METATYPE(struct dive *);
|
|
|
|
|
2024-03-16 15:06:39 +00:00
|
|
|
extern std::string existing_filename;
|
|
|
|
|
2014-02-11 18:14:46 +00:00
|
|
|
#endif // DIVE_H
|