Commit graph

121 commits

Author SHA1 Message Date
Dirk Hohndel
ee7dd4307a In a CCR dive the diluent and oxygen cylinders are both used
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-17 00:09:19 +00:00
Anton Lundin
09e8adf54e Convert volume calculations into floating point
The basic problem was that for gases containing more than 2147483648 ml
of nitrogen the calculations overflowed. This changes the code into
using floating point math for that calculation which will be more
accurate to.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-07 13:12:22 -08:00
Dirk Hohndel
3fab68dcd3 Fix two more potential crashes for dives without samples
This should be all of them (famous last words).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-03 07:50:30 -08:00
Dirk Hohndel
4d9c30d424 Explicit first gas only on first sample
Instead of the 30 second heuristic we only assume that this is an explicit
first gas if the event coincides the first sample.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-28 16:27:10 -07:00
Dirk Hohndel
e32ba4d6d8 Improve tank handling for Cobalt
This isn't Cobalt specific, this is specific to dive computers that
indicate the first tank that's in use with a gaschange event that
coincides with the first sample.

We need to make sure that we suppress showing that gas change event
(regardless which cylinder it goes to) and instead set the correct
cylinder index from the very start of the dive.

This works with the test data I have and doesn't seem to break thing with
any of the files that I tried... but I'm worried that this is not the
right way to do things.

Fixes #742

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-28 14:04:19 -07:00
Linus Torvalds
3aaf8b1f5a Make gas use statistics be coherent and more complete
The gas use logic in the dive statistics page is confused.

The SAC case had a special case for "unknown", but only for
the first gas. Other gases had the normal empty case.

Also, the logic was really odd - if you had gases that weren't used (or
pressures not known) intermixed with gases you *did* have pressure for,
the statistics got really confused.

The list of gases showed all gases that we know about during the dive,
but then the gas use and SAC-rate lists wouldn't necessarily match,
because the loops that computed those stopped after the first gas that
didn't have any pressure change.

To make things worse, the first cylinder was special-cased again, so it
all lined up for the single-cylinder case.

This makes all the cylinders act the same way, leaving unknown gas use
(and thus SAC) just empty for that gas.

It also fixes the SAC calculation case where we don't have real samples,
and the profile is a fake profile - possibly with gas changes in between
the fake points. We now make the SAC calculations match what we show -
which is admittedly not at all necessarily what the dive was, but at
least we're consistent.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-08-06 09:14:34 -07:00
Anton Lundin
950638ec1c Replace cylinder_is_used with is_cylinder_used
is_cylinder_used uses get_cylinder_index as underlaying function that
does the right thing with with respect on how to find the closest
matching cylinder, and handles both types of gaschange events correctly.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-17 08:28:21 -07:00
Anton Lundin
810880ea1d Rename is_gas_used to is_gas_used
This function operates on cylinder ids, so its actually about cylinders
not gases.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-17 08:27:40 -07:00
Dirk Hohndel
3cdd4df8e8 Statistics: change our notion of "bogus SAC rate"
With a pSCR it is entirely possible to have a SAC rate below 2.8l/min.
Since we still don't want to include SAC rates of 0 let's change the
cutoff to 0.1l/min.

Fixes #624

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-17 08:16:15 -07:00
Anton Lundin
b2288e1e3d Calculate approx gas bill on dives
This uses a bit of naive gas computations to figure out how much of
different base gases you used up on the dives the statistics is done for.

