summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2020-04-12 13:39:01 +0200
committerGravatar bstoeger <32835590+bstoeger@users.noreply.github.com>2020-04-13 09:42:29 +0200
commitb50d5b63adb0c10bf4eb48d0aef8c54864cd67ae (patch)
treeb26ff02f4fd9c61826538184639b92af1512d5e3 /core
parent1690ba7c0cd3f95f0681152236342a31b2262796 (diff)
downloadsubsurface-b50d5b63adb0c10bf4eb48d0aef8c54864cd67ae.tar.gz
Preserve events when editing dive in planner
The planner does not know about events except gas changes. But if the dive comes from the log, we should preserve the dive computer events. At least those that happend before we started to delete waypoints to let the planner take over. Signed-off-by: Robert C. Helling <helling@atdotde.de>
Diffstat (limited to 'core')
-rw-r--r--core/dive.c30
-rw-r--r--core/dive.h1
2 files changed, 31 insertions, 0 deletions
diff --git a/core/dive.c b/core/dive.c
index 3bba4179c..1658d3bdd 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -127,6 +127,11 @@ int event_is_gaschange(const struct event *ev)
ev->type == SAMPLE_EVENT_GASCHANGE2;
}
+bool event_is_divemodechange(const struct event *ev)
+{
+ return same_string(ev->name, "modechange");
+}
+
struct event *create_event(unsigned int time, int type, int flags, int value, const char *name)
{
int gas_index = -1;
@@ -573,6 +578,31 @@ void copy_events(const struct divecomputer *s, struct divecomputer *d)
*pev = NULL;
}
+/* copies all events from all dive computers before a given time
+ this is used when editing a dive in the planner to preserve the events
+ of the old dive */
+void copy_events_until(const struct dive *sd, struct dive *dd, int time)
+{
+ if (!sd || !dd)
+ return;
+
+ const struct divecomputer *s = &sd->dc;
+ struct divecomputer *d = &dd->dc;
+
+ while (s && d) {
+ const struct event *ev;
+ ev = s->events;
+ while (ev != NULL) {
+ // Don't add events the planner knows about
+ if (ev->time.seconds < time && !event_is_gaschange(ev) && !event_is_divemodechange(ev))
+ add_event(d, ev->time.seconds, ev->type, ev->flags, ev->value, ev->name);
+ ev = ev->next;
+ }
+ s = s->next;
+ d = d->next;
+ }
+}
+
int nr_cylinders(const struct dive *dive)
{
return dive->cylinders.nr;
diff --git a/core/dive.h b/core/dive.h
index 0d2dbc2a6..f15204a4a 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -352,6 +352,7 @@ extern struct dive *merge_dives(const struct dive *a, const struct dive *b, int
extern struct dive *try_to_merge(struct dive *a, struct dive *b, bool prefer_downloaded);
extern struct event *clone_event(const struct event *src_ev);
extern void copy_events(const struct divecomputer *s, struct divecomputer *d);
+extern void copy_events_until(const struct dive *sd, struct dive *dd, int time);
extern void free_events(struct event *ev);
extern void copy_cylinders(const struct cylinder_table *s, struct cylinder_table *d);
extern void copy_used_cylinders(const struct dive *s, struct dive *d, bool used_only);