The dive planner always showed the depth in our internal units, ie
millimeter, in the sidebar that showed the plan points.
That made little sense in metric mode, and none at all in imperial. The
_graph_ showed things in meter and feet.
So make the DivePlannerPointsModel always convert things to and from the
user units.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
I am not removing this but leaving it around as this is useful for a
feature that we still need to enable - the ability to filter out which
events to display. This existed in 3.1 but is missing in the Qt version.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
I always worry if these are worth following up on - but these seem pretty
clear and obvious to me. As far as the planner is concerned, depth is
unsigned.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We needed this in Gtk version as we were using a system font to show the
stars and that was missing on some ancient Windows versions. With the Qt
version we actually draw the stars so this has become obsolete.
Suggested-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
- 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>
Some people (free divers) are loving ft/s or m/s units for vertical speeds.
Now they can choose between /min or /s in the configuration (only Qt UI).
Signed-off-by: Patrick Valsecchi <patrick@thus.ch>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This patch adds a ruler QGraphicsItem which can be dragged
along the profile. The ruler displays minimum, maximum and
average for depth and speed (ascent/descent rate). Also, all used
gas will be displayed.
This also adds a new attribute to struct plot_data to store the
speed (not just as velocity_t).
Signed-off-by: Maximilian Güntner <maximilian.guentner@gmail.com>
This gets things mostly right.
It creates a dive and uses the planner widget to create samples which are
copied into the dive. It fills in some reasonable defaults (DC model,
timestamp), but doesn't allow editing the timestamp (or the temperatures
and air pressure).
On accept the planner gets reset and the dive appears correctly in the
dive list.
Cancel still needs to be handled.
And I bet there are many subtle bugs lurking here and there. But it's a
start.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
In add dive mode simply bring the diver safely back to the surface
(currently with a fixed ascent rate of 30ft/min (or 9m/min)).
We should make that rate configurable (for the planner as well as the dive
add function). Also, the dive add function should offer to automatically
include a safety stop.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This is correct C. But debuggers in C++ mode are broken and can't display
the global variables. While I hate having to do this change, I hate not
being able to debug my software because of broken tools even more.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The Command line execution of Subsurface happened before the
GUI was created, this leaded to various bugs by me(tm) over
time. This patch seems to fix all of those, by reusing the
same code for GUI interaction and CommandLine interaction.
I had to rework how the main.c worked, it used to be C code
calling C++ code, and this is non desirable, since C doesn't
really understand C++.
I Moved all of C-related code to 'subsurfacestartup.c/h' and
created a tiny wrapper to call it, so all of the C code is still
C code, and the new main.cpp calls the mainwindow->loadFiles and
mainWindow->importFiles to get rid of the bugs that happened before.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This bug manifested itself as too long deco obligation when moving
waypoints to later and then back to earlier times as all intermedite
versions were created as dives in the divelist (and the saturation of
these "previous dives" was taken into account.
It is not entirely clear to me how the dive will be permanently added to
the divelist once ok is pressed: One could in createDecoStops allocate
struct dive from the heap rather than from the stack and return a pointer
to it and which is then added to the dive list upon pressing ok.
[Dirk Hohndel: add include file to make this compile]
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Remove circle in plan by starting the first line at the first point
rather than the last.
In addition marks all entered points as entered and not just the first and
sets line color accordingly.
Makes plan_add_segment return the added data point.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This uses a bunch of default values that we eventually need to get from
the UI, but it's a first step towards a working dive planner.
This exhibits some graphical artifacts when running, but other than that
appears to be mostly correct.
Things go far worse if I enable the changing of the scale once the deco
makes the dive longer than the displayed time window. Things quickly
spiral out of control.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
I expanded the DiveHandler to include the actual time / depth of each
node on the graph - this way things will stay consistent if we need to
rescale the graph.
One thing that this makes obvious is that the whole design for the
planner so far assumes metric data. We need to make sure this works well
with feet instead of meters as well (and that it uses the information in
the units settings).
With this change we actually create a dive based on the plan input and
add the deco stops (if needed) to it - but we don't do anything with the
results of those calculations, yet.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This data structure was quite fragile and made 'undo' when editing
rather hard to implement. So instead I decided to turn this into a
QMultiMap which seemed like the ideal data structure for it.
This map holds all the dive computer related data indexed by the model. As
QMultiMap it allows multiple entries per key (model string) and
disambiguates between them with the deviceId.
This commit turned out much larger than I wanted. But I didn't manage to
find a clean way to break it up and make the pieces make sense.
So this brings back the Ok / Cancel button for the dive computer edit
dialog. And it makes those two buttons actually do the right thing (which
is what started this whole process). For this to work we simply copy the
map to a working copy and do all edits on that one - and then copy that
over the 'real' map when we accept the changes.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The biggest problem here was that bool has different sizes in C and C++
code. So using this in a structure shared between the two sides wasn't a
smart idea.
Instead I went with 'short', but that caused problems with Qt being to
smart for its own good and not doing the right thing when dealing with
'boolean' settings and a short value. This may be something in the way I
implemented things (as I doubt that something this fundamental would be
broken) but the workaround implemented here (explicitly using 0 or 1
depending on the value of the boolean) seems to work.
I also decided to get rid of the confusion of where gflow/gfhigh are
floating point (0..1) and when they are integers (0..100). We now use
integers anywhere outside of deco.c.
I also applied some serious spelling corrections to the preferences
dialog's ui file.
Finally, this enables the code that selects which partial pressure graph
to show.
Still to do: font size, metric/imperial logic
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This is a fun one.
We only want to mark the divelist changed if the user actually changed
something. So we try really hard to compare what was entered with what was
there and only if it is different do we overwrite existing values and
record this as a change to the divelist.
An additional challenge here is the fact that the user needs to enter a
working pressure before they can enter a size (when in cuft mode). That is
not really intuitive. We work around this by assuming working pressure is
3000psi if a size is given in cuft - but then if the user changes the
working pressure, that changes the volume. Now going back and changing the
volume again does the trick. Or enter the working pressure FIRST and then
the volume...
This also changes the incorrect MAXPRESSURE to WORKINGPRESSURE and uses
the text WorkPress in English (Gtk code used MaxPress which was simply
wrong - this is just the design pressure or working pressure, not some
hard maximum. In fact, people quite commonly "overfill" these tanks.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Instead of passing pointers to GError around we pass just pointers to
error message texts around and use kMessageWidget to show those. Problem
is that right now the close button on that doesn't do a thing - so the
error stays around indefinitely. Oops.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The DEBUGFILE logic isn't needed anymore. Nor are helpers dealing with
model / datastructure updates. Nor conditional compiles to use Gtk instead
of Qt.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
i
Added the code to show the cylinders from a dive,
this code also already permits additions from the
interface, so the user can click 'add' and insert
what he wants there.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
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>
Conditional inclusion of libzip, xslt and osm-gps-map just
makes testing more cumbersome, since testers might lack
Subsurface features without knowing.
Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The compiler on MacOSX wouldn't build Subsurface when bool
was redefined.
Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Functionality is unchanged, except we now have a nice process_dives
function that deals with all the logic and that gets called from
report_dives from the Gtk code.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This literally just creates the dialog and does not hook things up with
the dive list.
The idea is to abstract out the idea behind the invalid dives to allow the
user to select / deselect all kinds of dives and then do statistics on
the selected ones.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The Qt ui will need to read the dive_table to populate widgets with
dives. Gtk functionality in init_ui is required to parse the dives.
Split init_ui to allow parsing to proceed and complete before Qt ui
mainwindow constructor is called.
Play with qDebug()'s printf style (Thiago!)
Signed-off-by: Amit Chaudhuri <amit.k.chaudhuri@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Added the code that will load and populate the Tank Info
ComboBox that`s used by the user to select the Cylinder
description.
Code curerntly implements more than the GTK version since
the GTK version of it was a plain-list, this one is a
table based model that can be used in ListViews ( like
we use now in the ComboBox ) but also in TableViews
( if there`s a need in the future to see everything
that`s catalogued in the Tank Info struct. )
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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>
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>
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>
Relatively straight forward, just a handful of places where we call
show_error() (a UI function) from the logic code. In the process I noticed
a few places where error returns weren't dealt with correctly.
Added a new planner.h files for the necessary declarations.
This should make no difference to functionality.
Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Relatively straight forward, just a handful of places where we call
show_error() (a UI function) from the logic code. In the process I noticed
a few places where error returns weren't dealt with correctly.
Added a new planner.h files for the necessary declarations.
This should make no difference to functionality.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This is simplistic & brute force: any function that touches Gtk related
data structures is moved to divelist-gtk.c, everything else stays in
divelist.c.
Header files have been adjusted so that this still compiles and appears to
work. More thought is needed to truly abstract this out, but this seems to
be a good point to commit this change.
Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Remove the boolean parameter from parse_file; the code is more readable
by having an explicit call to set_filename() where necessary, rather
than a boolean parameter.
Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Alberto Mardegan <mardy@users.sourceforge.net>
This is simplistic & brute force: any function that touches Gtk related
data structures is moved to divelist-gtk.c, everything else stays in
divelist.c.
Header files have been adjusted so that this still compiles and appears to
work. More thought is needed to truly abstract this out, but this seems to
be a good point to commit this change.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Remove the boolean parameter from parse_file; the code is more readable
by having an explicit call to set_filename() where necessary, rather
than a boolean parameter.
Signed-off-by: Alberto Mardegan <mardy@users.sourceforge.net>
Rename gtk-gui.c to qt-gui.cpp, and make the necessary changes so that
the project still builds.
Signed-off-by: Alberto Mardegan <mardy@users.sourceforge.net>
get_cylinder_index() looks up which cylinder to use based on the
gaschange event that describes the mix. However, it was both buggy and
not very good.
It was buggy because it didn't understand about our air rules, and it
was not very good because it required an exact match (after rounding our
permille-based numbers to percent).
So fix it to use the right permille values, and look for a closest match
(using the normal sum-of-squares distance function - although I wonder
if we should consider helium percentages to be "more important" and give
them a stronger weight).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
.. so that different computers that have different ordering of the same
cylinders will see the end result the same way.
This also fixes up the sample sensor index and generates special initial
tank change events for the dive computers that had their cylinder
indexes renamed on them.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Create a little widget that lists all the gases / tanks we know about and
allow the user to pick one of them.
Turns out that add_event only added events at the end of the list - but we
treat that list as chronologically sorted. So I fixed that little
mis-feature as well.
This does raise the question whether we need the inverse operation
(removing a gas change). And if there are other things that we should be
able to manually edit, now that we have the infrastructure for this neat
little context menu...
See #60 -- this doesn't address all of the issues mentioned there, but at
least deals with the 'headline' of the feature request...
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This generates a .DLD file of selected dives to be uploaded to
divelogs.de. The actual upload functionality along with sensible user
interface is still to be implemented. However, the resulting file from
this patch is tested to work (as far as I can tell) using upload API of
divelogs.de.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Basic functionality is implemented but at least support for multiple
cylinders is missing. Event/alarm support is only partial.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The existing code has an embarrassing error in its logic. It picked the
last dive in the table and made sure that the relative start time was
either N minutes after 'now' or N minutes after the last dive ends,
whichever is later.
But once the planned dive has been added to the dive list (so once we have
a first depth and time entry, that last dive now is the planned dive. And
every time focus left the start time field the start time would be
recalculated relative to the end of the dive we are currently planning.
With this patch we instead simply remember the number of the last dive
just as we create the dive plan and use that to look up the end time of
previous dive. I could have just stored that end time but I figured maybe
there could be other reasons to go back to the last dive before the
planned dive, so this seemed cleaner.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This creates a helper function called "gas_volume()" that takes the
cylinder and a particular pressure, and returns the estimated volume of
the gas at surface pressure, including proper approximation of the
incompressibility of gas.
It very much is an approximation, but it's closer to reality than
assuming a pure ideal gas. See for example compressibility at
http://en.wikipedia.org/wiki/Compressibility_factor
Suggested-by: Jukka Lind <jukka.lind@iki.fi>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Uses profile.c:evn_foreach() to retrieve the number of events, which
if zero, no table is added in the dialog and the label is added instead.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Commit 90d3c5614a ("Centralising and redefining values as integers")
broke SAC-rate calculations. In particular, it changed "to_ATM()": to
use the centralized SURFACE_PRESSURE helper define, but in the process
it changed a floating point calculation to an integer calculation, and
it threw away all the fractional details. Any user of "to_ATM()"
basically dropped to an accuracy of a single atmosphere.
The good news is that we didn't use to_ATM() for things like depth
calculations, but only for cylinder pressures. As a result, the error
ends up being relatively small, since the pressures involved are big,
and thus the error of rounding to whole atmospheres is usually in the
1% range. The cylinder sizing tends to be off by more than that
anyway. But it was wrong, and not intentional.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This does a final pass after all the selection logic, and notices if we
have dive trips that are selected, but that have no dives in them
selected. In that case, we assume that the user wanted to select all
dives in that trip.
NOTE! This still allows a range selection that selects the dive trip
entry and a few dives under the trip. If a trip has any dives selected
in it, we leave that manual selection alone. So this new logic really
only triggers on the case where somebody selected *just* the trip.
Note: unselecting the trip still leaves the dives under it selected,
because having a dive trip that isn't selected have all the dives under
it be selected is normal, and we can't recognize that as some kind of
special event.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
..they are of a higher quality anyway, and this way we have one less
library to worry about. And this way there is nobody who can claim that
openssl is not a system library and thus not compatible with the GPL.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We now load and save this in the XML file, we do the right thing when
merging dives and show the edited air temperature in the Dive Info
notebook when a divecomputer doesn't have an air temperature.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Printf is not a way to issue warnings and errors. This is a very late
addition but seems necessary for a viable release of the planner.
This also adds one artificial limit and two warnings:
a) no dives deeper than 400m
b) warning of potentially very long calculation times for dives longer
than 3h (180min) before the ascent and dives deeper than 150m
It also creates quite a number of new strings that need to be translated
(and marks a few existing ones for translation as well).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Two separate bugs.
a) Air cylinders were created with o2=209 and no other value set.
sanitize_gasmix() turned that into o2=0 which meant that this cylinder was
now identified as "nodata", i.e., unset.
We now set a fake cylinder name to deal with that issue.
b) the gaschange event is inherited from libdivecomputer and therefore
only supports 1 percent granularity for o2 and h2. Since we didn't round
when assigning the value we ended up with air being stored as o2=20 he=0
which of course then didn't match air anymore (which we have defined as
208 <= o2 <= 210).
We now use o2=210 for air in the planner and carefully round the permille
values whenever we convert into percent - and compare gases with percent
granularity as well.
A better fix for b) would be to change the Subsurface event to not simply
copy the libdivecomputer behavior and use percent granularity but support
permille instead. But this closely before the 3.0 release that seemed like
a far too invasive change to make - the changes to the planner should have
no impact outside the planner module.
Reported-by: Chris Lewis <chrislewis915@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This adds watertemp and airtemp to the dive, populates them in fixup and
uses them elsewhere in the code.
WARNING: as a sideeffect we now edit the airtemp in the dive, but we never
display this in the DIve Info notebook (as that always displays the data
from the specific selected divecomputer). This is likely to cause
confusion. It's consistent behavior, but... odd. This brings back the
desire to have a view of "best data available" for a dive, in addition to
the "per divecomputer" view. This would also allow us to consolidate the
different pressure graphs we may be getting from different divecomputers
(consider the case where you dive with multiple air integrated computers
that are connected to different tanks - now we could have one profile with
all the correct tank pressure plots overlayed - and the best available (or
edited) data in the corresponding Dive Info notebook.
This commit also fixes a few remaining accesses to the first divecomputer
that fell through the cracks earlier and does a couple of other related
cleanups.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
When starting on this quest to stop using the first divecomputer instead
of data for the whole dive in commit eb73b5a528c8 ("Duration of a dive is
the maximum duration from all divecomputers") I introduced an accessor
function that calculates the dive duration on the fly as the maximum of
the durations in the divecomputers.
Since then Linus and I have added quite a few of the variables back to the
dive data structure and it makes perfect sense to do the same thing for
the duration as well and simply do the calculation once during fixup.
This commit also replaces accesses to the first divecomputer in
likely_same_dive to use the maxdepth and meandepth of the dive (those two
slipped through the cracks in the previous commits, it seems).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This is currently only used in one place (in statistics.c), but it
certainly is consistent with the other recent changes to avoid using only
the first divecomputer when trying to make statements about a dive.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Populate during dive fixup as the maximum depth shown by all the
divecomputers. Use this value (instead of the one in the first
divecomputer) in printing, statistics, etc.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
In commit b6c9301e58 ("Move more dive computer filled data to the
divecomputer structure") we moved the fields that get filled in by the
dive computers to be per-divecomputer data structures.
This patch re-creates some of those fields back in the "struct dive",
but now the fields are initialized to be a reasonable average from the
dive computer data. We already did some of this for the temperature
min/max fields for the statistics, so this just continues that trend.
The goal is to make it easy to look at "dive values" without having to
iterate over dive computers every time you do. Just do it once in
"fixup_dive()" instead.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
There are two ways to look at surface pressure. One is to say "what was
the surface pressure during that dive?" - in that case we now return an
average over the pressure reported by the different divecomputers (or the
standard 1013mbar if none reported any).
Or you want to do specific calculations for a specific divecomputer - in
which case we access only the pressure reported by THAT divecomputer, if
present (and fall back to the previous case, otherwise).
We still have lots of places in Subsurface that only act on the first
divecomputer. As a side effect of this change we now make this more
obvious as we in those cases pass a pointer to the first divecomputer
explicitly to the calculations.
Either way, this commit should prevent us from ever mistakenly basing our
calculations on a surface pressure of 0 (which is the initial bug in
deco.c that triggered all this).
Similar changes need to be made for other elements that we currently only
use from the first divecomputer, i.e., salinity.
Reported-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We'll want to use a 'static const' gasmix for the upcoming no-fly-time
code, so prepare for it by just marking the read-only gasmix argument as
'const'.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
So far we always used the duration of the first divecomputer. The same fix
needs to be done for some of the other calculations that always use the
first divecomputer.
This commit also removes some obsolete code from the webservice merging.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We had this special logic to not show the end of a dive when a dive
computer shows a series of very shallow samples (basically snorkeling
back to shore after the dive ended). However, that logic ended up being
global per dive, which is very annoying when you have two or more dive
computers, and it decides to cut off the second one because the first
one surfaces.
So get rid of this per-dive state, and just use the plot-info 'maxtime'
field for this (we never used the 'start' case anyway). That way we
will properly cut off boring surface entries only when they are past the
end of the interesting entries of *all* dive computers, and we won't be
cutting things short.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This moves some double/floating handling for po2 to plain integer. There
are still non int values around (also for phe and po2) in the plot area.
Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Something which is nice especially when asked on the list to share an
interesting dive is the possibility to save just some dives into a file.
This commit adds to the context menu shown with right-click the 'Save As'
entry. This entry allows to save selected dives.
[Dirk Hohndel: clean up white space, commit message and remove unused
variables]
Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
When the data file is closed we should reset the events that we offer for
filtering.
Reported-by: Sergey Starosek <sergey.starosek@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This no longer abuses the dive merging code (which would leave stray
"dives" behind if a gps fix couldn't be merged with any of the dives) and
instead parses the gps fixes into a second table and then walks that table
and tries to find matching dives.
The code tries to be reasonably smart about this. If we have
auto-generated GPS fixes at regular intervals, we look for a fix that is
during a dive (that's likely when the boat where the phone is staying dry
is more or less above the diver having fun). And if we have named entries
(so the user typed in a location name) we try to match them in order to
the dives that happened "that day" (where "that day" is about 6h before
and after the timestamp of the gps fix).
This commit also renames dive_has_location() to dive_has_gps_location() as
the difference between if(!dive->location) and if(dives_has_location) is a
bit too subtle...
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This only changes the infrastructure and actually loses functionality as
it no longer does the simplistic "just treat the locations as dives and
merge them".
The new code that does something "smart" with the gps_location_table is
yet to be written. But now we can use the XML parser to put the gps
locations downloaded from the webservice into their own data structure.
In the process I noticed that we never used the two delete functions in
parse-xml.c and removed them.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
It's only used by the Uemis importer, and Dirk always seems to import
his Uemis data first, so it wasn't very noticeable. But if the Uemis
data wasn't the first dive computer, it would not find the dive.
Side note: just comparing deviceid is not correct. We should pass in
the device model too. But again, that will realistically never really
matter, since non-Uemis importers will generate complex SHA1 hashes of
the dive data for the dive ID, so a collision with the Uemis numbers is
very unlikely.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Mostly coding style and whitespace changes plus making lots of functions
static that have no need to be extern. This also helped find a bit of code
that is actually no longer used.
This should have absolutely no functional impact - all changes should be
purely cosmetic. But it removes a bunch of lines of code and makes the
rest easier to read.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This misses a single issue to be used as a base for further discussion:
The CC setpoint is used for the next segment, not the one specified for. I
also have in mind to modify the existing code to use setpoints specified
in mbar and plain integer instead of float values.
Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
I have some concerns about the way this is implemented - especially the
use of gtk_grab_add to make the map widget work has me worried. But it
seems to work and survived some test cases that I threw at it.
The GtkButton with the Pixmap looks a little off on my screen, but this
way it was easy to implement. Feel free to come up with a better design.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
I'm sure there are better ways to do this, but this appears to grok most
rational formats I was able to find. NSEW or positive/negative numbers.
Decimal degrees (WGS84) or degrees and decimal minutes (that's what most
GPSs seem to provide). I'm sure there are still corner cases that confuse
it, but it seemed reasonably robust in testing.
I don't really love the ';' as separator but that solves the obvious
problem with locales that use a decimal comma.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This centralizes all occurrences of Kelvin to dive.h and standardizes all
usages to milliKelvin.
[Dirk Hohndel: renamed the constant plus minor white space cleanup]
Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The statistics page only used each dive's "watertemp" attribute,
regardless of actual higher/lower temperatures in the samples. By
finding the actual max/min temperatures, the statistics page utilize
more "real" data, and look better even on single dives.
Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We save the (more complete) dive computer information in the XML file
with serial numbers and firmware version if we know about them, so using
a complicated string in the system config was redundant and confusing.
So remove that code.
NOTE! Since the dive computer nicknames are now only saved if the XML
file is saved, we also mark the dive list "changed" when we edit the
nicknames. That way we'll be prompted to save things before exiting,
even if we don't actually edit any actual dive data.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We used to save dive computer information only if that dive computer was
actually used in any of the dives we saved. But we can simplify the
code if we just always save any dive computers we know about. And it
does allow for some usage cases where you have nicknames for other
peoples computers that you may not actively use, but you want to see if
you end up loading multiple XML files in one go.
So there's just no compelling reason to not just save all the info we
have. And this will make it less painful to remove the "use system
config for dive computer nicknames", because you can also use this to
continue to gather dive computer info in a separate XML file if you want
to.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Temperatures can actually be negative, which means that rounding by
adding 0.5 and casting to 'int' is not correct.
We could use '(int)(rint(val))' instead, but the only place we care
about might as well just print out the floating point representation
with a precision of two digits instead. So if you have a dive computer
that gives you the precision, you might see '3.5˚C' as the temperature.
Remove the helper functions that nobody uses and that get the rounding
wrong anyway.
Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This moves the fields 'duration', 'surfacetime', 'maxdepth',
'meandepth', 'airtemp', 'watertemp', 'salinity' and 'surface_pressure'
to the per-divecomputer data structure. They are filled in by the dive
computer, and normally not edited.
NOTE! All actual *use* of this data was then changed from dive->field to
dive->dc.field programmatically with a shell-script and sed, and the
result then edited for details. So while the XML save and restore code
has been updated, all the displaying etc will currently always just show
the first dive computer entry.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This adds the "Show in map" menu entry to the divelist only if we
actually have a location to show.
Of course, having some way to visually see whether we have a GPS
location even before we show the menu would probably be good. Maybe a
marker in the "location" string or something. But in the meanwhile, at
least we don't have that menu entry if we have nothing to show.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This adds a "Show in map" entry in the dive list context menu. It will
zoom to the dive location if it exists, otherwise the full map will be
displayed.
I've also switched map tiles from OpenStreetMap to Google Maps just to
show off that we can.
Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This makes it easy to print out a dive plan - it's simply stored in the
notes of the simulated dive we create.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This just provides the infrastructure to enter the data, nothing is
calculated, yet.
This adds a new get_thousandths() helper function so we can enter
information of the 'mili-' type as decimal values. So things like
"14.5 l/min" or "0.75 cuft/min" are parsed correctly and converted
into a ml value.
In the process of implementing that I also fixed a bug introduced in
commit ab7aecf16e ("Simplify dive planning code") which broke the
get_tenth() function.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Opening URI addresses from Subsurface does not work on Windows using
the latest GTK bundle from the Gnome website. The reason lies in GIO
and GLib and how it obtains assigned applications for protocols and MIME
types.
While gtk_show_uri() should be viable for both linux.c and macos.c,
in windows.c ShellExecute() is used, which provides proper support
for the URI calls.
subsurface_launch_for_uri() returns TRUE on success.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This patch centralizes the definition for surface pressure, oxygen in
air, (re)defines all such values as plain integers and adapts calculations.
It eliminates 11 (!) occurrences of definitions for surface pressure and
also a few for oxygen in air.
It also rewrites the calculation for EAD, END and EADD using the new
definitons, harmonizing it for OC and CC and fixes a bug for EADD OC
calculation.
And finally it removes the unneeded variable entry_ead in gtk-gui.c.
Jan
Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
- MOD: Maximum Operation Depth based on a configurable limit
- EAD: Equivalent Air Depth considering N2 and (!) O2 narcotic
- END: Equivalent Nitrogen (Narcotic) Depth considering just N2 narcotic
(ignoring O2)
- EADD: Equivalent Air Density Depth
Please note that some people and even diving organisations have opposite
definitions for EAD and END. Considering A stands for Air, lets choose the
above. And considering N for Nitrogen it also fits in this scheme.
This patch moves N2_IN_AIR from deco.c to dive.h as this is already used
in several places and might be useful for future use also. It also
respecifies N2_IN_AIR to a more correct value of 78,084%, the former one
also included all other gases than oxygen appearing in air. If someone
needs to use the former value it would be more correct to use 1-O2_IN_AIR
instead.
Signed-off-by: Jan Schubert / Jan.Schubert@GMX.li
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
For each dive recorded, place their GPS coordinates onto a map using the
OSM-GPS-MAP library.
This map is accessible via the "log" menu or the shortcut ctrl+M (M as map).
We check for the GPS coordinates "0, 0" which are the default when we do not
have real GPS coordinates set.
[Dirk Hohndel: fixed int/float math confusion, fixed some whitespace and
coding style issues, cleaned up some comments, added a
missing cast to prevent a compiler warning]
Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
Signed-Off-By: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
.. and add the usual logic to not save the default values.
This also simplifies the initial system-specific setup of both of these:
since we have defaults for all the preferences that get set up at
startup, we can just initialize those defaults to the system-specific
fonts then and there.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
.. and rename the badly named 'output_units/input_units' variables.
We used to have this confusing thing where we had two different units
(input vs output) that *look* like they are mirror images, but in fact
"output_units" was the user units, and "input_units" are the XML parsing
units.
So this renames them to be clearer. "output_units" is now just "units"
(it's the units a user would ever see), and "input_units" is now
"xml_parsing_units" and set by the XML file parsers to reflect the units
of the parsed file.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The legacy nickname wrappers (that use the device_info structure) are
left in gtk-gui.c. We can slowly start moving away from them, we don't
want to start exporting that thing as some kind of generic interface.
This isn't a pure code movement - because we leave the legacy interfaces
alone, there are a few new interfaces in device.c (like "create a new
device_info entry") that were embedded into the legacy "create nickname"
code, and needed to be abstracted out.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We have several places where we interpolate the depth based on two
samples and the time between them. Some of them use floating point, some
of them don't, some of them meant to do it but didn't.
Just use a common helper function for it. I seriously doubt the floating
point here really matters, since doing it in integers is not going to
overflow unless we're interpolating between two samples that are hours
apart at hundreds of meters of depth, but hey, it gives that rounding to
the nearest millimeter. Which I'm sure matters.
Anyway, we can probably just get rid of the rounding and the floating
point math, but it won't really hurt either, so at least do it
consistently.
The interpolation could be for other things than just depth, but we
probably don't have anything else we'd want to interpolate. But make the
function naming generic just in case.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
o) Instead of using gradient factors as means of comparison, I now use
pressure (as in: maximal ambient pressure).
o) tissue_tolerance_calc() now computes the maximal ambient pressure now
respecting gradient factors. For this, it needs to know about the
surface pressure (as refernce for GF_high), thus gets *dive as an
argument. It is called from add_segment() which this also needs *dive
as an additional argument.
o) This implies deco_allowed_depth is now mainly a ambient-pressure to
depth conversion with decorations to avoid negative depth (i.e. no deco
obliation), implementation of quantization (!smooth => multiples of 3m)
and explicit setting of last deco depth (e.g. 6m for O2 deco).
o) gf_low_pressure_this_dive (slight change of name), the max depth in
pressure units is updated in add_segment. I set the minimal value in
buehlmann_config to the equivalent of 20m as otherwise good values of
GF_low add a lot of deco to shallow dives which do not need deep stops
in the first place.
o) The bogus loop is gone as well as actual_gradient_limit() and
gradient_factor_calculation() and large parts of deco_allowed_depth()
although I did not delete the code but put it in comments.
o) The meat is in the formula in lines 147-154 of deco.c. Here is the
rationale:
Without gradient factors, the M-value (i.e the maximal tissue pressure)
at a given depth is given by ambient_pressure / buehlmann_b + a.
According to "Clearing Up The Confusion About "Deep Stops" by Erik C.
Baker (as found via google) the effect of the gradient factors is no
replace this by a reduced affine relation (i.e. another line) such that
at the surface the difference between M-value and ambient pressure is
reduced by a factor GF_high and at the maximal depth by a factor
GF_low.
That is, we are looking for parameters alpha and beta such that
alpha surface + beta = surface + gf_high * (surface/b + a - surface)
and
alpha max_p + beta = max_p + gf_low * (max_p/b + a - max_p)
This can be solved for alpha and beta and then inverted to obtain the
max ambient pressure given tissue loadings. The result is the above
mentioned formula.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This was just a crutch to get something out there for people to play with.
With the ability to input a plan in place this is now obsolete.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
As the user enters data into the entry fields, that data is validated and
as soon as there is enough data we start constructing a dive profile,
including the final ascent to the surface, including required deco stops,
etc.
This commit still has some serious issues.
- when data is input that doesn't validate, we just print a warning to
stdout - instead we need to change the backgroundcolor of the input
field or something.
- when we switch to the last dive in order to show the profile we don't
actually search for the last dive - we just show the first one in the
tree. This works for the default sort order but is of course wrong
otherwise
I'm sure there are many other bugs, but I want to push it out where it is
right now for others to be able to take a look.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We kept reduing all the deco calculations, including the previous dives
(if any) for each segment we add to the dive plan. This simply remembers
the last stage and then just adds to that.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
actual planning
Yes, you can actually enter your segments now.
No, it's not wonderfully user-friendly. If you don't enter enough
segments to create a dive plan, it will just silently fail, for example.
And the <tab> key that should get you to the next editable segment
doesn't. And so on. But it kind of works.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This comes with absolutely no gui - so the plan literally needs to be
compiled into Subsurface. Not exactly a feature, but this allowed me to
focus on the planning part instead of spending time on tedious UI work.
A new menu "Planner" with entry "Test Planner" calls into the hard-coded
function in planner.c. There a simple dive plan can be constructed with
calls to plan_add_segment(&diveplan, duration, depth at the end, fO2, pO2)
Calling plan(&diveplan) does the deco calculations and creates deco stops
that keep us below the ceiling (with the GFlow/high values currently
configured). The stop levels used are defined at the top of planner.c in
the stoplevels array - there is no need to do the traditional multiples of
3m or anything like that.
The dive including the ascents and deco stops all the way to the surface
is completed and then added as simulated dive to the end of the divelist
(I guess we could automatically select it later) and can be viewed.
This is crude but shows the direction we can go with this. Envision a nice
UI that allows you to simply enter the segments and pick the desired
stops.
What is missing is the ability to give the algorithm additional gases that
it can use during the deco phase - right now it simply keeps using the
last gas used in the diveplan.
All that said, there are clear bugs here - and sadly they seem to be in
the deco calculations, as with the example given the ceiling that is
calculated makes no sense. When displayed in smooth mode it has very
strange jumps up and down that I wouldn't expect. For example with GF
35/75 (the default) the deco ceiling when looking at the simulated dive
jumps from 16m back up to 13m around 14:10 into the dive. That seems very
odd.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The old implementation was broken in several ways.
For one thing the GF values are percentages, so they should normally be
0 < GF < 1 (well, some crazy people like to go above that).
With this most of the Bühlmann config constants were wrong.
Furthermore, after we adjust the pressure tolerance based on the gradient
factors, we need to convert this back into a depth (instead of passing
back the unmodified depth - oops).
Finally, this commit adds closed circuit support to the deco calculations.
Major progress and much more useful at this stage.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
There are a couple of issues with this commit:
GtkEntry should emit the 'changed' signal when it is modified (so that
changes in the preferences get applied right away) - but that doesn't
appear to be working consistently.
Also, this doesn't appear to affect the deco of any dives that I try it
with. So my guess is something is wrong with the underlying deco
algorithm. That's diappointing.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This also initializes the N2 tissue saturations to correct numbers
(setting them to zero was clearly silly).
With this commit we walk back in the dive_table until we find a surface
intervall that's longer than 48h. Or a dive that comes after the last one
we looked at; that would indicate that this is a divelist that contains
dives from multiple divers or dives that for other reasons are not
ordered. In a sane environment one would assume that the dives that need
to be taken into account when doing deco calculations are organized as one
trip in the XML file and so this logic should work.
One major downside of the current implementation is that we recalculate
everything whenever the plot_info is recreated - which happens quite
frequently, for example when resizing the window or even when we go into
loup mode. While this isn't all that compute intensive, this is an utter
waste and we should at least cache the saturation inherited from previous
dives (and clear that number when the selected dive changes). We don't
want to cache all of it as the recreation of the plot_info may be
triggered by the user changing equipment (and most importantly, gasmix)
information. In that case the deco data for this dive does indeed have to
be recreated. But without changing the current dive the saturation after
the last surface intervall should stay the same.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Usually dive computers show the ceiling in terms of the next deco stop -
and those are in 3m increments. This commit also adds the ability to chose
either the typical 3m increments or the smooth ceiling that the Bühlmann
algorithm actually calculates.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
For dives with more than 4 cylinders, the frame got very crowded and we
needed a magnifier to see the numbers.
If we used more than four tanks, let's put the info in another frame, if not, print
the OTUs, the maxcns and the weight sytem in the new frame.
There is still room for two more short data.
Changed naming of nitrox and trimix mixes.
Changed cylinder description.
There are issues with the size of some translations.
Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Having two spots to toggle autogroup had always been a clear sign of
insanity. The inconsistent ludicrous semantic of when we remembered the
state of autogroup was even worse.
This finally gets rid of that disaster and drops the autogroup setting
from the preferences and makes it instead a per file property. When you
save a file, it saves the state of the autogroup toggle. This seems much
more useful - you may have files where you want to create trips by
default. And others, where you don't.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This clarifies/changes the meaning of our "cylinderindex" entry in our
samples. It has been rather confused, because different dive computers
have done things differently, and the naming really hasn't helped.
There are two totally different - and independent - cylinder "indexes":
- the pressure sensor index, which indicates which cylinder the sensor
data is from.
- the "active cylinder" index, which indicates which cylinder we actually
breathe from.
These two values really are totally independent, and have nothing
what-so-ever to do with each other. The sensor index may well be fixed:
many dive computers only support a single pressure sensor (whether
wireless or wired), and the sensor index is thus always zero.
Other dive computers may support multiple pressure sensors, and the gas
switch event may - or may not - indicate that the sensor changed too. A
dive computer might give the sensor data for *all* cylinders it can read,
regardless of which one is the one we're actively breathing. In fact, some
dive computers might give sensor data for not just *your* cylinder, but
your buddies.
This patch renames "cylinderindex" in the samples as "sensor", making it
quite clear that it's about which sensor index the pressure data in the
sample is about.
The way we figure out which is the currently active gas is with an
explicit has change event. If a computer (like the Uemis Zurich) joins the
two concepts together, then a sensor change should also create a gas
switch event. This patch also changes the Uemis importer to do that.
Finally, it should be noted that the plot info works totally separately
from the sample data, and is about what we actually *display*, not about
the sample pressures etc. In the plot info, the "cylinderindex" does in
fact mean the currently active cylinder, and while it is initially set to
match the sensor information from the samples, we then walk the gas change
events and fix it up - and if the active cylinder differs from the sensor
cylinder, we clear the sensor data.
[Dirk Hohndel: this conflicted with some of my recent changes - I think
I merged things correctly...]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We used to have the rule that a dive trip has to have all dives in it in
sequential order, even though our XML file really is much more flexible,
and allows arbitrary nesting of dives within a dive trip.
Put another way, the old model had fairly inflexible rules:
- the dive array is sorted by time
- a dive trip is always a contiguous slice of this sorted array
which makes perfect sense when you think of the dive and trip list as a
physical activity by one person, but leads to various very subtle issues
in the general case when there are no guarantees that the user then uses
subsurface that way.
In particular, if you load the XML files of two divers that have
overlapping dive trips, the end result is incredibly messy, and does not
conform to the above model at all.
There's two ways to enforce such conformance:
- disallow that kind of behavior entirely.
This is actually hard. Our XML files aren't date-based, they are
based on XML nesting rules, and even a single XML file can have
nesting that violates the date ordering. With multiple XML files,
it's trivial to do in practice, and while we could just fail at
loading, the failure would have to be a hard failure that leaves the
user no way to use the data at all.
- try to "fix it up" by sorting, splitting, and combining dive trips
automatically.
Dirk had a patch to do this, but it really does destroy the actual
dive data: if you load both mine and Dirk's dive trips, you ended up
with a result that followed the above two technical rules, but that
didn't actually make any *sense*.
So this patch doesn't try to enforce the rules, and instead just changes
them to be more generic:
- the dive array is still sorted by dive time
- a dive trip is just an arbitrary collection of dives.
The relaxed rules means that mixing dives and dive trips for two people
is trivial, and we can easily handle any XML file. The dive trip is
defined by the XML nesting level, and is totally independent of any
date-based sorting.
It does require a few things:
- when we save our dive data, we have to do it hierarchically by dive
trip, not just by walking the dive array linearly.
- similarly, when we create the dive tree model, we can't just blindly
walk the array of dives one by one, we have to look up the correct
trip (parent)
- when we try to merge two dives that are adjacent (by date sorting),
we can't do it if they are in different trips.
but apart from that, nothing else really changes.
NOTE! Despite the new relaxed model, creating totally disjoing dive
trips is not all that easy (nor is there any *reason* for it to be
easty). Our GUI interfaces still are "add dive to trip above" etc, and
the automatic adding of dives to dive trips is obviously still based on
date.
So this does not really change the expected normal usage, the relaxed
data structure rules just mean that we don't need to worry about the odd
cases as much, because we can just let them be.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit makes deco handling in Subsurface more compatible with the way
libdivecomputer creates the data. Previously we assumed that having a
stopdepth or stoptime and no ndl meant that we were in deco. But
libdivecomputer supports many dive computers that provide the deco state
of the diver but with no information about the next stop or the time
needed there. In order to be able to model this in Subsurface this adds an
in_deco flag to the samples. This is only stored to the XML file when it
changes so it doesn't add much overhead but will allow us to display some
deco information on dive computers like the Atomic Aquatics Cobalt or many
of the Suuntos (among others).
The commit also removes the old event based deco code that was commented
out already. And fixes the code so that the deco / ndl information is
stored for the very last sample as well.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
There is no point writing out divecomputer nicknames that do not exist
(or that match the dive computer model), so don't.
Also, make the function to do this static to save-xml.c, which is the
only user (I initially didn't _find_ the function to create the XML
string because it was illogically hidden in gtk-gui.c), and change the
calling convention to be more direct (pass in a string and return a
result, rather than modify a "pointer to string").
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We only store the model/deviceid/nickname for those dive computers that
are mentioned in the XML file. This should make the XML files nicely
selfcontained.
This also changes the code to consistently use model & deviceid to
identify a dive computer. The deviceid is NOT guaranteed to be collision
free between different libdivecomputer backends...
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We now store the model information together with the deviceid and nickname
in order to be able to check if we have a record for any dive computer
with the same model (as that now triggers our nickname dialog).
This changes the format of the config entries for nicknames - the best
solution might be to just delete those and start again.
What is still missing is the code to store the nicknames in the XML file.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Having it there with the model information seemed to make sense but on
second thought it's the wrong spot to keep that information, especially
since we were storing it in the XML file in every single dive.
This change removes the nickname member from the divecomputer and makes
the rest of the code reasonably self consistent. It does not add much of
the new code for the new design to handle nicknames.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
If we havd divecomputer model and dive ID information available, use
that to match existing dives when trying to merge them.
Otherwise fall back to the fuzzy time-based merging logic.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We maintain a list of dive computers that we know about (by deviceid) and
their nicknames in our config. If the user downloads dive from a dive
computer that we haven't seen before, we give them the option to set a
nickname for that dive computer. That nickname is displayed in the profile
(and stored in the XML file, assuming it is not the same as the model).
This implementation attempts to make sure that it correctly deals with
utf8 nicknames.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
I foolishly changed visible_columns in both the (ill-named) cns branch and
master...
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Conflicts:
divelist.c
gtk-gui.c
profile.c
We either pick the CNS reported by the dive computer at the end of the
dive, or the maximum of that and the CNS values in the samples, if any.
As usual, this column in the dive list defaults to off and it is
controlled by a setting in the tec page of the preferences.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Now we can simply remember the state of all the preferences at the
beginning of preferences_dialog() and restore them if the user presses
'Cancel'.
Fixes#21
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This adds the new members to the sample structure and fills them from
supported dive computers (Uemis SDA and OSTC / Shearwater Predator,
assuming you have libdivecomputer 0.3).
Save relvant values of this to the XML file and load it back. Handle the
new fields when merging dives.
At this stage we don't DO anything with this, all we do is extract them
from the dive computer, save them to the XML file and load them back.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This actually makes us internally use 'micro-degrees' for latitude and
longitude, and we never turn them into floating point either at parse
time or save time.
That said, the Uemis downloader internally does still use atof() when
converting things, which is likely a bug (locale issues and all that),
but I'll ask Dirk to check it out.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit changes the code that was recently introduced to deal with
deco ceilings. Instead of handling these through events we now store the
ceiling (which in reality is the deepest deco stop with all known dive
computers) and the stop time at that ceiling in the samples.
This also adds support for NDL (non stop dive limit) which both dive
computers that appear to give us ceiling / deco information appear to
give us as well (when the diver isn't in deco).
If the mouse hovers over the profile we now add support for displaying the
NDL, the current deco obligation and (if we are able to tell from the
data) whether we are at a safety stop.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This was necessary for the Uemis downloader when we used the SDA file
format as intermediary data format and imported that as XML buffer.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The initial downloader reused the XML parsing of SDA files that was
implemented early in order to support the information extracted from the
SDA with the java applet. But creating this intermediary XML file and
handing it off to the XML import function always seemed like an ugly way
to do things. This became even more obvious when adding more features to
the Uemis downloader.
This commit completely changes the downloader to instead create dives and
record them directly.
This also adds support for divespots (which are stored in a seperate
database that needs to be queried after the divelog and dive entries have
been combined - the Uemis firmware clearly was written by monkeys on
crack - oh wait: I'm trusting these same people to get the deco right?).
This commit leaves the SDA import capability in the XML parser intact.
I'll remove that later. Because of this it actually adds a few lines of
code, but the overall change will be a substantial code deletion.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This removes the tripflag name array, since it's not actually useful.
The only information we ever save in the XML file is whether a dive is
explicitly not supposed to ever be grouped with a trip ("NOTRIP"), and
everything else is implicit.
I'm going to simplify the trip flags further (possibly removing it
entirely - like I did for dive trips already), and don't like having to
maintain the tripflag_names[] array logic.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Both dives and dive trips have the same 'tripflag' thing, but they are
used very differently. In particular, for dive trips, the only case
that has any meaning is the TF_AUTOGEN case, so instead of having that
trip flag, replace it with a bitfield that says whether the trip was
auto-generated or not.
And make the one-bit bitfields explicitly unsigned. Signed bitfields
are almost always a mistake, and can be confusing.
Also remove a few now stale macros that are no longer needed now that we
don't do the GList thing for dive list handling, and our autogen logic
has been simplified.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This makes the dive trip auto-generation a separate pass from the
showing of the dive trips, which makes things much more understandable.
It simplifies the code a lot too, because it's much more natural to
generate the automatic trip data by walking the dives from oldest to
newest (while the tree model wants to walk the other way).
It gets rid of the most annoying part of using the gtk tree model for
dive trip management, but some still remains.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
It had become a write-only field (apart from some now useless debugging)
when simplifying the remove_autogen_trips() function.
So remove it.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We already kept a count of dives per trip in order to figure out when
there are no more dives left and the trip needs to be freed. Now we
explicitly keep track of the list of dives associated with the trip too,
which simplifies the "find the time of the trip" logic.
We may want to sort it in time, but for now this is mainly about trying
to keep track of the divetrip relationships explicitly. I want to move
away from the whole "use the gtk tree model to keep track of things"
approach.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This simplifies the vendor/product fields into just a single "model"
string for the dive computer, since we can't really validly ever use it
any other way anyway.
Also, add 'deviceid' and 'diveid' fields: they are just 32-bit hex
values that are unique for that particular dive computer model. For
libdivecomputer, they are basically the first word of the SHA1 of the
data that libdivecomputer gives us.
(Trying to expose it in some other way is insane - different dive
computers use different models for the ID, so don't try to do some kind
of serial number or something like that)
For the Uemis Zurich, which doesn't use the libdivecomputer import, we
currently only set the model name. The computer does have some kind of
device ID string, and we could/should just do the same "SHA1 over the
ID" to give it a unique ID, but the pseudo-xml parsing confuses me, so
I'll let Dirk fix that up.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This also knows how to save and restore multiple dive computers in the
XML data, but there's no way to actually *create* that kind of
information yet (nor do we display it). Tested by creating fake XML
files with multiple dive computers by hand so far.
The dive computer information right now contains (apart from the sample
and event data that we've always had):
- the vendor and product name of the dive computer
- the date of the dive according to the dive computer (so if you change
the dive date manually, the dive computer date stays around)
Note that if the dive computer date matches the dive date, we won't
bother saving the redundant information in the XML file.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
For now we only have one fixed divecomputer associated with each dive,
so this doesn't really change any current semantics. But it will make
it easier for us to associate a dive with multiple dive computers.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We used to avoid some extra allocations by just allocating the dive
samples as part of the 'struct dive' allocation itself, but that ends up
complicating things, and will make it impossible to have multiple
different sets of samples (for multiple dive computers).
So stop doing it. Just allocate the dive samples array separately.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
When this was first implemented the assumption was that a downloaded dive
that is to be merged with an existing dive would have the same time stamp.
But as Linus pointed out even back then, this does fail if a dive has been
merged with a download from a different dive computer before (think:
download from computer a, then download same dive from b, then improve
something in the parsing from computer a and try to redownload; the time
stamp could have changed).
This commit also fixes a silly omission in the merge_dives() function
(which ended up ALWAYS prefering the downloaded dive) and finally
implements the necessary changes to mark dives downloaded from a Uemis SDA
as well.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
THe Uemis SDA allows the user to set it up for salt water and fresh water
use. We should take this into consideration for the water pressure to
depth conversion.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This will hopefully not be something we need often, but if we improve
support for a divecomputer (either in libdivecomputer or in our native
Uemis code or even in the way we handle (and potentially discard) events),
then it is extremely useful to be able to say "re-download things
from the divecomputer and for things that were not edited in Subsurface,
don't try to merge the data (which gives BAD results if for example you
fixed a bug in the depth calculation in libdivecomputer) but instead
simply take the samples, the events and some of the other unedited data
straight from the download".
This commit implements just that - a "force download" checkbox in the
download dialog that makes us reimport all dives from the dive computer,
even the ones we already have, and an "always prefer downloaded dive"
checkbox that then tells Subsurface not to merge but simply to take the
data from the downloaded dive - without overwriting the things we have
already edited in Subsurface (like location, buddy, equipment, etc).
This, as a precaution, refuses to merge dives that don't have identical
start times. So if you have edited the date / time of a dive or if you
have previously merged your dive with a different dive computer (and
therefore modified samples and events) you are out of luck.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This introduces the notion of merging two disjoint dives: you can select
two dives from the dive list, and if the selection is exactly two dives,
and they are adjacent (and share the same dive trip), we support the
notion of merging the dives into one dive.
The most common reason for this is an extended surface event, which made
the dive computer decide that the dive was ended, but maybe you were
just waiting for a buddy or a student at the surface, and you want to
stitch together two dives into one.
There are still details to be sorted out: my Suunto dive computers don't
actually do surface samples at the beginning or end of the dive, so when
you stitch two dives together, the profile ends up being this odd "a
couple of feet under water between the two parts of the dive" thing.
But that's an independent thing from the actual merging logic, and I'll
work on that separately.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This just re-organizes the dive merging code so that we expose a new
"merge_dives(a, b, offset)" function that merges two dives together into
one with the samples (and events) of 'b' at the specified offset after
'a'.
We'll want to use this if a dive computer has decided that the dive
ended (due to a pause at the surface), but we really want to just turn
the two computer dives into one long one with an extended surface swim.
No functional changes, but some independent cleanups due to the trip
simplifications.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We don't change any of the samples, we just don't plot (or consider for
dive time / mean calculations) the samples at the beginning or end of the
dive that are less than a certain threshold under water. Right now that's
an arbitrary 75cm which seems to Do The Right Thing(tm) for the dives I
tried this with - but I'm happy to look at other values if this causes
problems for people with dive computers I do not have access to.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This adds a couple of helper functions to manage dive trips
("add_dive_to_trip()" and "remove_dive_from_trip()") and makes those
functions do the trip statistics maintenance (trip beginning times,
number of dives, etc).
This was needed because the dive merge cases for multiple dive
computers showed some rather nasty special cases: especially if the
new dive information has been loaded into an XML file with trips
auto-generated, merging several of these kinds of xml files with
multiple dives in several overlapping trips would completely confuse
our previous code.
In particular, auto-generated trips that had the exact same date as
previous trips (because they were generated from the same dive
computer) really confused the code that used the trip timestamp to
manage the trips.
Adding the helper functions allows us to get the general case right
without having to have each piece of code that handles trip
information having to bother about all the odd rules. It will
eventually also allow us to make the dive trip data structures more
logical: right now the dive trip list is largely designed around the
odd gtk model handling, rather than some more higher-level conceptual
relationship with the actual dives.
But for now, this keeps all the data structures unchanged, and just
modifies them using the new helper functions.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This requires a patched libdivecomputer that can return salinity of the
water the dive was conducted in. Experimental patches exist that implement
this for the OSTC. The code is designed so that it simply defaults to salt
water if libdivecomputer doesn't include the feature.
The patch also fixes the dive merge code to merge two other recent
additions to the dive structure (surface_pressure and visibility).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The default filename handling is broken in two different ways:
(a) if we start subsurface with a non-existing file, we warn about
the inability to read that file, and then we exit without setting the
default filename.
This is broken because it means that if the user (perhaps by mistake,
by pressing ^S) now saves the file, he will overwrite the default
filename, even though that was *not* the file we read, and *not* the
file that subsurface was started with.
So just set the default filename even for a failed file open.
The exact same logic is true of a failed parse of an XML file that we
successfully opened. We do *not* want to leave the old default
filename in place just because the XML parsing failed, and possibly
then overwriting some file that was never involved with that failure
in the first place. So just get rid of all the logic to push the
filename saving into the XML parsing layer, it has zero relevance at
that point.
(b) if we do replace the default filename with a NULL file, we need
to set that even if we cannot do a strdup() on the NULL.
This fixes both errors.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This enables plotting the ceiling in deco dives and also adds the
necessary code to the uemis importer. The only other dive computer this
has been tested with the OSTC and that needs a libdivecomputer patch in
order to provide the deco/ceiling information to Subsurface.
Fixes#5
We now throw away redundant events, just as we throw away other redundant
data coming from the dive computer. Events are considered redundant if
they are less than 61 seconds apart and identical.
This also improves the display of the remaining events in the profile as
we now show the value of the event, if it is present (for example for a
deco event we show the duration of the deepest stop).
Finally, for events that define a range (so they set the beginning flag
and assume and end flag some time later) we no loger show the triangle but
assume that some other code handles visualizing them (as happens for the
ceiling events).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The dive data contains the surface pressure prior to the dive, and that is
what we need to compare p_amb_tol to, not the standard 1013mbar.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We used to have very spotty logic for picking the dive trip when
merging two dives. It turns out that that spotty logic almost never
really matters, because in practice you'll never hit the situation of
merging two dives with different dive trips, but it *can* happen.
In particular, it happens when you use multiple dive computers, and
end up loading the dives from one computer on top of the dives of your
other computer. If the clocks of the dive computers was set
sufficiently close to each other, the dive merging logic will kick in
and you may now have slightly different times for the dives that get
merged, and the trip merging logic got *really* confused.
The trip management also depends on the trip dates being updated
correctly when the dives associated with a trip are updated (whether
added or removed), and the trip merging code did none of that.
This fixes it all up. Hopefully correctly.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Lubomir's commit aec904b612 broke the Add
Dive menu item: The Edit Dive dialogue didn't show up after the initial
dialogue.
Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Turns out we had a data field for visibility as a length unit - but never
used it. I can never guess how much visibility we actually had on a dive -
but I think most everyone can assign a rating between abysmal (zero stars,
"I couldn't read my dive computer even right in front of my mask" - trust
me, I had some of those dives) to amazing ("five stars, I could see farther
than I though possible" - and I had one or two of those, too). So I
changed this to an integer and am re-using the star infrastructure we have
for the overall dive rating.
When displaying this I was dismayed that we are running out of space in
the "Dive Notes" notbook. So I moved this to the "Dive Info" notebook.
This is not consistent and not logical. I think we need to revisit the
notebooks and think about what we want to display where.
While adding the infrastructure to manually enter the visibility I went
ahead and added the ability to manually enter the air temperature as well
(that was one of the things missing in the previous commit).
Fixes#7
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
linux.c, macos.c, windows.c now contain
subsurface_os_feature_available() that can accept an enum type
os_feature_t defined in dive.h.
The function can be useful to check if a specific global feature
is available on a certain OS version.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
So far we only looked in the a local subdirectory, but once Subsurface has
been installed, we don't need to change the search path for translation
files anymore.
Fixes#2
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The MacOSX applications bundle needs to be told where to bind the
text domain from.
Also copy the gettext .mo files in the install-macosx target.
[Dirk Hohndel: minor change in main(): move the path declaration to
the beginning of the function]
Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This adds a few fields that we parse, but more importantly it also tries
to dynamically decide if the sample temperatures and pressures are in
imperial or metric units.
Dirk suspects that DivingLog generally always does everything in metric,
and the reason why he has crazy sample data in imperial units (both for
pressure and temperature) may be due to a bug in the early Uemis
importer for DivingLog.
Which would actually make a lot more sense than DivingLog really being
so insane on purpose.
Anyway, Dirk's brother Jurgen seems to have everything in metric units,
which would be much saner. Maybe we should throw away the support for
insane DivingLog files entirely, since it is possible that the only use
ever of the possible source of that bug was Dirk's use of the Uemis
importer.
But for now, we end up just guessing. Current guesses:
- water temperature is below 32 dgC, so 32+ degrees is in Fahrenheit.
- tank pressures are below 400 bar, so higher values than that must be
psi.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Only files that are opened should be considered r/w. Files that are
imported should be treated as if they were r/o.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
For unicode command line characters Windows uses UTF-16, while Glib
and GTK use UTF-8. To solve that we retrieve the command line
via __wgetmainargs() and use g_utf16_to_utf8() to convert each argument.
The used method should support wildcards passed as arguments
(e.g. *.xml).
Two new, OS abstracted functions appear in linux.c (NOP), macos.c (NOP),
windows.c:
subsurface_command_line_init(...)
subsurface_command_line_exit(...)
which are being called in main()
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The existing code (both my first single dive delete and then Lubomir's
multi dive delete code) had way too many issues and was just painfully
inefficient.
This new code takes a radically different approach and mostly ignores the
Gtk tree model (as that gets recreated after a delete, anyway) and instead
is linear time on the number of dives in the list. It does do its best to
maintain the existing selection and the expand state of tree model (the
latter isn't possible if we have switched to the list model).
Many thanks to "Lubomir I. Ivanov" <neolit123@gmail.com> for his work on
this - this commit actually contains a few lines out of one of the patches
that he wrote.
Reported-by: "Lubomir I. Ivanov" <neolit123@gmail.com>
Tested-by: "Lubomir I. Ivanov" <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This brings in the code to download dive information directly from a Uemis
Zurich dive computer.
The implementation contains a major hack that hooks the uemis code into
the same data structures used to setup libdivecomputer. This gives the
best result for the user, but is not something that I like as a long term
solution as it relies on internal libdivecomputer data structures.
Especially when asking non-developers for help debugging a problem it can
be extremely useful to have debugging output not go to the console but to
a log file instead.
This just adds the infrastructure to create (and close) such a file. No
changes to the debug output are made.
All this is of course #ifdef'ed out.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The "cylinders_equal()/copy_cylinders()" functions were buggered, and
only checked (and copied) the cylinder type. That was on purpose, since
you do want to be able to change the type of a cylinder without changing
the gasmix of the cylinder.
HOWEVER, the reverse is also true: you may want to change the gasmix of
a cylinder without changing the type.
So it's not that the type of the cylinder is special - it's that the
type and the gasmix should be considered separately.
Do that properly for the equipment editing case.
Reported-by: Ďoďo <dodo.sk@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
If we have no explicit cylinder info at all (it's normal air, no size or
working pressure information, and no beginning/end pressure information),
we don't save the cylinders in question because that would be redundant.
Such non-saved cylinders may still show up in the equipment list because
there may be implicit mention of them elsewhere, notably due to sample
data, so not saving them is the right thing to do - there is nothing to
save.
However, we missed one case: if there were other cylinders that *did* have
explicit information in it following such an uninteresting cylinder, we do
need to save the cylinder information for the useless case - if only in
order to be able to save the non-useless information for subsequent
cylinders.
This patch does that. Now, if you had an air-filled cylinder with no
information as your first cylinder, and a 51% nitrox as your second one,
it will save that information as
<cylinder />
<cylinder o2='51.0%' />
rather than dropping the cylinder information entirely.
This bug has been there for a long time, and was hidden by the fact that
normally you'd fill in cylinder descriptions etc after importing new
dives. It also used to be that we saved the cylinder beginning/end
pressure even if that was generated from the sample data, so if you
imported from a air-integrated computer and had samples for that cylinder,
we used to save it even though it was technically redundant.
We stopped saving redundant air sample information in commit 0089dd8819
("Don't save cylinder start/end pressures unless set by hand").
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Removed start and end in save_cylinder_info(). These two variables are no
longer used.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Merge the dive trip rewrite by Dirk Hohndel.
This just merges the dive trip changes with the timestamp handling
changes. There were multiple small data conflicts, along with some
newly added 'time_t' cases in the dive trip handling that needed to be
converted to 'timestamp_t' along the way.
* 'divetrip-rewrite' of git://github.com/torvalds/subsurface:
Convert FIND_TRIP into function
Partial rewrite of the dive trip code
Check if trip is NULL before calling DIVE_TRIP
The pointer size may not be large enough to contain a timestamp, so make
FIND_TRIP() just pass the pointer to the timestamp instead.
And use an inline function instead of macros with casts. That gets us
proper type safety while at it, so that we get a warning if somebody
doesn't pass the expected "timestamp_t *". Plus the code actually looks
simpler and way more straightforward.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This helps us deal with the issue that the g_list convenience functions
don't allow us to easily compare 64bit values on 32bit architectures. And
since these convenience functions are truly trivial in nature, it seemed
easier to simply implement our own logic here.
In the process I moved all the dive_trip_list helper functions into the
same spot in divelist.c
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This introduces a new data structure for dive trips - reuseing the struct
dive just got way too messy.
The dive_trip_t datastructure now allows the code to remember if the trip
was auto generated or if its time stamp changed when dives where added to
the trip during auto generation.
The algorithm also distinguishes between dives that were intentionally
added to a trip (either in an XML file or by adding them to trip in the
UI) and dives that were added to trips via autogen. Saving dives that were
added to trips via autogen makes that assignment "intentional".
With this partial rewrite several of the oddities of the old code should
be resolved - especially turning autogen on and off again should get the
divelist back to the previous stage.
Also, when dives are merged during file open or import we now try to pick
the correct tripflag (instead of just ignoring the tripflag completely and
resetting it to TF_NONE by mistake).
Finally, the dive trip debugging code got more verbose and is trying
harder to detect issues at the earliest time possible.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This makes the time type unambiguous, and we can use G_TYPE_INT64 for it
in the divelist too.
It also implements a portable (and thread-safe) "utc_mkdate()" function
that acts kind of like gmtime_r(), but using the 64-bit timestamp_t. It
matches our original "utc_mktime()".
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Thanks to Christian for running the static code analysis tool against
subsurface...
There were some false positives, a few style issues that I'll ignore for
now, and two actual potential bugs.
First: Don't check unsigned variables for < 0
This has been around for a while and we are lucky that while technically a
bug it still works as expected. Passing a negative idx simply turns it
into a very large unsigned integer which then fails the > dive_table.nr
test. So it still gets a NULL returned. A bug? Yes. Critical? No.
Mismatched allocation and free
This is an actual bug that potentially could cause issues. We allocate
memory with malloc and free it with g_free. Not good.
Reported-by: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
By now the default file code seems quite matured, so in preparation for
2.0 we'll bring it back into master.
I made a few small clean-ups during the merge, but the merge itself is
very much straight forward.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Several potential problems.
- we could end up dereferencing exiting_filename when it was NULL
- we could free the default_filename by mistake -
subsurface_default_filename always needs to return a copy of it
- closing the existing file before opening a new one repopulated the
existing_filename with the default filename - preventing the opened
file to become the new existing filename
Also, make existing filename a const char * and make file_open have the
same sensible default folder behavior as the other file related functions.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This seems to make sense since we have a pretty strong concept of the "active
file" that we are working on.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Calling edit from the context menu creates a combined editing widget that
contains both dive info and equipment. When editing cylinders or
weightsystems from that widget and confirming those edits with OK those
changes were already committed to the current_dive - regardless on which
dive the user clicked. Worse, even when the user clicked Cancel in the
edit widget, any changes to the equipment stayed in effect.
This had especially confusing consequences when editing multiple dives.
As a workaround this commit adds a global edit_dive variable. This fake
dive is edited by the secondary editing widgets and if the user accepts
changes with OK then they are copied over to the current dive (or all
selected dives in multi dive editing mode).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Display yearly statistics in a statistics window with option to expand
the viewing on monthly level. The amount of dives along with basic
information like duration, depth, water temperature and air consumption
is displayed in yearly and monthly level. Thus you are able to compare
e.g. development of air consumption or diving activity from year to
year.
Using already existing macro for splitting seconds into minutes:seconds.
Moving repetitive code to a function (couldn't think of the suggested
clever macro, but this should pretty much do the trick).
Now the statistics are updated every time the process_all_dives function
is called. It might make sense to actually verify the structures need to
be re-allocated, but such optimization is currently not implemented.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Combined two commits.
Minor cleanups for white space and boolean values.
Significant changes to use the correct units for volumes vs. depths and to
avoid unneccesary lookups of the model storage based on the tree.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Previously we always picked the last file that was openend as the file
name to save to. That seems counterintuitive when importing files or when
opening multiple files. Especially if Subsurface was executed without a
file on the command line and we are using the default file.
Now we only remember a file name if it was the first one to ever be
openend or if it was used in save-as.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The default file name is OS specific and tries to follow the customs on
each of the OSs. It can be configured through the preferences dialog.
On MacOS we get a strange warning which appears to be a well documented
Gtk bug on MacOS.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
There is an interesting issue when adding new dives into a dive list with
existing trips. Since fill_dive_list walks the list backwards and trips
are determined by the timestamp of the first dive in a trip, it is
non-trivial to know when a dive is added if it should be part of an
existing trip or not. Let's say when we see the dive we can also see a
trip entry that starts four days earlier. Without looking forward in the
list of dives we cannot tell if this is a multi-day trip that this dive
would fit into, or if there is a break of more than tree days (our current
trip threshold).
Instead this commit adds a second scan of the dives in chronological order
that does the right thing for new dives.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
When inserting a trip into the dive_trip_list we already check for
duplicate trips, but we still kept the additional dive_trip around.
With this change we instead replace it with the existing one.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Now that we can load and store trips we needed to add the capability to
manipulate those trips as well.
This commit allows us remove a dive from a trip via a right click
operation on the dive list.
The commit also adds code to split a trip into two, to merge two trips and
to create a new trip out of a top level dive.
To make all that useful this commit changes the right-click on the dive
list to identify and act on the record we are actually on (instead of
acting on the selection).
The right-click menu ("context menu") changes depending which divelist
entry the mouse pointer is on - so different operations are offered,
depending on where you are.
We also add simplistic editing of location and notes for a trip (but the
notes are never displayed so far).
To make our lives easier this commit adds a link from the dive to the dive
trip it is part of. This allowed to hugely simplify the auto trip
generation algorithm (among other things). The downside of this change is
that there are now three different ways in which we express the
relationship of dives and trips: in the dive_trip_list, in the tree_model,
and with these pointers. Somehow this screams that I should rethink my
data structures...
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
In preparation for the next stage of the trips handling this commit makes
the macros used to access trips (and some frequently used variables for
the tree and list models) more consistent.
This also changes the way we display un-grouped dives in the dive list,
i.e. dives that are not part of a dive trip. Their dive number is now
printed bold.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Merge the initial 'track trips explicitly' code from Dirk Hohndel.
Fix up trivial conflicts in save-xml.c due to the new 'is_attribute'
flag.
* 'trips' of git://git.hohndel.org/subsurface:
Fix an issue with trips that have dives from multiple input files
Some simple test dives for the trips code
First cut of explicit trip tracking
The existing code didn't handle the case of different trips for the same
date coming from different sources. It also got confused if the first dive
processed (which is, chronologically, the last dive) happened to be a
"NOTRIP" dive.
This commit adds a bit of debugging infrastructure for the trip handling,
too.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>