Commit graph

85 commits

Author SHA1 Message Date
Willem Ferguson
9a8bab21c9 Improve profile display in planner
This patch allows the planner to save the last manually-entered
dive planner point of a dive plan. When the plan has been saved
and re-opened for edit, the time of the last-entered dive planner
point is used to ensure that dive planning continues from the same
point in the profile as was when the original dive plan was saved.
Mechanism:

1) In dive.h, create a new dc attribute dc->last_manual_time
   with data type of duration_t.
2) In diveplanner.c, ensure that the last manually-entered
   dive planner point is saved in dc->last_manual_time.
3) In save-xml.c, create a new XML attribute for the <divecomputer>
   element, named last-manual-time. For dive plans, the element would
   now look like:
   <divecomputer model='planned dive' last-manual-time='31:17 min'>
4) In parse-xml.c, insert code that recognises the last-manual-time
   XML attribute, reads the time value and assigns this time to
   dc->last_manual_time.
5) In diveplannermodel.cpp, method DiveplannerPointModel::loadfromdive,
   insert code that sets the appropriate boolean value to dp->entered
   by comparing newtime (i.e. time of dp) with dc->last_manual_time.
6) Diveplannermodel.cpp also accepts profile data from normal dives in
   the dive log, whether hand-entered or loaded from dive computer. It
   looks like the reduction of dive points for dives with >100 points
   continues to work ok.
The result is that when a dive plan is saved with manually entered
points up to e.g. 10 minutes into the dive, it can be re-opened for edit
in the dive planner and the planner re-creates the plan with manually
entered points up to 10 minutes. The rest of the points are "soft"
points, shaped by the deco calculations of the planner.

Improvements: Improve code for profile display in dive planner

This responds to #1052.
Change load-git.c and save-git.c so that the last-manual-time is
also saved in the git-format dive log.

Several stylistic changes in text for consistent C source code.

Improvement of dive planner profile display:

Do some simplification of my alterations to diveplannermodel.cpp

Two small style changes in planner.c and diveplannermodel.cpp
as requested ny @neolit123

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-19 12:38:11 +02:00
Berthold Stoeger
e85ecdd925 Introduce helper function empty_string()
There are ca. 50 constructs of the kind
  same_string(s, "")
to test for empty or null strings. Replace them by the new helper
function empty_string().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-11 06:07:13 +01:00
Berthold Stoeger
86ef9fce75 Change return code of string comparison functions to bool
These functions were returning 0 or 1 anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-11 06:07:13 +01:00
Jan Mulder
5faf3f9410 Unused code: has_hr_data()
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10 16:45:42 +01:00
Jan Mulder
b7a6b7c6be Unused code: report_message()
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10 16:45:42 +01:00
Jan Mulder
dc54b4aaeb Unused code: remove weightsystems_equal()
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10 16:45:42 +01:00
Jan Mulder
b2c7a4cf1d Unused code: weekday()
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10 16:45:42 +01:00
Jan Mulder
3cd3653972 Unused code: remove taglist_equal()
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10 16:45:42 +01:00
Jan Mulder
768f0db991 Unused code: remove shift_times()
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10 16:45:42 +01:00
Berthold Stoeger
afeb2e3652 Make a few functions of static linkage
Make functions in core/file.c, core/parse.c and core/import-csv.c
that were not used outside their translation unit of static linkage.

parse_date is moved from core/file.c to core/import-csv.c, since it
is used only there.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-08 09:52:55 +02:00
Berthold Stoeger
b0fc718f65 Trivial: remove redundant declarations of downloadTable
downloadTable was declared twice in "dive.h". Remove one occurence.

