Commit graph

3057 commits

Author SHA1 Message Date
Michael Keller
478e444cd9 Fix problems from rebase, clean up debian packaging definition.
Signed-off-by: Michael Keller <github@ike.ch>
2024-09-21 11:03:53 +12:00
Dirk Hohndel
40c22f0fe9 deal with typo in older versions of libraw
longtitude instead of longitude prior to libraw 0.20.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2024-09-21 11:03:53 +12:00
Berthold Stoeger
13d1188c41 media: load metadata and thumbnails of raw pictures using libraw
The distinguished photographer shoots raw images. There is a
comprehensive library that can extract metadata and thumbnails
from these images. Let's use it if available.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-21 11:03:53 +12:00
Richard Fuchs
a6a15f9d3a core: add missing types to return values
Fixes build failing on Debian Buster (gcc 8.3.0) with:

/build/subsurface-beta-202409160411/./core/units.h: In function 'duration_t operator""_sec(long long unsigned int)':
/build/subsurface-beta-202409160411/./core/units.h:149:48: error: could not convert '{((int32_t)sec)}' from '<brace-enclosed initializer list>' to 'duration_t'
  return { .seconds = static_cast<int32_t>(sec) };

Signed-off-by: Richard Fuchs <dfx@dfx.at>
2024-09-16 22:02:51 +02:00
Berthold Stoeger
1a3bc9bf71 units: add comment concerning unit literals
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-11 10:23:07 +02:00
Berthold Stoeger
dd5def35f5 units: replace SURFACE_PRESSURE by 1_atm
Moreover, convert diveplan::surface_pressure from int to
pressure_t.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-11 10:23:07 +02:00
Berthold Stoeger
ae81b42fe2 core: introduce a few user-defined literals for unit types
Thise makes initialization of unit types more palatable.

For example:

    surface.time = sample.time - duration_t { .seconds = 20 };
=>  surface.time = sample.time - 20_sec;

    delta_depth.mm = feet_to_mm(1.0); // 1ft
=>  delta_depth = 1_ft;

    get_cylinderid_at_time(..., { .seconds = 20 * 60 + 1 }));
=>  get_cylinderid_at_time(..., 20_min + 1_sec));

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-11 10:23:07 +02:00
Berthold Stoeger
f09601bc93 core: remove to_feet() function
It wasn't used anywhere.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-11 10:23:07 +02:00
Berthold Stoeger
77b12bbccf core: add cast_int<> function
We had a pattern where doubles were converted to long with
lrint() and then down-cast to a narrower int type.

Because this is unwieldy, introduce a function encapsulating
this.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-11 10:23:07 +02:00
Berthold Stoeger
110e64bc66 general: simplify a few unit manipulations
Now that we have defined addition and subtraction on unit
classes, let's use them in a few examples.

Yes, some of these are a bit pointless, because they are
of the kind
        a.mbar - b.mbar => (a-b).mbar

However, these probably should be further simplified
by storing the result in a unit type.

This commit is mostly a proof-of-concept.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-11 10:23:07 +02:00
Berthold Stoeger
729cc16fc5 core: add addition / subtraction to unit types
When adding / subtracting unit objects it is completely
irrelevant with respect to which unit the data is stored.
Why should the user know this?

Therefore add addition / subtraction functions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-11 10:23:07 +02:00
Berthold Stoeger
12ca172a9e core: add CRTP base class to unit types
The goal here is to add general addition and scalar multiplication
functions to the unit types.

Thereto, we need a CRTP
(https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern)
base class.

However, this breaks compound initialization, so we have to use
named initializers:
	weight_t { 2000 } -> weight_t { .grams = 2000 }
The good thing is that this is exactly how these classes were
supposed to be used: make the unit explicit!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-11 10:23:07 +02:00
Berthold Stoeger
696ba61eef planner: move gaschange_before / gaschange_after into loop
Declaring everything at the begin of the function is a K&R
disease, that makes code very hard to follow.

Remove the last assignment to gaschange_after since that is
a noop (found by Coverity).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-11 07:54:50 +02:00
Berthold Stoeger
6f91a73a05 planner: add move assignment constructor and operator to diveplan
Makes coverity happy and is a good idea.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-11 07:54:50 +02:00
Berthold Stoeger
1287880be0 planner: return decotable from plan()
The old return code was not used by any caller.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-11 00:13:04 +12:00
Berthold Stoeger
3e006e678a planner: don't use fixed size deco stop table
This was quite ominous: a 60-element fixed size table was
passed as argument to plan(). But there was no check for 60
anywhere? Use a dynamic vector instead.

