Commit graph

197 commits

Author SHA1 Message Date
Dirk Hohndel
5bc5cae6dc Planner: only copy cylinders that were used in the template dive
This was only semi-implemented the first time around. Now we really only
copy the ones that are indeed used.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-03 23:09:12 -07:00
Dirk Hohndel
d211bc55be When calculating the maximum of unsigned values, use unsigned variable
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-03 17:06:59 -07:00
Willem Ferguson
eaf6d56487 CCR code: Change to sample structure
1) All the variables in the sample structures are strongly typed
2) Two additional types were declared in units.h:
     o2pressure_t
     bearing_t
3) The following variables were added:
     diluentpressure
     o2setpoint
     o2sensor[3]
4) Changes to a number of files were made to chanf
     sample->po2 to sample->po2.mbar
     bearing to bearring.degrees

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-03 17:05:25 -07:00
Tomaz Canabrava
f53b5c4d3f Fix linked list corruption, move code to C.
The picture list is a single linked list where the pictures have a node to
their next element. When adding the same picture to two dives, things got
way way wrong and crashes were appearing.

This will replicate the information (filename, latitude and longitude) for
each dive that has the picture, BUT it still tries to save as much as
possible on the actual pixmap.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-03 16:39:06 -07:00
Dirk Hohndel
b249370ffe Not all C compilers like uint
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-03 00:10:39 -07:00
Tomaz Canabrava
d95d1735b5 Break picture handling code from C++ to C.
This commit breaks the loading of images that were done in the divelist
into smaller bits. A bit of code refactor was done in order to correct the
placement of a few methods.

ShiftTimesDialog::EpochFromExiv got moved to Exif::epoch dive_add_picture
is now used instead of add_event picture_load_exif_data got implemented
using the old listview code.  dive_set_geodata_from_picture got
implemented using the old listview code.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-02 23:59:29 -07:00
Tomaz Canabrava
dfac5e93c4 Add a FOR_EACH_PICTURE macro and the code for picture_count.
Add the FOR_EACH_PICTURE macro and the code for picture count.
This uses C99 - but I will keep it like this and wait for dirk
to scream at me.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-02 23:57:51 -07:00
Tomaz Canabrava
cfa51c6526 Add stubs for the main methods that will operate on pictures.
add, remove, get count, and picture_load_exif_data.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-02 23:57:16 -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
Dirk Hohndel
c539c8f861 Remove the .used member of the cylinder structure
Instead calculate this information on the fly, taking into account all
dive computers on the dive in questions.

There is one wrinkle to this - previously we abused the '.used' member to
make sure that a manually added cylinder didn't disappear the moment it
was added (think of the workflow: you add a cylinder, then you add a gas
change to that cylinder -> right after you add it it is unused and would
not be shown).

I am thinking that we might have to add the "manually_added" property to
the properties that we store in XML / git.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-01 12:43:40 -07:00
Dirk Hohndel
1a04013453 Encapsulate the horrid gas encoding in gas change events
We should never pass permille values around as integers. And we shouldn't
have to decode the stupid value in more than one place.

This doesn't tackle all the places where we access O2 and He "too early"
and should instead keep passing around a gaxmix. But it's a first step.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-01 12:07:29 -07:00
Dirk Hohndel
56395b3894 Don't assume that pressures are always positive
When planning a dive, the dive could use more gas than is in the cylinder.
So getting a negative end pressure is a useful indication to the user that
there plan might not be a good one.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-29 13:18:13 -07:00
Dirk Hohndel
cfe865dd0c Merge branch 'atdotde'
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>

Conflicts:
	qt-ui/diveplanner.cpp
	qt-ui/models.cpp
2014-05-26 08:23:22 -07:00
Robert C. Helling
04b6b6aaf9 Use get_o2() and get_he() instead of accessing permilles directly
This gets rid of problems with air.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-26 08:12:32 -07:00
Tomaz Canabrava
ef4705070f Create a 'remove_event' function that removes an event.
The logic of removing the event was in the UI, and this makes
the code harder to test because we need to take into account
also the events that the interface is receiving, instead of
only relying on the algorithm to test.

