diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-07-30 10:33:25 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-11 16:22:27 -0700 |
commit | 63b65a7e20615d7e049ab09ae7dc6053d705c04b (patch) | |
tree | 870e1872e70cea37eabcedaea5564721cab79ed4 /core | |
parent | ec7d85835fb26ee9c0a9c780907441c312d7ac3f (diff) | |
download | subsurface-63b65a7e20615d7e049ab09ae7dc6053d705c04b.tar.gz |
Undo: implement autogrouping of trips in DiveAdd
If the autogroup flag is set, search for appropriate trips in
DiveAdd() and add the dive to this trip. If no trip exists, add
a new trip.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r-- | core/divelist.c | 32 | ||||
-rw-r--r-- | core/divelist.h | 1 |
2 files changed, 33 insertions, 0 deletions
diff --git a/core/divelist.c b/core/divelist.c index 08fde01ff..902bbb5ac 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -24,6 +24,7 @@ * void add_dive_to_trip(struct dive *dive, dive_trip_t *trip) * dive_trip_t *create_and_hookup_trip_from_dive(struct dive *dive) * dive_trip_t *get_dives_to_autogroup(int start, int *from, int *to, bool *allocated) + * dive_trip_t *get_trip_for_new_dive(struct dive *new_dive, bool *allocated) * void autogroup_dives(void) * void combine_trips(struct dive_trip *trip_a, struct dive_trip *trip_b) * dive_trip_t *combine_trips_create(struct dive_trip *trip_a, struct dive_trip *trip_b) @@ -926,6 +927,37 @@ dive_trip_t *create_and_hookup_trip_from_dive(struct dive *dive) } /* + * Find a trip a new dive should be autogrouped with. If no such trips + * exist, allocate a new trip. The bool "*allocated" is set to true + * if a new trip was allocated. + */ +dive_trip_t *get_trip_for_new_dive(struct dive *new_dive, bool *allocated) +{ + struct dive *d; + dive_trip_t *trip; + int i; + + /* Find dive that is within TRIP_THRESHOLD of current dive */ + for_each_dive(i, d) { + /* Check if we're past the range of possible dives */ + if (d->when >= new_dive->when + TRIP_THRESHOLD) + break; + + if (d->when + TRIP_THRESHOLD >= new_dive->when && d->divetrip) { + /* Found a dive with trip in the range */ + *allocated = false; + return d->divetrip; + } + } + + /* Didn't find a trip -> allocate a new one */ + trip = create_trip_from_dive(new_dive); + trip->autogen = true; + *allocated = true; + return trip; +} + +/* * Collect dives for auto-grouping. Pass in first dive which should be checked. * Returns range of dives that should be autogrouped and trip it should be * associated to. If the returned trip was newly allocated, the last bool diff --git a/core/divelist.h b/core/divelist.h index 8bcf9f55c..9449e36e2 100644 --- a/core/divelist.h +++ b/core/divelist.h @@ -32,6 +32,7 @@ extern dive_trip_t *alloc_trip(void); extern dive_trip_t *create_trip_from_dive(struct dive *dive); extern dive_trip_t *create_and_hookup_trip_from_dive(struct dive *dive); extern dive_trip_t *get_dives_to_autogroup(int start, int *from, int *to, bool *allocated); +extern dive_trip_t *get_trip_for_new_dive(struct dive *new_dive, bool *allocated); extern void autogroup_dives(void); extern struct dive *merge_two_dives(struct dive *a, struct dive *b); extern bool consecutive_selected(); |