aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Stefan Fuchs <sfuchs@gmx.de>2017-11-29 10:16:00 +0100
committerGravatar Jan Mulder <jlmulder@xs4all.nl>2018-02-27 09:17:57 +0100
commit4cbf8b87a3586d15cff9770d1e3fc9f813498037 (patch)
tree1e524f5f07080f4d3d19034218e5c762d0104781 /core
parentcd5e17cf79c2f1eb896efd0436c103221de446ae (diff)
downloadsubsurface-4cbf8b87a3586d15cff9770d1e3fc9f813498037.tar.gz
Updated strategy for removing cylinders
Change the strategy when to allow cylinder removal from a dive: - Not remove when cylinder has gas switch events, in any other cases allow removal - Remove this whole "cylinder with same gas" thing being a criteria for cylinder removal When removing a cylinder which has corresponding pressure info in samples, also remove this pressure info from the samples. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
Diffstat (limited to 'core')
-rw-r--r--core/dive.c14
-rw-r--r--core/dive.h1
-rw-r--r--core/statistics.c13
3 files changed, 26 insertions, 2 deletions
diff --git a/core/dive.c b/core/dive.c
index 528cf9efa..c4a903eec 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -2072,7 +2072,7 @@ static void dc_cylinder_renumber(struct dive *dive, struct divecomputer *dc, int
if (mapping[0] > 0)
add_initial_gaschange(dive, dc);
- /* Remap the sensor indexes */
+ /* Remap or delete the sensor indexes */
for (i = 0; i < dc->samples; i++) {
struct sample *s = dc->sample + i;
int j;
@@ -2081,8 +2081,18 @@ static void dc_cylinder_renumber(struct dive *dive, struct divecomputer *dc, int
int sensor;
sensor = mapping[s->sensor[j]];
- if (sensor >= 0)
+ if (sensor == -1) {
+ // Remove sensor and gas pressure info
+ if (i == 0) {
+ s->sensor[j] = 0;
+ s->pressure[j].mbar = 0;
+ } else {
+ s->sensor[j] = s[-1].sensor[j];
+ s->pressure[j].mbar = s[-1].pressure[j].mbar;
+ }
+ } else {
s->sensor[j] = sensor;
+ }
}
}
diff --git a/core/dive.h b/core/dive.h
index b6f9c835f..b152d59e9 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -812,6 +812,7 @@ extern void free_events(struct event *ev);
extern void copy_cylinders(struct dive *s, struct dive *d, bool used_only);
extern void copy_samples(struct divecomputer *s, struct divecomputer *d);
extern bool is_cylinder_used(struct dive *dive, int idx);
+extern bool is_cylinder_prot(struct dive *dive, int idx);
extern void fill_default_cylinder(cylinder_t *cyl);
extern void add_gas_switch_event(struct dive *dive, struct divecomputer *dc, int time, int idx);
extern struct event *add_event(struct divecomputer *dc, unsigned int time, int type, int flags, int value, const char *name);
diff --git a/core/statistics.c b/core/statistics.c
index 678843b99..eed24505c 100644
--- a/core/statistics.c
+++ b/core/statistics.c
@@ -345,6 +345,19 @@ bool is_cylinder_used(struct dive *dive, int idx)
return false;
}
+bool is_cylinder_prot(struct dive *dive, int idx)
+{
+ struct divecomputer *dc;
+ if (cylinder_none(&dive->cylinder[idx]))
+ return false;
+
+ for_each_dc(dive, dc) {
+ if (has_gaschange_event(dive, dc, idx))
+ return true;
+ }
+ return false;
+}
+
void get_gas_used(struct dive *dive, volume_t gases[MAX_CYLINDERS])
{
int idx;