aboutsummaryrefslogtreecommitdiffstats
path: root/equipment.c
AgeCommit message (Collapse)Author
2014-12-04When (re)planning use prefs.decopo2 for modGravatar Anton Lundin
Use our the decopo2 from preferences for mod/switchdepth calculations when re-planning a dive or planning a dive based on a previous dive. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-14Make sure we always have copies of equipment descriptionsGravatar Dirk Hohndel
Having pointers copied around that might get freed elsewhere could be a problem. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-08-05Add standard double cylindersGravatar Dirk Hohndel
Fixes #689 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-16Planner: don't track cylinder pressure if working pressure is 0Gravatar Dirk Hohndel
The pressure graph will go from 0 to negative - one could make a weak argument that this would at least tell you how much pressure you'd need in the cylinder to start with, but that's kinda lame. Fixes #615 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-05Planner: reset deco gas used memberGravatar Dirk Hohndel
Otherwise every recalculation will continue to incorrectly increase the deco gas used value. Fixes #598 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-04Planner: don't set cylinder start and end pressure when adding diveGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-01Show ascent gas consumption separately in plannerGravatar Robert C. Helling
In the worst gase you have to provide gas for your buddy during all the ascent. So you should have the amount of gas used in ascent as a reserve. This patch makes the planner notes display that value separately. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-25Make gas mod be reasonable for users of imperial units as wellGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-25Make pO2 settings functional in plannerGravatar Robert C. Helling
Spin boxes for pO2 are now hooked up to preference values. Adding new cylinders (or changing their fo2) computes the MOD accordin to the current value of decopo2. Note that chaning the limits for deco pO2 does _not_ automatically update the switch depth of all cylinders as those might have been manually entered. Furthermore, MOD has now to option of rounding to multiples of a given depth. That is used for the automatic switch depth which are now always multiples of 3m (so that EAN50 is switched to at 21m rather than 22m). Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-25Add ALU7 to common cylindersGravatar Joakim Bygdell
Fixes #562 Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-23Use that pretty ℓ in the equipment list as wellGravatar Henrik Brautaset Aronsen
Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> 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-01Planner: track gas used even if we don't have a real cylinderGravatar Dirk Hohndel
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-05-30Planner: make sure all cylinders have a sane depthGravatar Dirk Hohndel
When copying cylinders from an existing dive, the mod of the cylinder might not be set. Assume a conservative 1.4 pO2 and fill in those data. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-29Planner: track gas consumption in cylinders and samplesGravatar Dirk Hohndel
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-06Simplify string comparisonGravatar Dirk Hohndel
This is based on Linus' idea on the mailing list. Treat NULL strings and empty strings as identical. Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-27Massive automated whitespace cleanupGravatar Dirk Hohndel
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-01-16Convert the C code to using stdbool and true/falseGravatar Anton Lundin
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>
2013-12-28Update tank model with custom tanks used in XML filesGravatar Dirk Hohndel
Fixes #377 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-09Next step towards working translationsGravatar Dirk Hohndel
This may seem like a really odd change - but with this change the Qt tools can correctly parse the C files (and qt-gui.cpp) and get the context for the translatable strings right. It's not super-pretty (I'll admit that _("string literal") is much easier on the eye than translate("gettextFromC", "string literal") ) but I think this will be the price of success. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-07Remove even more code and declarationsGravatar Dirk Hohndel
There's lots more stuff that can go. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-06Delete code and files that are no longer usedGravatar Dirk Hohndel
Most of this is Gtk related, some of it is helpers that we don't need anymore. I love the diffstat. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-06Trying to switch to Qt translationGravatar Dirk Hohndel
This compiles and looks about right, but it doesn't appear to work, yet. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-06First steps towards removing glib dependenciesGravatar Dirk Hohndel
- remove the build flags and libraries from the Makefile / Configure.mk - remove the glib types (gboolean, gchar, gint64, gint) - comment out / hack around gettext - replace the glib file helper functions - replace g_ascii_strtod - replace g_build_filename - use environment variables instead of g_get_home_dir() & g_get_user_name() - comment out GPS string parsing (uses glib utf8 macros) This needs massive cleanup, but it's a snapshot of what I have right now, in case people want to look at it. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-02Added 3L Pony tanks to the list of default tanks in equipment.cGravatar Tim Wootton
Signed-off-by: Tim Wootton <tim@tee-jay.demon.co.uk> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-02Add AL40 to list of standard tanksGravatar Benjamin
Fixes #191 on the bug tracker list Signed-off-by: Benjamin Fogel <nystire@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-09-10Change ws_info and tank_info typesGravatar Dirk Hohndel
This is correct C. But debuggers in C++ mode are broken and can't display the global variables. While I hate having to do this change, I hate not being able to debug my software because of broken tools even more. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-09-10Fill ws_info structure and use it when entering weight systemsGravatar Dirk Hohndel
The code to initialize the weight systems from the last datafile loaded had not been brought over from the Gtk version. We now correctly update the data structure when loading file (but not yet when editing values). Most likely the same needs to be done for the tanks as well. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-23Enable the weightsystem info and move the declarations to dive.hGravatar Dirk Hohndel
Having the tank_info declared in models.cpp seemed unintuitive. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-22Actually remove cylinders and weightsystems from the data structuresGravatar Dirk Hohndel
The UI had only stubbed this code out. This adds the implementation of the helpers and calls them. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-21Correctly use the weightsystem_none / cylinder_none helpersGravatar Dirk Hohndel
Plus a couple of minor formatting changes Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-17Merge branch 'Qt'Gravatar Dirk Hohndel
After the 3.1 release it is time to shift the focus on the Qt effort - and the best way to do this is to merge the changes in the Qt branch into master. Linus was extremely nice and did a merge for me. I decided to do my own merge instead (which by accident actually based on a different version of the Qt branch) and then used his merge to double check what I was doing. I resolved a few things differently but overall what we did was very much the same (and I say this with pride since Linus is a professional git merger) Here's his merge commit message: This is a rough and tumble merge of the Qt branch into 'master', trying to sort out the conflicts as best as I could. There were two major kinds of conflicts: - the Makefile changes, in particular the split of the single Makefile into Rules.mk and Configure.mk, along with the obvious Qt build changes themselves. Those changes conflicted with some of the updates done in mainline wrt "release" targets and some helper macros ($(NAME) etc). Resolved by largely taking the Qt branch versions, and then editing in the most obvious parts of the Makefile updates from mainline. NOTE! The script/get_version shell script was made to just fail silently on not finding a git repository, which avoided having to take some particularly ugly Makefile changes. - Various random updates in mainline to support things like dive tags. The conflicts were mainly to the gtk GUI parts, which obviously looked different afterwards. I fixed things up to look like the newer code, but since the gtk files themselves are actually dead in the Qt branch, this is largely irrelevant. NOTE! This does *NOT* introduce the equivalent Qt functionality. The fields are there in the code now, but there's no Qt UI for the whole dive tag stuff etc. This seems to compile for me (although I have to force "QMAKE=qmake-qt4" on f19), and results in a Linux binary that seems to work, but it is otherwise largely untested. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-15Avoid reading an uninitialized variable when adding new cylindersGravatar Dirk Hohndel
If mbar = 0 then *p would not be set, but the variable was then used in the calling function. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-03Fix compiler warningsGravatar Dirk Hohndel
Doing this on Arch Linux with gcc 4.8.0 helped find one real bug. The rest are simply changes to make static functions externally visible (as they are kept around to eventually become helpers used by Qt) which for now avoids the warnings. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-03Remove the majority of the Gtk related codeGravatar Dirk Hohndel
- rip all Gtk code from qt-gui.cpp - don't compile Gtk specific files - don't link against Gtk libraries - don't compile modules we don't use at all (yet) - use #if USE_GTK_UI on the remaining files to disable Gtk related parts - disable the non-functional Cochran support while I'm at it Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-15Added the code that will load and populate the Tank InfoGravatar Tomaz Canabrava
Added the code that will load and populate the Tank Info ComboBox that`s used by the user to select the Cylinder description. Code curerntly implements more than the GTK version since the GTK version of it was a plain-list, this one is a table based model that can be used in ListViews ( like we use now in the ComboBox ) but also in TableViews ( if there`s a need in the future to see everything that`s catalogued in the Tank Info struct. ) Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-13Started the real code on the Qt Interface.Gravatar Tomaz Canabrava
1 - Open File already open files, it tries to not break the Gtk version, but some methods on the GTK version still need to be called inside Qt because the code is too tight-coupled. 2 - Close file already close files, same comments for the open file dialog applies here. 3 - The code for adding new cylinders in the cylinder dialog is done, already works and it's integrated with the system. There's a need to implement the edit and delete now, but it will be easyer since I'm starting to not get lost on the code. 4 - Some functions that were used to convert unities have been moved to convert.h ( can be changed later, put there because it's easyer to find something that converts in a convert.h =p ) because they were static functions that operated in the GTK version but I need those functions in the Qt version too. [Dirk Hohndel: lots and lots of whitespace and coding style changes] Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-17Manually add gas changes to a diveGravatar Dirk Hohndel
Create a little widget that lists all the gases / tanks we know about and allow the user to pick one of them. Turns out that add_event only added events at the end of the list - but we treat that list as chronologically sorted. So I fixed that little mis-feature as well. This does raise the question whether we need the inverse operation (removing a gas change). And if there are other things that we should be able to manually edit, now that we have the infrastructure for this neat little context menu... See #60 -- this doesn't address all of the issues mentioned there, but at least deals with the 'headline' of the feature request... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-03Try to capture some more potential buffer overflows caused by localizationGravatar Dirk Hohndel
A couple of these could clearly cause a crash just like the one fixed by commit 00865f5a1e1a ("equipment.c: Fix potential buffer overflow in size_data_funct()"). One would append user input to fixed length buffer without checking. We were hardcoding the (correct) max path length in macos.c - replaced by the actual OS constant. But the vast majority are just extremely generous guesses how long localized strings could possibly be. Yes, this commit is likely leaning towards overkill. But we have now been bitten by buffer overflow crashes twice that were caused by localization, so I tried to go through all of the code and identify every possible buffer that could be affected by this. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-03equipment.c: Fix potential buffer overflow in size_data_funct()Gravatar Lubomir I. Ivanov
strcpy() with buffer[10], could overflow on most languages. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-18Clear statistics and equipment when no dive is selectedGravatar Dirk Hohndel
This all seems very strange forward. The reason for the check whether the stats_w widget has been populated is that at the very beginning, when the UI is still being assembled, a first call to switch_page() happens as the notebook pages are assembled. At that point the stats_w widget is still empty which tells us that we aren't ready to display anything. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-30Massive cleanupGravatar Dirk Hohndel
Mostly coding style and whitespace changes plus making lots of functions static that have no need to be extern. This also helped find a bit of code that is actually no longer used. This should have absolutely no functional impact - all changes should be purely cosmetic. But it removes a bunch of lines of code and makes the rest easier to read. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-28Clean up gtk combo box handlingGravatar Linus Torvalds
This cleans up our handling of combo boxes and all the duplicated completion logic, and simplifies the code. In particular, we get rid of the deprecated GtkComboBoxEntry. While it made some things easier, it made other things harder. Just using GtkComboBox and setting that up correctly ends up being simpler, and also makes the logic work with gtk-3. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-28Make subsurface compile with -DGSEAL_ENABLEGravatar Linus Torvalds
This forces us to use the proper gtk accessor functions. It may not be worth it if people actually do the Qt conversion, but if we want to try gtk3 at some point, this might help. This all came about because I was trying to explain on G+ what an immense pain this all was to even figure out, if you don't actually know gtk at all. Google and the gtk migration guide are almost useless, and the gtk2 documentation itself actually uses the fields directly without any accessor functions in several places. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-14Centralising and redefining values as integersGravatar Jan Schubert
This patch centralizes the definition for surface pressure, oxygen in air, (re)defines all such values as plain integers and adapts calculations. It eliminates 11 (!) occurrences of definitions for surface pressure and also a few for oxygen in air. It also rewrites the calculation for EAD, END and EADD using the new definitons, harmonizing it for OC and CC and fixes a bug for EADD OC calculation. And finally it removes the unneeded variable entry_ead in gtk-gui.c. Jan Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-10Split up preference data structure definition into 'pref.h'Gravatar Linus Torvalds
.. and rename the badly named 'output_units/input_units' variables. We used to have this confusing thing where we had two different units (input vs output) that *look* like they are mirror images, but in fact "output_units" was the user units, and "input_units" are the XML parsing units. So this renames them to be clearer. "output_units" is now just "units" (it's the units a user would ever see), and "input_units" is now "xml_parsing_units" and set by the XML file parsers to reflect the units of the parsed file. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-10Move global variables covered by Preferences into one structureGravatar Dirk Hohndel
Now we can simply remember the state of all the preferences at the beginning of preferences_dialog() and restore them if the user presses 'Cancel'. Fixes #21 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-10gtk spinbuttons are crazy - fix possible divide-by-zeroGravatar Linus Torvalds
When we fill the cylinder information in an imperial unit world, a working pressure of zero is a special case, and forces us to use the actual physical size of the cylinder in liter, despite the fact that we normally would use cuft. However, we compare that value against zero in a 'double', and in between going through the gtk spinbutton logic, the zero we have filled in then gets read out as some very tiny epsilon value from the gtk spinbuttons (typically in the 10**-317 range). This causes us to think that the zero isn't actually a zero, because gtk has done odd things with it. Fix this by calculating the millibar value (as an integer) first, and check that *integer* against zero. Any crazy epsilon values will have been rounded away, and our logic works again. There's a good reason why subsurface does everything using integers (ie the afore-mentioned "convert to integer millibar" etc) and doesn't use floating point for any core data structures, only for conversion. FP rounding and inexact behavior can be really subtle. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>