so, now it lives in dive.h/.c and a unittest is easyer to make.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-22 07:28:27 +09:00
Linus Torvalds
7821b87983 Use the last 'diveid' when merging dives for one dive computer
When we merge two dives into the same dive because a divecomputer had
incorrectly considered it two separate dives (due to surface time within
the dive) we should pick the dive ID from the later dive to be the
diveid of the resulting merged dive.  Otherwise we might re-download the
(now merged) partial dive.

This is a rather unusual special case, but it actually hit me with the
Uemis on my last dive in Palau: Chandelier Cave has multiple surface
points where you can spend time admiring the cave above water, and the
Uemis (but not my Suunto's) decided that the dive was actually four
short dives back-to-back.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-20 14:16:00 +09: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
a117428ff4 Add ability to make a dive computer the first dive computer of a dive
If a dive has multiple dive computers we enable a special context menu
when the user right-clicks on the dive computer name AND is not already
showing the first dive computer. In that case we offer to make the
currently shown dive computer the first one.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-19 20:12:59 +09:00
Dirk Hohndel
b36c8f07c7 Assign the uniq dive ID the moment a dive is allocated
Previously we only did this when we did fixup_dive(), but that way we
can't reference dives "early" in their life cycle (e.g., right after they
got downloaded).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-19 20:12:59 +09:00
Dirk Hohndel
818542eeca Don't merge divecomputers if we know they are different
When merging dives, if we know for sure that the dive computers are
different, don't merge them into one (by interleaving the data), but
instead keep both as separate dive computers in the same dive.

This fixes a bug when due to a faulty download the same dive from two dive
computers looks quite different. They don't get merged automatically
(which is fine - they are quite different), but when manually merging
them, we of course want one dive with two dive computers, not one dive
with one merged dive computer.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-14 13:08:06 +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
Tomaz Canabrava
9e8c0c9366 Prefix a method with 'dive_' because it should work only with dives
I'll probably add prefixes to functions to make it easier to find method
via autocomplete from the grep or interface helpers, do you wanna know all
the functions that works with a dive?  ask for the completion for dive_,
do you wanna know all the functions that works with a divelist? ask for
the completions on divelist_ or run grep -rIs divelist_ on the header
files.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-11 01:57:41 -07:00
Anton Lundin
96f707abfe Remove unnecessary include from dive.c
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-08 14:58:01 -07:00
Robert C. Helling
c3a3c1a1e7 Planner: Implement ascend rate according to GUE standard procedures
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-08 12:28:09 -07:00
Dirk Hohndel
6545855b65 Fix standard cylinder names
We need to pass the size as an integer.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-05 14:52:13 -07:00
Dirk Hohndel
0be8512ab0 Add small helper to determine if dive computer has HR data
Currently unused, but requested for a future feature.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-25 07:19:18 -07:00
Tomaz Canabrava
9598462830 Removed the globals 'userid' and 'save_userid_local' variables
This is a preferences setting, it should belong to the preferences
structure.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:37:31 -07:00
Gehad
8ca4437624 Add current time and adjusted time to gui when adjusting dive's timestamp
This patch adds the current dive time and the adjusted time to the time
shift window. I added a function to dive.c to get the timestamp of the
first selected dive.

This will view the time of the first selected dive only even when multi
dives are selected but it does change the times for multiple dives
properly.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-21 21:26:09 -07:00
Linus Torvalds
eb47b2a8d8 Get rid of crazy empty tag_list element at the start
So this is totally unrelated to the git repository format, except for
the fact that I noticed it while writing the git saving code.

The subsurface divetag list handling is being stupid, and has a
initial dummy entry at the head of the list for no good reason.

I say "no good reason", because there *is* a reason for it: it allows
code to avoid the special case of empty list and adding entries to
before the first entry etc etc.  But that reason is a really *bad*
reason, because it's valid only because people don't understand basic
list manipulation and pointers to pointers.

So get rid of the dummy element, and do things right instead - by
passing a *pointer* to the list, instead of the list. And then when
traversing the list and looking for a place to insert things, don't go
to the next entry - just update the "pointer to pointer" to point to
the address of the next entry. Each entry in a C linked list is no
different than the list itself, so you can use the pointer to the
pointer to the next entry as a pointer to the list.

