summaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c76
1 files changed, 68 insertions, 8 deletions
diff --git a/dive.c b/dive.c
index 4f42e48d6..38599b104 100644
--- a/dive.c
+++ b/dive.c
@@ -188,6 +188,17 @@ double get_volume_units(unsigned int ml, int *frac, const char **units)
return vol;
}
+int units_to_sac(int volume)
+{
+ if(get_units()->volume == CUFT)
+ if (volume < 10)
+ return cuft_to_l(volume) * 100;
+ else
+ return cuft_to_l(volume) * 10;
+ else
+ return volume * 1000;
+}
+
unsigned int units_to_depth(double depth)
{
if (get_units()->length == METERS)
@@ -410,6 +421,38 @@ struct dive *clone_dive(struct dive *s)
return dive;
}
+#define CONDITIONAL_COPY_STRING(_component) \
+ if (what._component) \
+ d->_component = copy_string(s->_component)
+
+// copy elements, depending on bits in what that are set
+void selective_copy_dive(struct dive *s, struct dive *d, struct dive_components what, bool clear)
+{
+ if (clear)
+ clear_dive(d);
+ CONDITIONAL_COPY_STRING(location);
+ CONDITIONAL_COPY_STRING(notes);
+ CONDITIONAL_COPY_STRING(divemaster);
+ CONDITIONAL_COPY_STRING(buddy);
+ CONDITIONAL_COPY_STRING(suit);
+ if (what.rating)
+ d->rating = s->rating;
+ if (what.visibility)
+ d->visibility = s->visibility;
+ if (what.gps) {
+ d->longitude = s->longitude;
+ d->latitude = s->latitude;
+ }
+ if (what.tags)
+ STRUCTURED_LIST_COPY(struct tag_entry, s->tag_list, d->tag_list, copy_tl);
+ if (what.cylinders)
+ copy_cylinders(s, d, false);
+ if (what.weights)
+ for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++)
+ d->weightsystem[i] = s->weightsystem[i];
+}
+#undef CONDITIONAL_COPY_STRING
+
/* only copies events from the first dive computer */
void copy_events(struct divecomputer *s, struct divecomputer *d)
{
@@ -448,16 +491,21 @@ int nr_weightsystems(struct dive *dive)
return nr;
}
+/* copy the equipment data part of the cylinders */
void copy_cylinders(struct dive *s, struct dive *d, bool used_only)
{
int i;
if (!s || !d)
return;
- for (i = 0; i < MAX_CYLINDERS; i++)
- if (!used_only || is_cylinder_used(s, i))
- d->cylinder[i] = s->cylinder[i];
- else
- memset(&d->cylinder[i], 0, sizeof(cylinder_t));
+ for (i = 0; i < MAX_CYLINDERS; i++) {
+ memset(&d->cylinder[i], 0, sizeof(cylinder_t));
+ if (!used_only || is_cylinder_used(s, i)) {
+ d->cylinder[i].type = s->cylinder[i].type;
+ d->cylinder[i].gasmix = s->cylinder[i].gasmix;
+ d->cylinder[i].depth = s->cylinder[i].depth;
+ d->cylinder[i].manually_added = true;
+ }
+ }
}
void copy_samples(struct divecomputer *s, struct divecomputer *d)
@@ -1849,6 +1897,11 @@ static int match_dc_dive(struct divecomputer *a, struct divecomputer *b)
return 0;
}
+static bool new_without_trip(struct dive *a)
+{
+ return a->downloaded && !a->divetrip;
+}
+
/*
* Do we want to automatically try to merge two dives that
* look like they are the same dive?
@@ -1882,9 +1935,16 @@ static int likely_same_dive(struct dive *a, struct dive *b)
{
int match, fuzz = 20 * 60;
- /* Don't try to merge dives in different trips */
- if (a->divetrip && b->divetrip && a->divetrip != b->divetrip)
- return 0;
+ /* Don't try to merge dives with different trip information */
+ if (a->divetrip != b->divetrip) {
+ /*
+ * Exception: if the dive is downloaded without any
+ * explicit trip information, we do want to merge it
+ * with existing old dives even if they have trips.
+ */
+ if (!new_without_trip(a) && !new_without_trip(b))
+ return 0;
+ }
/*
* Do some basic sanity testing of the values we