Moreover, "uemis-downloader.c" also declared downloadTable. This can
likewise be removed, because "uemis-downloader.c" indirectly includes
"dive.h".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-06 09:21:33 +01:00
Berthold Stoeger
956cb53cd5 Turn autogroup from short into bool
All users of autogroup are clearly expecting a boolean value, so
let the type reflect this.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-04 08:21:43 -08:00
Jan Mulder
eabba1f071 cleanup: correct signature and declare extern
clear_vpmb_state() was declared with incorrect signature, and all
functios in this change are extern, so declare them as such.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-28 17:30:25 +01:00
Stefan Fuchs
82170579ad Enable removal of pictures from different dives at the same moment
Suggested-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-12-13 05:48:20 -08:00
Berthold Stoeger
ea0cbba804 Remove second parameter (bool force) in set_filename()
The last force=false case was removed in commit 96d1cc570e.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-11 00:17:39 +01:00
Stefan Fuchs
8a92484b0c Add debug function dump_cylinders
This function can be used to dump print all cylinder data.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-27 22:40:16 +01:00
Robert C. Helling
8e21a65653 Localize global planner state
For UI responsiveness, we need to be able to run the planner in the background. This needs the
planner state to be localized (and we need to pass a pointer around).

In order to not let too many lines overrun (and to save typing in the future)
I have renamed instances of struct deco_state to ds. Yes this should have gone
to a separate commit but I accidentally commit --amend'ed it.

Computing of planner variations is temporarily disabled.

Unlock the planner when returning early

So we don't deadlock in add dive and recreational mode (which
use the planner without actually planning).

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-11-25 20:13:01 +01:00
Berthold Stoeger
cc5a56b275 Cleanup: remove unused extern declaration
Removes the extern declaration of edit_dive, which wasn't defined
anywhere.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-25 07:38:20 -08:00
Berthold Stoeger
dd8e4fae2a Make handling of booleans consistent on the C++-side of preferences
In general, the C++-side of the preferences code consistently uses
the bool data type for boolean settings. There are five exceptions,
which use short instead:
  showPo2
  showPn2
  showPhe
  saveUserIdLocal
  displayInvalidDives
This patch attempts to make the code more consistent by turning
these into bools as well.

Tests showed that writing as short and reading as bool is handled
gracefully by the Qt variant code. Therefore, an upgrade should not
cause user-visible changes to their settings.

As a bonus, two extern declarations of the set_save_userid_local()
function, which is not defined anywhere, were removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-20 20:56:13 +01:00
Berthold Stoeger
1f651a7b83 Prevent annoying signed/unsigned comparison warning
Commit d6c013f303 introduced a cast to avoid a signed/unsigned
comparison warning for all translation units that included
core/dive.h.

Commit 1f8506ce64 then changed the definition of duration_t from
unsigned to signed, inverting the effect of d6c013f303.

Thus, revert d6c013f303 to allow compilation with -Wall without
flooding.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-18 21:50:43 +01:00
Linus Torvalds
2e82a5d2ed Properly declare 'has_gaschange_event()' function
It's already used in core/gaspressures.c where it was declared
privately, and we'll have a new user in the profile code, so just
declare it in a proper header file like it should have been.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-11-17 15:25:26 +01:00
Stefan Fuchs
1f8506ce64 Display values in info box only if value is interesting
Type duration_t changed from uint to int.

Default value of '-1' introduced for some of the values in struct sample:
NDL used -1 as default.
Bearing uses -1 as default (no bearing set).

Display pXX, EAD, END, density, MOD only if values are larger than 0.

In profile don't display data from two first and two last plot_data
entries in info box.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-13 20:50:10 -08:00
Jan Mulder
9771255919 CNS can be higher than 255%
I'm sure this bug has heen here forever, but the CNS clock is
not very relevant for most divers, and even some technical divers
do not care about this value.

However, doing long decompression dives, the value can easily
grow over 100%, and a lot further. For example, the OSTC computers
use 2 bytes to store the CNS value in the profile data, and I
have multiple dives in my logbook going way over 255%.