This is a pet peeve of mine. The real beauty of pointers can never be
understood unless you understand the indirection they allow. People
who grew up with Pascal and were corrupted by that mindset are
mentally stunted. Niklaus Wirth has a lot to answer for!

But never fear. You too can overcome that mental limitation, it just
needs some brain exercise. Reading this patch may help. In particular,
contemplate the new "taglist_add_divetag()".

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-10 11:36:17 -07:00
Linus Torvalds
689fe36030 Initial implementation of git save format
This saves the dive data into a git object repository instead of a
single XML file.

We create a git object tree with each dive as a separate file,
hierarchically by trip and date.

NOTE 1: This largely duplicates the XML saving code, because trying to
share it seemed just too painful: the logic is very similar, but the
details of the actual strings end up differing sufficiently that there
are tons of trivial differences.

The git save format is line-based with minimal quoting, while XML quotes
everything with either "<..\>" or using single quotes around attributes.

NOTE 2: You currently need a dummy "file" to save to, which points to
the real save location: the git repository and branch to be used.  We
should make this a config thing, but for testing, do something like
this:

	echo git /home/torvalds/scuba:linus > git-test

to create that git information file, and when you use "Save To" and
specify "git-test" as the file to save to, subsurface will use the new
git save logic to save to the branch "linus" in the repository found at
"/home/torvalds/scuba".

NOTE 3: The git save format uses just the git object directory, it does
*not* check out the result in any git working tree or index.  So after
you do a save, you can do

     git log -p linus

to see what actually happened in that branch, but it will not affect any
actual checked-out state in the repository.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-06 14:52:03 -08:00
Dirk Hohndel
1b103c5c69 Another small tweak to whitespace tool
clang-format doesn't appear to reindent multi line #define statements
correctly - so this hopefully will clean those up.

The included whitespace corrections to the code should stay in place when
using the updated tool.

This includes cleaning up some multi-line comments that were messed up the
last time around as well as a few other minor changes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-05 13:02:23 -08:00
Dirk Hohndel
7c535452f9 Whitespace cleanup
Minor change to the perl postprocessing script and resulting changes to
the affected source files.

This deals with two issues:
- "foreach"-like structures were not always treated correctly
- some longer calculations that ended on "+ constant" were reformatted in
  a rather unatractive manner

In one source file (divelist.c) I ended up adding braces to the sources...
trying to cascade the indentation further down without having the block
there seemed a lot more trouble than it's worth.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-03 13:29:22 -08:00
Nicu Badescu
b3c0f8938d Fix negative value for depths in Information Box
The get_depth_units function was expecting an unsigned int as a first parameter.
When it received a negative integer, the function made a cast to an unsigned int,
resulting in a very big number.

Signed-off-by: Nicu Badescu <badescunicu@yahoo.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-28 16:32:01 -08: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
Linus Torvalds
8de62c64dc Fix missed "+0.5" rounding - use rint() instead
In commit 23baf20f56 (Use "rint()" instead of rounding manually with
"+ 0.5") I had missed this one remaining place where we rounded things
by adding "+0.5" and then truncated.

Fix that up.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-16 13:19:16 -08:00
Linus Torvalds
23baf20f56 Use "rint()" instead of rounding manually with "+ 0.5"
rint() is "round to nearest integer", and does a better job than +0.5
(followed by the implicit truncation inherent in integer casting).  We
already used 'rint()' for values that could be negative (where +0.5 is
actively wrong), let's just make it consistent.

Of course, as is usual for the messy C math functions, it depends on the
current rounding mode.  But the default round-to-nearest is what we want
and use, and the functions that explicitly always round to nearest
aren't standard enough to worry about.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-12 17:41:49 -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
Anton Lundin
a8bad45b62 Remove unused variable
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-15 15:49:45 +07:00
Dirk Hohndel
23973e8abd Don't show tanks that aren't used during a dive
Some dive computers will always download all tanks that they store, not
just the ones used in a dive. Most people only want to see the tanks that
they actually used during the dive (and for the others there's an option
to go back to the old behavior, just in case).

All this is only in memory / during runtime. If the dive computer provided
the extra data we will not throw it away.

