Switch the Divesoft log file importer to use the parser in
libdivecomputer. This adds support for the newer Divesoft Freedom+ log
file format.
Also refactor the OSTCTools log file importer to share common
functionality.
Signed-off-by: Michael Keller <github@ike.ch>
Switch the Divesoft log file importer to use the parser in
libdivecomputer. This adds support for the newer Divesoft Freedom+ log
file format.
Also refactor the OSTCTools log file importer to share common
functionality.
Signed-off-by: Michael Keller <github@ike.ch>
When computing the suggested switch depth for a gas,
we should take the next stop depth above the MOD, i.e.
round down. Otherwise we can produce MOD violation warnings.
We need, however, a bit of fudge as otherwise we do not
suggest to switch to o2 at 6m.
TestPlan uses the MOD to determine the depth to switch to
Tx21/35. This happens to be 65.378m. Therefore, switching
at 66m violates the MOD, the switch should be at 63m.
This then affects the gas usage.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
A dive without events could lead to json with extra closing brackets that
prevents browsers from rendering the dive log.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Previously, the subtitle generation was hardcoded, making it unsuitable
if you didn't want all of the displayed values. This has been replaced
by a format string that is configurable in the settings, using predefined
tags that are replaced with the values. The default value for this has
been set to (mostly) match the currently generated subtitle string. This
also provides a good starting point for users that want to modify the string.
Signed-off-by: Victor Arvidsson <victarv@gmail.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>