Commit graph

144 commits

Author SHA1 Message Date
Dirk Hohndel
fece3f321f Switch more functions to use gasmix type
This time it's get_gas_string().

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-01 16:12:01 -07:00
Dirk Hohndel
fe773241ee 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>
2014-06-01 15:40:46 -07:00
Dirk Hohndel
2bf46381a8 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>
2014-06-01 14:19:19 -07:00
Dirk Hohndel
1a04013453 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>
2014-06-01 12:07:29 -07:00
Dirk Hohndel
fb4d9b34f8 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>
2014-06-01 10:16:59 -07:00
Dirk Hohndel
2a871d7fe5 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>
2014-06-01 10:16:59 -07:00
Dirk Hohndel
f44a7509b3 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>
2014-06-01 10:16:48 -07:00
Dirk Hohndel
81e3f77447 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>
2014-06-01 07:55:28 -07:00
Dirk Hohndel
ed26dfdd6b Planner: don't include the disclaimer in the dive plan detail widget
We want the disclaimer in the final dive that can be printed, but it's
distracting when shown while planning the dive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-31 21:25:03 -07:00
Dirk Hohndel
b9946b89fa Planner: look harder to find the right gas
Silly bug - while we normally fill the cylinders in a tight group with no
"null" cylinders in the middle, since we copy from an existing dive and
since that may end up with an odd sequence of cylinders, we need to
continue looking at ALL cylinders and not stop with the first one that's
empty.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-31 13:49:51 -07:00
Dirk Hohndel
65f3135a92 Planner: don't do unnecessary work on empty dive plans
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-30 15:40:13 -07:00
Robert C. Helling
26dd86e437 Planner: start the ascend with the strongest allowed deco mix.
In analyze_gaslist() we were only keeping gases that had their .depth
above the current depth, i.e. where we could switch to in the future. Now
we take note as well of the strongest gas that we could have already
switched to and switch to it before we attempt to ascend.

[Dirk Hohndel: minor whitespace and code cleanup]

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-30 09:06:22 -07:00
Dirk Hohndel
63c21d55de Planner: clean up the function that tracks our gases
This doesn't add gases. It just makes sure they are there.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-29 17:36:39 -07:00
Dirk Hohndel
d054e8c457 Planner: track gas consumption in cylinders and samples
This commit is a little bigger than I usually prefer, but it's all
somewhat interconnected.

- we pass around the cylinders throughout the planning process and as we
  create the plan we calculate the gas consumption in every segment and
  track this both in the end pressure of the cylinder and over time in
  the samples
- because of that we no longer try to calculate the gas consumption after
  being done planning; we just use what we calculated along the way