The whole thing is weird, as the depth of the decostop table
doesn't seem to be used.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-11 00:13:04 +12:00
Berthold Stoeger
0745c50e58 planner: C++-ify a bit more
Use constructor and member functions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-11 00:13:04 +12:00
Berthold Stoeger
8704a8b6f9 planner: turn diveplan into a C++ structure
No more memory management woes.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-11 00:13:04 +12:00
Michael Keller
ee25e8a1db Refactoring: Improve event_loop.
Improve the event loop architecture by making it set the divecomputer in
the constructor - using the same loop for multiple dive computers is not
intended to work.
Also change `next()` in `divemode_loop` to `at()` to make the name more
aligned with its function.

Signed-off-by: Michael Keller <github@ike.ch>
2024-09-03 21:24:40 +02:00
Michael Keller
33bb39f1ca Planner: Fix Warning from Coverity.
Fix an interger overflow warning when parsing setpoints.

@bstoeger: In the end it turned out that this parser was only used in
one place in the planner UI, and it was simplest to switch this to
using `QVariant.toFloat()` in the model itself, which is consistent how
the rest of the input values is parsed and validated.

Signed-off-by: Michael Keller <github@ike.ch>
2024-09-04 07:04:35 +12:00
Berthold Stoeger
cc55c442a3 core: fix undo of dive merging
When merging two dives, if a divesite is chosen that doesn't
have a GPS location, but another divesite has a GPS location,
then the GPS location of the former is set to that of the
latter.

However, that was done outside of the undo system, so that
it is not undone and the frontend is not made aware of the
change.

Fix this. To simplify things, move the code from the undo
machinery to the core.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-03 18:20:48 +12:00
Berthold Stoeger
27a89b0232 core: remove dive_site member from merge_result
All callers were just using that member to set the dive_site
in the resulting dive. We might just do that in the called
function [merge_dives()].

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-03 18:20:48 +12:00
Michael Keller
5b46d8cc33 Profile: Refactor use of .
Signed-off-by: Michael Keller <github@ike.ch>
2024-09-03 18:19:44 +12:00
Michael Keller
db516b6d4e Profile: Fix the Initial Gasmix.
Fix the initial gasmix that is shown in the tank bar of the profile.

Also add a meaningful gas name for gases with negative values for
percentages.

@bstoeger: This is a side effect of the `event_loop` functionality
introduced as part of #4198. In the case of an `event_loop("gasmix")`
this does not take into account the edge case where there is no
gaschange event at the very beginning of the dive, and the first gasmix
is implicitly used as the starting gasmix. This happens for planned and
manually added dives, but also for some dive computers.
We are using the
same kind of loop in a number of other places in `core/profile.cpp`,
`core/dive.cpp`, `core/gaspressures.cpp`, and `profile-widget/tankitem.cpp`,
and I am wondering if we should be converting these to use
`gasmix_loop` instead to avoid being bit by this special case?

Signed-off-by: Michael Keller <github@ike.ch>
2024-09-03 18:19:44 +12:00
Berthold Stoeger
38fe08e5e1 planner: use std::move() to store planner notes
Avoids a copy and makes coverity happy (rightfully so).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-02 08:16:29 +02:00
Linus Torvalds
aa3a93a466 Fix location in result of dive merging
This is the minimal fix to actually include the resulting location in
the merged dive.  I'm not sure what the background was to setting the
dive location only in the "merge_result" variable, and not in the actual
result dive itself.

Berthold says that the whole site handling may be broken:

 "From a quick glance, the code in dive_table::merge_dives looks
  fundamentally broken, because it may overwrite site->location outside
  of the undo system. I.e. this will not be undone."

but the "this will not be undone" is about the site location setting,
and is separate and independent of the dive->dive_set setting.

Presumably we would need to make a copy of the site for the undo
functionality.  That will be for somebody else to worry about, this at
least fixes the resulting location in the dive itsels.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2024-08-28 10:35:26 +02:00
Linus Torvalds
da6c753502 Fix sample times in dive merging
Commit c27314d60 ("core: replace add_sample() by append_sample()") broke
the dive computer interleaving when merging two dives: the sample
merging (done by "merge_samples()") no longer took the offset between
the two merged dives into account, and instead just blindly copied the
samples from the second dive computer with no time offset.

The end result was a completely broken profile.

This adds back the sample offset.  It also takes the offset not from the
difference in time of the two dives, but the difference in time of the
dive computers.  That way we're not mixing up different times from
different sources that aren't necessarily in sync (the time *difference*
is hopefully the same, but still..).

