aboutsummaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Giorgio Marzano <marzano.giorgio@gmail.com>2015-10-06 17:41:36 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-10-06 21:12:33 +0100
commit637c3502e9fefbebc9a6c884518cf62fa1dd2b8d (patch)
tree96dc261e09a26fc4ab4c0e4f38e67dfa065889e7 /dive.c
parent645bc0b46e3567a53cc54429b2fb1346c1848216 (diff)
downloadsubsurface-637c3502e9fefbebc9a6c884518cf62fa1dd2b8d.tar.gz
Force split dives attributes update.
Moved relevant code in a new helper function Signed-off-by: Giorgio Marzano <marzano.giorgio@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c55
1 files changed, 40 insertions, 15 deletions
diff --git a/dive.c b/dive.c
index 215789522..2fdedb10f 100644
--- a/dive.c
+++ b/dive.c
@@ -2845,6 +2845,42 @@ static struct dive *create_new_copy(struct dive *from)
return to;
}
+static void force_fixup_dive(struct dive *d)
+{
+ struct divecomputer *dc = &d->dc;
+ int old_maxdepth = dc->maxdepth.mm;
+ int old_temp = dc->watertemp.mkelvin;
+ int old_mintemp = d->mintemp.mkelvin;
+ int old_maxtemp = d->maxtemp.mkelvin;
+ duration_t old_duration = d->duration;
+
+ d->maxdepth.mm = 0;
+ dc->maxdepth.mm = 0;
+ d->watertemp.mkelvin = 0;
+ dc->watertemp.mkelvin = 0;
+ d->duration.seconds = 0;
+ d->maxtemp.mkelvin = 0;
+ d->mintemp.mkelvin = 0;
+
+ fixup_dive(d);
+
+ if (!d->watertemp.mkelvin)
+ d->watertemp.mkelvin = old_temp;
+
+ if (!dc->watertemp.mkelvin)
+ dc->watertemp.mkelvin = old_temp;
+
+ if (!d->maxtemp.mkelvin)
+ d->maxtemp.mkelvin = old_maxtemp;
+
+ if (!d->mintemp.mkelvin)
+ d->mintemp.mkelvin = old_mintemp;
+
+ if (!d->duration.seconds)
+ d->duration = old_duration;
+
+}
+
/*
* Split a dive that has a surface interval from samples 'a' to 'b'
* into two dives.
@@ -2911,21 +2947,10 @@ static int split_dive_at(struct dive *dive, int a, int b)
event->time.seconds -= t;
}
}
- dc1->maxdepth.mm = 0;
- dc2->maxdepth.mm = 0;
- d1->maxdepth.mm = 0;
- d2->maxdepth.mm = 0;
- d1->duration.seconds = 0;
- d2->duration.seconds = 0;
- d1->watertemp.mkelvin = 0;
- d2->watertemp.mkelvin = 0;
- d1->maxtemp.mkelvin = 0;
- d2->maxtemp.mkelvin = 0;
- d1->mintemp.mkelvin = 0;
- d2->mintemp.mkelvin = 0;
-
- fixup_dive(d1);
- fixup_dive(d2);
+
+ force_fixup_dive(d1);
+ force_fixup_dive(d2);
+
if (dive->divetrip) {
d1->divetrip = d2->divetrip = 0;
add_dive_to_trip(d1, dive->divetrip);