It's quite useful to get a minimum line about how big your gas bill is
going to be after a dive trip.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-29 17:15:09 -07:00
Dirk Hohndel
28093ae957 Remove is_air() and convert its users to gasmix
Also make gasname() and get_gas_string() global functions (which allows us
to delete code elsewhere).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-01 20:57:11 -07:00
Anton Lundin
05d9cc409c Migrate code to for_each_dive and for_each_dc
[Dirk Hohndel: this overlapped with my commit 09e7c61fee ("Consistently
	       use for_each_dive (and use it correctly)") so I took the
	       pieces that I had missed]

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-20 11:51:40 +09:00
Dirk Hohndel
09e7c61fee Consistently use for_each_dive (and use it correctly)
The way the macro is written there is no need to test the dive against
NULL before dereferencing.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-20 06:37:19 +09:00
Tomaz Canabrava
c86d055db7 Do not check for null before free.
C specs says that we can safelly free a NULL pointer, so there's no reason
to check if it's null before freeing it.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-13 09:26:50 +09:00
Linus Torvalds
0c5ec1d6db Don't calculate SAC-rates for negative pressure changes
They happen - maybe the cylinder actually warmed up, or maybe the user
entered just a ending pressure without a starting pressure.  Regardless,
just ignore cylinder pressure changes that go up.

Also ignore cylinders with a zero ending pressure: that's really a
*missing* pressure rather than an actual zero pressure.  As Dirk says,
the scuba regulators don't even work without a healthy positive pressure
differential, so even when you breathe down a tank to "empty", it won't
be at zero pressure (this is true even with gauge pressure, where zero
means "atmospheric pressure").

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-26 17:24:12 -07:00
Dirk Hohndel
76e6420f6b Massive automated whitespace cleanup
I know everyone will hate it.
Go ahead. Complain. Call me names.
At least now things are consistent and reproducible.
If you want changes, have your complaint come with a patch to
scripts/whitespace.pl so that we can automate it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-27 20:09:57 -08:00
Anton Lundin
33391a77e9 Convert the C code to using stdbool and true/false
Earlier we converted the C++ code to using true/false, and this converts
the C code to using the same style.

We already depended on stdbool.h in subsurfacestartup.[ch], and we build
with -std=gnu99 so nobody could build subsurface without a c99 compiler.

[Dirk Hohndel: small change suggested by Thiago Macieira: don't include
               stdbool.h for C++]

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16 09:34:50 +07:00
Miika Turkia
f43a3052cb Ensure gaslist is NULL terminated
If buffer copying is restricted by the buffer size in strncpy or
snprintf, the copied string is not NULL terminated.  Add one to the end
just to make sure.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-11 16:46:31 +07:00
Anton Lundin
160fb321bc Close warning first might be garbage
First might be garbage if get_ranges would be called when
dive_table.nr == 0. This would rather signal that something else is
broken, but at least we shouldn't make it worse.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-11 22:17:50 +01:00
Anton Lundin
eae1624f24 Make local helpers static
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-08 09:41:54 +01:00
Miika Turkia
5a1a25a476 Fix a crash when no trip exists
When there are no trips at all, we have to skip the Yearly statistics
alltogether, including the header line (that should display all the
dives added together).

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-30 07:46:17 -08:00
Anton Lundin
d4da15f53f Rewrite is_gas_used to use get_cylinder_index
get_cylinder_index implements a algorithm to map gaschange events to gas
idx. This is a bit clumsy to use it to map if a gas idx have bin used,
but its consistent with other parts.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-29 08:22:56 -08:00
Anton Lundin
9b5c7c2bbe Only return gas volumes for gases used
We check in get_gaslist is_gas_used, so if were going to be consistent
about what we return from get_gaslist and in get_gas_used, only return
gas volumes that we actually consumed during the dive.

The problem now this fixes can be seen in dives/test10.xml

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-27 14:15:12 -08:00
Anton Lundin
a25d351b64 Bugfix crash in trip statistics for non trip dives
This fixes a crash when you have non-trip dives in your logbook.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-24 07:02:56 -08:00
Miika Turkia
ce525bd285 Adding trip based statistics
This adds trip based statistics to the Yearly Statistics
view.

Signed-off-by: Miika Turkia <miika.turkia@nixu.fi>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-23 22:07:18 -08:00
Dirk Hohndel
60a5d1d070 Fix a couple of warnings
Removing unused variables.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-21 15:50:56 -08:00
Anton Lundin
eb027f2a4b Do per cylinder statistics
This shows how much gas form each cylinder was used. I would like to add
SAC to that list too but it became a mess trying to calculate average
depth per cylinder.

Design based on idea in #284

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-19 15:46:19 -08:00
Maximilian Güntner
6fe8cb6521 Replaced the tag implementation
The new implementation supports custom tags
which are provided by the user as well as
default tags which are provided by subsurface.
Default tags can be translated and will be written
to XML in their non-localized form.

Signed-off-by: Maximilian Güntner <maximilian.guentner@gmail.com>
2013-11-02 02:55:03 +01:00
Miika Turkia
bdedf46e4c Get rid of compiler warning on format strings
This gets rid of compiler warnings "format not a string literal and no
format arguments [-Wformat-security]". E.g. when building distribution
packages these warnings are often treated as errors preventing the
build (with good reason).

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2013-10-20 15:25:27 +02:00
Dirk Hohndel
193d20c479 Next step towards working translations
This may seem like a really odd change - but with this change the Qt tools
can correctly parse the C files (and qt-gui.cpp) and get the context for
the translatable strings right.

It's not super-pretty (I'll admit that _("string literal") is much easier
on the eye than translate("gettextFromC", "string literal") ) but I think
this will be the price of success.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-09 22:51:59 -07:00
Anton Lundin
9cbd0febbc Make is_gas_used work with SAMPLE_EVENT_GASCHANGE
SAMPLE_EVENT_GASCHANGE only contains o2 part, and not the he part so
when looking at ex the gaslist for dives/test20.xml it got it realy
wrong.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-06 11:19:53 -07:00
Dirk Hohndel
4d3e74a236 Trying to switch to Qt translation
This compiles and looks about right, but it doesn't appear to work, yet.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-06 10:42:32 -07:00
Dirk Hohndel
4b12f28ca4 First steps towards removing glib dependencies
- remove the build flags and libraries from the Makefile / Configure.mk
- remove the glib types (gboolean, gchar, gint64, gint)
- comment out / hack around gettext
- replace the glib file helper functions
- replace g_ascii_strtod
- replace g_build_filename
- use environment variables instead of g_get_home_dir() & g_get_user_name()
- comment out GPS string parsing (uses glib utf8 macros)

