Display maximum CNS in the divelist

We either pick the CNS reported by the dive computer at the end of the
dive, or the maximum of that and the CNS values in the samples, if any.

As usual, this column in the dive list defaults to off and it is
controlled by a setting in the tec page of the preferences.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2012-12-10 21:18:48 -08:00
parent 9463e7895b
commit 39f80a1e0f
5 changed files with 43 additions and 2 deletions

View file

@ -19,6 +19,7 @@ typedef struct {
gboolean nitrox;
gboolean sac;
gboolean otu;
gboolean maxcns;
} visible_cols_t;
typedef struct {

3
dive.c
View file

@ -414,6 +414,7 @@ struct dive *fixup_dive(struct dive *dive)
add_location(dive->location);
add_suit(dive->suit);
sanitize_cylinder_info(dive);
dive->maxcns = dive->cns;
dc = &dive->dc;
for (i = 0; i < dc->samples; i++) {
struct sample *sample = dc->sample + i;
@ -474,6 +475,8 @@ struct dive *fixup_dive(struct dive *dive)
depthtime += (time - lasttime) * (lastdepth + depth) / 2;
lastdepth = depth;
lasttime = time;
if (sample->cns > dive->maxcns)
dive->maxcns = sample->cns;
}
dive->start = start;
dive->end = end;

2
dive.h
View file

@ -316,7 +316,7 @@ struct dive {
cylinder_t cylinder[MAX_CYLINDERS];
weightsystem_t weightsystem[MAX_WEIGHTSYSTEMS];
char *suit;
int sac, otu;
int sac, otu, cns, maxcns;
/* Eventually we'll do multiple dive computers */
struct divecomputer dc;

View file

@ -28,7 +28,7 @@ struct DiveList {
GtkWidget *container_widget;
GtkTreeStore *model, *listmodel, *treemodel;
GtkTreeViewColumn *nr, *date, *stars, *depth, *duration, *location;
GtkTreeViewColumn *temperature, *cylinder, *totalweight, *suit, *nitrox, *sac, *otu;
GtkTreeViewColumn *temperature, *cylinder, *totalweight, *suit, *nitrox, *sac, *otu, *maxcns;
int changed;
};
@ -61,6 +61,7 @@ enum {
DIVE_NITROX, /* int: dummy */
DIVE_SAC, /* int: in ml/min */
DIVE_OTU, /* int: in OTUs */
DIVE_MAXCNS, /* int: in % */
DIVE_LOCATION, /* "2nd Cathedral, Lanai" */
DIVELIST_COLUMNS
};
@ -691,6 +692,26 @@ static void otu_data_func(GtkTreeViewColumn *col,
g_object_set(renderer, "text", buffer, NULL);
}
/* Render the CNS data (in full %) */
static void cns_data_func(GtkTreeViewColumn *col,
GtkCellRenderer *renderer,
GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data)
{
int value, idx;
char buffer[16];
gtk_tree_model_get(model, iter, DIVE_INDEX, &idx, DIVE_MAXCNS, &value, -1);
if (idx < 0 || !value)
*buffer = '\0';
else
snprintf(buffer, sizeof(buffer), "%d%%", value);
g_object_set(renderer, "text", buffer, NULL);
}
/* calculate OTU for a dive */
static int calculate_otu(struct dive *dive, struct divecomputer *dc)
{
@ -841,6 +862,7 @@ static void fill_one_dive(struct dive *dive,
DIVE_RATING, dive->rating,
DIVE_SAC, dive->sac,
DIVE_OTU, dive->otu,
DIVE_MAXCNS, dive->maxcns,
DIVE_TOTALWEIGHT, total_weight(dive),
DIVE_SUIT, suit,
-1);
@ -920,6 +942,7 @@ void update_dive_list_col_visibility(void)
gtk_tree_view_column_set_visible(dive_list.nitrox, visible_cols.nitrox);
gtk_tree_view_column_set_visible(dive_list.sac, visible_cols.sac);
gtk_tree_view_column_set_visible(dive_list.otu, visible_cols.otu);
gtk_tree_view_column_set_visible(dive_list.maxcns, visible_cols.maxcns);
return;
}
@ -1273,6 +1296,7 @@ static struct divelist_column {
[DIVE_NITROX] = { "O" UTF8_SUBSCRIPT_2 "%", nitrox_data_func, nitrox_sort_func, 0, &visible_cols.nitrox },
[DIVE_SAC] = { N_("SAC"), sac_data_func, NULL, 0, &visible_cols.sac },
[DIVE_OTU] = { N_("OTU"), otu_data_func, NULL, 0, &visible_cols.otu },
[DIVE_MAXCNS] = { N_("maxCNS"), cns_data_func, NULL, 0, &visible_cols.maxcns },
[DIVE_LOCATION] = { N_("Location"), NULL, NULL, ALIGN_LEFT },
};
@ -1414,6 +1438,7 @@ static int copy_tree_node(GtkTreeIter *a, GtkTreeIter *b)
DIVE_CYLINDER, &cylinder_text,
DIVE_SAC, &store_dive.sac,
DIVE_OTU, &store_dive.otu,
DIVE_MAXCNS, &store_dive.maxcns,
DIVE_LOCATION, &store_dive.location,
-1);
gtk_tree_store_set(STORE(dive_list), b,
@ -1429,6 +1454,7 @@ static int copy_tree_node(GtkTreeIter *a, GtkTreeIter *b)
DIVE_CYLINDER, cylinder_text,
DIVE_SAC, store_dive.sac,
DIVE_OTU, store_dive.otu,
DIVE_MAXCNS, store_dive.maxcns,
DIVE_LOCATION, store_dive.location,
-1);
free(cylinder_text);
@ -2337,6 +2363,7 @@ GtkWidget *dive_list_create(void)
G_TYPE_INT, /* Nitrox */
G_TYPE_INT, /* SAC */
G_TYPE_INT, /* OTU */
G_TYPE_INT, /* MAXCNS */
G_TYPE_STRING /* Location */
);
dive_list.treemodel = gtk_tree_store_new(DIVELIST_COLUMNS,
@ -2353,6 +2380,7 @@ GtkWidget *dive_list_create(void)
G_TYPE_INT, /* Nitrox */
G_TYPE_INT, /* SAC */
G_TYPE_INT, /* OTU */
G_TYPE_INT, /* MAXCNS */
G_TYPE_STRING /* Location */
);
dive_list.model = dive_list.treemodel;
@ -2380,6 +2408,7 @@ GtkWidget *dive_list_create(void)
dive_list.nitrox = divelist_column(&dive_list, dl_column + DIVE_NITROX);
dive_list.sac = divelist_column(&dive_list, dl_column + DIVE_SAC);
dive_list.otu = divelist_column(&dive_list, dl_column + DIVE_OTU);
dive_list.maxcns = divelist_column(&dive_list, dl_column + DIVE_MAXCNS);
dive_list.location = divelist_column(&dive_list, dl_column + DIVE_LOCATION);
fill_dive_list();