This all said. Just store the CNS value in an unsigned 16 bit.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-11-09 14:43:57 +01:00
Rick Walsh
fe474ac266 VPMB profile: use deco_time rather bottom_time from planner
This makes the calculations in profile.c a little simpler, especially now we
adopt consistent final ascent rate to determine deco_time since d15779a27

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-11-08 15:22:32 +01:00
Rick Walsh
a06848c237 VPM-B: move bottom_time into deco_state
Removing ext variable from profile.c should facilitate future performance
gains

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-11-08 15:22:32 +01:00
Lubomir I. Ivanov
0c74f7a2c8 win32: optimize the console and logging logic
Currently one has to explicitly use --win32console and/or
--win32log to enable a dedicated console (a console window
that opens next to the Subsurface window) or to enable file
logging on Win32.

This patch makes the following changes:
- removes the --win32* command line arguments
- removes the dedicated console window support
- if the app starts from a shortcut and not from a console, always
redirect stderr and stdout to _err & _out log files
- if the app starts from a console redirect stderr and stdout to that
console

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-11-03 07:49:11 -07:00
Dirk Hohndel
1c42750cdf Add new helfer for strcasestr
That's not a standard functions, so let's just build it. This is not
the most efficient way to write it, but it will do.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-30 12:27:29 -07:00
Dirk Hohndel
eccd4b993a Set error callback helper
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-26 14:37:39 +02:00
Lubomir I. Ivanov
e4a9787c5e dive.h: add handling of NULL in get_dive_dc()
This line:
    dc = &dive->dc
can SIGSEGV for a NULL 'dive' pointer.
return NULL if 'dive' is NULL.

Also handle NULL 'dc' in get_gasmix() and set 'ev' to NULL.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-10-19 22:03:51 -04:00
Robert C. Helling
a422957cd6 Use displayed_dc instead of current_dc
current_dc is a macro that determines the dive computer
based on the current dive number. When the planner is started
from an emtpy dive list, the dive number ends up being -1 and
that doesn't produce a valid dive computer. Use the divecomputer
of the displayed_dive instead. This is done via a macro that
can also be used in two other places. Without this patch, the
planner crashed when called on an empty dive list.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-10-19 14:57:02 -04:00
Stefan Fuchs
4158a4c7de init_deco correctly identify previous dives and report overlapping dives
When changing the date/time of a dive in the planner the dive may end
up in a totaly new position in respect to date/time of other dives in
dive list table. It can be moved to the past or the future before or after
other existing dives. It also could overlap with an existing dive.

This change enables identification of a new "virtual" dive list position
and based on this starts looking for previous dives.
Then it (as before the change) does init the deco calculation with any
applicable previous dive and surface interval.
If some of these applicable dives overlap it returns a neg. surface time
which is then used in the planner notes to prohibit display of results.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-18 23:19:13 +02:00
Stefan Fuchs
df6933326d In dive.c make cylinder_renumber an external function...
instead of dc_cylinder_renumber() because it is the one which is really
useful elsewhere.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-16 17:14:17 +02:00
Stefan Fuchs
c29456f0bb Used gas in dive planner points: Support for multiple cyl with same gas
In the planner if one adds two or more cylinders with the same gasmix
(e.g. back gas and bottom stage 18/45) the drop down and data in the
used gas column of the planner points table will be filled with a more
verbose string mentioning also the cyl number and the cyl type
description.
Makes it easier in such a case to select the right cylinder.

Introduces also a helper function which tells you if there is another
cylinder with the same gasmix as the provided cylinder.
This also has an option if it should consider unused cylinders or not.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-16 17:14:17 +02:00
Dirk Hohndel
21d78121ad Don't add separate country field, use taxonomy
The more I looked at the code that added the country to the dive site,
the more it seemed redundant given what we have with the taxonomy.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-04 08:05:09 -07:00
Tomaz Canabrava
e1bd006cd6 [Divesite] request dive country
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-02 09:52:50 -07:00
Robert C. Helling
1f50485732 More VPMB state in special structure
... and reset deco information in profile ceiling computation.