The dive merging still messes up the dive location. That's some other bug.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2024-08-28 10:35:26 +02:00
Linus Torvalds
914cdb102b Fix Suunto FIT file import dive duration mis-calculation
The Suunto FIT files end up creating a sample every second, but a lot of
those samples with no depth information, marked as "depth.mm" being negative.

That doesn't end up being a problem for subsurface, _except_ that it
really confuses our "dc_fixup_duration()" logic, and the dive duration
ends up being completely nonsensical (generally roughly by a factor of
five: every tenth sample has a depth, and we only count samples that
"begin or end under water" as being relevant for the dive duration, so
two out of the ten samples will count towards the dive time).

Saving the dive will then not save these invalid depths, so saving and
reloading the dive ends up fixing the dive duration calculation.

The fix is trivial - we just ignore samples with negative depth in
dc_fixup_duration().

The FIT file parser should probably be taught to not even bother sending
empty samples to subsurface, but that's a separate cleanup.  This fixes
the actual bad behavior.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2024-08-26 21:01:32 -07:00
Richard Fuchs
3c3856f9e8 core: add missing #include <tuple>
Fixes gcc complaining about

/build/subsurface-beta-202408210659/core/divecomputer.cpp: In function 'bool operator<(const event&, const event&)':
/build/subsurface-beta-202408210659/core/divecomputer.cpp:290:21: error: 'tie' is not a member of 'std'
  290 |         return std::tie(ev1.time.seconds, ev1.name) <
      |                     ^~~
/build/subsurface-beta-202408210659/core/divecomputer.cpp:13:1: note: 'std::tie' is defined in header '<tuple>'; did you forget to '#include <tuple>'?
   12 | #include <stdlib.h>
  +++ |+#include <tuple>
   13 |
/build/subsurface-beta-202408210659/core/divecomputer.cpp:291:21: error: 'tie' is not a member of 'std'
  291 |                std::tie(ev2.time.seconds, ev2.name);
      |                     ^~~
/build/subsurface-beta-202408210659/core/divecomputer.cpp:291:21: note: 'std::tie' is defined in header '<tuple>'; did you forget to '#include <tuple>'?

Signed-off-by: Richard Fuchs <dfx@dfx.at>
2024-08-26 12:37:07 +12:00
Michael Keller
2d8e343221 Planner: Improve Gas Handling in CCR Mode.
This has become a bit of a catch-all overhaul of a large portion of the
planner - I started out wanting to improve the CCR mode, but then as I
started pulling all the other threads that needed addressing started to
come with it.

Improve how the gas selection is handled when planning dives in CCR
mode, by making the type (OC / CCR) of segments dependent on the gas use
type that was set for the selected gas.
Add a preference to allow the user to chose to use OC gases as diluent,
in a similar fashion to the original implementation.
Hide gases that cannot be used in the currently selected dive mode in
all drop downs.
Include usage type in gas names if this is needed.
Hide columns and disable elements in the 'Dive planner points' table if
they can they can not be edited in the curently selected dive mode.
Visually identify gases and usage types that are not appropriate for the
currently selected dive mode.
Move the 'Dive mode' selection to the top of the planner view, to
accommodate the fact that this is a property of the dive and not a
planner setting.
Show a warning instead of the dive plan if the plan contains gases that
are not usable in the selected dive mode.
Fix the data entry for the setpoint in the 'Dive planner points' table.
Fix problems with enabling / disabling planner settings when switching
between dive modes.
Refactor some names to make them more appropriate for their current
usage.

One point that is still open is to hide gas usage graphs in the planner
profile if the gas isn't used for OC, as there is no way to meaningfully
interpolate such usage.

Signed-off-by: Michael Keller <github@ike.ch>
2024-08-26 12:36:31 +12:00
Richard Fuchs
a6ce6e56d3 core: add missing #include <tuple>
Fixes gcc complaining about

/build/subsurface-beta-202408190452/core/event.cpp: In member function 'bool event::operator==(const event&) const':
/build/subsurface-beta-202408190452/core/event.cpp:64:21: error: 'tie' is not a member of 'std'
   64 |         return std::tie(time.seconds, type, flags, value, name) ==
      |                     ^~~
/build/subsurface-beta-202408190452/core/event.cpp:6:1: note: 'std::tie' is defined in header '<tuple>'; did you forget to '#include <tuple>'?
    5 | #include "subsurface-string.h"
  +++ |+#include <tuple>
    6 |
/build/subsurface-beta-202408190452/core/event.cpp:65:21: error: 'tie' is not a member of 'std'
   65 |                std::tie(b.time.seconds, b.type, b.flags, b.value, b.name);
      |                     ^~~