View file

@ -477,6 +477,7 @@ static void name(GtkWidget *w, gpointer data) \
}
OPTIONCALLBACK(otu_toggle, visible_cols.otu)
OPTIONCALLBACK(maxcns_toggle, visible_cols.maxcns)
OPTIONCALLBACK(sac_toggle, visible_cols.sac)
OPTIONCALLBACK(nitrox_toggle, visible_cols.nitrox)
OPTIONCALLBACK(temperature_toggle, visible_cols.temperature)
@ -683,6 +684,11 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(otu_toggle), NULL);
button = gtk_check_button_new_with_label(_("maxCNS"));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.maxcns);
gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(maxcns_toggle), NULL);
frame = gtk_frame_new(_("Profile Settings"));
gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
@ -782,6 +788,7 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
subsurface_set_conf("NITROX", PREF_BOOL, BOOL_TO_PTR(visible_cols.nitrox));
subsurface_set_conf("SAC", PREF_BOOL, BOOL_TO_PTR(visible_cols.sac));
subsurface_set_conf("OTU", PREF_BOOL, BOOL_TO_PTR(visible_cols.otu));
subsurface_set_conf("MAXCNS", PREF_BOOL, BOOL_TO_PTR(visible_cols.maxcns));
subsurface_set_conf("divelist_font", PREF_STRING, divelist_font);
subsurface_set_conf("autogroup", PREF_BOOL, BOOL_TO_PTR(autogroup));
@ -1139,6 +1146,7 @@ void init_ui(int *argcp, char ***argvp)
visible_cols.suit = PTR_TO_BOOL(subsurface_get_conf("SUIT", PREF_BOOL));
visible_cols.nitrox = PTR_TO_BOOL(subsurface_get_conf("NITROX", PREF_BOOL));
visible_cols.otu = PTR_TO_BOOL(subsurface_get_conf("OTU", PREF_BOOL));
visible_cols.maxcns = PTR_TO_BOOL(subsurface_get_conf("MAXCNS", PREF_BOOL));
visible_cols.sac = PTR_TO_BOOL(subsurface_get_conf("SAC", PREF_BOOL));
partial_pressure_graphs.po2 = PTR_TO_BOOL(subsurface_get_conf("po2graph", PREF_BOOL));