Fixes #373

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-11 22:02:35 +07:00
Linus Torvalds
9fca37acec Properly handle user dive merge requests
When the user asks to merge dives in the divelist, we would always use
the "try tp find matching dive computers and merge at an offset" model.

That is incorrect if the intent is to actually merge two *identical*
dives (with different dive computers), as opposed to merging two short
dives into one longer one with a surface interval.

Normally this doesn't ever trigger (the "same dive" merging will have
been done automatically after downloading from the dive computer), but
if the dive computer times are off, and the user fixes them, and then
asks to merge dives, we should use the non-offset dive merging logic.

We already have that "likely_same_dive()" function that is used to
determine when downloaded dives get merged, so just use it for the user
merge case too.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-11 16:46:21 +07:00
Dirk Hohndel
65e9fecd80 Add a unique id to every dive
This id is just held in memory. It's not supposed to be used for anything
but having a unique handle that represents a dive. Whenever you need to
remember a dive across an operation that might change the dive_table, this
is what you should hold on to, not a dive number, a dive pointer, or
anything like that.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-07 12:02:42 +08:00
Dirk Hohndel
0421a161b4 Silence a few warnings
None of these are actual bugs. But none of the fixes are harmful, either.
And much as I hate adding the 'default' clauses, I'd rather not have the
build output cluttered by invalid warnings.

The exception is the fix in divelistview.cpp - while I don't think it is
possible for this function to be called with no dive selected,
initializing pd to NULL is cheap insurance in case that does happen for
some weird reason.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-20 09:53:06 -08:00
Dirk Hohndel
ff5fa70a88 Editing air or water temperature should modify dive computer, not dive
The dive fields are summary fields, the actual data needs to be in the
divecomputer specific fields.

Fixes #307
2013-11-29 12:05:21 -08:00
Anton Lundin
ef06afde14 Remove duplicate of add_gas_switch_event in dive.c
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-20 11:29:48 -08:00
Anton Lundin
f6b29d093f Use get_cylinder_index in per_cylinder_mean_depth
Use get_cylinder_index that handles SAMPLE_EVENT_GASCHANGE and
SAMPLE_EVENT_GASCHANGE2.

This also removes the need for a special case where get_gasidx returns
-1, because get_cylinder_index always returns the "closest" gas that it
finds.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-20 11:21:48 -08:00
Dirk Hohndel
51345e4ad8 Fix potential crash in the per tank sac calculation
In an inconsistant XML file (like our own dives/test20.xml) it is possible
that a gas change event refers to a non-existing gas. In that case
get_gasidx returns -1 - which we shouldn't use as index into the arrays.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-20 07:44:45 -08:00
Dirk Hohndel
0ca12c3601 Collect per tank SAC rate
This is a bit painful, but we basically walk the samples and pick the
valid tank from the events. And then we do a simple discrete integration
to figure out the mean depth per tank and duration per tank. And then we
assemble all that into per tank statistics.

Strangely the value calculated here seems slightly higher than one would
expect from the overall SAC rate. This inconsistency should be
investigated a bit further, but my guess it it's based on the assumption
that the DC provided mean depth is possibly more accurate than what we can
calculate from the profile.

Fixes #284

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-19 23:07:04 -08:00
Maximilian Güntner
65e980d483 Only translate default tags
We translate only tags we know since possible
translations of custom tags (provided by the user)
may be out of context and therefore wrong.

Signed-off-by: Maximilian Güntner <maximilian.guentner@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-19 10:42:58 -08:00
Robert Helling
4966336e1d Shift times of selected dives
This patch adds the possibility to shift the times of all selected dives
by a fixed amount to correct for time zone problems or mis-set dive
computer clocks.

Select the dives and right click in the dive list.

[Dirk Hohndel: added .ui file to FORMS and fixed some whitespace damage]

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-18 10:03:45 -08:00
Tomaz Canabrava
314cf4c628 Removed duplicated method.
This patch removes a duplicated method: get_divenr and
get_index_for_dive. The two are exactly the same  ( if my
c is not broken, but I may be broken since I'm working like
crazy for almost 30h nonstop. ), so please take a good look
before applying this one.

[Dirk Hohndel: Tomaz took the slightly broken of the two implementations,
               so I switched that out for the correct one]

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-16 20:27:54 -08:00