1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <time.h>
#include "dive.h"
#include "display.h"
#include "divelist.h"
static struct tank_info {
const char *name;
int size; /* cuft or mliter depending on psi */
int psi; /* If zero, size is in mliter */
} tank_info[] = {
{ "None", },
{ "10.0 l", 10000 },
{ "11.1 l", 11100 },
{ "AL72", 72, 3000 },
{ "AL80", 80, 3000 },
{ "LP85", 85, 2640 },
{ "LP95", 95, 2640 },
{ "HP100", 100, 3442 },
{ "HP119", 119, 3442 },
{ NULL, }
};
static void fill_tank_list(GtkListStore *store)
{
GtkTreeIter iter;
struct tank_info *info = tank_info;
while (info->name) {
int size = info->size;
int psi = info->psi;
int mbar = 0, ml = size;
/* Is it in cuft and psi? */
if (psi) {
double bar = 0.0689475729 * psi;
double airvolume = 28316.8466 * size;
double atm = bar / 1.01325;
ml = airvolume / atm + 0.5;
mbar = bar*1000 + 0.5;
}
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter,
0, info->name,
1, ml,
2, mbar,
-1);
info++;
}
}
static void cylinder_widget(GtkWidget *box, int nr, GtkListStore *model)
{
GtkWidget *frame, *hbox, *size;
GtkCellRenderer *cell;
char buffer[80];
snprintf(buffer, sizeof(buffer), "Cylinder %d", nr);
frame = gtk_frame_new(buffer);
gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 0);
hbox = gtk_hbox_new(TRUE, 3);
gtk_container_add(GTK_CONTAINER(frame), hbox);
size = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model));
cell = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(size), cell, TRUE);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(size), cell, "text", 0, NULL );
gtk_box_pack_start(GTK_BOX(hbox), size, FALSE, FALSE, 0);
}
static GtkListStore *create_tank_size_model(void)
{
GtkListStore *model;
model = gtk_list_store_new(3,
G_TYPE_STRING, /* Tank name */
G_TYPE_INT, /* Tank size in mliter */
G_TYPE_INT, /* Tank working pressure in mbar */
-1);
fill_tank_list(model);
return model;
}
GtkWidget *cylinder_management_widget(void)
{
int i;
GtkWidget *vbox;
GtkListStore *model;
vbox = gtk_vbox_new(TRUE, 3);
model = create_tank_size_model();
for (i = 0; i < MAX_CYLINDERS; i++)
cylinder_widget(vbox, i, model);
return vbox;
}
|