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