diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-09-11 12:53:59 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-09-11 15:49:50 -0700 |
commit | 0c4e1697db2d9e15a05bc76056fca13e9ccb9ba4 (patch) | |
tree | f46f240c6f19cf0c46e817190e451ab96e023fe1 | |
parent | 61d0aa10e1a88ac2e5ddcab9e0f05a729b3ab9e9 (diff) | |
download | subsurface-0c4e1697db2d9e15a05bc76056fca13e9ccb9ba4.tar.gz |
Be more careful about unit changes
When we change units, we need to flush any currently active dive
information in the old units, and then carefully reload it in the new
units.
Otherwise crazy stuff happens - like having current cylinder working
pressure values that are in PSI because that *used* to be the output
unit, but then interpreting those values as BAR, because we changed the
units.
Also, since we now properly import working pressure from Diving Log,
stop importing the (useless) cylinder description. The Diving Log
cylinder descriptions are things like "Alu" or "Steel". We're better
off just making up our own.
Finally, since Diving Log has cylinder size in metric, make sure that we
do the "match standard cylinder sizes" *after* we've done all the
cylinder size conversions to proper units.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | dive.h | 3 | ||||
-rw-r--r-- | divelist.h | 3 | ||||
-rw-r--r-- | main.c | 4 | ||||
-rw-r--r-- | parse-xml.c | 15 | ||||
-rw-r--r-- | save-xml.c | 2 |
5 files changed, 15 insertions, 12 deletions
@@ -166,6 +166,9 @@ struct dive_table { extern struct dive_table dive_table; +extern int selected_dive; +#define current_dive (get_dive(selected_dive)) + static inline struct dive *get_dive(unsigned int nr) { if (nr >= dive_table.nr) diff --git a/divelist.h b/divelist.h index 2d6c5dce6..797a89641 100644 --- a/divelist.h +++ b/divelist.h @@ -10,9 +10,6 @@ struct DiveList { GtkTreeViewColumn *date, *depth, *duration; }; -extern int selected_dive; -#define current_dive (get_dive(selected_dive)) - extern struct DiveList dive_list_create(void); extern void dive_list_update_dives(struct DiveList); extern void update_dive_list_units(struct DiveList *); @@ -98,9 +98,9 @@ void update_dive(struct dive *new_dive) if (old_dive) { flush_dive_info_changes(old_dive); flush_dive_equipment_changes(old_dive); + buffered_dive = new_dive; } if (new_dive) { - buffered_dive = new_dive; show_dive_info(new_dive); show_dive_equipment(new_dive); } @@ -312,6 +312,8 @@ static void unit_dialog(GtkWidget *w, gpointer data) gtk_widget_show_all(dialog); result = gtk_dialog_run(GTK_DIALOG(dialog)); if (result == GTK_RESPONSE_ACCEPT) { + /* Make sure to flush any modified old dive data with old units */ + update_dive(NULL); output_units = menu_units; update_dive_list_units(&dive_list); repaint_dive(); diff --git a/parse-xml.c b/parse-xml.c index 14c21972c..91bcced6e 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -639,7 +639,6 @@ static int divinglog_dive_match(struct dive *dive, const char *name, int len, ch MATCH(".depth", depth, &dive->maxdepth) || MATCH(".tanksize", cylindersize, &dive->cylinder[0].type.size) || MATCH(".presw", pressure, &dive->cylinder[0].type.workingpressure) || - MATCH(".tanktype", utf8_string, &dive->cylinder[0].type.description) || MATCH(".comments", utf8_string, &dive->notes) || MATCH(".country.name", utf8_string, &country) || MATCH(".city.name", utf8_string, &city) || @@ -1017,7 +1016,8 @@ static void sanitize_gasmix(gasmix_t *mix) */ static void match_standard_cylinder(cylinder_type_t *type) { - int psi, cuft, len; + double cuft; + int psi, len; const char *fmt; char buffer[20], *p; @@ -1025,7 +1025,8 @@ static void match_standard_cylinder(cylinder_type_t *type) if (type->description) return; - cuft = type->size.mliter / 1000; + cuft = type->size.mliter / 28317.0; + cuft *= type->workingpressure.mbar / 1013.25; psi = type->workingpressure.mbar / 68.95; switch (psi) { @@ -1047,7 +1048,7 @@ static void match_standard_cylinder(cylinder_type_t *type) default: return; } - len = snprintf(buffer, sizeof(buffer), fmt, cuft); + len = snprintf(buffer, sizeof(buffer), fmt, (int) (cuft+0.5)); p = malloc(len+1); if (!p) return; @@ -1078,15 +1079,15 @@ static void sanitize_cylinder_type(cylinder_type_t *type) if (!type->size.mliter) return; - /* Ok, we have both size and pressure: try to match a description */ - match_standard_cylinder(type); - if (input_units.volume == CUFT || import_source == SUUNTO) { volume_of_air = type->size.mliter * 28.317; /* milli-cu ft to milliliter */ atm = type->workingpressure.mbar / 1013.25; /* working pressure in atm */ volume = volume_of_air / atm; /* milliliters at 1 atm: "true size" */ type->size.mliter = volume + 0.5; } + + /* Ok, we have both size and pressure: try to match a description */ + match_standard_cylinder(type); } static void sanitize_cylinder_info(struct dive *dive) diff --git a/save-xml.c b/save-xml.c index 3ed67fe39..a9800d001 100644 --- a/save-xml.c +++ b/save-xml.c @@ -232,7 +232,7 @@ void save_dives(const char *filename) return; /* Flush any edits of current dives back to the dives! */ - update_dive(NULL); + update_dive(current_dive); fprintf(f, "<dives>\n<program name='diveclog' version='%d'></program>\n", VERSION); for (i = 0; i < dive_table.nr; i++) |