aboutsummaryrefslogtreecommitdiffstats
path: root/core/dive.h
AgeCommit message (Collapse)Author
2018-07-21Uninline functions in dive.hGravatar Berthold Stoeger
There were numerous inlined functions in dive.h. For many of them inlining is dubious. Let's uninline most of them, with the exception of trivial accessors and interpolate(). On current master, this gave a size reduction of 5 pages: -rwxrwxr-x 1 bs bs 5863656 Jul 18 20:57 subsurface-inline -rwxrwxr-x 1 bs bs 5843176 Jul 18 20:48 subsurface-noinline ----------------------------------------------------------- 20480 Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-19Undo: remember deleted trip in UndoRemoveDivesFromTrip::undo()Gravatar Berthold Stoeger
If the last dive of a trip is removed, the trip is deleted. On redo the dive is added to a non existing trip, leading to a segfault. Therefore, keep a copy of the trip to reinstate it on redo. Note: this cannot work for a sequence of multiple commands. One would have to rewrite the whole undo-history. Nevertheless, let's do this as a stop-gap measure. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-18Cleanup: rename trip->index to trip->savedGravatar Berthold Stoeger
The index-field was misused by the IO routines to mark which dives had been saved. Somewhat questionable, but let's at least name the field accordingly. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-17Cleanup: simplify dive_getUniqID()Gravatar Berthold Stoeger
dive_getUniqID() is used to create unique dive ids, which are stable during application lifetime. It was passed a dive, checked that the id was not set (if it was that it is know to the application) and set a new id (in contradiction to its name!) if it hadn't any. There were three callers: alloc_dive(): called the function on a zeroed dive struct. fixup_dive(): called the function only if the dive had a 0 id. MainWindow::setupForAddAndPlan(): called the function on a zeroed dive struct. Thus, in all three callers the id is guaranteed to be zero and the whole keeping-track-of-ids logic is moot. Remove the logic, don't pass a dive struct to dive_getUniqID() and move the function to the C-backend. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-07save-git: allocate user_info members on the heapGravatar Lubomir I. Ivanov
subsurface_user_info() only works on Linux (linux.c), but it doesn't allocate values on the heap. Solve this ownership problem by always allocating .name and .email on the heap in subsurface_user_info() and freeing in the caller. If subsurface_user_info() did not modify any of the values from NULL, use default ones, but allocate them on the heap too. Ref #1346 Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2018-07-03Profile context menu entry to split a diveGravatar Robert C. Helling
Allow the user to manually split a dive in two. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-06-20equipment: sanitize 'ws_info' loop limitsGravatar Lubomir I. Ivanov
Instead of a constant or a macro for the maximum number of 'ws_info' elements the 100 literal was used. Define MAX_WS_INFO in dive.h and use it everywhere. Also clamp loops that iterate `ws_info' to MAX_WS_INFO. Prevents potential out-of-bounds reading, similarly to the previous commit about 'tank_info'. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2018-06-20core: add free_samples helperGravatar Dirk Hohndel
And use it in the UI and planner code. See #1411 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-28Distinguish between user and internal divemode namesGravatar Robert C. Helling
The former should be translated but not those that go to xml/git. ... and fix capitalization of pSCR. Suggested-by: Stefan Fuchs <sfuchs@gmx.de> Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-05-18core: removed clang warnings from dive.hGravatar jan Iversen
interpolate, rel_mbar_to_depth, gas_mod and gas_mnd returns int but uses a function that returns long, causing clang to warn about conversion loss due to implicit conversion. Adding a cast, shows that it is correct. Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-14Rename enum dive_comp_type to divemode_tGravatar Robert C. Helling
...as the usuage is not anymore about a computer but a momentary dive mode. Rename the end indicator as well. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-05-14Add planner infra structure for bailoutGravatar Robert C. Helling
Add a divemode column to the planner model and a corresponding field to struct divepoint and fill it in the corresponding functions. Signed-off-by: Robert C. Helling <helling@atdotde.de>
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-14Read and write divemode changes (xml and git)Gravatar Willem Ferguson
This provides for reading of divemode change events from dive logs and for writing them to dive logs. This applies to xml and git divelogs. Divemode change events have the following structure: event->name = "modechange" event->value = integer corresponding to enum dive_comp_type (dive.c), reflecting the type of divemode change (OC, CCR, PSCR, etc). In the dive log file, the event value is written as a string that corresponds to each of the enum values, e.g. <event name='modechange' divemode='OC' /> This xml is also read from the dive log file and translated to an appropriate value of event->value. The file diveeventitem.cpp was udated to reflect this new way of dealing with divemode change events. 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-14Simplify bailout events in the dive logGravatar Willem Ferguson
I removed the special event type that has been used for bailout events. Bailout events are now just bookmarks with a specific name "e.g. OC, CCR, PSCR). This removes a case where a segmentation error occurred when trying to remove a bailout event from the dive profile. Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-05-14Implement bailout outside of the dive plannerGravatar Willem Ferguson
This is the second step for implementing bailout. The indirect calls to fill_pressures through add_segment() (in deco.c) are addressed. Bailout is now fully implemented in the dive log but not in the dive planner. 1) The parameters to add_segment() are changed to take a divemode as the second last parameter, and not a *dive. 2) Call to add_segment() in profile.c and in divelist.c are adapted. In divelist.c some calls to add_segment were left using dc-> divemode instead of possible bailout. This appears tp be the most appropriate route. 3) The functions get_divemode_from_time() and get_next_divemodechange() in dive.c have had some small changes. 4) The calls to get_segment(0 in planner.c were changed to reflect the new parameter list, but not updated to reflect bailout. This is the next step. 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-05-14Core: introduce new subsurface-string headerGravatar Dirk Hohndel
First small step to shrinking dive.h. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-13Dive pictures: replace picture struct by QStringGravatar Berthold Stoeger
In imagedownloader.cpp the only thing we need from the picture struct is the filename. Therefore, use QStrings instead of the picture struct. This simplifies memory management. Remove the clone_picture() function, which is not needed anymore. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-05-07Planner: don't return static data in fake_dc()Gravatar Berthold Stoeger
fake_dc() used to return a statically allocated dc with statically allocated samples. This is of course a questionable practice in the light of multi-threading / resource ownership. Once these problems were recognized, the parameter "alloc" was added. If set to true, the function would still return a statically allocated dc, but heap-allocated samples, which could then be copied in a different dc. All in all an ownership nightmare and a recipie for disaster. The returned static dc was only used as a pointer to the samples anyway. There are four callers of fake_dc() and they all have access to a dc-structure without samples. Therefore, change the semantics of fake_dc() to fill out the passed in dc. If the caller does not care about the samples, it can simply reset the sample number to zero after work. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-29When looking for gas change events only use thoseGravatar Robert C. Helling
This function looks for the last gas change before a given time. We should initialize it with a gaschange event as we might later use this event to read a gasmix from it. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-04-11Look for actual isobaric counter diffusionGravatar Robert C. Helling
Identify segements that fullfill the folllowing criteria for the leading compartment: He is off-gasing while N2 is on-gasing Overall there is on-gasing Add a line to the info box for those segments Signed-off-by: Robert C. Helling <helling@atdotde.de>
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-09Change taglist_get_tagstring to support 'unlimited' tag list sizeGravatar Jeremie Guichard
Previous taglist_get_tagstring signature/implementation did not allow handling of cases where inputted buffer could not contain all tags. New implementation allocates buffer based on pre-computed size allowing to insert all tags in the returned string. Added get_taglist_string in qthelper to handle conversion to QString Added TestTagList with tests for taglist_get_tagstring Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2018-04-01Dive pictures: Move metadata functions into own translation unitGravatar Berthold Stoeger
Move all metadata function into new core/metadata.cpp file. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-14Cleanup: constify string arguments in core/dive.cGravatar Berthold Stoeger
Make arguments to set_informational_units(), set_git_prefs(), set_userid(), dive_remove_picture() and update_event_name() "const char *" for consistency with the rest of core/dive.c. This will allow replacing toUtf8().data() with the constData() version in a subsequent commit. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05Cleanup: Remove hash field from picture-structureGravatar Berthold Stoeger
The hash field in the picture-structure was in principle non-operational. It was set on loading, but never actually changed. The authoritative hash comes from the filename->hash map. Therefore, make this explicit by removing the hash field from the picture structure. Instead of filling the picture structure on loading, add the hash directly to the filename->hash map. This is done in the register_hash() function, which does not overwrite old entries. I.e. the local hash has priority over the save-file. This policy might be refined in the future. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-27Updated strategy for removing cylindersGravatar Stefan Fuchs
Change the strategy when to allow cylinder removal from a dive: - Not remove when cylinder has gas switch events, in any other cases allow removal - Remove this whole "cylinder with same gas" thing being a criteria for cylinder removal When removing a cylinder which has corresponding pressure info in samples, also remove this pressure info from the samples. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-24Correct comments for struct temperature_t value rangeGravatar Stefan Fuchs
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-12Cleanup: remove declaration of get_error_string()Gravatar Berthold Stoeger
This function was removed in #8f81a22e7f26729cc2f4902ba7db8f696314539f. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-31Make report_error() reentrantGravatar Berthold Stoeger
Remove the global error buffer and pass the error string directly to the frontend. The frontend is then responsible for accumulating errors. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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-19Improve profile display in plannerGravatar Willem Ferguson
This patch allows the planner to save the last manually-entered dive planner point of a dive plan. When the plan has been saved and re-opened for edit, the time of the last-entered dive planner point is used to ensure that dive planning continues from the same point in the profile as was when the original dive plan was saved. Mechanism: 1) In dive.h, create a new dc attribute dc->last_manual_time with data type of duration_t. 2) In diveplanner.c, ensure that the last manually-entered dive planner point is saved in dc->last_manual_time. 3) In save-xml.c, create a new XML attribute for the <divecomputer> element, named last-manual-time. For dive plans, the element would now look like: <divecomputer model='planned dive' last-manual-time='31:17 min'> 4) In parse-xml.c, insert code that recognises the last-manual-time XML attribute, reads the time value and assigns this time to dc->last_manual_time. 5) In diveplannermodel.cpp, method DiveplannerPointModel::loadfromdive, insert code that sets the appropriate boolean value to dp->entered by comparing newtime (i.e. time of dp) with dc->last_manual_time. 6) Diveplannermodel.cpp also accepts profile data from normal dives in the dive log, whether hand-entered or loaded from dive computer. It looks like the reduction of dive points for dives with >100 points continues to work ok. The result is that when a dive plan is saved with manually entered points up to e.g. 10 minutes into the dive, it can be re-opened for edit in the dive planner and the planner re-creates the plan with manually entered points up to 10 minutes. The rest of the points are "soft" points, shaped by the deco calculations of the planner. Improvements: Improve code for profile display in dive planner This responds to #1052. Change load-git.c and save-git.c so that the last-manual-time is also saved in the git-format dive log. Several stylistic changes in text for consistent C source code. Improvement of dive planner profile display: Do some simplification of my alterations to diveplannermodel.cpp Two small style changes in planner.c and diveplannermodel.cpp as requested ny @neolit123 Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-11Introduce helper function empty_string()Gravatar Berthold Stoeger
There are ca. 50 constructs of the kind same_string(s, "") to test for empty or null strings. Replace them by the new helper function empty_string(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-11Change return code of string comparison functions to boolGravatar Berthold Stoeger
These functions were returning 0 or 1 anyway. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-10Unused code: has_hr_data()Gravatar Jan Mulder
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10Unused code: report_message()Gravatar Jan Mulder
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10Unused code: remove weightsystems_equal()Gravatar Jan Mulder
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10Unused code: weekday()Gravatar Jan Mulder
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10Unused code: remove taglist_equal()Gravatar Jan Mulder
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10Unused code: remove shift_times()Gravatar Jan Mulder
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-08Make a few functions of static linkageGravatar Berthold Stoeger
Make functions in core/file.c, core/parse.c and core/import-csv.c that were not used outside their translation unit of static linkage. parse_date is moved from core/file.c to core/import-csv.c, since it is used only there. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-06Trivial: remove redundant declarations of downloadTableGravatar Berthold Stoeger
downloadTable was declared twice in "dive.h". Remove one occurence. Moreover, "uemis-downloader.c" also declared downloadTable. This can likewise be removed, because "uemis-downloader.c" indirectly includes "dive.h". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-04Turn autogroup from short into boolGravatar Berthold Stoeger
All users of autogroup are clearly expecting a boolean value, so let the type reflect this. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-28cleanup: correct signature and declare externGravatar Jan Mulder
clear_vpmb_state() was declared with incorrect signature, and all functios in this change are extern, so declare them as such. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-13Enable removal of pictures from different dives at the same momentGravatar Stefan Fuchs
Suggested-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-12-11Remove second parameter (bool force) in set_filename()Gravatar Berthold Stoeger
The last force=false case was removed in commit 96d1cc570e31396039e4970d2bf75d5f00f1e550. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-27Add debug function dump_cylindersGravatar Stefan Fuchs
This function can be used to dump print all cylinder data. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-25Localize global planner stateGravatar Robert C. Helling
For UI responsiveness, we need to be able to run the planner in the background. This needs the planner state to be localized (and we need to pass a pointer around). In order to not let too many lines overrun (and to save typing in the future) I have renamed instances of struct deco_state to ds. Yes this should have gone to a separate commit but I accidentally commit --amend'ed it. Computing of planner variations is temporarily disabled. Unlock the planner when returning early So we don't deadlock in add dive and recreational mode (which use the planner without actually planning). Signed-off-by: Robert C. Helling <helling@atdotde.de>