]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Use unit functions to get column headers, add unit function for pressure
authorDirk Hohndel <dirk@hohndel.org>
Wed, 2 Nov 2011 03:13:14 +0000 (20:13 -0700)
committerDirk Hohndel <dirk@hohndel.org>
Wed, 2 Nov 2011 03:13:14 +0000 (20:13 -0700)
Finally getting more consistent overall in how we convert between the
different units and how we decide which units to display.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
dive.c
dive.h
divelist.c
profile.c

diff --git a/dive.c b/dive.c
index 53a874b9b0950356500fa0835a8b4c9e3b4b9deb..cb94e7925ce01695659ac1c5de33da192e77ef30 100644 (file)
--- a/dive.c
+++ b/dive.c
@@ -29,6 +29,30 @@ void add_event(struct dive *dive, int time, int type, int flags, int value, cons
        remember_event(name);
 }
 
+int get_pressure_units(unsigned int mb, const char **units)
+{
+       int pressure;
+       const char* unit;
+
+       switch (output_units.pressure) {
+       case PASCAL:
+               pressure = mb * 100;
+               unit = "pascal";
+               break;
+       case BAR:
+               pressure = (mb + 500) / 1000;
+               unit = "bar";
+               break;
+       case PSI:
+               pressure = mbar_to_PSI(mb);
+               unit = "psi";
+               break;
+       }
+       if (units)
+               *units = unit;
+       return pressure;
+}
+
 double get_temp_units(unsigned int mk, const char **units)
 {
        double deg;
diff --git a/dive.h b/dive.h
index 5eec6f170da66bbbcbdcd6dbe140d26309976af7..fe4515ee6a26ea5b20a6b0572a823ed864a0d80f 100644 (file)
--- a/dive.h
+++ b/dive.h
@@ -86,6 +86,7 @@ typedef struct {
        pressure_t start, end;
 } cylinder_t;
 
+extern int get_pressure_units(unsigned int mb, const char **units);
 extern double get_depth_units(unsigned int mm, int *frac, const char **units);
 extern double get_volume_units(unsigned int mm, int *frac, const char **units);
 extern double get_temp_units(unsigned int mm, const char **units);
@@ -146,6 +147,12 @@ static inline double to_ATM(pressure_t pressure)
        return pressure.mbar / 1013.25;
 }
 
+static inline int mbar_to_PSI(int mbar)
+{
+       pressure_t p = {mbar};
+       return to_PSI(p);
+}
+
 struct sample {
        duration_t time;
        depth_t depth;
index ca984b4eb169ed90b520ce0541ae3670c3765daf..acaf08d38a8e5ce29e26d95c932b7d9b43bd182d 100644 (file)
@@ -420,27 +420,10 @@ void update_dive_list_units(void)
        const char *unit;
        GtkTreeModel *model = GTK_TREE_MODEL(dive_list.model);
 
-       switch (output_units.length) {
-       case METERS:
-               unit = "m";
-               break;
-       case FEET:
-               unit = "ft";
-               break;
-       }
+       (void) get_depth_units(0, NULL, &unit);
        gtk_tree_view_column_set_title(dive_list.depth, unit);
 
-       switch (output_units.temperature) {
-       case CELSIUS:
-               unit = UTF8_DEGREE "C";
-               break;
-       case FAHRENHEIT:
-               unit = UTF8_DEGREE "F";
-               break;
-       case KELVIN:
-               unit = "Kelvin";
-               break;
-       }
+       (void) get_temp_units(0, &unit);
        gtk_tree_view_column_set_title(dive_list.temperature, unit);
 
        gtk_tree_model_foreach(model, set_one_dive, NULL);
index f81ae7138dae8f92a91c9eb26739ef06456bd0d0..7caa5da9f98eb40071bbc390bef39ab93fc9eaac 100644 (file)
--- a/profile.c
+++ b/profile.c
@@ -611,32 +611,13 @@ static void plot_cylinder_pressure(struct graphics_context *gc, struct plot_info
        plot_pressure_helper(gc, pi, INTERPOLATED_PR);
 }
 
-static int mbar_to_PSI(int mbar)
-{
-       pressure_t p = {mbar};
-       return to_PSI(p);
-}
-
 static void plot_pressure_value(struct graphics_context *gc, int mbar, int sec,
                                int xalign, int yalign)
 {
        int pressure;
        const char *unit;
 
-       switch (output_units.pressure) {
-       case PASCAL:
-               pressure = mbar * 100;
-               unit = "pascal";
-               break;
-       case BAR:
-               pressure = (mbar + 500) / 1000;
-               unit = "bar";
-               break;
-       case PSI:
-               pressure = mbar_to_PSI(mbar);
-               unit = "psi";
-               break;
-       }
+       pressure = get_pressure_units(mbar, &unit);
        text_render_options_t tro = {10, 0.2, 1.0, 0.2, xalign, yalign};
        plot_text(gc, &tro, sec, mbar, "%d %s", pressure, unit);
 }