summaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-02-14 09:44:18 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-02-14 09:44:18 -0800
commit23cfd907dea74dd8e4c8bbf93c8c3f598868623e (patch)
tree820717f6b5cb2614129c06b9b43ddff14ddd3efb /dive.c
parentca19578e407424221309f8724b451ffe2c1f9769 (diff)
downloadsubsurface-23cfd907dea74dd8e4c8bbf93c8c3f598868623e.tar.gz
Better handling of manually edited air temperature
We now load and save this in the XML file, we do the right thing when merging dives and show the edited air temperature in the Dive Info notebook when a divecomputer doesn't have an air temperature. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/dive.c b/dive.c
index e337ca319..35f1c3f46 100644
--- a/dive.c
+++ b/dive.c
@@ -484,11 +484,13 @@ static void fixup_watertemp(struct dive *dive)
dive->watertemp.mkelvin = (sum + nr / 2) / nr;
}
-static void fixup_airtemp(struct dive *dive)
+void fixup_airtemp(struct dive *dive)
{
struct divecomputer *dc;
int sum = 0, nr = 0;
+ if (dive->airtemp.mkelvin)
+ return;
for_each_dc(dive, dc) {
if (dc->airtemp.mkelvin) {
sum += dc->airtemp.mkelvin;
@@ -499,6 +501,20 @@ static void fixup_airtemp(struct dive *dive)
dive->airtemp.mkelvin = (sum + nr / 2) / nr;
}
+/* zero out the airtemp in the dive structure if it was just created by
+ * running fixup on the dive. keep it if it had been edited by hand */
+static void un_fixup_airtemp(struct dive *a)
+{
+ temperature_t temp;
+ temp.mkelvin = a->airtemp.mkelvin;
+ a->airtemp.mkelvin = 0;
+ fixup_airtemp(a);
+ if (a->airtemp.mkelvin && a->airtemp.mkelvin != temp.mkelvin)
+ a->airtemp.mkelvin = temp.mkelvin;
+ else
+ a->airtemp.mkelvin = 0;
+}
+
/*
* events are stored as a linked list, so the concept of
* "consecutive, identical events" is somewhat hard to
@@ -983,6 +999,13 @@ static void merge_equipment(struct dive *res, struct dive *a, struct dive *b)
merge_weightsystem_info(res->weightsystem+i, a->weightsystem + i, b->weightsystem + i);
}
+static void merge_airtemps(struct dive *res, struct dive *a, struct dive *b)
+{
+ un_fixup_airtemp(a);
+ un_fixup_airtemp(b);
+ MERGE_NONZERO(res, a, b, airtemp.mkelvin);
+}
+
/*
* When merging two dives, this picks the trip from one, and removes it
* from the other.
@@ -1616,6 +1639,7 @@ struct dive *merge_dives(struct dive *a, struct dive *b, int offset, gboolean pr
MERGE_NONZERO(res, a, b, cns);
MERGE_NONZERO(res, a, b, visibility);
merge_equipment(res, a, b);
+ merge_airtemps(res, a, b);
if (dl) {
/* If we prefer downloaded, do those first, and get rid of "might be same" computers */
join_dive_computers(&res->dc, &dl->dc, &a->dc, 1);