aboutsummaryrefslogtreecommitdiffstats
path: root/core/plannernotes.c
AgeCommit message (Collapse)Author
2018-05-14Implement get_divemode() to find the divemode at a particular timeGravatar Willem Ferguson
Replaced a rather cumbersome function that that did the above. Upon the suggestion of Robert Helling who proposed a much shorter way, this new function replaced the previous ones. This necessitated changes to divelist.c, profile.c and plannernotes.c, as well as dive.c/h. Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-05-14Simplify the bailout detection functions.Gravatar Willem Ferguson
Function peek_next_divemodechange() is redundant if get_next_divemodechange() has one additional parameter. Calls to get_next_divemodechange() were updated in divelist.c, plannernotes.c and profile.c. Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-05-14Incorporate bailout events in CCR & PSCR gas calculations.Gravatar Willem Ferguson
This is a first step to interpret bailout events. 1) The event structures have a new attribute: divemode. Currently interpreted dive modes are OC, CCR, PSCR. 2) When doing fill_pressures(), the calculation is aware of divemode. When divemode is OC (==bailout), then the appropriate calculations of gas pressures are done. 3) Two new functions get_next_divemodechange() and get_divemode_at_time() are created to find divemode changes in the events linked list and to determine the dive mode at any point during the dive. 4) fill_pressures gets a small amendment to facilitate the correct calculations, depending on divemode. The cases where fill_pressures() is used *outside the planner* are changed. The result is that, for dives with bailout, the correct gas pressures are shown on the dive profile. The deco for bailout dives is not yet correct. This is the next step. Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-04-11Cleanup: Fix memory leak in plannernotes.cGravatar Berthold Stoeger
dive->notes was overwritten without free()ing the old buffer. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-11Cleanup: fix "unsave" snprintf()s in plannernotes.cGravatar Berthold Stoeger
The planner notes were constructed using a sequence of len += snprintf(buf, buflen - len, ...); calls. This will fail once len > buflen, because the second parameter of snprintf is unsigned. Note that snprintf returns the number of bytes that would have been written if it weren't truncated. Fix this by using membuffer with put_format()/put_string() and asprintf_loc(). Fixes #1155. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-11Cleanup: unconstify results of two functionsGravatar Berthold Stoeger
get_dive_date_c_string() and get_current_date() return copied strings. Make this explicit by returning non-const pointers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-11Cleanup: make local functions in core/plannernotes.c of static linkageGravatar Berthold Stoeger
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-09Cleanup: Move *_loc formatting functions into new format.cpp fileGravatar Berthold Stoeger
qthelper.cpp is already quite voluminous. Move the recently introduced localized versions of (v)snprintf() and put_format() into their own translation unit. Moreover, adopt C-style semantics for asprintf_loc(). This function will be used to remove fixed-size buffers in core/plannernotes.c. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05Localization: implement *_loc() functions in plannernotes.cGravatar Berthold Stoeger
Replace snprintf() and put_format() by snprintf_loc() and put_format_loc(), respectively to localize formatting of integers and floats. Acked-by: Stefan Fuchs <sfuchs@gmx.de> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-26Cleanup: Unify qthelper.h and qthelperfromc.hGravatar Berthold Stoeger
Since all qt-helpers are defined in qthelper.cpp, there seems to be no reason to have two include files. By unifying the two files, duplication and inconsistencies are removed. The C++-only part is simply compiled away with #ifdefs. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-25Correctly suppress display of ICD table if prefs.show_icd is falseGravatar Stefan Fuchs
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-22Exit add_plan_to_notes() in plannernotes.c always via label finishedGravatar Stefan Fuchs
Replace an early "return" in add_plan_to_notes() with a "goto finished;" This was the initial idea of doing it plus it fixes a potential memory leak (missing free for icdbuffer). Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-20Indicate direction of transition in verbatim planGravatar Robert C. Helling
Replace "Transition to" by "Ascent to" or "Descend to" Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-02-02Print icd data only when it is really neededGravatar Willem Ferguson
Reduce the impact and visibility of icd calculations by writing the data to the planner output only in cases where gas switches involve: 1) ascent 2) helium is used as part of breathing gas 3) gas switch results in an increase in partial pressure of nitrogen. Coding change: 1) The code for writing the header of the icd table as well as the inclusion of the data in the planner output is made conditional on the above three requirements. This involves moving the code that writes the table header into the function that writes an icd data item to buffer. 2) Manipulation of a boolean variable that controls writing of the table header to buffer and that also determines whether any icd results should be inluded in the planner results. 3) Reorganise comments so that there are not multiple tabs between the code and the start of a comment. Correct type and insert braces where important Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-24Planner: print icd information at 0.1 resolutionGravatar Willem Ferguson
The gas fractions (in %) are now printed at a resolution of 0.1% and not at 0.01% as previously. The string in the info box that provides icd data is reformatted so that the info-box is as narrow as possible. Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-21Planner notes min gas: Remove incorrect line wrap inside printf stringGravatar Stefan Fuchs
With old code the tabs at the start of the second line were incorrectly added to the string. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-01-21Planner notes ICD: Format HTML with DIV, do table title differentlyGravatar Stefan Fuchs
In the planner notes format the HTML for different sections with div tags. Put the table title for the ICD table outside the table because then the alignment looks a little bit nicer. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-01-21Planner notes ICD: Coding style change onlyGravatar Stefan Fuchs
Avoid the need for a char array for the "old_gas_name" by passing two pointers to the gasmixes to the add_icd_entry function and calling helper function gasname() there twice. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-01-21Planner notes ICD: Print correct runtime for gaschangeGravatar Stefan Fuchs
If a gaschange happens at the beginning of a segment, currently the wrong runtime (end of segment time) is printed in the ICD table. This is corrected here. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-01-20Move function isobaric_counterdiffusion()Gravatar Willem Ferguson
Move the above function from plannernotes.c to dive.c so that it is available to be called from the dive log part of the software, and not only from the planner. The following was done: 1) Edit the comment above the code to make it more accurate 2) Move the structure icd_data to dive.h 3) Create an external reference in dive.h for the above function 4) Copy the body of isobaric_counterdiffusion() to dive.c Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-19Implement ICD calculations in planner outputGravatar Willem Ferguson
This patch implements the calculation and printing of icd parameters in the dive planner output. It does: 1) icd parameters are calculated following the rule-of-fifths for OC trimix dives. For each gas change on the ascent that involves helium, the change in gas composition as well as the change in partial pressures are shown. If rule-of-fifths is exceeded, a warning message is prinetd. 2) An independent function is provided that in principle enables calculation of icd paramaters outside of the context of the dive planner. Further updates to icd calculations These changes respond to #1047. Code style conventions have been improved. The ICD table is now also printed when the planner is set to verbatim mode. The code that created the html icd results has been moved to a function. This does not make the code more efficient (many parameters passed) but it makes the code more clean. Free a new dynamic variable (old_gas_name) Stylistic changes to new code in plannernotes.c Changes in comments to explain some of the changes I made. Preparation of comments and functioning of isobaric_counterdiffusion() and its dependent data structure for possible transfer to dive.c and dive.h after finalisation and merging of the present PR. Smaller stylistic changes to conform to our coding rules. The several comments and suggestions during github review (@atdotde, @leolit123, @sfuchs79) are incorporated. Fixed up mis-aligned comments and text descriptions by replacing tab characters with space characters, thereby hard-forcing alignment of indented lines of text. Remove parameter *dive from function isobaric_counterdiffusion(). Improve a few constructs to conform to our style rules. Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-11Fix indentations for plannernotes.cGravatar Willem Ferguson
The last 2 commits have now been squashed. S Fuchs's comment on line 315 has been fixed Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2017-12-28Planner notes: don't omit deco stops with rapid ascent ratesGravatar Rick Walsh
This fixes a bug where if the user entered very high ascent (or less commonly descent) rates such that the time to ascend (or descend) from one level to the next was less than 10s, that leg would be skipped in the dive plan notes. Reported-by: Alexander Maier <maieralex@me.com> Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-12-26Cleanup: avoid memory leakGravatar Dirk Hohndel
Coverity CID 208308 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-17Unify float calulations: use doubleGravatar Berthold Stoeger
Internal floating point (FP) calculations should be performed using double unless there is a very good reason. This avoids headaches with conversions. Indeed, the vast majority of FP calculations were already done using double. This patch adapts most remaining calculations. Not converted where things that were based on binary representations and variables which weren't used anyway. An analysis of all instances follows: core/plannernotes.c, l.404: This was a comparison between two floats. On the left side, first an integer was cast to float then multiplied with and integer and divided by a constant double. The right hand side was an integer cast to a float. Simply divide by 1000.0 first to convert to double and continue with calculations. On the right hand side, remove the cast, because the integer will be implicitely cast to double for comparison. This conversion actually emits less instructions, because no conversion to double and back is performed. core/planner.c, l.613: Same analysis as previous case. subsurface-desktop-main.cpp, l.155: A local variable representing the version OpenGL version. Turn this into integer logic. Not only does this avoid dreaded FP rounding issues, it also works correctly for minor version > 10 (not that such a thing is to be expected anytime soon). abstractpreferenceswidget.[h/cpp]: A widget where the position is described as a float. Turn into double. desktop-widgets/divelogexportdialog.cpp, l.313: total_weight is described as float. Use double arithmetics instead. This instance fixes a truncation warning emitted by gcc.
2017-12-01Document background computation of variationsGravatar Robert C. Helling
Update changelog, update user manual, clarify meaning in dive notes. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-12-01Disable plan variation in recreational modeGravatar Rick Walsh
Calculating variations when in recreational mode doesn't make sense, and can prevent variations from being calculated when switching back to Buhlmann or VPM-B modes. Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-12-01Round up diveplan duration the same way values in diveplan are roundedGravatar Stefan Fuchs
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-25In strings start lower case in parenthesisGravatar Stefan Fuchs
Start with lower case letter inside a parenthesis. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-19Trivial: fix indentationGravatar Berthold Stoeger
Fix an obvious indentation bug where one line more than intended was indented. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-10-30Planner remove unnecessary gas consumption info from notesGravatar Stefan Fuchs
If we consumed 0l/0bar in total from a cylinder there is no need to also state that we consumed 0l/0bar during ascend. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-28Planner: Do not translate VARIATIONSGravatar Salvador Cuñat
This string is substituted with the runtime increments derived of slight variations in depth or bottom time in: diveplannermodel.cpp:1058: displayed_dive.notes = strdup(notes.replace("VARIATIONS", QString(buf)).toUtf8().data()); Translating it avoids substitution and we just get the translated string. Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-10-18init_deco correctly identify previous dives and report overlapping divesGravatar Stefan Fuchs
When changing the date/time of a dive in the planner the dive may end up in a totaly new position in respect to date/time of other dives in dive list table. It can be moved to the past or the future before or after other existing dives. It also could overlap with an existing dive. This change enables identification of a new "virtual" dive list position and based on this starts looking for previous dives. Then it (as before the change) does init the deco calculation with any applicable previous dive and surface interval. If some of these applicable dives overlap it returns a neg. surface time which is then used in the planner notes to prohibit display of results. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-18plannernotes.c coding style fixesGravatar Stefan Fuchs
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-18Minimum gas calculation: Change text colors for delta value output...Gravatar Stefan Fuchs
and adapt the strings for translation to s.th. which can be handled more easily. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-04Planner minimum gas calculation: Print delta pressure in resultsGravatar Stefan Fuchs
Print the delta between the required minimum gas result and the cylinder pressure at last bottom datapoint in results. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-09-20Add a checkbox to turn off plan variationsGravatar Robert C. Helling
... as those come with a performance penalty Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-08-29Show variations in Runtime stringGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-08-29Change color to red if minimum gas is violated.Gravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-08-03Always show the ascent to the initial deco stopGravatar Robert C. Helling
...even when not showing transitions, this makes the first stop look more like a stop (since it does not include several minutes of ascent). Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-05-26Move planner notes to separate fileGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de>