The planner test then needs to know about the struct holding the deco
state.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-10-01 23:58:55 +03:00
Robert C. Helling
5b080bedde Remove option to apply GFlow at maxdepth
This option should have never been there. This is not how
gradient factors are supposed to work. It would only trick
users to use the wrong value..

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-09-20 08:54:41 -07:00
Robert C. Helling
2832141d2c Compute variations of plans
Print out partial derivatives of stop times with respect to
variation of depth and duratin of last manual segment.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-08-29 06:49:44 -07:00
Robert C. Helling
e6545a7b0f Store a table of deco stops in planner
... in addition to struct diveplan which combines all kinds
of information

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-08-29 06:49:44 -07:00
Robert C. Helling
82aac4efff Make plan take dive and decotimestep as arguments
...rather than use a global variable and a macro.

This should be a no-op in preparation to allow planning
several versions of a dive.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-08-29 06:49:44 -07:00
Dirk Hohndel
d6c013f303 Hide signed/unsigned comparison warning
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-08-26 09:38:52 -07:00
Linus Torvalds
df1bd0015a Calculate momentary SAC rates with the right gases
The momentary SAC rate got broken by the multiple ressure handling too,
and always used just the first cylinder.

This uses the new "get_gasmix()" helper to see what you're breathing,
and will do the SAC rate over all the cylinders that contain that gas.
So it should now DTRT even for sidemount diving (assuming you had the
same gas in the sidemount cylinders).

NOTE! We could just do the SAC rate over *all* the gases you have
pressures for, and maybe that's the right thing to do.  The ones you are
not breating from shouldn't have their pressure change.  But maybe some
people add their drysuit argon gas to the gas list?

So this may need more work, but it's a step in the right direction.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-28 21:50:23 -07:00
Linus Torvalds
1e337518b8 Add "get_gasmix()" helper function to iterate over gas changes
We have a few places that used to get the gasmix by looking at the
sensor index in the plot data, which really doesn't work any more.

To make it easier for those users to convert to the new world order,
this adds a "get_gasmix()" function.  The gasmix function takes as its
argument the dive, the dive computer, and the time.

In addition, for good performance (to avoid looping over the event list
over and over and over again) it maintains a pointer to the next gas
switch event, and the previous gas.  Those need to be initialized to
NULL by the caller, so the standard use-case pattern basically looks
like this:

	struct gasmix *gasmix = NULL;
	struct event *ev = NULL;

	loop over samples or plot events in increasing time order: {
		...
		gasmix = get_gasmix(dive, dc, time, &ev, gasmix);
		...
	}

and then you can see what the currently breathing gas is at that time.

If for some reason you need to walk backwards in time, you can just pass
in a NULL gasmix again, which will reset the event iterator (at the cost
of now having to walk all the events again).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-28 21:50:15 -07:00
Linus Torvalds
c5167f0039 Make sample pressure helper functions available to everybody
We had a "add_sample_pressure()" helper functions that was local to just
the libdivecomputer downloading code, but it really is applicable to
pretty much any code that adds cylinder pressure data to a sample.

Also add another helper: "legacy_format_o2pressures()" which checks the
sample data to see if we can use the legacy format, and returns the o2
pressure sensor to use for that legacy format.

Because both the XML and the git save format will need a way to save the
compatible old-style information, when possible, but save an extended
format for when we have data from multiple concurrent sensors.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-25 22:04:56 -07:00
Linus Torvalds
adb4b66a05 Try to sanely download multiple concurrent cylinder pressures
This tries to sanely handle the case of a dive computer reporting
multiple cylinder pressures concurrently.

NOTE! There are various "interesting" situations that this whole issue
brings up:

 - some dive computers may report more cylinder pressures than we have
   slots for.

   Currently we will drop such pressures on the floor if they come for
   the same sample, but if they end up being spread across multiple
   samples we will end up re-using the slots with different sensor
   indexes.

   That kind of slot re-use may or may not end up confusing other
   subsurface logic - for example, make things believe there was a
   cylidner change event.

 - some dive computers might send only one sample at a time, but switch
   *which* sample they send on a gas switch event.  If they also report
   the correct sensor number, we'll now start reporting that pressure in
   the second slot.

   This should all be fine, and is the RightThing(tm) to do, but is
   different from what we used to do when we only ever used a single
   slot.

 - When people actually use multiple sensors, our old save format will
   start to need fixing.  Right now our save format comes from the CCR
   model where the second sensor was always the Oxygen sensor.

   We save that pressure fine (except we save it as "o2pressure" - just
   an odd historical naming artifact), but we do *not* save the actual
   sensor index, because in our traditional format that was always
   implicit in the data ("it's the oxygen cylinder").

