Commit graph

20293 commits

Author SHA1 Message Date
Dirk Hohndel
a5effbe0a6 macOS: reorder build of dependencies
libcurl needs openssl.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2024-09-09 15:15:38 -07:00
Michael Keller
96fdaf660b Fix a compiler warning.
Signed-off-by: Michael Keller <mikeller@042.ch>
2024-09-09 12:59:13 +12:00
Michael Keller
515f593a56 Planner: Start with Correct Dive Mode.
Fix a bug introduced in #4245, causing an incorrect dive mode to be
selected when starting the dive planner from a CCR dive.

Signed-off-by: Michael Keller <github@ike.ch>
2024-09-09 12:53:13 +12:00
Berthold Stoeger
f585726283 planner: don't pass reference to asynchronous lambda
A reference to a unique_ptr<> was captured by a lambda used
to calculate variations in the background.

This is of course disastrous, because if the caller runs
first it will delete the object. It's a wonder that this
didn't crash regularly!?

The problem is that capturing unique_ptr<>s in lambdas
works, but makes the lambda non-copyable. Sadly, the
QtConcurrent::run() function wants to copy the lambda.

For now, do this by a release/reaquire pair. This is
not exception safe. However, sine Qt doesn't support
exceptions, we can live with that.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-04 14:44:46 +02: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
Tim D. Hammer
069f8a5d18 correct re-plan menu label in documentation
The (presumably) older label "Re-plan dive" in the Log menu was replaced with "Edit dive in planner",
but the documentation section "Modifying an existing dive plan" was not updated.

Signed-off-by: Tim D. Hammer <tdhammer@linux.com>
2024-08-26 12:37:29 +12: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
14b9074f40 Fix layering violations in DivePlannerPointsModel.
Signed-off-by: Michael Keller <mikeller@042.ch>
2024-08-26 12:36:31 +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
Berthold Stoeger
7106c4d5f0 desktop: reinstate WSInfoModel constructor
In 1af00703b3 the constructor of
WSInfoModel was removed, not realizing that it contains a crucial
call to setHeaderDataStrings().

Fixes #4294

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-23 09:03:24 +02:00
Michał Sawicz
8b435c9d8f snap: use a local /etc/gitconfig
Fixes: #3465

Signed-off-by: Michał Sawicz <michal@sawicz.net>
2024-08-21 14:06:57 +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
01705a6449 undo: exit early if no event in RemoveEvent()
To avoid dereferencing a null pointer.

Found by Coverity.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-18 16:26:31 +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
e305546046 undo: fix RemoveEvent if we can't find the event
We check for the event, but then access it anyway even if it
doesn't exist. Should not happen, but let's be safe.

Found by Coverity.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-17 23:37:00 +12:00
Berthold Stoeger
5c6ca2c1ce undo: don't use moved-from string
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
Michael Keller
48b4308a7d Windows: Fix smtk-import Build.
Fix a copy/paste error introduced in #4273.

Signed-off-by: Michael Keller <github@ike.ch>
2024-08-17 23:33:58 +12:00
gregbenson314
a75c9c3872 Update equipment.c Add D7 232 Bar Tank
D7 232 Bar tank added in line 342.

D7 232 Bar are common in Europe, not just D7 300 Bar.

Signed-off-by: gregbenson314 <99766165+gregbenson314@users.noreply.github.com>
2024-08-15 18:09:32 +12:00
Michael Keller
a905a78178 Update core/units.h
Signed-off-by: Michael Keller <github@ike.ch>
2024-08-13 19:28:30 +02:00
Michael Keller
94ed723015 Update core/units.h
Signed-off-by: Michael Keller <github@ike.ch>
2024-08-13 19:28:30 +02:00
Michael Keller
67f38ce3ce Update core/units.h
Signed-off-by: Michael Keller <github@ike.ch>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
80b5f6bfcd core: move add_cylinder() to struct cylinder_table
Feels natural in a C++ code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
22a1120b30 core: move gasname() to struct gasmix
Also, turn it to use std::string instead of writing into a
global(!) buffer. This was not reentrant.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00