2017-04-27 18:18:03 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2011-09-05 19:12:58 +00:00
|
|
|
#ifndef DIVELIST_H
|
|
|
|
#define DIVELIST_H
|
|
|
|
|
2019-03-04 22:20:29 +00:00
|
|
|
#include "dive.h"
|
|
|
|
|
2013-04-01 10:51:49 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
2013-04-24 23:52:18 +00:00
|
|
|
#endif
|
2013-04-24 23:33:29 +00:00
|
|
|
|
2015-06-20 13:45:12 +00:00
|
|
|
/* this is used for both git and xml format */
|
|
|
|
#define DATAFORMAT_VERSION 3
|
|
|
|
|
2011-11-13 17:29:07 +00:00
|
|
|
extern void update_cylinder_related_info(struct dive *);
|
2017-12-11 21:23:52 +00:00
|
|
|
extern void mark_divelist_changed(bool);
|
2011-09-21 04:29:09 +00:00
|
|
|
extern int unsaved_changes(void);
|
2017-11-22 19:42:33 +00:00
|
|
|
extern int init_decompression(struct deco_state *ds, struct dive *dive);
|
2013-04-07 03:49:06 +00:00
|
|
|
|
|
|
|
/* divelist core logic functions */
|
2018-09-23 10:53:35 +00:00
|
|
|
extern void process_loaded_dives();
|
2019-01-13 20:53:57 +00:00
|
|
|
/* flags for process_imported_dives() */
|
|
|
|
#define IMPORT_PREFER_IMPORTED (1 << 0)
|
|
|
|
#define IMPORT_IS_DOWNLOADED (1 << 1)
|
|
|
|
#define IMPORT_MERGE_ALL_TRIPS (1 << 2)
|
|
|
|
#define IMPORT_ADD_TO_NEW_TRIP (1 << 3)
|
2019-03-03 14:12:22 +00:00
|
|
|
extern void add_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table, struct dive_site_table *import_sites_table,
|
|
|
|
int flags);
|
|
|
|
extern void process_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table, struct dive_site_table *import_sites_table,
|
|
|
|
int flags,
|
2018-12-23 21:08:00 +00:00
|
|
|
struct dive_table *dives_to_add, struct dive_table *dives_to_remove,
|
2019-03-03 14:12:22 +00:00
|
|
|
struct trip_table *trips_to_add, struct dive_site_table *sites_to_add);
|
2018-10-13 20:32:53 +00:00
|
|
|
extern char *get_dive_gas_string(const struct dive *dive);
|
2013-10-07 20:43:17 +00:00
|
|
|
|
2018-11-08 13:02:36 +00:00
|
|
|
extern struct dive **grow_dive_table(struct dive_table *table);
|
2018-11-24 09:11:07 +00:00
|
|
|
extern int dive_table_get_insertion_index(struct dive_table *table, struct dive *dive);
|
2019-03-04 22:20:29 +00:00
|
|
|
extern void add_to_dive_table(struct dive_table *table, int idx, struct dive *dive);
|
2019-04-14 13:37:19 +00:00
|
|
|
extern void append_dive(struct dive *dive);
|
2018-10-13 20:32:53 +00:00
|
|
|
extern void get_dive_gas(const struct dive *dive, int *o2_p, int *he_p, int *o2low_p);
|
2018-08-23 17:18:43 +00:00
|
|
|
extern int get_divenr(const struct dive *dive);
|
2018-12-23 09:08:44 +00:00
|
|
|
extern struct dive_trip *unregister_dive_from_trip(struct dive *dive);
|
2019-03-11 23:25:31 +00:00
|
|
|
extern int remove_dive(const struct dive *dive, struct dive_table *table);
|
2019-03-17 20:52:45 +00:00
|
|
|
extern void remove_dive_from_trip(struct dive *dive, struct trip_table *trip_table_arg);
|
2018-09-23 19:22:48 +00:00
|
|
|
extern dive_trip_t *alloc_trip(void);
|
|
|
|
extern dive_trip_t *create_trip_from_dive(struct dive *dive);
|
2019-03-17 20:52:45 +00:00
|
|
|
extern dive_trip_t *create_and_hookup_trip_from_dive(struct dive *dive, struct trip_table *trip_table_arg);
|
2018-11-24 06:50:13 +00:00
|
|
|
extern dive_trip_t *get_dives_to_autogroup(struct dive_table *table, int start, int *from, int *to, bool *allocated);
|
2018-07-30 08:33:25 +00:00
|
|
|
extern dive_trip_t *get_trip_for_new_dive(struct dive *new_dive, bool *allocated);
|
2013-09-24 10:42:40 +00:00
|
|
|
extern bool consecutive_selected();
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
extern void select_dive(struct dive *dive);
|
|
|
|
extern void deselect_dive(struct dive *dive);
|
2014-05-24 20:19:05 +00:00
|
|
|
extern void select_dives_in_trip(struct dive_trip *trip);
|
|
|
|
extern void deselect_dives_in_trip(struct dive_trip *trip);
|
2014-11-12 06:59:04 +00:00
|
|
|
extern void filter_dive(struct dive *d, bool shown);
|
2018-12-08 18:47:28 +00:00
|
|
|
extern dive_trip_t *combine_trips(struct dive_trip *trip_a, struct dive_trip *trip_b);
|
2014-05-24 15:27:42 +00:00
|
|
|
extern struct dive *first_selected_dive();
|
|
|
|
extern struct dive *last_selected_dive();
|
2018-08-23 17:18:43 +00:00
|
|
|
extern bool is_trip_before_after(const struct dive *dive, bool before);
|
2018-07-19 20:35:25 +00:00
|
|
|
extern int get_dive_nr_at_idx(int idx);
|
2014-08-18 19:12:05 +00:00
|
|
|
extern void set_dive_nr_for_current_dive();
|
2018-10-06 07:21:27 +00:00
|
|
|
extern timestamp_t get_surface_interval(timestamp_t when);
|
2018-09-28 08:21:23 +00:00
|
|
|
extern void delete_dive_from_table(struct dive_table *table, int idx);
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
extern struct dive *find_next_visible_dive(timestamp_t when);
|
2018-11-22 22:11:23 +00:00
|
|
|
extern bool trip_is_single_day(const struct dive_trip *trip);
|
|
|
|
extern int trip_shown_dives(const struct dive_trip *trip);
|
2013-04-07 03:49:06 +00:00
|
|
|
|
2015-06-20 13:45:12 +00:00
|
|
|
int get_min_datafile_version();
|
|
|
|
void reset_min_datafile_version();
|
|
|
|
void report_datafile_version(int version);
|
2016-04-14 12:34:19 +00:00
|
|
|
int get_dive_id_closest_to(timestamp_t when);
|
2015-07-24 20:18:30 +00:00
|
|
|
void clear_dive_file_data();
|
2018-10-14 13:33:46 +00:00
|
|
|
void clear_table(struct dive_table *table);
|
2019-05-05 03:46:42 +00:00
|
|
|
void clear_trip_table(struct trip_table *table);
|
2015-06-20 13:45:12 +00:00
|
|
|
|
More accurate CNS calculations (following comments on github)
Update table of maximum oxygen exposure durations, used in CNS calulations.
This table shows the official NOAA maximum O2 exposure limits
(in seconds) for different PO2 values. It also gives
slope values for linear interpolation for intermediate PO2 values
between the tabulated PO2 values in the 1st column.
Top & bottom rows are inserted that are not in the NOAA table:
(1) For PO2 > 1.6 the same slope value as between
1.5 & 1.6 is used. This exptrapolation for PO2 > 1.6 likely
gives an underestimate above 1.6 but is better than the
value for PO2=1.6 (45 min). (2) The NOAA table only
tabulates values for PO2 >= 0.6. Since O2-uptake occurs down to
PO2=0.5, the same slope is used as for 0.7 > PO2 > 0.6.
This gives a conservative estimate for 0.6 > PO2 > 0.5. To
preserve the integer structure of the table, all slopes are
given as slope*10: divide by 10 to get the valid slope.
The columns below are:
po2 (mbar), Maximum Single Exposure (seconds), single_slope,
Maximum 24 hour Exposure (seconds), 24h_slope */
Then update Calculations of the CNS for a single dive -
this only takes the first divecomputer into account.
The previous version of the code did a table lookup and
used the max O2 exposure for the next-higher PO2 category.
This gave a shorter max O2 exposure time and a higher CNS
contribution for a specific dive segment, resulting in a
slightly conservative value of CNS, often some 2 - 3 % too high.
This code does an interpolation for PO2 values inbetween
PO2 entries in the lookup table and therefore results in a more
accurate maximum O2 exposure time for that PO2.
The maximum O2 exposure duration for each segment
is also calculated based on the mean depth of the two
samples (start & end) that define each segment. The CNS
contribution of each segment is found by dividing the
time duration of the segment by its maximum exposure duration.
The contributions of all segments of the dive are summed to
get the total CNS% value. This is a partial implementation
of the proposals in Erik Baker's document "Oxygen Toxicity Calculations" */
Overall, this PR does not radically alter the existing CNS calculation,
it only makes it more accurate and more consistent by doing
interpolation and by using mean segment depth to find PO2.
Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
2018-11-10 11:49:52 +00:00
|
|
|
typedef enum {PO2VAL, SINGLE_EXP, SINGLE_SLOPE, DAILY_EXP, DAILY_SLOPE, NO_COLUMNS} cns_table_headers;
|
|
|
|
|
2013-04-07 03:49:06 +00:00
|
|
|
#ifdef DEBUG_TRIP
|
|
|
|
extern void dump_selection(void);
|
|
|
|
extern void dump_trip_list(void);
|
|
|
|
#endif
|
|
|
|
|
2013-04-01 10:51:49 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-02-11 18:14:46 +00:00
|
|
|
#endif // DIVELIST_H
|