Commit graph

254 commits

Author SHA1 Message Date
Berthold Stoeger
cd32c280ae undo: remove invalidate_dive_cache() call from make_first_dc()
The make_first_dc() function clones a dive with a certain dive
computer moved to the front. This is used by the
MoveDiveComputerToFront undo command.

make_first_dc() calls invalidate_dive(). However, the undo
command does that by itself on every undo/redo. Thus,
remove the call in make_first_dc().

Aside from consistency, the goal is to move invalidate_dive()
to command/* so that we can be more aggressive about the whole
topic: Store only "const dive *" pointers and thus force any
writing access to explicitly invalidate the dive cache.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-11 08:42:17 -08:00
Berthold Stoeger
be9f9efb0e profile: pass dive to EventItem
Don't access the global displayed_dive variable in an effort
to make the profile reentrant.

Note that this still accesses the global dc_number variable,
which will likely have to be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10 15:57:39 -08:00
Berthold Stoeger
18acb85a01 cleanup: don't save PASCAL pressure units to git
The way I understand, the PASCAL pressure unit is used to parse
obscure dive logs. However, there is no support in the UI for
using Pa as pressure unit. Therefore remove reading / writing
this unit to git divelogs.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-02 10:26:29 -08:00
Berthold Stoeger
b36178a00a cylindermodel: remove in_planner() use
in_planner() is problematic, since it is uses desktop-only
application state. Since the cylinder-model already has
an appropriate inPlanner flag, use this instead.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-11-24 10:54:10 +01:00
Robert C. Helling
10bedf02d0 Gracefully handle infinite MND for oxygen
When breathing pure oxygen and considering it not
narcotic, there is not maximal narcotic depth and
the formula divides by zero. So better, handle this
case separately.

Fixes #3080

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-11-13 11:10:48 -08:00
Berthold Stoeger
f728923c79 cleanup: move interpolate inline function to its own header file
This is not really related to struct dive, so let's move it.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25 13:59:52 -07:00
Berthold Stoeger
0e196310f9 cleanup: split out divecomputer functions from dive.c
Since dive.c is so huge, split out divecomputer-related functions
into divecomputer.[c|h], sample.[c|h] and extradata.[c|h].

This does not give huge compile time improvements, since
struct dive contains a struct divecomputer and therefore
dive.h has to include divecomputer.h. However, it make things
distinctly more clear.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25 13:59:52 -07:00
Berthold Stoeger
4aa571d5a0 cleanup: remove get_times() functions
The function
1) was misnamed: it determined the time of the first selcted dive.
2) had only one caller.
3) would crash if there was no selected dive.

Let's just fold the functionality into the caller. It's a one-liner
anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25 13:59:52 -07:00
Berthold Stoeger
464dd93fe8 cleanup: move fill_pressures from dive.c to gas.c
This function does not access a dive structure.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25 13:59:52 -07:00
Berthold Stoeger
8212acc992 cleanup: break out event-related code into event.[c|h]
In an effort to reduce the size of dive.h and dive.c, break out
the event related functions. Moreover event-names were handled
by the profile-code, collect that also in the new source files.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25 13:59:52 -07:00
Berthold Stoeger
b7a586a5b4 core: remove create_device_node() from fixup_dive()
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-24 09:51:37 -07:00
Berthold Stoeger
8549f24c91 core: add device_table parameter to device table functions
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-16 14:26:37 -07:00
Berthold Stoeger
b3f5473b66 core: don't merge sample-derived pressures in merge_one_cylinder()
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-05 12:59:02 -07:00
Berthold Stoeger
6729428b6a core: improve merging of cylinders pressures
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-05 12:59:02 -07:00
Berthold Stoeger
23da23a534 core: add N2 and general gas component accessors
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-10-03 10:29:15 -07:00
Robert C. Helling
efdc875aa3 Use correct pO2 when computing MOD in equipment tab
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-29 15:46:55 -07:00
Berthold Stoeger
bee2dea7cc cleanup: remove invalidate_dive_cache() call in clone_delete_divecomputer()
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-08 17:20:09 -07:00
Berthold Stoeger
0a747608b1 cleanup: remove dead code from delete_divecomputer()
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-08 17:20:09 -07:00
Berthold Stoeger
048cdcaa31 cleanup: remove count_divecomputers() function
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-08 17:20:09 -07:00
Berthold Stoeger
e5923a105a cleanup: use taxonomy_get_country() in get_dive_country()
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-06 12:59:54 -07:00
Robert C. Helling
b1a1dc3639 Function for "gravity conversion"
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-06 12:50:59 -07:00
Robert C. Helling
7e82205e9b Planner: Properly initialize salinity
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-09-02 09:43:38 -07:00
Linus Torvalds
77a11400a1 Fix event merging when merging dives
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-08-15 09:46:19 -07:00
Robert C. Helling
912e1faaf2 Make MND display depend on O2 narcotic preference
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-07-11 10:37:49 -07:00
Linus Torvalds
628c7c8f13 Fix dive merging with multiple cylinders
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-06-29 10:44:01 -07:00
Berthold Stoeger
87c91af824 cleanup: constify time_during_dive_with_offset() function
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-22 14:40:49 -07:00
Berthold Stoeger
9365061e27 cleanup: remove unused function get_dive_n_near()
The last caller was removed in 7eb422d988.
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-22 14:40:49 -07:00
Berthold Stoeger
4374605c12 undo: make adding of pictures undoable
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-06 13:58:09 -07:00
Berthold Stoeger
6ae2d36e38 core: move picture-related function from dive.c to picture.c
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-06 13:58:09 -07:00
Berthold Stoeger
74f03e3537 media: move addition of pictures out of create_picture()
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-06 13:58:09 -07:00
Berthold Stoeger
0935513636 core: remove new_picture_for_dive() function in dive.c
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-06 13:58:09 -07:00
Berthold Stoeger
989d6a3f96 media: use table instead of linked list for media
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-06 13:58:09 -07:00
Berthold Stoeger
2c4975f2ed cleanup: move copy_cylinders from dive.c to equipment.c
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-06 13:58:09 -07:00
Monty Taylor
95e6792c4f Grantlee: Add salinity and water type to grantlee variables
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-05 17:31:47 +03:00
Berthold Stoeger
95284c026e cleanup: move dive_table from dive.h to divelist.h
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-01 09:42:31 -07:00
Berthold Stoeger
8bc4233add profile: return air for one-past last cylinder
This is the code for "surface air".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01 12:36:28 +02:00
Berthold Stoeger
ffc3e598fa core: create fake cylinder at end of cylinder table (hack!)
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-05-01 12:36:28 +02:00
Berthold Stoeger
4aebcdc021 core: return -1 from explicit_first_cylinder() if dive has no cylinders
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-20 12:59:06 -07:00
Robert C. Helling
b50d5b63ad Preserve events when editing dive in planner
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-13 09:42:29 +02:00
Berthold Stoeger
f3b817c2d5 media: invalidate correct dive when removing picture
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-11 11:12:33 -07:00
Dirk Hohndel
6d187b5f4a
Merge pull request #2643 from bstoeger/cylinder4
First steps of cylinder-editing undo
2020-04-11 11:03:05 -07:00
Berthold Stoeger
3f3869ff65 media: move picture function from dive.c to picture.c
Currently, move only those functions that do not access dive
structures.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-10 10:53:03 -07:00
Berthold Stoeger
34657f62ae cleanup: remove picture_free()
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-10 10:53:03 -07:00
Berthold Stoeger
aa8cadbcdd cleanup: remove dive_get_picture_count() function
The last user was removed in 5b7e4c57f7.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-10 10:53:03 -07:00
Berthold Stoeger
7081674b67 cleanup: remove remove_event() function
No user left.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
9fe1951db2 core: split out create_gas_change_event() from add_gas_change_event()
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-07 00:13:35 +02:00
Berthold Stoeger
b1906dd04f cleanup: move add_gas_switch_event to dive.c
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-07 00:13:35 +02:00
Berthold Stoeger
ab8e317b28 undo: implement renaming of events
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-07 00:13:35 +02:00
Berthold Stoeger
3aa1bb5bfa core: add remove_event_from_dc() function
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-07 00:13:35 +02:00
Berthold Stoeger
2417a54675 core: split add_event() in two parts
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-04-07 00:13:35 +02:00