Commit graph

331 commits

Author SHA1 Message Date
Berthold Stoeger
bdd5527005 core: move *_to_depth() functions into struct dive
Seems logical 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
bf84d66df2 core: move depth_to_* functions into struct dive
Seems logical 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
3660241993 core: remove get_dive() function
This implicitly accessed the global divelog. Most of the users were
in the test/ folder anyway. Replace by explicit accesses to the
global divelog.dives.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
ccdd92aeb7 preferences: use std::string in struct preferences
This is a messy commit, because the "qPref" system relies
heavily on QString, which means lots of conversions between
the two worlds. Ultimately, I plan to base the preferences
system on std::string and only convert to QString when
pushing through Qt's property system or when writing into
Qt's settings.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
b95ac3f79c core: turn C dive-table into an owning table
This is a humongous commit, because it touches all parts of the
code. It removes the last user of our horrible TABLE macros, which
simulate std::vector<> in a very clumsy way.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
a1e6df46d9 core: move functions into struct dive
Nothing against free-standing functions, but in the case
of dc_watertemp(), dc_airtemp(), endtime() and totaltime(),
it seems natural to move this into the dive class and avoid
polution of the global name space.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
aa60e5d21d core: return unique_ptr<> from merge-dive functions
Try to remove plain owning pointers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
1e09ec77d7 core: make clone_* functions return a unique_ptr<>
Don't use plain pointers for owning pointers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
0ef497c3c9 core: make split_dive() and related functions return unique_ptrs
This prepares for turning the dive table into a list of owning
pointers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
c9d4ce0c15 fulltext: replace plain pointer by std::unique_ptr<>
This was a plain pointer owing to C compatibility.

Replacing it by a unique_ptr<> allows us to make it
'self-desctruct' in the constructor. However, we do this
with a special twist: the data is _not_ copied when copying
the dive, since the copied dive is not registered in the fulltext
system. Hackish, but it should(!) work.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
9e3e0a5a05 core: turn picture-table into std::vector<>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
3cb04d230b core: turn struct dive string data into std::string
Much easier memory management!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
f18acf6fb9 core: port tag-list to C++
Also adds a new test, which tests merging of two tag-lists.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
640ecb345b core: convert weightsystem_t and weightsystem_table to C++
As for cylinders, this had to be done simultaneously,

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
28520da655 core: convert cylinder_t and cylinder_table to C++
This had to be done simultaneously, because the table macros
do not work properly with C++ objects.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
284582d2e8 core: turn divecomputer list into std::vector<>
Since struct divecomputer is now fully C++ (i.e. cleans up
after itself), we can simply turn the list of divecomputers
into an std::vector<>. This makes the code quite a bit simpler,
because the first divecomputer was actually a subobject.

Yes, this makes the common case of a single divecomputer a
little bit less efficient, but it really shouldn't matter.
If it does, we can still write a special std::vector<>-
like container that keeps the first element inline.

This change makes pointers-to-divecomputers not stable.
So always access the divecomputer via its index. As
far as I can tell, most of the code already does this.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
27dbdd35c6 core: turn event-list of divecomputer into std::vector<>
This is a rather long commit, because it refactors lots of the event
code from pointer to value semantics: pointers to entries in an
std::vector<> are not stable, so better use indexes.

To step through the event-list at diven time stamps, add *_loop classes,
which encapsulate state that had to be manually handled before by
the caller. I'm not happy about the interface, but it tries to
mirror the one we had before.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
8ddc960fa0 core: remove update_event_name
Since the name of an event is not incorporated into the even
structure anymore, we don't need these shenanigans. Just assign
the event name.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
f120fecccb core: use std::vector<> to store divecomputer samples
This is a hairy one, because the sample code is rather tricky.

There was a pattern of looping through pairs of adjacent samples,
for interpolation purposes. Add an range adapter to generalize
such loops.

Removes the finish_sample() function: The code would call
prepare_sample() to start parsing of samples and then
finish_sample() to actuall add it. I.e. a kind of commit().

Since, with one exception, all users of prepare_sample()
called finish_sample() in all code paths, we might just add
the sample in the first place. The exception was sample_end()
in parse.cpp. This brings a small change: samples are now
added, even if they could only be parsed partially. I doubt
that this makes any difference, since it will only happen
for broken divelogs anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
cc39f709ce core: add constructor/destructor pairs to dive and divecomputer
This allows us to use non-C member variables. Convert a number
of pointers to unique_ptr<>s.

