aboutsummaryrefslogtreecommitdiffstats
path: root/dive.c
AgeCommit message (Collapse)Author
2014-08-04Planner: show mean depthGravatar Dirk Hohndel
Almost invisible, mostly looking like an odd bug in the profile code, there was a tiny red line at depth 0 in the planned profile. Turns out that was the missing mean depth. We didn't populate enough data in the dive computer of the dive we generated from the plan (and the length of the depth line was incorrectly determined by the duration of the dive instead of the duration stored in the dive computer). Fixes #570 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-30Implement the functionality of remove_picture.Gravatar Tomaz Canabrava
Added the remove_picture functionality, with code shamelessy stolen from remove_event, and hoock it up with the interface. Fixes #650 Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-29Don't cross link events between displayed_dive and current_diveGravatar Tomaz Canabrava
The copy_dive assumed that the event being removed was from current_dive, wich was until a very recent past. now it can't assume that anymore, so instead of setting ev = assumed_dive->event->next, we do a ev = current_dive->event->next. Fixes #663 Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-17Replace cylinder_is_used with is_cylinder_usedGravatar Anton Lundin
is_cylinder_used uses get_cylinder_index as underlaying function that does the right thing with with respect on how to find the closest matching cylinder, and handles both types of gaschange events correctly. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-16Convert ternary "?:" into if for translation tools to workGravatar Dirk Hohndel
It seems the translation tools don't like the ?: in the argument - can't blame them. So use an explicit if clause instead. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-15Planner: even with broken plans, don't divide by 0Gravatar Dirk Hohndel
This fixes the crash in #623, but not the other oddities. See #623 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-12Rename event: correctly replace event with new oneGravatar Dirk Hohndel
I don't like that the event structure includes the variable length array. That really makes it a pain to change the name of an event (on the flip side, freeing events is easier I guess). Anyway, to correctly rename an event we need to actually remove the event from the correct dc and then add a new event with the new name. The previous code was insane (it only worked if the new name was of smaller or equal length, otherwise it had a beautiful buffer overflow). And of course we need to do this both for the current_dive and the displayed_dive. Fixes #616 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-12Remove event: don't compare pointers, compare eventsGravatar Dirk Hohndel
This used to work because we actually displayed the current_dive. Now with displayed_dive the pointers are of course different! So we need to compare the actual events instead. See #616 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-10Fix potential division by zeroGravatar Anton Lundin
Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-10Fix potential leak of newdc in make_first_dc()Gravatar Anton Lundin
Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-10Add helper functions to ensure we have sane tag listsGravatar Dirk Hohndel
There should never be empty or duplicate tags on those lists. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-08Fix picture loadingGravatar Dirk Hohndel
Signed vs unsigned comparisons are such a pain. Since we want offsets to be +/- 30 minutes around the dive we need to allow negative offsets - but duration_t was defined as uint32_t. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-06When copying dives, make copies of samples/events in first DCGravatar Dirk Hohndel
We carefully copied the dive computers and their samples and events, but only for the second and later DCs. For the first DC we simply copied the pointers but not what they were pointing at. So when the copied dive was freed, those pointers in the original went to freed memory. Not good. Fixes #599 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-03UI restructure: add clone_dive helperGravatar Dirk Hohndel
This is kind of the inverse to copy_dive(). Instead of duplicating all the data that the dive points to, it moves it to a new struct dive and zeroes out the old one so there are no two sets of pointers to these data. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-03Add a "smart strdup" helper named copy_string()Gravatar Dirk Hohndel
If the string is non-NULL, copy it, otherwise return NULL. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-03UI restructure: add helper function to copy and clear a diveGravatar Dirk Hohndel
This way we can safely copy around dives (specifically, copy the dive to be displayed / edited into the displayed_dive). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-02UI restructure: use a global variable to hold the dive we show / editGravatar Dirk Hohndel
There is massive confusion about what we display when and where and which dive structure (or pointer to a dive structure) contains which information at which stage. This is the first step towards restructuring all of this. This creates a global variable displayed_dive which at any point in time should be what is displayed on screen (both in the profile and in the maintab). It removes the editedDive concept from MainTab. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-01Picture loading: only add the pictures to "reasonable" divesGravatar Dirk Hohndel
If the picture has a timestamp that was within 30 minutes of the start and finish of the dive, we take it. Otherwise we don't. If the timestamps of the images are off, the time shift dialog allows the user to fix this. And with this patch the user can select all the dives of a trip and all the pictures they took on the trip and the "right thing" will happen. Fixes #578 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-11Allow the user to delete a dive computer from a diveGravatar Dirk Hohndel
This can't be the only dive computer, of course. Goes nicely with the ability to reprder them. Fixes #551 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-09Picture handling: switch to stronger typed offsetGravatar Dirk Hohndel
Also change the on file XML to be even easier to read by making it a duration as well (which gets us '32:34 min' instead of un-typed seconds). This is backwards compatible, it will happily read what was written with the previous commit). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-08Display liters with script elGravatar Robert C. Helling
Use script ell instead of 'l' for liters to avoid confusion with digit 1. Let's hope that this glyph is available in the common fonts, otherwise we'll have to revert it. [Dirk Hohndel: split commit into two] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-08Picture handling: change data structure to store offset instead timestampGravatar Dirk Hohndel
It makes no sense to store a 64bit time stamp with every picture. Even the 32bit offset (in seconds) from the dive start is WAY overkill. But switching to that makes the code much more simple in a number of spots. And makes what is saved to the XML file easier to read, too. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-08Picture handling: keep picture list sortedGravatar Dirk Hohndel
And simplify the list handling algorithm. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-08Picture handling: don't add the same picture more than onceGravatar Dirk Hohndel
It confuses us elsewhere (the model suddenly doesn't match the list of pictures as the model doesn't reflect the duplicate pictures). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-08Picture handling: adjust timestamp after it's setGravatar Dirk Hohndel
We need to first parse the exif and then adjust the timestamp. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-03Planner: only copy cylinders that were used in the template diveGravatar Dirk Hohndel
This was only semi-implemented the first time around. Now we really only copy the ones that are indeed used. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-03When calculating the maximum of unsigned values, use unsigned variableGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-03CCR code: Change to sample structureGravatar Willem Ferguson
1) All the variables in the sample structures are strongly typed 2) Two additional types were declared in units.h: o2pressure_t bearing_t 3) The following variables were added: diluentpressure o2setpoint o2sensor[3] 4) Changes to a number of files were made to chanf sample->po2 to sample->po2.mbar bearing to bearring.degrees Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-03Fix linked list corruption, move code to C.Gravatar Tomaz Canabrava
The picture list is a single linked list where the pictures have a node to their next element. When adding the same picture to two dives, things got way way wrong and crashes were appearing. This will replicate the information (filename, latitude and longitude) for each dive that has the picture, BUT it still tries to save as much as possible on the actual pixmap. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-03Not all C compilers like uintGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-02Break picture handling code from C++ to C.Gravatar Tomaz Canabrava
This commit breaks the loading of images that were done in the divelist into smaller bits. A bit of code refactor was done in order to correct the placement of a few methods. ShiftTimesDialog::EpochFromExiv got moved to Exif::epoch dive_add_picture is now used instead of add_event picture_load_exif_data got implemented using the old listview code. dive_set_geodata_from_picture got implemented using the old listview code. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-02Add a FOR_EACH_PICTURE macro and the code for picture_count.Gravatar Tomaz Canabrava
Add the FOR_EACH_PICTURE macro and the code for picture count. This uses C99 - but I will keep it like this and wait for dirk to scream at me. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-02Add stubs for the main methods that will operate on pictures.Gravatar Tomaz Canabrava
add, remove, get count, and picture_load_exif_data. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-01Remove is_air() and convert its users to gasmixGravatar Dirk Hohndel
Also make gasname() and get_gas_string() global functions (which allows us to delete code elsewhere). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-01Remove the .used member of the cylinder structureGravatar Dirk Hohndel
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>
2014-06-01Encapsulate the horrid gas encoding in gas change eventsGravatar Dirk Hohndel
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-05-29Don't assume that pressures are always positiveGravatar Dirk Hohndel
When planning a dive, the dive could use more gas than is in the cylinder. So getting a negative end pressure is a useful indication to the user that there plan might not be a good one. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-26Merge branch 'atdotde'Gravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org> Conflicts: qt-ui/diveplanner.cpp qt-ui/models.cpp
2014-05-26Use get_o2() and get_he() instead of accessing permilles directlyGravatar Robert C. Helling
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-22Create a 'remove_event' function that removes an event.Gravatar Tomaz Canabrava
The logic of removing the event was in the UI, and this makes the code harder to test because we need to take into account also the events that the interface is receiving, instead of only relying on the algorithm to test. so, now it lives in dive.h/.c and a unittest is easyer to make. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-20Use the last 'diveid' when merging dives for one dive computerGravatar Linus Torvalds
When we merge two dives into the same dive because a divecomputer had incorrectly considered it two separate dives (due to surface time within the dive) we should pick the dive ID from the later dive to be the diveid of the resulting merged dive. Otherwise we might re-download the (now merged) partial dive. This is a rather unusual special case, but it actually hit me with the Uemis on my last dive in Palau: Chandelier Cave has multiple surface points where you can spend time admiring the cave above water, and the Uemis (but not my Suunto's) decided that the dive was actually four short dives back-to-back. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-20Migrate code to for_each_dive and for_each_dcGravatar Anton Lundin
[Dirk Hohndel: this overlapped with my commit 09e7c61feeea ("Consistently use for_each_dive (and use it correctly)") so I took the pieces that I had missed] Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-19Add ability to make a dive computer the first dive computer of a diveGravatar Dirk Hohndel
If a dive has multiple dive computers we enable a special context menu when the user right-clicks on the dive computer name AND is not already showing the first dive computer. In that case we offer to make the currently shown dive computer the first one. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-19Assign the uniq dive ID the moment a dive is allocatedGravatar Dirk Hohndel
Previously we only did this when we did fixup_dive(), but that way we can't reference dives "early" in their life cycle (e.g., right after they got downloaded). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-14Don't merge divecomputers if we know they are differentGravatar Dirk Hohndel
When merging dives, if we know for sure that the dive computers are different, don't merge them into one (by interleaving the data), but instead keep both as separate dive computers in the same dive. This fixes a bug when due to a faulty download the same dive from two dive computers looks quite different. They don't get merged automatically (which is fine - they are quite different), but when manually merging them, we of course want one dive with two dive computers, not one dive with one merged dive computer. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-13Do not check for null before free.Gravatar Tomaz Canabrava
C specs says that we can safelly free a NULL pointer, so there's no reason to check if it's null before freeing it. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-11Prefix a method with 'dive_' because it should work only with divesGravatar Tomaz Canabrava
I'll probably add prefixes to functions to make it easier to find method via autocomplete from the grep or interface helpers, do you wanna know all the functions that works with a dive? ask for the completion for dive_, do you wanna know all the functions that works with a divelist? ask for the completions on divelist_ or run grep -rIs divelist_ on the header files. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-08Remove unnecessary include from dive.cGravatar Anton Lundin
Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-08Planner: Implement ascend rate according to GUE standard proceduresGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-05Fix standard cylinder namesGravatar Dirk Hohndel
We need to pass the size as an integer. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>