Commit graph

97 commits

Author SHA1 Message Date
Dirk Hohndel
18b8247cb3 Add new helper function to get temperature and unit
Designed along the lines of get_depth_units - except we don't define a
specific number of digits to show.

Use this in the one spot we need it right now in profile.c

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-11-01 19:52:12 -07:00
Linus Torvalds
ceed8b6bc9 Fix up end conditions for dives
We used to have the dive plot have two "filler" entries at the beginning
and the end, and indeed that is how they are allocated.  However, we fix
up "pi->nr" later to be "lastindex+1", where "lastindex" is the index of
the time we surface.

So when we loop over the plot entries, we actually need to loop all the
way to the end: use "i < pi->nr" instead of "i < pi->nr-2".

We still do have the two extra filler entries at the beginning, though.
So depending on the loop, we might want to start at entry 2.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-10-29 15:57:26 -07:00
Linus Torvalds
7c1deb37c7 Plot fake profile for non-sample dives
Right now it just plots something ridiculous, the code is really just
meant to be an example.  We migth be able to plot a traditional
staircase plot and make it look somewhat saner by taking mean depth into
account (if it exists).

Right now it just plots a (skewed) rectangular dive profile using the
max depth and total time. Which is obviously insane.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-10-29 14:09:27 -07:00
Linus Torvalds
b74cc4f523 Fix use of uninitialized variable if there are no samples
When creating the plot_info, the 'entry' variable pointing to the last
plot_info data was not initialized (because there was no data to fill
in), and was then incorrectly used to fill in the last tank pressure.

We also used to look at 'dive->sample[0].cylinderindex' even if no
sample[0] necessarily existed.

Reported-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-10-29 13:24:56 -07:00
Dirk Hohndel
98efa0794a Add menu item and dialog to select which events to display
Right now they are displayed in one hbox which doesn't work if you have
many events - but the code itself works and correctly toggles the events
on and off.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-25 02:51:16 -07:00
Dirk Hohndel
499cc0c87c Don't plot an event if an event is disabled in ev_namelist
We don't have a way to actually configure this in the app, yet, but
toggling the bits in the debugger shows that this works, so commit this
code now.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-25 01:25:12 -07:00
Dirk Hohndel
5ca49b0460 Remember the event names as we encounter them
First step to being able to filter the events that we display in the
profile. We could (in theory) walk all the dives in the divelist when we
need this data, but it seems much more convenient to have them in an array
in one place.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-25 01:05:08 -07:00
Linus Torvalds
a72408400c Merge branch 'ui' of git://github.com/dirkhh/subsurface
* 'ui' of git://github.com/dirkhh/subsurface:
  Disable sorting by dive number
  Fix oversight in preference implementation
  Make columns for temperature, cylinder, and nitrox optional
  Show dive number in dive list
  Improve time marker handling and add printing of some time labels
2011-10-24 07:03:22 +02:00
Dirk Hohndel
86fdd83e7b Improve time marker handling and add printing of some time labels
We now draw time markers at most every 5 min, but no more than 12 markers.
For convenience we do 5, 10, 15 or 30 min intervals.
This allows for 6h dives - enough (I hope) for even the craziest divers -
but just in case, for those 8h depth-record-breaking dives, we double the
interval if this still doesn't get us to 12 or fewer time markers.

We label the first and then every other time marker with the minute text.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-23 08:04:54 -07:00
Linus Torvalds
2b4fa480ae Handle 'gas change' events correctly
Dirk wrote the multi-cylinder support assuming that the dive computer
always gives the selected cylinder index in the sample data - that's
what his Uemis does, and it makes sense for any dive computer that
supports multiple pressure transmitters.

However, the other case is a dive computer where the pressure samples
are all from cylinder 0, and any other cylinder will have the starting
and ending pressure set by hand.  And the gas change events show when
the cylinder change happened.

So this creates a "turn gas change events into pressure sample fixups"
phase just before we actually analyze the pressures.  That way the
pressure analysis can alway sdo the right thing, regardless of how the
data was originally stores in the dive.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-10-23 18:01:30 +03:00
Linus Torvalds
2b2b6775de Split the cylinder pressure analysis into a second loop
For the dive computers that give cylinder change events, we want to
re-write the cylinder index and pressure information with the event
information before we start analyzing the pressures.  So instead of
filling the plot info and analyzing in one loop, split it up into two
phases.  We'll do the "fix up cylinder pressure info based on events" in
between those phases.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-10-23 18:01:16 +03:00
Dirk Hohndel
473fb14b56 Plot tank pressures for multiple tanks
The code keeps track of the segments of time when a specific tank was used
and interpolates the pressure values for that tank based on a simulated
average SAC rate for the times in which no pressure readings are
available.