This needs massive cleanup, but it's a snapshot of what I have right now, in
case people want to look at it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-06 10:41:44 -07:00
Anton Lundin
34a747dead Bugfix typo in get_gas_used
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-03 09:41:40 -07:00
Dirk Hohndel
138a00bd10 Improve readability of yearly statistics
Make the entries for years bold, keep the months non-bold.
It's still a sea of data, but this is an improvement.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-19 10:31:01 -07:00
Dirk Hohndel
ee3bf421e1 Show EANxx for Nitrox in info tab
Showing all gases (except air) as (o2/he) feels a bit odd, most people
would only use the two gas notation if they are actually diving trimix.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-12 12:07:47 -04:00
Dirk Hohndel
ff6e730e30 List only the gases used in the Info tab
The equipment tab will still show all defined gases, but the info for
the dive should only list the ones used.

Also change the name of the two gas related boxes to better reflect the
data that is shown.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-31 13:43:49 +09:00
Dirk Hohndel
1298aa87e5 Continue populating the DiveInfo tab
Pulled one more helper from statistics-gtk.c (but didn't modify the code
there to use it as that code is no longer being compiled).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-19 08:08:29 -07:00
Dirk Hohndel
f3f7bf51fa Merge branch 'Qt'
After the 3.1 release it is time to shift the focus on the Qt effort - and
the best way to do this is to merge the changes in the Qt branch into
master.

Linus was extremely nice and did a merge for me. I decided to do my own
merge instead (which by accident actually based on a different version of
the Qt branch) and then used his merge to double check what I was doing.

I resolved a few things differently but overall what we did was very much
the same (and I say this with pride since Linus is a professional git
merger)

Here's his merge commit message:

    This is a rough and tumble merge of the Qt branch into 'master',
    trying to sort out the conflicts as best as I could.

    There were two major kinds of conflicts:

     - the Makefile changes, in particular the split of the single
       Makefile into Rules.mk and Configure.mk, along with the obvious Qt
       build changes themselves.

       Those changes conflicted with some of the updates done in mainline
       wrt "release" targets and some helper macros ($(NAME) etc).

       Resolved by largely taking the Qt branch versions, and then editing
       in the most obvious parts of the Makefile updates from mainline.

       NOTE! The script/get_version shell script was made to just fail
       silently on not finding a git repository, which avoided having to
       take some particularly ugly Makefile changes.

     - Various random updates in mainline to support things like dive tags.

       The conflicts were mainly to the gtk GUI parts, which obviously
       looked different afterwards.  I fixed things up to look like the
       newer code, but since the gtk files themselves are actually dead in
       the Qt branch, this is largely irrelevant.

       NOTE! This does *NOT* introduce the equivalent Qt functionality.
       The fields are there in the code now, but there's no Qt UI for the
       whole dive tag stuff etc.

    This seems to compile for me (although I have to force
    "QMAKE=qmake-qt4" on f19), and results in a Linux binary that seems to
    work, but it is otherwise largely untested.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-17 22:01:41 -07:00
