aboutsummaryrefslogtreecommitdiffstats
path: root/divelist.c
AgeCommit message (Collapse)Author
2013-02-08Add maxdepth back to the dive structureGravatar Dirk Hohndel
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>
2013-02-08Do more dive fixup for each dive computerGravatar Linus Torvalds
In commit b6c9301e5847 ("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>
2013-02-09Clean up the handling of surface pressureGravatar Dirk Hohndel
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>
2013-02-08Duration of a dive is the maximum duration from all divecomputersGravatar Dirk Hohndel
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>
2013-02-08Properly de-select dives in collapsed trips that are unselectedGravatar Linus Torvalds
We had the logic for the "select" case, but not for the "deselect" case. Ugh. Reported-by: Dirk Hohndel <dirk@hohndel.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-03Fixing SP handling in planner, adding eventGravatar Jan Schubert
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>
2013-02-02Add 'Save As' entry to context menu shown when right clicking on a diveGravatar Pierre-Yves Chibon
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>
2013-02-01Move flag icon to include fileGravatar Dirk Hohndel
Just like with the satellite icon we are creating a pixdata structure for the flag. The Makefile cleanup in commit df6a9ddd8a21 ("Auto-generate C file dependencies, and make the build more quiet") removed the rules for generating the .h file by mistake (I hope). This adds a more generic rule back in and also makes sure that the data structures get more useful names. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-01When switching sort order, scroll the dive list to the current diveGravatar Linus Torvalds
Now that we actually seem to understand the whole notion of setting the active dive, let's take that code a bit further, and always scroll to it when we're introducing a new sort ordering. Sure, there may be other selected dives, but we have one primary (current) dive that we show the profile and dive data for, and when we switch sort order we probably want to see that dive in the dive list. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-31Make sure that the planned dive is selectedGravatar Dirk Hohndel
With the changes to the selection logic the selected_dive variable didn't get updated at the end of planning a dive. With an empty dive list that could cause selected_dive to be -1 which would subsequently cause a SIGSEGV when trying to edit the newly created dive. With this commit we use the shared go_to_iter() function and also make sure that selected_dive is set correctly. Reported-by: Sergey Starosek <sergey.starosek@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-31Make the dive selection logic also set the treeview cursorGravatar Linus Torvalds
This fixes "enter" after moving around with the cursor keys. Hinted-at-by: Carl Worth <cworth@cworth.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-31Better algorithm to merge gps locations & locations names from webserviceGravatar Dirk Hohndel
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>
2013-01-30Fix segfault pressing Menu keyGravatar Henrik Brautaset Aronsen
Pierre wrote: "On my keyboard I have a key on the right side of the space bar, between the alt+gr key and the right ctrl which most of the time emulates the right mouse click. If I press this button on subsurface, I end up with: Segmentation fault (core dumped) This whatever the selection and nicely always reproducible." This patch doesn't make the key work, but it fixes the segfault. Reported-by: Pierre-Yves Chibon <pingou@pingoured.fr> Debugged-and-acked-by: Sergey Starosek <sergey.starosek@gmail.com> Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-30Massive cleanupGravatar Dirk Hohndel
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>
2013-01-30Make the selection logic more robustGravatar Dirk Hohndel
In commit 304526850c91 ("Don't deselect all dives on all selection "change" events") the handling of "selected_dive" is incorrect. We ended up with non-sensical values for the selected dive, including dives that Gtk didn't think were selected. This commit tries to be smart about what to do when the dive that we currently consider selected is unselected (we have this weird notion of many dives being selected, but one of them is shown in the profile and that is the "selected_dive"). As long as there are others selected, we pick one of them (first walking to earlier dives and if there are none that are selected, looking for a later dive) as the new selected dive. This appears to give us a rather intuitive behavior when playing with multiple selected dives. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-30Don't deselect all dives on all selection "change" eventsGravatar Linus Torvalds
gtk sends the selection change events all the time, for pretty much any "divelist changed - so selection changed". The expansion of a trip, the switch to a new model, yadda yadda. But we actually want selections to be sticky across these events, so we can't just forget all of our old selection state and repopulate it. So we re-introduce the "am I allowed to change this row" callback, which we used to use to create a list of every actual selection that was changed. But instead of remembering the list (and having the stale entries issue with that remembered list that caused problems), we now just use that as a "that *particular* selection cleared" event. So this callback works as the "which part of the visible, currently selected state got cleared" notifier, and handles unselection. Then, when the selection is over, we use the new model of "let's just traverse the list of things gtk thinks are selected" and use that to handle new selections in the visible state that gtk actually tracks well. So that logic handles the new selections. This way, dives that aren't visible to gtk don't ever get modified: gtk won't ask about them being selected or not, and gtk won't track them in its selection logic, so with this model their state never changes for us. gtk selections are annoying. They are simple for the case gtk knows about (ie they are *visually* selected in the GUI), but since we very much want to track selection across events that change the visual state, we need to have this insane "impedance match". Reported-by: Dirk Hohdnel <dirk@hohndel.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-30Fix cursor up/down logicGravatar Linus Torvalds
The dive selection rewrite didn't set the selected dive index, breaking the cursor key logic. Reported-by: Dirk Hohndel <dirk@hohndel.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-28Rewrite gtk dive selection tracking logicGravatar Linus Torvalds
We used to generate a list of possibly changed selections using the gtk tree selection "selection function". But that's actually meant to just tell gtk whether an entry can be selected or not, and our list of possibly changed entries ended up being stale if the selection change was due to a list entry removal, for example. So rip out the old model entirely, and instead just walk the whole selection that gtk gives us on a selection "change" event. We throw all our old selections away when this happens, and just rebuild it all. This should fix the occasional internal gtklib-quartz assertion that Henrik is seeing. And it actually simplifies the code too. 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>
2013-01-28Make dive planner more useful for closed circuit divingGravatar Dirk Hohndel
Add a sample at time 0 to allow for a pO2 from the start of the dive. Remember the last pO2 so it doesn't have to be repeated (and the right thing happens for the planned part of the dive). This still doesn't allow us to change the setpoint at a certain depth (which would be analogous to being able to switch to a certain gas at a certain depth in OC plans), but with this commit it's already usable. This commit also fixes a couple of small bugs in commit b8ee3de870fa ("Dive planning for closed circuit rebreather") where a pO2 of 1.1 was hardcoded in one place, throwing off all plan calculations and integer math was used to calculate a floating point value (leading to most pO2 values actually used being 1.0). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-28Dive planning for closed circuit rebreatherGravatar Jan Schubert
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>
2013-01-28Pick GPS coordinates of dive location via map widgetGravatar Dirk Hohndel
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>
2013-01-25Fix potential uninitialized variable accessGravatar Dirk Hohndel
There are paths through this function that reach the comparison at the end of it without trip_a and/or trip_b being initialized. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-25Small fix for a possible crash in divelist.cGravatar Lubomir I. Ivanov
divelist.c:copy_tree_node(): pass the pointer "icon" to gtk_tree_store_set() Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-23Fix setting of the dive_table.preexisting logicGravatar Linus Torvalds
The 'preexisting' value is used for downloading dives: we want to add new dives but, but then compare those new dives against the preexisting ones before we start sorting things and possibly merging them. However, the value was only updated sporadically, resulting in it having stale information in it. Which would cause problems particularly if you deleted dives, so that the preexisting value would point past the actual existing values! So just update it unconditionally in dive_list_update_dives(), which anything that changes the dive list is supposed to call in order to display the changes anyway. Also, just for safety, when removing a dive, put NULL in the last dive table location. Nobody should ever access past the end anyway (this is enforced by 'get_dive()') but there are places that access the dive list table directly, and the libdivecomputer download was one of those. No reason to leave stale dive pointers possibly around for uses like that. 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>
2013-01-23Move more dive computer filled data to the divecomputer structureGravatar Linus Torvalds
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>
2013-01-23divelist.c:icon_click_cb(): check if a GtkTreePath is foundGravatar Lubomir I. Ivanov
In icon_click_cb() we need to check if a correct GtkTreePath is found (using gtk_tree_view_get_path_at_pos()) before requesting a GtkTreeIter for it. Without this patch a bug is reproducible, where the user may click outside of the GtkTreeView entries, but still in the GtkTreeView - e.g. when only one entry is available. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-22Use proper helper functions for dive location and for_each_diveGravatar Linus Torvalds
This makes the code use the "dive_has_location()" function rather than check the longitude and latitude directly. It also uses "for_each_dive()" rather than open-coding it. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-22Fix crash when clicking on icon column in trip header entriesGravatar Dirk Hohndel
Silly oversight. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-22Add GPS icon to the location column for dive sites where we have GPS dataGravatar Dirk Hohndel
This replaces the really lame "italics text" from commit abe810ca1a29 ("Mark locations that have GPS location data attached") with a marginally less lame GPS icon.There's a reason why I am not making a living as graphics artist. But I think this is a huge step forward from what we had before... The satellite.svg file is very loosely based on a different icon that I found as public domain here http://www.clker.com/clipart-30400.html. From that I created the PNG and then that was converted into the GdkPixdata via gdk-pixbuf-csource; a rule for that was added to the Makefile but commented out as I don't know if this tool will always be available in the path. Having this icon included in the sources avoids locating yet another icon file. Better icons are certainly welcome! Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-20Mark locations that have GPS location data attachedGravatar Dirk Hohndel
This is rather lame - we simply turn the location text into italics for those dives where we have GPS location data. Underlining might be more natural, but Gtk plays games with the underline attribute if the mouse hovers over text. Ideally I would have prefered a little GPS logo next to the location text - but I couldn't figure out how to do that without writing my own cell renderer which seemed total overkill. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-17Hack Makefile, gtk-gui.c and divelist.c to allow building w/o osm-gps-mapGravatar Dirk Hohndel
While we are waiting for an autotools generated Makefile, this should allow people to build that don't have osm-gps-map. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-16Only offer to show dive on map if we have location informationGravatar Linus Torvalds
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>
2013-01-15Show single dives in map.Gravatar Henrik Brautaset Aronsen
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>
2013-01-14Centralising and redefining values as integersGravatar Jan Schubert
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>
2013-01-13Scroll the divelist to show the planned diveGravatar Dirk Hohndel
Just put the code to do so in a function and reuse that function elsewhere as well. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-13Correctly show the planned dive in the divelistGravatar Dirk Hohndel
Previously we would simply show the first dive in the divelist - which worked fine in the default sort by trip setting and assuming that there are no dives from the future in the divelist. With this commit we actually find the correct dive in the divelist and select it instead. If you sort by depth you will see the dive move around in the divelist, but it will stay selected and visible in the profile. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-13Make sure init_decompression works for dive 0 as wellGravatar Dirk Hohndel
The loop would actually get entered for dive 0 and try to compare things with dive -1. Which of course fails. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-13During multi-dive deco calculations don't look at dives from other tripsGravatar Dirk Hohndel
Previously the code in init_decompression() would mindlessly walk back the dive_table until it found a gap of at least 48h and take all those dives into consideration when calculating tissue saturation. This goes horribly wrong if you load dives from two divers into the same data file. With this commit things will still turn out correctly, as long as the dives are in separate trips in for each of the divers. So with this I can load both Linus' and my divelog and things stay sane even on our shared dive trips. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-11Add default filename and divelist font to prefs structureGravatar Linus Torvalds
.. 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>
2013-01-10Split up preference data structure definition into 'pref.h'Gravatar Linus Torvalds
.. 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>
2013-01-09Clean up duplicated depth interpolationGravatar Linus Torvalds
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>
2013-01-08Rewrite of the deco codeGravatar Robert C. Helling
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>
2013-01-07Improve dive trip sort comparison functionGravatar Linus Torvalds
We do want to compare "loose" dives too, but we need to be a bit careful, and always use the trip date as the primary sort key for any dives that are not in the same trip. Reported-and-tested-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06Display dive profile of the dive we plan, as we plan itGravatar Dirk Hohndel
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>
2013-01-04First stab at simplistic dive planningGravatar Dirk Hohndel
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>
2013-01-04Clean up DEBUG codeGravatar Dirk Hohndel
It's still a mess (and the symbols aren't used consistently), but it's a tiny bit more logical... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-04Fix deco calculations to correctly use GF values and add CC supportGravatar Dirk Hohndel
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>
2013-01-03Merge branch 'deco2'Gravatar Dirk Hohndel
Bringing in the first attempts to do our own deco calculations
2013-01-03Improvements to select_prev_dive() and select_next_dive()Gravatar Lubomir I. Ivanov
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>
2013-01-03Consider previous dives when calculating decoGravatar Dirk Hohndel
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>