This changes the way we used to plot the pressure when only beginning and
end pressure of a tank are known; it used to be a straight line, now it is
a sloped line where the steepness of the slope is proportional to the
depth at that point - which is much more realistic.

We also plot the pressures in two colors now. The old green for pressure
data that came from the input file (that is not the same thing as saying
it came from the computer - divelog for example appear to create pressure
readings in the samples even if it only has beginning and end pressure).
Interpolated values are plotted in yellow. If you have a sub-standard dive
computer which has a frequently failing pressure sensor, you can now tell
the parts of the plot where data was missing and we are filling in.

The function that prints the pressure text labels had to be completely
redone as it previously assumed one tank for the whole dive and
simplisticly printed that tank's start and end pressure at the beginning
and end of the profile plot with the y-values being the maximum and
minimum pressure...

This commit introduces a custom simplistic single linked list data
structure to keep track of the pressure information per segment - Linus
hated the idea of using GList for this purpose, and I have to admit that
in the end this was very straight forward to implement and made the code
easier to read and debug.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-23 05:30:33 -07:00
Dirk Hohndel
bf1dc48dfe Change plot_info to use depth (instead of val) for depth value
Also changed a couple of corresponding local variables

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-22 23:03:23 -07:00
Linus Torvalds
e919a0f2ea Add quick hack for "no sample pressure but tank index changed" case
This isn't right if you switch back to the same cylinder multiple times,
but for the first time it kind of works - just take the beginning
cylinder pressure if we have one.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-10-20 22:25:38 +03:00
Linus Torvalds
45d4d5ecde Fix up multi-cylinder code as per Dirk
Too much cut-and-paste, as Dirk points out.  With multiple cylinders,
we're not necessarily going to start at time zero.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-10-20 13:55:55 +03:00
Linus Torvalds
0a33d0bd7d Start some rough multi-cylinder pressure data plot infrastructure
It doesn't actually do multiple cylinders correctly yet, but it should
be a nice framework for it.  And accidentally (not) it also ends up
drawing the final line for the end pressure of a single-cylinder dive
that has been fixed up by hand too.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-10-19 09:47:46 -07:00
Dirk Hohndel
d78e6a4876 Change event symbol to bigger yellow triangle with exclamation point
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-04 15:14:54 -07:00
Dirk Hohndel
53f809ccca Replace event text with small red triangle and tooltip
We draw a little red triangle (of hardcoded size - not sure if this SHOULD
scale with the size of the plot... I like it better if it doesn't) to the
left of an event.

We then maintain an array of rectangles that each circumscribe one of
those event triangles and if the mouse pointer enters one of these
rectangles then we display (after a short delay) a tooltip with the event
text.

Manually creating these rectangles, maintaining the coordinate offset,
checking if we are inside one of these rectangles and then showing a
tooltip... this all seems like there should be gtk functions to do this by
default... but if there are then I failed to find them. So instead I
manually implemented the necessary logic.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-04 12:27:55 -07:00
Dirk Hohndel
b72ade0e78 Change plot routine to take a drawing_area as argument
Previously we passed in width and height and the routine itself decided to
keep 5% margin around each edge - oddly doing this with double precision,
even though this is all integer coordinates.

Instead we are now passing in a drawing_area. We are kind of abusing the
cairo_rectangle_int_t data type here - but it seemed silly to redefine a
new data type for this.
Width and height give the size of the TOTAL drawing area (as before).
x and y give the offset from the edges - so the EFFECTIVE drawing area is
width-2x and height-2y
This is in preparation for adding tooltips - those need to know the
coordinate offsets from the edges - so having this hard coded inside the
plot function didn't make sense anymore.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-04 12:14:26 -07:00
Dirk Hohndel
c487ea055d Distinguish internally between min pressure and end pressure
And don't artificially end dives on min pressure

This may be a problem for dive computers like Linus' Suunto Vyper Air
where the failure mode seems to be _high_ pressure readings (that's scary,
btw). If the transmitter fails at the end of the dive the pressure plot
ends with incorrect high pressure. But that's simply a bug with the dive
computer and not something that subsurface should hack around. Maybe we
should offer a way to edit the incorrect data points instead.

Always ending on the minimum pressure is definitely wrong as it causes
bogus plots when you do a valve shutdown during the dive (which means that
valid data gets plotted incorrectly).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-30 06:49:24 -07:00
Dirk Hohndel
ab3c6731be Fix the profile coloring
We were missing the last sample (which is usually a fast ascent).
Also, reduced the velocity smoothing to 15 seconds as the 30 seconds were
hiding too much valid information

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-29 22:53:03 -07:00
Dirk Hohndel
912ce7941f Remove average depth from print
It looks confusing in black and white

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-28 15:53:16 -07:00
Linus Torvalds
bd0f274771 Show events on the dive profile
This is *really* ugly.  We really should just create some kind of widget
that when moused over will show the event.  Or something.  Rather than
putting text on top of other text: the events - when they happen - are
usually bunched together (PO2 warnings, max depth, fast ascent leading
to mandatory safety stop, you name it).

But at least this way we see that the data is there, even if we see it
in ugly ways.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-22 21:15:36 -07:00
Linus Torvalds
515a917152 Add helper function for doing depth unit calculations
.. and use it for printing too.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-21 12:12:54 -07:00
Linus Torvalds
fcc7a01c6e Fix array underrun when calculating velocity
That code is messy. And it was buggy. Noticed by valgrind.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-21 08:29:08 -07:00
Linus Torvalds
6eefcf40e6 Fix 'struct plot_info' memory leak
The plot_info was never freed, so every time you'd plot something, we'd
leak memory.

I'm running valgrind to see if there's anything bad going on.  So far it
all looks fairly benign.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-20 22:47:12 -07:00
Linus Torvalds
957aaf619f Fix up printing some more
Use the actual degree sign for temperatures (°F and °C), and make sure
everything uses the proper "set_source_rgb[a]()" wrappers to set the
colors.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-20 17:56:56 -07:00
Linus Torvalds
368623113c Print out only simplified depth profile
None of the colors, nothing like that.  Just a gray fill and a plain
black depth line.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-20 17:24:10 -07:00
Linus Torvalds
9cfe9aa8cd Clean up and simplify depth plot
Dirk wrote this before we have the 'plot_info' structure with the
cleaned-up dive info.  No need to maintain that separate array of depths
and seconds.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-20 17:17:30 -07:00
Linus Torvalds
e276b0602b Don't show the smoothed dive profile or the min/max info
It was good for debugging, it's not something we really want to show people.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-20 16:45:33 -07:00
Dirk Hohndel
682135838f Separate out the UI from the program logic
The following are UI toolkit specific:
gtk-gui.c   - overall layout, main window of the UI
divelist.c  - list of dives subsurface maintains
equipment.c - equipment / tank information for each dive
info.c      - detailed dive info
print.c     - printing

The rest is independent of the UI:
main.c i    - program frame
dive.c i    - creates and maintaines the internal dive list structure
libdivecomputer.c
uemis.c
parse-xml.c
save-xml.c  - interface with dive computers and the XML files
profile.c   - creates the data for the profile and draws it using cairo

This commit should contain NO functional changes, just moving code around
and a couple of minor abstractions.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-20 12:48:56 -07:00
Dirk Hohndel
e1171a57a7 Attempt to smooth out the velocity readings
If the velocity is slower than FAST then we look back up to 30 seconds and
calculate the velocity for the past 30 seconds instead.

For the first version I'm not doing the average of the changes but simply
the change from beginning to end.

The alternative would be to do another triangle smoothing or something
like that - but as we don't know how many samples we have in the 30 second
window, it's a little harder here.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-16 21:45:32 -07:00
Dirk Hohndel
d5b102bdf3 Flip tank pressure graph to show the RIGHT way
This annoyed me from the first moment Linus added the tank pressure graph.
As the pressure goes down, the graph needs to go down. Seriously.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-16 20:53:05 -07:00
Dirk Hohndel
bbf5f960e1 Stop plotting the gas / consumption information into the profile
And move the code into info.c where it now belongs

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-16 20:44:40 -07:00
Dirk Hohndel
6911229278 Make handling of empty airconsumption string consistent
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-16 20:20:28 -07:00
Dirk Hohndel
1937df188a Stop tank / gas / consumption info from changing info_frame size
Simply set it to an empty string with TWO lines when there is nothing to
display

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-16 16:29:43 -07:00
Dirk Hohndel
c58da2ee0c Indicate vertical velocity through color
So far Linus has hated all of my attempts to visualize vertical velocity
through color. This time I'm trying something dramatically new: there is
no PURPLE involved. Maybe that will convince him of the value.

We simply calculate the vertical velocity for the current plot segment
(last sample point to this sample point - in this version even without
divisions by zero) and assign a label based on the rate of change. These
labels are translated through a predefined table into colors:

Dark green is +/- 5ft/min (stable)
Light green is descents up to 30ft/min and ascents up to 15ft/min
Yellow is descents up to 60ft/min and ascents up to 30ft/min
Orange is descents up to 100ft/min and ascents up to 60ft/min
Red is outside of those ranges - you are most likely in danger

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-16 16:22:00 -07:00
Dirk Hohndel
89fe2c723f Show tank / nitrox / air consumption information in the info_frame
Even though we go down to an 8pt font the info_frame changes size when the
air info is added. I don't like this but want to see how Linus would like
this resolved before going overboard.

Minor tweaks to the formating (we don't need two decimals when printing
the liters of air consumed).

This patch does NOT remove the plot of the air information in the profile
graph. I think we want to remove that once we like the text where it is,
but I wanted to do one thing at a time.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-16 15:45:14 -07:00
Dirk Hohndel
40b123f63a Tweak temperature plot to look better for small fluctuations
If the temperature is in a very narrow range the existing code visually
exaggerated the fluctuations. This tries to dampen that effect a bit.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-16 11:35:04 -07:00
Linus Torvalds
f3e70c5496 Tweak plot scaling a bit
Change the duration max rounding as noted by Dirk, and move the air
consumption down further towards the bottom right corner.  In
particular, I make the text positions not scale with the window size,
purely by the size of the text.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-16 10:49:49 -07:00
Dirk Hohndel
60a62cf843 Minor corrections to printing of the last temperature
- the time stamp where we printed the last temp was wrong
 - we really shouldn't check mK for being identical - especially on dive
   computers that store a lot of samples

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-16 09:51:38 -07:00
Linus Torvalds
ec97a62f34 Use plot_info for final remaining temperature and pressure data plots too
Ok, this is pretty much it now.  Instead of having various random checks
for "is the time of the sample past the end of the dive" hacks, we not
plot all graphs from the cleaned-up plot_info structure instead of the
raw samples.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-16 09:23:54 -07:00
Linus Torvalds
82f143d229 Plot pressure data based on 'struct plot_info' rather than raw dive data
Further movement to using the sanitized and cleaned-up plot info rather
than the raw data.

The raw dive data contains samples from the end of the dive that we
don't want to drop, but that we also don't want to actually use for
plotting the dive.  So the eventual end goal here is to not ever use the
raw dive samples directly for plotting, but use the diveplot data that
we have analyzed for min/max (properly ignoring final entries) etc.

There's still some data that we take from the samples when plotting, but
it's getting rarer.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-16 09:10:13 -07:00
Linus Torvalds
7c5c9e2024 Do min/max pressure and temperature based on the non-surface data
Do the min/max calculations only *after* we have removed the extra
surface events at the end.

The Uemis data in particular has a lot of surface events after the dive,
and we don't really want to take them into account since we won't be
plotting them anyway.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-16 08:53:12 -07:00
Linus Torvalds
adda1c6e86 Plot temperature info using 'struct plot_info' rather than the raw dive samples
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-16 08:42:27 -07:00
Linus Torvalds
33fed10d66 Start using 'plot_info' more for dive-time limits
.. I'll want to move pressure limit calculations into the 'plot_info',
so that we can do several passes of analysis and change dive limits etc
without having to actually modify the dive data itself (or add new
fields to 'struct dive' just for plotting).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-16 08:20:06 -07:00
Dirk Hohndel
efb1fa44b8 Print the end temperature of the dive
Currently we print the temperature every five minutes. Especially with
dive computers that keep rather frequent temperature samples that means
that we have one more interesting data point that we don't label: the
surface temperature at the end of the dive.

This patch adds some logic to try to print the last temperature sample
that was recorded before the dive ended - unless that same value has
already been printed (to avoid silly duplications on dive computers with
less frequent sampling)

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-15 09:33:13 -07:00
Dirk Hohndel
b49c878a74 Don't draw temperature plot past the end of the dive
Just like we end depth and tank pressure plots once we are on the surface
(this is relevant for dive computers like the uemis Zurich that keep
recording samples after the end of the dive)

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-15 09:33:13 -07:00
Linus Torvalds
b4c84c1a2e I'm trying to figure something out that prints reasonably..
I'll get there.  Shrink it down a bit, start adding notes and location,
and maybe put three per page. That might work.

.. or maybe I should just take a look at how others have done this.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-13 20:39:43 -07:00
Linus Torvalds
a0096f3a6b Make the printout look different
Not *better* mint you. Just different.

I suck at graphs.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-13 19:49:48 -07:00