Code in uemis-downloader.cpp had to be refactored, because
it mixed owning and non-owning pointers. Mad.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
e39dea3d68 core: replace divesite_table_t by a vector of std::unique_ptr<>s
This is a long commit, because it introduces a new abstraction:
a general std::vector<> of std::unique_ptrs<>.

Moreover, it replaces a number of pointers by C++ references,
when the callee does not suppoert null objects.

This simplifies memory management and makes ownership more
explicit. It is a proof-of-concept and a test-bed for
the other core data structrures.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
b82fdd1d20 general: remove (void) function parameter declarations
To my understanding, declaring empty parameter lists using "(void)"
is an artifact from the bad old K&R times, when functions were
declared without(!) parameters. Which in hindsight was an absolute
recipe for disaster. So for backwards compatibility, functions
without parameters had to be declared using "(void)" as "()"
could also mean "any function".

That was 40 years ago. Meanwhile, C++ introduced references,
which made it a necessity to declare the function parameters.
So "(void)" is redundant and inconsistent in C++ code and
just makes no sense.

Remove it.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
b56dd13add build: remove extern "C" linkage
No more C source files, no more necessity to use C-linkage.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
03b910ee7f core: remove __cplusplus ifdefs
Since all source files are now C++, this is redundant.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
7d3977481a core: convert divesite strings to std::string
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
3f8b4604be core: convert taxonomy.c to C++
Since the taxonomy is now a real C++ struct with constructor
and destructor, dive_site has to be converted to C++ as well.

A bit hairy for now, but will ultimately be distinctly simpler.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Michael Keller
528532572f Planner: Fix Editing of Plans in Multi-Divecomputer Dives.
Currently editing of planned dives that have been merged with actual
(logged) dives only works if the 'Planned dive' divecomputer is the
first divecomputer, and this divecomputer is selected when clicking
'Edit planned dive'. In other cases the profile of the first
divecomputer is overlaid with the profile of the planned dive, and the
first divecomputer's profile is overwritten when saving the dive plan.
Fix this problem.

Triggered by @SeppoTakalo's comment (https://github.com/subsurface/subsurface/issues/1913#issuecomment-2075562119): Users don't like that planned dives show up as their own entries in the dive list, so being able to merge them with the actual dive after it has been executed is a good feature - but this wasn't working well until now.

Signed-off-by: Michael Keller <github@ike.ch>
2024-05-11 12:51:45 +12:00
Michael Keller
f3c7dcf9c9 Desktop: Fix 'planned' and 'logged' Filters.
Fix the filters for planned (i.e. has at least one dive plan attached)
and logged (i.e. has at least one dive computer log attached) dives.
Also refactor the respective functions for improved readability.

Signed-off-by: Michael Keller <github@ike.ch>
2024-04-30 12:25:31 +12:00
Berthold Stoeger
41cb916060 core: turn existing_filename into std::string
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-24 17:53:19 +01:00
Berthold Stoeger
cca4c8cae5 core: return std::string from get_dive_date_c_string()
Had to convert uemis-donwloader.c to C++. Lot's of
non-const clean code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Michael Keller
df1974a244 Mobile: Fix Configuration of Ceiling Display.
Fix the configuration of the deco ceilings in the mobile version:
- make the settings work;
- remove reading of the dive computer ceiling from git;
- hide the gradient factor in the profile when the calculated ceiling is
  not shown;
- when the calculated ceiling is disabled in the settings, disable
  editing of the gradient factor.

Signed-off-by: Michael Keller <github@ike.ch>
2024-02-06 11:58:49 +13:00
Dirk Hohndel
8e212c0858 Fedora Rawhide builds fail without stdlib include
Implicit declarations of malloc, free, atoi, and others are considered an
error now.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2023-12-04 12:55:10 -08:00
Berthold Stoeger
4c02d1c279 planner: get rid of global displayed_dive variable
Allocate the dive in the planner. This is all a bit convoluted
and needs more cleanup.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-16 20:23:59 +02:00
Berthold Stoeger
9f455b1457 selection: move current dive and divecomputer to selection.cpp
This tries to encapsulate the management of the current dive and
divecomputer in the selection code. The current dive is alreay
set by setSelection(). Add a new parameter to also set the
current divecomputer. If -1 is passed, then the current
computer number is remained. This will allow us to audit the code.
Because for now, the whole "current dive computer" thing seems
to be ill-defined.