/build/subsurface-beta-202408190452/core/event.cpp:65:21: note: 'std::tie' is defined in header '<tuple>'; did you forget to '#include <tuple>'?

Signed-off-by: Richard Fuchs <dfx@dfx.at>
2024-08-19 22:47:59 +02:00
Berthold Stoeger
26c594382e core: fix deletion of events in fixup_dc_events()
If there were more than one redundant event in the 60 sec range,
the event would be deleted multiple time, leading to a crash.

Only mark for deletion once.

Moreover, don't consider events that were already marked for
deletion, because that would mean that redundant events all 59 secs
would lead to all events (but the first one) deleted.

Finally, optimize the loop by stopping once the 60 sec limit
is reached.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-19 13:14:47 +02:00
Berthold Stoeger
0dc47882cb code hygiene: use std::swap instead of temporary variable
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-19 13:14:47 +02:00
Berthold Stoeger
bdfd37c95b core: fix sorting of events
Fix an embarrassing bug: the less than operator for events
was wrong.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-19 13:14:47 +02:00
Berthold Stoeger
d295ca1d17 code cleanup: use std::move() to potentially void copies
Found by Coverity.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-18 16:26:31 +02:00
Berthold Stoeger
2d5094a48b profile: add move constructor and assignment operator to plot_info
To make Coverity happy.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-17 23:37:00 +12:00
Berthold Stoeger
92abfb4b90 ostctools: avoid string copy
Found by Coverity.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-17 23:37:00 +12:00
Berthold Stoeger
1578c7be99 uemis downloader: use move instead of copy to return string
Found by Coverity.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-17 23:37:00 +12:00
Berthold Stoeger
f78662acce uemis downloader: close reqtxt_file in case of error
Found by Coverity. Should switch to proper C++ type, though
no priority for now.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-17 23:37:00 +12:00
Berthold Stoeger
a3340298b6 liquivision import: move notes string
Avoids one copy. Found by Coverity.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-17 23:37:00 +12:00
Berthold Stoeger
ef9ae5f6d6 seac import: report database error
Also free the error message. Annoying C interface - found by
Coverity.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-17 23:37:00 +12:00
Berthold Stoeger
1dade48aa6 filter: use std::move() to pass around std::string
Suggested by Coverity. Seems like a good idea.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-17 23:37:00 +12:00
Berthold Stoeger
455bc8f40c core: add copy constructors/assignment operators to device_data_t
To make Coverity happy.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-17 23:37:00 +12:00
Berthold Stoeger
6d08903917 uemis: close reqtxt file in error case
Found by Coverity. Should switch to C++ "RAII" type, but no
priority for now.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-17 23:37:00 +12:00
Berthold Stoeger
2bbc95e8f1 planner: check nextdp for null
As correctly noted by Coverity, we check nextdp for null
and later dereference it.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-17 23:37:00 +12:00
Berthold Stoeger
c91884223f pressures: do floating point division when interpolating
Coverity correctly complains about an integer division followed
by an assignment to double. Hard to say if intended - but let's
do a floating point division instead.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-17 23:37:00 +12:00
Berthold Stoeger
ad2ccc8888 core: add move constructor/copy assignment to weight and cylinder
Make Coverity happy (shrug).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-17 23:37:00 +12:00
Berthold Stoeger
1fc5a294a6 uemis import: disable seemingly dead code
This is probably related to another commented out piece of code.
Disable until someone complains.

Fixes a (good) Coverity warning.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-17 23:37:00 +12:00
Berthold Stoeger
df568fbb5d suunto import: give and free error message
There was a memory leak in the error case of sqlite3_exec():
The error message was not freed (and also not displayed).

Display and free it. Is there a reasonable C++ version of this
library?

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-17 23:37:00 +12:00
Berthold Stoeger
152e6966c9 fix copy/paste of dive-site
The copy/pasting of dive-sites was fundamentally broken in at least two
ways:

1) The dive-site pointer in struct dive was simply overwritten, which
   breaks internal consistency. Also, no dive-site changed signals where
   sent.

2) The copied dive-site was stored as a pointer in a struct dive. Thus,
   the user could copy a dive, then delete the dive-site and paste.
   This would lead to a dangling pointer and ultimately crash the
   application.

Fix this by storing the UUID of the dive-site, not a pointer.
To do that, don't store a copy of the dive, but collect all
the data in a `dive_paste_data` structure.
If the dive site has been deleted on paste, do nothing.
Send the appropriate signals on pasting.

The mobile version had an additional bug: It kept a pointer to the
dive to be copied, which might become stale by undo.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-17 23:34:16 +12:00