so while this code hopefully makes our libdivecomputer download do the
right thing, there *will* be further fallout from having multiple
cylinder pressure sensors.  We're not done yet.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-25 06:11:10 -07:00
Linus Torvalds
1e38d9239a Start cleaning up sensor indexing for multiple sensors
This is a very timid start at making us actually use multiple sensors
without the magical special case for just CCR oxygen tracking.

It mainly does:

 - turn the "sample->sensor" index into an array of two indexes, to
   match the pressures themselves.

 - get rid of dive->{oxygen_cylinder_index,diluent_cylinder_index},
   since a CCR dive should now simply set the sample->sensor[] indices
   correctly instead.

 - in a couple of places, start actually looping over the sensors rather
   than special-case the O2 case (although often the small "loops" are
   just unrolled, since it's just two cases.

but in many cases we still end up only covering the zero sensor case,
because the CCR O2 sensor code coverage was fairly limited.

It's entirely possible (even likely) that this migth break some existing
case: it tries to be a fairly direct ("stupid") translation of the old
code, but unlike the preparatory patch this does actually does change
some semantics.

For example, right now the git loader code assumes that if the git save
data contains a o2pressure entry, it just hardcodes the O2 sensor index
to 1.

In fact, one issue is going to simply be that our file formats do not
have that multiple sensor format, but instead had very clearly encoded
things as being the CCR O2 pressure sensor.

But this is hopefully close to usable, and I will need feedback (and
maybe test cases) from people who have existing CCR dives with pressure
data.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 16:33:19 -07:00
Linus Torvalds
11a0c0cc70 Unify sample pressure and o2pressure as pressure[2] array
We currently carry two pressures around for all the samples and plot
info, but the second pressure is reserved for CCR dives as the O2
cylinder pressure.

That's kind of annoying when we *could* use it for regular sidemount
dives as the secondary pressure.

So start prepping for that instead: don't make it "pressure" and
"o2pressure", make it just be an array of two pressure values.

NOTE! This is purely mindless prepwork.  It literally just does a
search-and-replace, keeping the exact same semantics, so "pressure[1]"
is still just O2 pressure.

But at some future date, we can now start using it for a second sensor
value for sidemount instead.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-20 17:32:54 -07:00
Lubomir I. Ivanov
27deb317b0 tankinfomodel.cpp: clamp row index to [0 - MAX_TANK_INFO]
MAX_TANK_INFO is a new macro in dive.h to define the
maximum number of tank_info_t objects.

TankInfoModel's data() and setData() now check for valid
row indexes before accessing the tank_info[] array directly.

Without this patch TankInfoMode::data() can cause a SIGSEGV.

Reported-by: Pedro Neves <nevesdiver@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-15 14:48:49 -07:00
Tomaz Canabrava
dec47e11cd Separate the download thread from the widget logic
This is important to not duplicate code for the Qml
view. Now the DownloadFromDiveComputer widget is mostly
free from important code (that has been upgraded to the
core folder), and I can start coding the QML interface.

There are still a few functions on the desktop widget
that will die so I can call them via the QML code later.

I also touched the location of a few globals (please, let's
stop using those) - because it was declared on the
desktop code and being used in the core.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-27 07:53:14 -07:00
Robert C. Helling
bb6ceba4ac Compute and display gas density
This appears to be critical for work of breathing so it might be
worthwhile to compute. So far only in infobox.

For background, see

https://www.youtube.com/watch?v=QBajM3xmOtc

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-05-26 15:52:04 -07:00