This fixes a bug: the dive-computer number wasn't validated
when making a new dive the current dive. The new code has some
drawbacks though: when selecting a whole trip, the validation
will be called for all dives in the trip and thus the dive computer
number will depend on the dive with the lowest amount of dive
computers in the trip. This will need to be fixed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-16 20:23:59 +02:00
Berthold Stoeger
b61732da42 core: remove autogroup global
Use the flag in the divelog structure, since this will be saved
in the dive log.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-14 21:20:23 +02:00
Berthold Stoeger
acd385048a Prefer real data over planned
When a dive has both real dive computers as well as at
least a planned version (which is just another dive
computer with a special name), only use the data from
real dive computers for aggregate values like maxdepth,
dive time, average depth etc in order not to have
imagined data on the dive list, statistics etc.

Macro-magic-provided-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2022-08-25 13:38:12 -07:00
Berthold Stoeger
d5fafc0e44 core: remove current_dc macro
There were only three users of that. For now do it inline, but
we may think about a separate function, which is only available
on desktop.

Moreover, add nullptr-checks, even if they are not strictly
necessary.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-03-13 15:07:33 -07:00
Berthold Stoeger
12406786f1 core: pass dc-number to update_event_name()
The dive was passed as an argument to update_event_name(), but
the divecomputer was derived from the global dc_number variable.
That makes no sense. Therefore, pass the dc_number as argument
and update the only caller (smtk-import).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-03-13 15:07:33 -07:00
Berthold Stoeger
9e0712d5dc core: replace dive master by dive guide
In general, replace "dive master" by "dive guide".

However, do not change written dive logs for now. On reading,
accept both versions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-02-15 09:35:43 -08:00
Robert C. Helling
9fd531dcc5 Round gas depth properly
The D in MOD, EAD, END, and EADD stands for "depth" and
as such these should be mm in int rather than double.

The intermediate fn2 and fhe2, however, as intermediate
value should not be rounded to an integer.

The upshot of this is a litle more numerical stability.
It should lead to more stable values in TestProfile
when run on architectures with different floating
point precision.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2021-12-06 22:29:04 +01:00
Berthold Stoeger
28fe6a7b38 core: add a function to test for sensors of a given cylinder
We want to prevent the user from accidentally deleting a
cylinder with sensor readings. Therefore, we need such a
function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-09-03 13:35:28 -07:00
mikeller
2d734c529b desktop: Add the capability to copy / paste dive number and date / time.
This is adding the capability to select 'Dive number' and 'Date / Time'
in the 'Copy dive components' dialog, and then copy them into the
clipboard.
When using 'Paste dive components, these values will then be pasted into
the selected dive(s).
This is intended to help with workflows that import dive information
from two different sources, like general information from another
logging program, and CCR ppO2 sensor readings from a unit log, and then
stitch them together into one cohesive entry with all data per dive.
Copied data is also output into formatted text when pasting the
clipboard outside of the application:

```
Dive number: 401
Date / time: Sun 2 May 2021 12:00 AM
```

No translations have been added as of now - I could not find any
information on how strings are translated for this project.

Signed-off-by: Michael Keller <github@ike.ch>
2021-05-19 15:15:34 -07:00
Berthold Stoeger
193513a61f profile: pass dive to plot function of profile-items
Instead of accessing the global displayed_dive variable,
pass the dive to the various profile items. This is a
step in making the profile code reentrant.

This removes the last user of the displayed_dc macro,
which can now be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10 15:57:39 -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
4c85357dcc cleanup: move monthname to time.c
Weirdly, this function was declared in dive.h and defined in
subsurface-startup.c. Let's move declaration and definition to
more appropriate places, viz. subsurface-time.h and time.c.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-29 08:34:09 -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
Berthold Stoeger
b984839836 cleanup: remove pref.h include in dive.h
If source files want to access preferences functions, they should
include pref.h themselves.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25 13:59:52 -07:00
Berthold Stoeger
a719bfbeaf cleanup: move git-pref declarations into core/pref.h
These seem to be an artifact.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25 13:59:52 -07:00
Berthold Stoeger
975ef65913 cleanup: move sort_dive_table declaration to divetable.h
Apparently this was forgotten in a previous include-reshuffling.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25 13:59:52 -07:00
Berthold Stoeger
f2494931e9 cleanup: move cylinder_use_text declaration to equipment.h
This is unrelated to struct dive and also wasn't defined in
dive.c

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25 13:59:52 -07:00