- we also no longer add gases during the planning process - all gases
  have to come from the list of cylinders passed in (which makes sense
  as we should only use those gases that the user added in the UI or
  inherited from a the selected dive (when starting to plan with a dive
  already selected)

With this patch I think we are close do being able to move all of the
planning logic back into the planner.c code where it belongs. The one
issue that still bothers me is that we are juggling so many dive
structures and then keep copying content around. It seems like we should
be able to reduce that.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-29 14:43:24 -07:00
Dirk Hohndel
b37422c447 Planner: record the new dive at the correct time
We don't want to do this when calling plan() from createTemporaryPlan() -
we only want to record the dive at the end of createPlan().

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-28 22:16:15 -07:00
Dirk Hohndel
4ed8b5f86f Planner: add missing disclaimer
This may not be the best way to do it, but it's better than just printing
"(null)".

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-28 22:11:37 -07:00
Tomaz Canabrava
4e3793c053 Paint the dive red if the user is breaking ceiling on the planner.
This patch paints the dive red if the user is breaking ceiling
on the planner - it's quite fast, it analizes the depth over the
max(tissue_1 .. tissue_16) and changes the color of the profile.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-26 15:42:43 -07:00
Dirk Hohndel
0f023791f8 Fix warning
When converting from assert to if I forgot to invert the comparison...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-26 14:21:37 -07:00
Dirk Hohndel
9cc8e39d42 Merge branch 'Planner' 2014-05-26 13:28:18 -07:00
Dirk Hohndel
cf3701bbac Planner: convert assert into warning
We need to make sure we let the user know about this in a more user
friendly way...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-26 13:25:50 -07:00
Robert C. Helling
1093d6235b Reenabled copying the diveplan to dive notes.
Gas consumption calculation fixed. Pressure difference still needs cylinder size to be set.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-26 09:58:23 -07:00
Robert C. Helling
04b6b6aaf9 Use get_o2() and get_he() instead of accessing permilles directly
This gets rid of problems with air.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-26 08:12:32 -07:00
Robert C. Helling
a422aa2986 Planner: Add waipoints when changing ascend rate in planner
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-08 12:28:16 -07:00
Robert C. Helling
c3a3c1a1e7 Planner: Implement ascend rate according to GUE standard procedures
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-08 12:28:09 -07:00
Dirk Hohndel
3063991e4e Fix bug in handling of fake SAMPLE_EVENT_PO2 events
In commit bcdd6192fe ("Show translated event names in tooltip") I was
too aggressive in replacing the checking for event names with checking for
event types. It turns out that we are abusing an existing event type in
the planner (and use a different event name to mark the difference). By
just checking for the type this now caused incorrect information to be
displayed in the info box (a simply "PO2 warning" on a Suunto D9 could
turn into a "Bailing out to OC" notice).

The correct fix is to get our own range of SAMPLE_EVENT_xxx numbers from
libdivecomputer. Once we have those, we can do this the right way. For now
we just fall back to also checking the event name (which is what I wanted
to get away from so translated names don't trip us up).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-05 09:32:13 -07:00
Dirk Hohndel
bcdd6192fe Show translated event names in tooltip
In order for this to work we need to compare against the event type
instead of the event name - which makes much more sense to do, anyway.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-29 22:38:55 -07:00
Dirk Hohndel
d191f5af6f Remove unused variables and fix signed/unsigned mismatch
The depth types are unsigned for dive plan datapoints.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-18 13:06:21 -07:00
Robert C. Helling
cb4daa85c3 Comments added to planner
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-18 10:01:46 -07:00
Robert Helling
9ddef367b5 Improvement for various bits of the planner
Rewrite of the actual planner logic. Now ascend to the next potential stop
depth. There the state is cached and we try to ascend to the next stop
depth. If we hit the ceiling while doing that we go back to the cached
state and wait there for a minute. Then we try again. Then loop.

Converted all depth related variables from unsigned int to int. During
planning, in a time step the current depth can temporarily be negative and
comparisons of a negative int with an unsigned it have not the result I
expected ( (int) -2 < (unsigned int) 3 turns out to be false). And we
don’t really need the 32nd bit that unsigned buys us for depths.

Deco stops are now shown in the same table as manually entered stops in
boldface (I removed the second table to save screen estate).

The gas shown in the table is still misleading as it means the gas used on
the segment leading up to that event.

The update of the profile only works partially upon changes in the list of
available gases.

Treatment of various gases is basically there but needs some more love.

The ascent velocity is now provided by a function that takes the current
depth as argument. Currently it always returns 10m/min but that will later
be variable (and hopefully user configurable).

The profile is not redrawn while deco is computed (avoiding an infinite
recursion).

The table got a new column for the duration of a segment while the old
“duration” column was renamed “Runtime” to reflect what it actually shows.
Currently, only the run time but not the duration are editable.

All deco gases are used from the depth where their pO2 is 1.4bar. This
should become more flexible.

Calculation of the pressure drop in cylinders without configured volumes
is suppressed. This solves a problem with the planner crashing when saving
a dive where not all cylinders had been manually given a volume.

[Short rant break: Treating 0/0 as air bites back at so many places. E.g.
Cylinder data is initialized with memsetting the whole structures to 0.
Then later suddenly this totally unconfigured cylinder is being treated as
it would contain air. Maybe at some point this was a feature. But it lead
to a naughty bug which took me over an hour to resolve. We should
seriously reconsider this choice and better move to 209/0 being air if
changing this everywhere is not too much trouble]

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 07:29:44 -07:00
Dirk Hohndel
0de21c24fa Merge branch 'planner-mods'
Nothing exciting here, just a few independent changes close to each other.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-31 22:18:00 -07:00
Robert C. Helling
30bdfc8160 Distinguish between entered and calculated waypoints
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-31 22:01:05 -07:00
Dirk Hohndel
6ba140571e Only use a default cylinder if it is explicitly set
We used to fall back to an AL80 default cylinder, but that meant that a
user who doesn't want a default cylinder at all had no way to indicate
that.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-15 13:09:36 -07:00
Linus Torvalds
609715ab69 Convert other users of showError() to the new world order
The "report_error()" interface is a lot simpler, although some of the
C++ code uses QStrings which make them a bit annoying, especially for
the varargs model.  Still, even with the explicit conversion to UTF8 and
"char *", the report_error() model is much nicer.

This also just makes refreshDisplay() do the error reporting in the UI
automatically, so a number of error paths don't even have to worry.  And
the multi-line model of error reporting means that it all automatically
does the right thing, and reports errors for each file rather than just
for the last file that failed to open.

So this removes closer to a hundred lines of cruft, while being a
simpler interface and doing better error reporting.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-14 12:36:06 -07:00
Dirk Hohndel
396106e307 Don't use negative gas index
This shouldn't happen, but in case we run out of gases we shouldn't use
the negative gas index (which is the error return of get_gas_idx()) for
the array. Let's fall back to the (incorrect) first gas.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-03 21:54:52 -08:00
Dirk Hohndel
76e6420f6b Massive automated whitespace cleanup
I know everyone will hate it.
Go ahead. Complain. Call me names.
At least now things are consistent and reproducible.
If you want changes, have your complaint come with a patch to
scripts/whitespace.pl so that we can automate it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-27 20:09:57 -08:00
Anton Lundin
33391a77e9 Convert the C code to using stdbool and true/false
Earlier we converted the C++ code to using true/false, and this converts
the C code to using the same style.

We already depended on stdbool.h in subsurfacestartup.[ch], and we build
with -std=gnu99 so nobody could build subsurface without a c99 compiler.

[Dirk Hohndel: small change suggested by Thiago Macieira: don't include
               stdbool.h for C++]

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16 09:34:50 +07:00
Anton Lundin
c46ae27c3b Match sizeof with pointer type
More to get clang-scan to quiet down that for the unlikely event that
unsigned int and int is different sizes.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-11 03:13:30 +01:00
Anton Lundin
0d4fb44c18 Remove some safety stop code in plan()
Some code in plan() left from the gtk days introduced a safety stop in the
plan. It created a un-editable diveplanpoint.

Fixes #349

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-10 08:00:52 +01:00
Anton Lundin
eae1624f24 Make local helpers static
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-08 09:41:54 +01:00
Anton Lundin
28943d2def Add some assert guard around gas finding code
The code would have leaved gasidx undefined if it doesn't find a correct
gas, so this asserts instead of using uninitialized variables as array
index.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-08 09:41:28 +01:00
Dirk Hohndel
4dc3061aa5 Use AL80 as default if no default cylinder is set
Otherwise the user could get uninitialized values for newly created
cylinders.

Fixes #345

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-07 14:29:05 -08:00
Anton Lundin
70a9c280f4 Bugfix first deco stop finder
The previous code checked against the current depth to find the next
deco stop, not the ceiling we actually should head for.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-07 08:02:48 -08:00
Anton Lundin
d0fbfc7a9c Create a drop down to choose default cylinder
This also renames the ui element to match.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-24 15:07:25 -08:00
Dirk Hohndel
904c20feef Use the default cylinder if defined
With this every cylinder downloaded from a divecomputer that doesn't
provide cylinder data, and every cylinder manually added anywhere will
default to the default cylinder that is set in the preferences.

For people who most of the time dive with the same equipment (always on
dive boats with AL80, or almost always diving their personal HP119) this
should be a nice improvement.

If you don't like this behavior, simply leave the default cylinder setting
in the preferences empty.

This commit also fixes the incorrect s->value call (should be
s->setValue). I wonder what this did to the default filename before...

Fixes #145

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-23 22:01:11 -08:00
Patrick Valsecchi
fe2eabf375 Added a configuration option to have gf_low apply at max depth instead of at deepest ceiling.
Signed-off-by: Patrick Valsecchi <patrick@thus.ch>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-21 08:11:40 -08:00
Dirk Hohndel
33b15ea906 Silence some warnings when building on Mac
The *-clang* selector doesn't appear to work correctly in my build environment
(or I just don't understand how it is supposed to work). Either way, making
this conditional on !mac works.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-21 05:03:56 -08:00
Anton Lundin
746e6da75a Use add_gas_switch_event in instead of duplicate
There is a add_gas_switch_event, so don't duplicate the code.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-20 11:22:40 -08:00
Dirk Hohndel
36cb50fb37 Add gas change event from profile context menu
This allows to add missing gas change events to the currently shown dive
computer. Only gases defined in the Equipment section are offered.

Fixes: #250

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-19 20:35:15 -08:00
Dirk Hohndel
8ae8c81d3d Fix various issues with the dive add / edit manual dive code
- get_gas_from_events does NOT always set o2/he. It only updates them IFF
  a matching event is found; so we need to make sure we start out with a
  valid gas mix
- the way we tried to restore the edited dive in case of an edit to a
  manually added that is cancelled was completely bogus. Way too complex
  when we can simply and reliably simply store the dive and then copy it
  back

Fixes #270

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-18 11:55:56 -08:00
Dirk Hohndel
aa76d35923 Instead of a "Cylinder for planning" use a default cylinder
Right now hardcoded to AL80. This way in the future we'll have a volume of
gas that's available. And this makes much more sense then a random string
in the description field.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-13 21:45:24 +09:00