summaryrefslogtreecommitdiffstats
path: root/core/dive.c
AgeCommit message (Collapse)Author
2020-10-24core: remove create_device_node() from fixup_dive()Gravatar Berthold Stoeger
The device nodes are created for all DCs, when importing the dives. There is no point in creating only the device node for the first DC in fixup_dive(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16core: add device_table parameter to device table functionsGravatar Berthold Stoeger
Instead of accessing the global device table directly, add a parameter to all device-table accessing functions. This makes all places in the code that access the global device table grep-able, which is necessary to include the device-table code in the undo system. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-05core: don't merge sample-derived pressures in merge_one_cylinder()Gravatar Berthold Stoeger
These will be recalculated from the pressures in fixup_dive() anyway. Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-05core: improve merging of cylinders pressuresGravatar Berthold Stoeger
When merging cylinders pressures derived from samples were taken as maximum of the start and minimum of the end pressure, which makes sense, since we believe that this is the same cylinder. However, for manually entered pressures, this was not done. Moreover, when one dive had manual pressures and the other only pressure from samples, the manual pressure was taken. However, that could have been the wrong one, for example if the end pressure was manually set for the cylinder of the first part of the dive, but not the last. Therefore, improve merging of manuall set pressures in two ways: 1) use maximum/minimum for start/end pressure 2) if the pressure of one cylinder was manually set, but not for the other, complete with the sample pressure (if that exists). Fixes #2884. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-03core: add N2 and general gas component accessorsGravatar Berthold Stoeger
There were helper functions to access O2 and He component fractions. Add another one for N2. Indeed, this can be used in three cases, where N2 was deduced indirectly. Moreover, add a general accessor with a gas_component argument. This will be used by the filter code to filter for gas components. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29Use correct pO2 when computing MOD in equipment tabGravatar Robert C. Helling
The cylinder model is used both in the planner and the equipment tab. We have three preferences for the pO2 that is used to compute MOD: In the planner, there is one for the bottom part of the dive and another one for deco. Those are set in the planenr UI. There is another value, controlled in the Tec Prefernces. That one should be used in the equipment tab rather than the one from the planner. Fixes #2984 Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-09-08cleanup: remove invalidate_dive_cache() call in clone_delete_divecomputer()Gravatar Berthold Stoeger
The function was called on a freshly copied dive, which has its git cache invalidated automatically in copy_dive(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-08cleanup: remove dead code from delete_divecomputer()Gravatar Berthold Stoeger
delete_divecomputer had legacy code, which 1) invalidated the git dive cache 2) made sure that the dive computer was not displayed anymore However, both callers called on a freshly copied dive, which has its dive cache invalidated in copy_dive() and can't be the currently displayed dive. Therefore, this code is dead code and can be removed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-08cleanup: remove count_divecomputers() functionGravatar Berthold Stoeger
There is a number_of_computers() function which does the same thing with two exceptions: 1) checks for null-dive 2) returns an unsigned int Replace calls to count_divecomputers() by calls to number_of_computers(). In one case, the return type makes a different - add a cast to int there. Ultimately, we should probably change the dc_number to signed int throughout the code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-06cleanup: use taxonomy_get_country() in get_dive_country()Gravatar Berthold Stoeger
get_dive_country() was essentially a reimplementation of taxonomy_get_country(). Let's just use the already existing function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-06Function for "gravity conversion"Gravatar Robert C. Helling
This adds a common macro to convert salinity (which is given as a density in terms of g per 10l) to a specific weight with units of mbar / mm = bar / m that is used to translate between pressures and depths. The weired factor of 10 (from the unusual unit of salinity) is included in the macro. It is there for historical reasons, as it goes back to 05b55542c8 from 2012 where it was introduced in code for downloading from Uemis dive computers. Now, salinity appears in too many places to easily remove this unconventional factor of 10 everywhere without breaking to many things (including various dive computer downloads). Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-09-02Planner: Properly initialize salinityGravatar Robert C. Helling
When the dive has no explicity salinity, our conversion between pressure and depth assumed salt water. Make this explicity by using the corresponding macro. When the planner starts and no salinity is set explicity, set the water type chooser to salt water to reflect our default assumption. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-08-15Fix event merging when merging divesGravatar Linus Torvalds
The merge_events() function was subtly and not-so-subtly broken in a couple of ways: - in commit 8c2383b49 ("Undo: don't modify source-dives on merge"), we stopped walking the event list after we merged the first event from a dive when the other dive computer had run out of events. In particular, this meant that when merging consecutive dives, the second dive only had the first event copied over to the merged dive. This happened because the original code just moved the whole old list over when there was nothing left from the other dive, so the old code didn't need to iterate over the event list. The new code didn't realize that the pointer movement used to copy the whole rest of the list, and also stopped iterating. In all fairness, the new code did get the time offset right, which the old code didn't. So this was always buggy. - similarly, the "avoid redundant gas changes" case was not handled for the "we ran out of events for the other dive computer" case. This fixes both issues. Cc: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-07-11Make MND display depend on O2 narcotic preferenceGravatar Robert C. Helling
A while ago, we introduced a preference whether O2 should be considered narcotic. We used this when computing best mix or when entering the He content via MND. But we forgot to make the displayed MND depend on this preference. This patch add this. Fixes #2895 Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-06-29Fix dive merging with multiple cylindersGravatar Linus Torvalds
We did something really horribly wrong when merging cylinders. It's been broken since commit 7c9f46a ("Core: remove MAX_CYLINDERS restriction"), and used some really strange logic. This rewrites the logic to be (I think) a bit more easy to understand. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-05-22cleanup: constify time_during_dive_with_offset() functionGravatar Berthold Stoeger
There is no reason to pass a non-const dive pointer as first argument. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-22cleanup: remove unused function get_dive_n_near()Gravatar Berthold Stoeger
The last caller was removed in 7eb422d98837b3cfb289a66fa0f3a8f78f222001. Since this is the only caller of dive_within_time_range(), remove that function as well. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06undo: make adding of pictures undoableGravatar Berthold Stoeger
This one is a bit hairy, because two things might happen if the picture has a geo location: - A dive gets a newly generated dive site set. - The dive site of a dive is edited. Therefore the undo command has to store keep track of that. Oh my. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06core: move picture-related function from dive.c to picture.cGravatar Berthold Stoeger
Move the two functions create_picture() and picture_check_valid_time() from dive.c to picture.c. This might be somewhat questionable, as these functions are not purely picture related, but check the nearest selected dives, etc. However, dive.c is so huge, that slimming it down can't hurt. Moreover, getting the nearest selected dive is more divelist- than dive functionality anyway. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06media: move addition of pictures out of create_picture()Gravatar Berthold Stoeger
If we want to make addition of pictures undoable, then create_picture() must not add directly to the dive. Instead, return the dive to which the picture should be added and let the caller perform the addition. This means that the picture-test has to be adapted. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06core: remove new_picture_for_dive() function in dive.cGravatar Berthold Stoeger
We can do the same with get_picture_idx(). Yes, it is a bit more unwieldy. However a full reimplementation seems not worth it. We could make this a one-liner helper function though. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06media: use table instead of linked list for mediaGravatar Berthold Stoeger
For consistency with equipment, use our table macros for pictures. Generally tables (arrays) are preferred over linked lists, because they allow random access. This is mostly copy & paste of the equipment code. Sadly, our table macros are quite messy and need some revamping. Therefore, the resulting code is likewise somewhat messy. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06cleanup: move copy_cylinders from dive.c to equipment.cGravatar Berthold Stoeger
Since this doesn't touch struct dive, dive.c is not an appropriate place for this function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-05Grantlee: Add salinity and water type to grantlee variablesGravatar Monty Taylor
These can be useful in a printed divelog, especially if the log entry is also showing weight and exposure suit. Signed-off-by: Monty Taylor <mordred@inaugust.com>
2020-05-01cleanup: move dive_table from dive.h to divelist.hGravatar Berthold Stoeger
This allows us to decouple dive.h and divelist.h, a small step in include disentangling. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01profile: return air for one-past last cylinderGravatar Berthold Stoeger
This is the code for "surface air". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01core: create fake cylinder at end of cylinder table (hack!)Gravatar Berthold Stoeger
When we had fixed-sized cylinder arrays, the planner used the last empty cylinder for "surface air". This was not recognized by the UI as a separate cylinder, because "empty cylinder" was the sentinel for the end of the table. The conversion to dynamically sized cylinder tables broke this code: everytime the surface segment is changed, a new dummy cylinder is added, which is visible in the UI. As a very temporary stop-gap fix, emulate the old code by creating a cylinder and then setting the end-of-table to before that cylinder. This means that we have to loosen the out-of-bound checks. That's all very scary and should be removed as soon as possible. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-20core: return -1 from explicit_first_cylinder() if dive has no cylindersGravatar Berthold Stoeger
Arguably, returning 0 for a dive with no cylinders is wrong, since the 0 is a valid cylinder id, however that cylinder doesn't exist. Instead, return -1. All callers of explicit_first_cylinder() return early anyway for dives with no cylinders. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-13Preserve events when editing dive in plannerGravatar Robert C. Helling
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>
2020-04-11media: invalidate correct dive when removing pictureGravatar Berthold Stoeger
This fixes a bug: when deleting a picture when multiple dives were selected, possibly the wrong dive was invalidated. Thus, the dive wouldn't have been saved to the git repository. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-11Merge pull request #2643 from bstoeger/cylinder4Gravatar Dirk Hohndel
First steps of cylinder-editing undo
2020-04-10media: move picture function from dive.c to picture.cGravatar Berthold Stoeger
Currently, move only those functions that do not access dive structures. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-10cleanup: remove picture_free()Gravatar Berthold Stoeger
There is the free_picture() function with the same functionality. The compiler/linker should recognize that and remove the duplicate code, but still... Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-10cleanup: remove dive_get_picture_count() functionGravatar Berthold Stoeger
The last user was removed in 5b7e4c57f78c9ec2087726ecad89797132a32d08. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cleanup: remove remove_event() functionGravatar Berthold Stoeger
No user left. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07core: split out create_gas_change_event() from add_gas_change_event()Gravatar Berthold Stoeger
For undo, we want to create gas change events without adding them immediately to the dive computer. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cleanup: move add_gas_switch_event to dive.cGravatar Berthold Stoeger
Since all the other event-functions are also defined there. Ultimately, we should probably move them to their own event.c translation unit. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07undo: implement renaming of eventsGravatar Berthold Stoeger
There is a slight complexity here owing to the fact that the profile works on a copy of the current dive: We get a copy of the event and have to search for the original event in the current dive. This could be done in the undo command. Nevertheless, here we do it in the profile so that when in the future the profile can work on a non-copied dive we can simply remove this function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07core: add remove_event_from_dc() functionGravatar Berthold Stoeger
We have a remove_event() function that 1) frees the event 2) works on the current divecomputer 3) compares the events because the profile has copies of events However, for undo commands 1) we want to keep the event so that we can readd it later 2) we have to work on arbitrary divecomputers 3) we don't work with copies of events Therefore, create a new remove_event_from_dc() function that does all that. Moreover, make the event argument to remove_event() const to (slightly) point out the difference in the API. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07core: split add_event() in two partsGravatar Berthold Stoeger
add_event() creates and adds an event from the given parameters. For undo, we want to do these separately, therefore split this function in two parts: create_event() and add_event_to_dc(). Keep the add_event() function for convenience. Moreover, keep the remember_event() call in there, so that undo-commands can call remember_event() once, not on every undo/redo action. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-11Grammar: replaces 'indexes' by 'indices'Gravatar Robert C. Helling
Grammar-nazi ran git grep -l 'indexes' | xargs sed -i '' -e 's/indexes/indices/g' to prevent future wincing when reading the source code. Unfortunatly, Qt itself is infected as in QModelIndexList QItemSelection::indexes() const Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-03-06Core: don't return invalid cylinders from explicit_first_cylinder()Gravatar Berthold Stoeger
For reasons which I don't yet understand, when plotting a dive whose first cylinder is not cylinder 0 and then plotting a dive with only one cylinder, it can happen that for the latter explicit_first_cylinder() returns an erroneous value. This is due to the way in which we copy the dive to be plotted to displayed_dive. For now, make sure that no invalid cylinder is returned to avoid crashes. This will have to be changed anyway, since this is very fundamentally not thread-safe and inefficient. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-01filter: compile fulltext index on mobileGravatar Berthold Stoeger
The code is not used yet. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-01filter: index/unindex dives on loading or clearing logsGravatar Berthold Stoeger
When loading dive data, populate the fulltext index. When clearing dive data, free the fulltext index. When deleting a dive, remove it from the fulltext index. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-01-10code cleanup: use gasmix_air for zero initialized gasGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-05Fix get_divemode logicGravatar Robert C. Helling
Commit dbb504 tried to prevent an uninitialized dc pointer from being dereferenced. But I screwed up the logic always setting the event pointer to NULL. This fixes this error. Reported-by: willemferguson@zoology.up.ac.za Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-11-16Don't acces null dive computerGravatar Robert C. Helling
Fixes CID 350111 Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-11-09Cylinders: access cylinders with get_cylinder()Gravatar Berthold Stoeger
Instead of accessing the cylinder table directly, use the get_cylinder() function. This gives less unwieldy expressions. But more importantly, the function does bound checking. This is crucial for now as the code hasn't be properly audited since the change to arbitrarily sized cylinder tables. Accesses of invalid cylinder indexes may lead to silent data-corruption that is sometimes not even noticed by valgrind. Returning NULL instead of an invalid pointer will make debugging much easier. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Desktop: support no-cylinders in dive information tabGravatar Berthold Stoeger
The tab was crashing if there were no cylinders because 1) per_cylinder_mean_depth() would access non-existing cylinders. 2) TabDiveInformation::updateProfile() would access a non-existing mean. Fix both of these crash conditions by checking whether the dive actually has cylinders. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Cleanup: return cylinder from add_empty_cylinder()Gravatar Berthold Stoeger
As a convenience, return the cylinder from add_empty_cylinder() to spare the caller from the nasty expression to fetch the last cylinder. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>