Dirk Hohndel
d00c16d4ee Add tag for deco dives
Fixes #85

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-14 21:52:55 -04:00
Dirk Hohndel
b75a89aa86 Start populating the maintab Dive Info widget
Establish some useful helpers and use them when updating the values.

One of the helpers (from statistics.c) puzzlingly doesn't link - so that's
ifdefed out.

Also had to re-arrange the settings reading code (it came too late) and to
extract the expanding code of the top dive from the settings reading code
(as it had no business being there to begin with).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-06 20:38:38 -07:00
Dirk Hohndel
d25de98b7c Separate Gtk related code from core logic: statistics
Fairly straight forward, so far just one tiny bit of code restructuring,
everything else separated cleanly.

Added statistics-gtk.c and statistics.h

This should make no difference to functionality.

Cherry-picked from Qt branch; fixed merge issues mostly caused by
dive_tags and Makefile changes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-15 21:52:41 -07:00
Dirk Hohndel
944d286132 Separate Gtk related code from core logic: statistics
Fairly straight forward, so far just one tiny bit of code restructuring,
everything else separated cleanly.

Added statistics-gtk.c and statistics.h

This should make no difference to functionality.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-14 20:25:34 -07:00
Dirk Hohndel
a9055049f1 Add four more tags
Student (training), Instructor (teaching), Photo and Video

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-10 08:49:11 -07:00
Dirk Hohndel
3611b0ae2d Automatically show Freshwater tag (but don't set it)
If the salinity is 10000 we show (but do not set) the Freshwater tag.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-09 19:46:05 -07:00
Henrik Brautaset Aronsen
51c4a5335b Add tags for night and freshwater
Also trim the redundant "Dive" text from "Lake Dive", "Pool Dive", ....

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-09 16:13:28 -07:00
Pierre-Yves Chibon
7cacbdf762 Add lake and river to the list of supported tags
[Dirk Hohndel: minor cleanups]

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-09 13:56:33 -07:00
Dirk Hohndel
9e4f9fad19 Store the tag names instead of an opaque number
And as we need the names for that, simplify the way we show the tags in the
Dive Info tab (and mark them for translation while we are at it).

In the process I renamed the constants to DTAG_ from DTYPE_ (and made
their nature as being just bits more obvious).

Also mark the box on the Info tab "Dive Tags", not "Dive Type".

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-09 13:06:30 -07:00
Ďoďo
ed3f67bc33 Add dive tags and support invalid dives
This started out as a way to keep dives in the dive list but being able to
mark them as 'invalid' so they wouldn't be visible (with an option to
disable that feature).

Now it supports an (at this point, fixed) set of tags that can be assigned
to a dive with 'invalid' being just one of them (but one that is special
as it gets some additional support for hiding such dive and marking dives
as (in)valid from the divelist).

[Dirk Hohndel: merged with the latest code and minor changes for coding
	       style and consistency. Ensure divelist is marked as
	       modified when changing 'invalid' tag]

Signed-Off-By: Jozef Ivanecký (dodo.sk@gmail.com)
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-09 10:31:36 -07:00
Dirk Hohndel
a70a889872 Fix some of the gcc-4.8 warnings
Most of the warnings are IMHO false positives:
e.g.: an enum variable is initialized in a switch statement that has a case for
      each possible enum value - yet gcc 4.8 warns that it could be used
      uninitialized;
or:   two variables are initialized together in the code - second one of them
      is previously initialized to -1 at declaration time, both are initialized
      in an if (second one == -1) clause - so they are guaranteed to both be
      initialized...
I did not "fix" those as the code is actually correct.

But there are three spots where it catches things that could indeed go wrong
(with odd input data in one of them).

This commit also adds a check to only call g_type_init() for older versions of
glib as in newer ones it is deprecated.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-07 20:31:49 -07:00