There should be NO other changes in this commit - just moving the code and
adjusting the includes (and adding the entry point to display-gtk.h).
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>
When incrementally building dives with gas changes there are still some
serious issues and inconsistencies. But at least now the gases in the dive
we create appear to be correct.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Now that the pressure_time calculations are done in our "native"
integer units (millibar and seconds), we might as well keep using
integer variables.
We still do floating point calculations at various stages for the
conversions (including turning a depth in mm into a pressure in mbar),
so it's not like this avoids floating point per se. And the final
approximation is still done as a fraction of the pressure-time values,
using floating point. So floating point is very much involved, but
it's used for conversions, not (for example) to sum up lots of small
values.
With floating point, I had to think about the dynamic range in order
to convince myself that summing up small values will not subtly lose
precision.
With integers, those kinds of issues do not exist. The "lost
precision" case is not subtle, it would be a very obvious overflow,
and it's easy to think about. It turns out that for the pressure-time
integral to overflow in "just" 31 bits, we'd have to have pressures
and times that aren't even close to the range of scuba cylinder air
use (eg "spend more than a day at a depth of 200+ m").
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
I fixed the pressure-time calculations to use "proper" units, but
thinking about it some more, it turns out that units don't really
matter. As long as we use the *same* unit for calculating the
integral, and then re-calculating the step-wise entries, the units
will cancel out.
So we can simplify the "pressure_time()" function a bit, and use
whatever units are most natural for our internal representation. So
instead of using atm, use "mbar".
Now, since the units don't matter, this patch doesn't really make much
of a difference conceptually. Sure, it's a slightly simpler function,
but maybe using more "natural" units for it would be worth it. But it
turns out that using milli-bar and seconds has an advantage: we could
do all the pressure_time integral using 32-bit integers, and we'd
still be able to represent values that would be equivalent to staying
at 24 bar for a whole day.
This patch doesn't actually change the code to use integers, but with
this unit choice, we at least have that possibility.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This splits up the function to create the estimated pressures for
missing tank pressure information.
The code now has a separate pass to create the beginning and ending
pressures for segments that lack them, and fill them in to match the
overall SAC-rate for that cylinder.
In the process, it also fixes the calculation of the interpolated gas
pressure: you can see this in test-dive 13, where we switch back to the
first tank at the end of the dive. It used to be that the latter
segment of that cylinder showed in a different color from the first
segment, showing that we had a different SAC-rate. But that makes no
sense, since our interpolation is supposed to use a constant SAC-rate
for each cylinder.
The bug was that the "magic" calculation (which is just the pressure
change rate over pressure-time) was incorrect, and used the current
cylinder pressure for start-pressure calculation. But that's wrong,
since we update the current cylinder pressure as we go along, but we
didn't update the total pressure_time.
With the separate phase to calculate the segment beginning/ending
pressures, the code got simplified and the bug stood out more.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The code was using bar, not atm to calculate the pressure_time
multiplier. But SAC-rate is relative to atm.
We could do the correction at the end (and keep the pressure_time in
"bar-seconds"), but let's just use the expected units during the
integration. Especially since this also makes a helper function to do
the calculations (with variables to keep the units obvious) instead of
having multi-line expressions that have the wrong units.
This fixes what I thought were rounding errors for the pressure graphs.
They were just unit confusion.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This splits up the (very complex) function that calculates all the plot
info data, so that the gas pressure logic is in several helper
functions, and the deco and partial pressure calculations are in a
function of their own.
That makes the code almost readable.
This also changes the cylinder pressure calculations so that if you have
manually set the beginning and end pressures, those are the ones we will
show (by making them fake "sensor pressures"). We used to shopw some
random pressure that was related to the manually entered ones only
distantly (through various rounding phases and the SAC-rate calculations).
That does make the rounding errors more obvious in the graph, but we can
fix that separately.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
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>
This was added in commit 594da00612ab "Do a minimal hook-up of the dive
plan tree view to the actual planning" and has been replaced by a
different UI in subsequent commits. No point in keeping it around.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This simplifies - and improves - the code to generate the plot info
entries from the samples.
We used to generate exactly one plot info entry per sample, and then -
because the result doesn't have high enough granularity - we'd
generate additional plot info entries at gas change events etc.
Which resulted in all kinds of ugly special case logic. Not only for
the gas switch, btw: you can see the effects of this in the deco graph
(done at plot entry boundaries) and in the gas pressure curves.
So this throws that "do special plot entries for gas switch events"
code away entirely, and replaces it with a much more straightforward
model: we generate plot entries at a minimum of ten-second intervals.
If you have samples more often than that, you'll get more frequent
plot entries, but you'll never get less than that "every ten seconds".
As a result, the code is smaller and simpler (99 insertions, 161
deletions), and actually does a better job too.
You can see the difference especially in the test dives that only have
a few entries (or if you create a new dive without a dive computer,
using the "Add Dive" menu entry). Look at the deco graph of test-dive
20 before and after, for example. You can also see it very subtly in
the cylinder pressure curves going from line segments to curves on
that same dive.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
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>
GTK's logic might be a bit flawed (or complicated) in terms of
"focus-out-event" and GtkComboBoxEntry objects as it does not work
by attaching said signal type directly to the GtkComboBoxEntry.
Perhaps it only makes sense for text input.
Since "focus-out-event" works for GtkEntry, we can retrieve the child
GtkEntry from the combo using gtk_bin_get_child(GTK_BIN(combo)
and attach the event handler to that.
This change should make it possible to update gas_model (GtkListStore)
when changing the widget focus with both the keyboard and mouse clicks.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Once again Gtk does everything it can to make our lives miserable. It
requires major hackery to be able to add new gases to the drop down lists
"on the fly". Right now this only works if you edit the gas and then use
Tab to move to the next field.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Just after pushing out the last set of changes I had one more idea what I
could try. And of course that was it. Don't queue up a redraw. Simply run
gtk_widget_show_all on the dialog! That does the trick.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Linus' treeview for the plan input is just too ugly for words. And doesn't
work, either.
So let's go with plan C: a table of waypoint entries. Depth, duration (or
absolute time), and gas used. The gas is a combobox that does completion.
I am reusing Linus' validation functions / parsers.
This works if you can fit your dive into the four waypoints that are there
by default. The add waypoint button is hooked up but even though it does
what I think should modify the dialog that is currently displayed that
clearly doesn't work.
But at least it "mostly" works and isn't as horrifyingly uggly as the
first two attempts.
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 doesn't actually do the real work yet, but it creates all the
infrastructure to edit a tree model, and verify the contents for time,
depth and gas mix.
Now we just need the ability to add entries to the tree model (this adds
one fake one, just to test the editing), and then read out the final end
result and turn it into a plan.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This is not doing anything (which is why there are so many unused variable
warnings). It's just a couple of entries lined up to give a visual
impression how some of this could look.
I am not a UI designer. And there are good reasons for that...
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The ceiling calculations for the gradient factors still had a 3m increment
hardcoded. This is now also conditional on the smooth parameter.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
For dives with no samples, we crate a fake dive computer with a set of
made-up samples and use those to display the profile.
However, the actual calculations to do the maximum duration and depth
etc were always done with the "real" dive information, which is empty.
As a result, the scale of the plot ended up being bogus, and part of
the dive would be missing.
Trivially fix by just passing the same dive computer information to
calculate_max_limits() that we use for everything else.
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>
Without this the cairo_close_path call could do silly looking things
(intersecting polygons...).
Reported-by: "Robert C. Helling" <helling@atdotde.de>
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>
This seems like a strange way to capture the FOCUS_CHANGE event, but
manually trying to register a callback for it fails. Yet registering a
callback for every event and then filtering for FOCUS_CHANGE in the
callback works. Go figure.
But with this commit you can actually change the GF settings in the
preferences dialog and once you tab out of the entry field the change gets
immediately applied - nice to play with the effects of changing GF values.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
There were some minor problems when moving the selection
cursor around:
1) If the selection was larger than 1, it was possible
for the selection to get "stuck" in the middle of the list.
This patch approaches this by always calling
gtk_tree_selection_unselect_all() before
gtk_tree_selection_select_iter(), or simply always making
sure we have one selected iterator when navigating with the keys.
2) When there was a single top level dive before the first trip
it wasn't possible to navigate trough the child dives of said
trip in both directions.
The patch attempts to fix this by having the hunks/checks:
if (idx < 0) {
(idx is of a trip) performed regardless of other conditions.
*** Note: testing was done by importing all test*.xml
dives with auto-group on.
[Dirk Hohndel: adjusted the patch to also fix on_key_press to only grab
the key if no modifier key is pressed; otherwise this
breaks shift-cursor-keys for selecting multiple dives.]
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
If we print out the pressure difference (because we do not have a cylinder
size), we didn't initialize the precision. We should print out pressures
without decimals.
The attached patch fixes that, and also avoids a NULL pointer printout
(which on Linux will just print out "(null)") if there is no cylinder
type descriptor string. It also cleans things up a bit and uses the
"cyl" pointer instead of repeating the "dive->cylinder[n]" thing.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
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>
This is on top of the deco information reported by the dive computer (in a
different color - currently ugly green). The user needs to enable this via
the Tec page of the preferences.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The cylinder information in the printouts was wrong in many ways. As
Dirk noted, it didn't work at all for air-integrated computers that
had the pressures in the samples, but the math was also confusing and
wrong.
This should fix it.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This function had a couple of bugs. Two different off by one errors and on
top of that it was matching only the deviceid instead of model and
deviceid.
So I simply rewrote it to match against the full pattern and take a much
more straight forward approach to replacing the entry for the divecomputer
under consideration. If the new nickname is entry this implementation
allocates one extra byte - but that didn't seem worth the extra code to
fix it.
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>
And include the compatibility header to build on newer versions.
Reported-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
In commit 96db56f89c ("Allow overlapping (and disjoint) dive trips")
I allowed dives to be part of arbitrary dive trips regardless of date,
which meant that the divelist tree model code needed to find the right
parent for a dive as it was inserted.
That code stupidly assumed that the top level of the dive list tree
containted *only* trips, which is not at all the case. It happens to
be true if you group all your dives into divetrips (the common case
for autogroup=1, which real users do tend to have), but now that Dirk
made the autogrouping be a per-xml-file setting, it became much easier
to trigger the "mixed trips and non-trip dives" case, and that showed
the stupid bug with the test dives.
So instead of just blindly iterating to the 'n'th entry, search for
the actual entry that is the dive trip we want to associate a dive
with.
Reported-by: Lubomir Ivanov <neolit123@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This patch will convert a heading bookmark to Subsurface format.
Suunto's bookmark uses "Heading: <degrees>°" format and was previously
set as the full event name. Now the resulting event will look like:
<event name="heading" value="333" time="0:58 min"/>
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This patch makes the divelist behave more as you would expect it as you
scroll up and down through its entries.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
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>
When called from the parser the model string is freed right after passing
it to remember_dc. So we need to get our own copy.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Right now this isn't used but it will be needed for the yet to be written
UI to manage our divecomputer database.
This commit also fixes an oversight in the remember_dc function. Updates
to nicknames weren't committed to the config.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The existing code had the somewhat retarded Ctrl-C binding for displaying
the next divecomputer and no way to go back to the previous one. With this
commit we use our keyboard grab to map Left and Right to previous and next
divecomputer. Much nicer.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>