mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
1690ba7c0c
commit
b50d5b63ad
4 changed files with 48 additions and 8 deletions
30
core/dive.c
30
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue