Planner: add warning if the plan consumes more gas than provided

If we have size information including working pressure for a cylinder, we
already track the expected pressure at each way point - this way we can
also alert the user if more gas is consumed than is available in the
cylinder.

This does not include sound planning strategies like "rule of thirds". It
simply assumes that you won't be able to breathe down the cylinder past
about 10bar (using 0 as cutoff seemed silly).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Planner: more fixes for gas tracking

Gas switches are now for the current segment, not for the next.

We can only track gas for cylinders for which we have size / working
pressure information. Print a warning for others.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Planner: track gas used even if we don't have a real cylinder

We tracked gas used by simulating a dive with a cylinder - but for that we
need a cylinder size and working pressure. If the user just enters a gas
but no cylinder data (likely in order to figure out how much gas is used
so that she then can pick a big enough cylinder), we didn't show any gas
consumption.

It kinda sucks to add another member to the cylinder structure, but this
seemed far more reasonable then some other, global structure that
independently tracks gas usage. This just seemed to make sense.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Planner: correctly track gas used

This part of the algorithm was off as part of it (but not all of it -
crazy, I know) assumed the old semantic for gas changes where the new gas
was introduced at the end of the segment and not at the beginning.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Encapsulate the horrid gas encoding in gas change events

We should never pass permille values around as integers. And we shouldn't
have to decode the stupid value in more than one place.

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

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Remove the .used member of the cylinder structure

Instead calculate this information on the fly, taking into account all
dive computers on the dive in questions.

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

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

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Use proper types

This is step one of many to use gasmix instead of int o2/he.
Right now some of these changes look ridiculous because after changing a
few lines we immediately go back to o2 = get_o2(gas). The reason is that I
wanted to convert a hand full of functions at a time. So in this commit I
only change validate_gas(), get_gas_from_events() and get_gasidx() to use
a struct gasmix instead of int o2, int he.

This state builds and survived some mild testing. Let's continue on top of
that.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Next step to using gasmix instead of o2/he

This changes the divedatapoints and functions that deal with them.

It changes plan_add_segment(), create_dp(), gasToStr(), and tankInUse() to
consume gasmix instead of o2/he.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Remove some unused variables

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Simplify ruler update code.

This should fix the infinite recursion on OSX and also clean a lot of
code, which is also very nice. <3

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Fix layout on the Shift-Image-Time import dialog

The dialogs where hard-coded and some variations of themes
could broke the placement of the text on it.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Do not replot for each picture added to dive.

Instead wait until all pictures have been set and plot that.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Add stub for a widget to show the dive pictures.

This has a few classes: the model is the list of pictures for the current
dive, the delegate is how this pictures will be displayed on screen, the
widget is the collection of delegates, and the DivePictureThumbnailThread
is a worker-thread to generate the thumbnails so the UI will not freeze.

[Dirk Hohndel: added the new files to subsurface.pro]

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Add a new widget on the main tab: Pictures.

Currently this does nothing, but since "dive photos" can also mean
photos that were taken during the trip to the dive, some of them
will not be visible on the profile. this currently shows nothing,
because I didn't work out the Model bits yet.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Add a method to update the dive pictures on the model.

Call that method from the mainWindow when the dive changes.
The updateDivePictures walks around the events of the first dc (since all
pictures are distributed allong all dive computers) to get the events of
type '123' (I wonder if there's not a better way to save pictures on the
dive, like an linked list of char* named pictures.)

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Add threaded processing of image pixmaps

This code adds threaded processing of a batch of images. It uses the
QtConcurrent implementations to call a function repeteadly using
MAX_THREADS (Qt gets that for us) and returns a list of it.

This call is blocking, so while the pixmaps are being scaled in threads,
it will wait for all scalling to be done.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Switch more functions to use gasmix type

This time it's get_gas_string().

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Switch verify_gas_exists to take gasmix argument

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Change add_plan_to_notes() to operated on gasmix

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
More cleanup for planner.c

Remove unused variables and make the ifdef'ed out debug code work again.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>