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