~ubuntu-branches/ubuntu/natty/gnome-chemistry-utils/natty-security

« back to all changes in this revision

Viewing changes to programs/gchemtable-elt.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jordan Mantha
  • Date: 2007-12-12 20:34:25 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20071212203425-yfb4zry8fdy8iupn
Tags: 0.8.4-3ubuntu1
* Merge from Debian unstable
* debian/control: add firefox to gcu-plugin dependencies
* Modify Maintainer value to match the DebianMaintainerField
  specification.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- C++ -*-
2
 
 
3
 
/* 
4
 
 * Gnome Chemistry Utils
5
 
 * programs/gchemtable-elt.cc 
6
 
 *
7
 
 * Copyright (C) 2005-2006 Jean Bréfort <jean.brefort@normalesup.org>
8
 
 *
9
 
 * This program is free software; you can redistribute it and/or 
10
 
 * modify it under the terms of the GNU General Public License as 
11
 
 * published by the Free Software Foundation; either version 2 of the
12
 
 * License, or (at your option) any later version.
13
 
 *
14
 
 * This program is distributed in the hope that it will be useful,
15
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 
 * GNU General Public License for more details.
18
 
 *
19
 
 * You should have received a copy of the GNU General Public License
20
 
 * along with this program; if not, write to the Free Software
21
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22
 
 * USA
23
 
 */
24
 
 
25
 
#include "config.h"
26
 
#include "gchemtable-elt.h"
27
 
#include "gchemtable-app.h"
28
 
#include <gcu/element.h>
29
 
#include <glib/gi18n.h>
30
 
#include <list>
31
 
 
32
 
extern void on_show_curve (GObject *obj, char const* name);
33
 
static void on_focus_in (GChemTableElt *dlg)
34
 
{
35
 
        dlg->OnFocusIn ();
36
 
}
37
 
 
38
 
GChemTableElt::GChemTableElt (GChemTableApp *App, int Z): Dialog (App, GLADEDIR"/eltpage.glade", "eltdlg")
39
 
{
40
 
        Element *elt = Element::GetElement (Z);
41
 
        m_Z = Z;
42
 
        char *buf;
43
 
        gtk_window_set_title (dialog, elt->GetName ());
44
 
        g_signal_connect_swapped (G_OBJECT (dialog), "focus-in-event", G_CALLBACK (on_focus_in), this);
45
 
        GtkWidget *w = glade_xml_get_widget (xml, "symbol");
46
 
        buf = g_strconcat ("<span font_desc=\"64\">", elt->GetSymbol (), "</span>", NULL);
47
 
        gtk_label_set_markup (GTK_LABEL (w), buf);
48
 
        g_free (buf);
49
 
        buf = g_strdup_printf ("%d", Z);
50
 
        w = glade_xml_get_widget (xml, "z");
51
 
        gtk_label_set_text (GTK_LABEL (w), buf);
52
 
        g_free (buf);
53
 
        int prec;
54
 
        double weight = elt->GetWeight (prec);
55
 
        char *format = (prec > 0)? g_strdup_printf ("%%0.%df",prec): g_strdup ("(%.0f)");
56
 
        buf = g_strdup_printf (format, weight);
57
 
        w = glade_xml_get_widget (xml, "weight");
58
 
        gtk_label_set_text (GTK_LABEL (w), buf);
59
 
        g_free (format);
60
 
        g_free (buf);
61
 
        w = glade_xml_get_widget (xml, "elec-conf-lbl");
62
 
        /* The <sup> </sup> markup at the end of the chain is there to ensure that
63
 
        things will be correcly aligned, add the same to the translated string */
64
 
        gtk_label_set_markup (GTK_LABEL (w), _("Electronic configuration:<sup> </sup>"));
65
 
        w = glade_xml_get_widget (xml, "elec-conf");
66
 
        gtk_label_set_markup (GTK_LABEL (w), elt->GetElectronicConfiguration ().c_str ());
67
 
        //Add composition list
68
 
        GtkListStore *pclist = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
69
 
        GtkTreeView *tree = GTK_TREE_VIEW (glade_xml_get_widget (xml, "names"));
70
 
        gtk_tree_view_set_model (tree, GTK_TREE_MODEL (pclist));
71
 
        g_object_unref (pclist);
72
 
        GtkCellRenderer *renderer;
73
 
        GtkTreeViewColumn *column;
74
 
        /* column for element */
75
 
        renderer = gtk_cell_renderer_text_new ();
76
 
        column = gtk_tree_view_column_new_with_attributes (_("Lang"), renderer, "text", 0, NULL);
77
 
        /* set this column to a minimum sizing (of 100 pixels) */
78
 
        gtk_tree_view_column_set_sizing(GTK_TREE_VIEW_COLUMN (column), GTK_TREE_VIEW_COLUMN_GROW_ONLY);
79
 
        gtk_tree_view_column_set_min_width(GTK_TREE_VIEW_COLUMN (column), 100);
80
 
        gtk_tree_view_append_column (tree, column);
81
 
        /* column for x */
82
 
        renderer = gtk_cell_renderer_text_new ();
83
 
        column = gtk_tree_view_column_new_with_attributes (_("Name"), renderer, "text", 1, NULL);
84
 
        g_object_set (G_OBJECT (renderer), "xalign", 1.0, NULL);
85
 
        /* set this column to a fixed sizing (of 100 pixels) */
86
 
        gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column), GTK_TREE_VIEW_COLUMN_FIXED);
87
 
        gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 100);
88
 
        gtk_tree_view_append_column (tree, column);
89
 
        map<string, string> Names = elt->GetNames ();
90
 
        map<string, string>::iterator i, end = Names.end ();
91
 
        GtkTreeIter iter;
92
 
        for (i = Names.begin (); i != end; i++) {
93
 
                gtk_list_store_append (pclist, &iter);
94
 
                gtk_list_store_set (pclist, &iter,
95
 
                                  0, (*i).first.c_str (),
96
 
                                  1, (*i).second.c_str (),
97
 
                                  -1);
98
 
        }
99
 
        // electronic properties page
100
 
        w = glade_xml_get_widget (xml, "pauling-en");
101
 
        GcuElectronegativity en;
102
 
        en.scale = "Pauling";
103
 
        en.Z = elt->GetZ ();
104
 
        if (elt->GetElectronegativity (&en)) {
105
 
                buf = gcu_value_get_string (&en.value);
106
 
                gtk_label_set_text (GTK_LABEL (w), buf);
107
 
                g_free (buf);
108
 
        } else
109
 
                gtk_label_set_text (GTK_LABEL (w), _("n.a."));
110
 
        w = glade_xml_get_widget (xml, "pauling-btn");
111
 
        g_object_set_data (G_OBJECT (w), "app", App);
112
 
        g_signal_connect (G_OBJECT (w), "clicked", G_CALLBACK (on_show_curve), (void*) "en/Pauling");
113
 
        // ionization energies
114
 
        int n = 1;
115
 
        GcuDimensionalValue const *value;
116
 
        GtkWidget *val, *button;
117
 
        GtkTable *table = GTK_TABLE (glade_xml_get_widget (xml, "ei-table"));
118
 
        while ((value = elt->GetIonizationEnergy (n))) {
119
 
                if (n > 1) {
120
 
                        gtk_table_resize (table, 4, n);
121
 
                        buf = g_strdup_printf (_("%d:"), n);
122
 
                        w = gtk_label_new (buf);
123
 
                        g_free (buf);
124
 
                        gtk_table_attach (table, w, 0, 1, n - 1, n,
125
 
                                (GtkAttachOptions) (GTK_SHRINK | GTK_FILL),
126
 
                                (GtkAttachOptions) 0 , 0, 0);
127
 
                        val = gtk_label_new ("");
128
 
                        gtk_table_attach (table, val, 1, 2, n - 1, n,
129
 
                                (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL),
130
 
                                (GtkAttachOptions) 0 , 0, 0);
131
 
                        button = gtk_button_new_with_label (_("Show curve"));
132
 
                        gtk_table_attach (table, button, 2, 3, n - 1, n,
133
 
                                (GtkAttachOptions) GTK_FILL,
134
 
                                (GtkAttachOptions) 0 , 0, 0);
135
 
                } else {
136
 
                        val = glade_xml_get_widget (xml, "ei-value");
137
 
                        button = glade_xml_get_widget (xml, "ei-btn");
138
 
                }
139
 
                buf = gcu_dimensional_value_get_string (value);
140
 
                gtk_label_set_markup (GTK_LABEL (val), buf);
141
 
                g_free (buf);
142
 
                buf = g_strdup_printf ("ei/%d", n);
143
 
                g_object_set_data (G_OBJECT (button), "app", App);
144
 
                g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (on_show_curve), (void*) buf);
145
 
// FIXME: clean this on exit
146
 
                n++;
147
 
        }
148
 
        gtk_widget_show_all (GTK_WIDGET (table));
149
 
        if (n == 1) {
150
 
                w = glade_xml_get_widget (xml, "ei-lbl");
151
 
                gtk_label_set_text (GTK_LABEL (w), _("n.a."));
152
 
                w = glade_xml_get_widget (xml, "ei-btn");
153
 
                gtk_widget_hide (w);
154
 
        }
155
 
        // electronic affinities
156
 
        n = 1;
157
 
        table = GTK_TABLE (glade_xml_get_widget (xml, "ae-table"));
158
 
        while ((value = elt->GetElectronAffinity (n))) {
159
 
                if (n > 1) {
160
 
                        gtk_table_resize (table, 4, n);
161
 
                        buf = g_strdup_printf (_("%d:"), n);
162
 
                        w = gtk_label_new (buf);
163
 
                        g_free (buf);
164
 
                        gtk_table_attach (table, w, 0, 1, n - 1, n,
165
 
                                (GtkAttachOptions) (GTK_SHRINK | GTK_FILL),
166
 
                                (GtkAttachOptions) 0 , 0, 0);
167
 
                        val = gtk_label_new ("");
168
 
                        gtk_table_attach (table, val, 1, 2, n - 1, n,
169
 
                                (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL),
170
 
                                (GtkAttachOptions) 0 , 0, 0);
171
 
                        button = NULL; // not enough values to draw a curve.
172
 
                } else {
173
 
                        val = glade_xml_get_widget (xml, "ae-value");
174
 
                        button = glade_xml_get_widget (xml, "ae-btn");
175
 
                        g_object_set_data (G_OBJECT (button), "app", App);
176
 
                        g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (on_show_curve), (void*) "ae");
177
 
                }
178
 
                buf = gcu_dimensional_value_get_string (value);
179
 
                gtk_label_set_markup (GTK_LABEL (val), buf);
180
 
                g_free (buf);
181
 
                n++;
182
 
        }
183
 
        gtk_widget_show_all (GTK_WIDGET (table));
184
 
        if (n == 1) {
185
 
                w = glade_xml_get_widget (xml, "ae-lbl");
186
 
                gtk_label_set_text (GTK_LABEL (w), _("n.a."));
187
 
                w = glade_xml_get_widget (xml, "ae-btn");
188
 
                gtk_widget_hide (w);
189
 
        }
190
 
        // Radii page
191
 
        // First covalent radius
192
 
        GcuAtomicRadius r;
193
 
        r.Z = Z;
194
 
        r.type = GCU_COVALENT;
195
 
        r.charge = 0;
196
 
        r.scale = NULL;
197
 
        r.cn = -1;
198
 
        r.spin = GCU_N_A_SPIN;
199
 
        button = glade_xml_get_widget (xml, "covalent-btn");
200
 
        if (elt->GetRadius (&r)) {
201
 
                buf = gcu_dimensional_value_get_string (&r.value);
202
 
                w = glade_xml_get_widget (xml, "covalent-radius");
203
 
                gtk_label_set_text (GTK_LABEL (w), buf);
204
 
                g_free (buf);
205
 
                g_object_set_data (G_OBJECT (button), "app", App);
206
 
                g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (on_show_curve), (void*) "covalent");
207
 
        } else {
208
 
                w = glade_xml_get_widget (xml, "covalent-radius");
209
 
                gtk_label_set_text (GTK_LABEL (w), _("n.a."));
210
 
                gtk_widget_hide (button);
211
 
        }
212
 
        r.type = GCU_VAN_DER_WAALS;
213
 
        button = glade_xml_get_widget (xml, "vdw-btn");
214
 
        if (elt->GetRadius (&r)) {
215
 
                buf = gcu_dimensional_value_get_string (&r.value);
216
 
                w = glade_xml_get_widget (xml, "vdw-radius");
217
 
                gtk_label_set_text (GTK_LABEL (w), buf);
218
 
                g_free (buf);
219
 
                g_object_set_data (G_OBJECT (button), "app", App);
220
 
                g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (on_show_curve), (void*) "vdw");
221
 
        } else {
222
 
                w = glade_xml_get_widget (xml, "vdw-radius");
223
 
                gtk_label_set_text (GTK_LABEL (w), _("n.a."));
224
 
                gtk_widget_hide (button);
225
 
        }
226
 
        r.type = GCU_METALLIC;
227
 
        button = glade_xml_get_widget (xml, "metallic-btn");
228
 
        if (elt->GetRadius (&r)) {
229
 
                buf = gcu_dimensional_value_get_string (&r.value);
230
 
                w = glade_xml_get_widget (xml, "metallic-radius");
231
 
                gtk_label_set_text (GTK_LABEL (w), buf);
232
 
                g_free (buf);
233
 
                g_object_set_data (G_OBJECT (button), "app", App);
234
 
                g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (on_show_curve), (void*) "metallic");
235
 
        } else {
236
 
                w = glade_xml_get_widget (xml, "metallic-radius");
237
 
                gtk_label_set_text (GTK_LABEL (w), _("n.a."));
238
 
                gtk_widget_hide (button);
239
 
        }
240
 
        GcuAtomicRadius const **radii = elt->GetRadii ();
241
 
        list <GcuAtomicRadius const*> radii_list;
242
 
        list <GcuAtomicRadius const*>::iterator j, jend;
243
 
        int maxspin = 0;
244
 
        if (radii) while (*radii) {
245
 
                if (((*radii)->type == GCU_IONIC) && !strcmp ((*radii)->scale, "Shannon")) {
246
 
                        j = radii_list.begin ();
247
 
                        jend = radii_list.end ();
248
 
                        while ((j != jend) && (((*j)->charge < (*radii)->charge) || 
249
 
                                (((*j)->charge == (*radii)->charge) && ((*j)->cn < (*radii)->cn) ||
250
 
                                (((*j)->cn == (*radii)->cn) && ((*j)->spin < (*radii)->spin)))))
251
 
                                j++;
252
 
                        radii_list.insert (j, *radii);
253
 
                        if ((*radii)->spin > maxspin)
254
 
                                maxspin = (*radii)->spin;
255
 
                }
256
 
                radii++;
257
 
        }
258
 
        if (radii_list.size () == 0) {
259
 
                w = gtk_label_new (_("n.a."));
260
 
                gtk_widget_show (w);
261
 
                gtk_box_pack_start (GTK_BOX (glade_xml_get_widget (xml, "ionic-radii")),
262
 
                                                                w, FALSE, FALSE, 0);
263
 
                gtk_widget_hide (glade_xml_get_widget (xml, "radii-scrolled"));
264
 
        } else {
265
 
                pclist = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
266
 
                tree = GTK_TREE_VIEW (glade_xml_get_widget (xml, "radii-list"));
267
 
                gtk_tree_view_set_model (tree, GTK_TREE_MODEL (pclist));
268
 
                g_object_unref (pclist);
269
 
                /* column for element */
270
 
                renderer = gtk_cell_renderer_text_new ();
271
 
                column = gtk_tree_view_column_new_with_attributes (_("Ion"), renderer, "markup", 0, NULL);
272
 
                /* set this column to a minimum sizing (of 80 pixels) */
273
 
                gtk_tree_view_column_set_spacing (column, 5);
274
 
                gtk_tree_view_append_column (tree, column);
275
 
                /* column for x */
276
 
                renderer = gtk_cell_renderer_text_new ();
277
 
                /* C.N. stands for coordination number */
278
 
                column = gtk_tree_view_column_new_with_attributes (_("C.N."), renderer, "text", 1, NULL);
279
 
                g_object_set (G_OBJECT (renderer), "xalign", 1.0, NULL);
280
 
                /* set this column to a fixed sizing (of 50 pixels) */
281
 
                gtk_tree_view_column_set_spacing (column, 5);
282
 
                gtk_tree_view_append_column (tree, column);
283
 
                column = gtk_tree_view_column_new_with_attributes (_("Spin"), renderer, "text", 2, NULL);
284
 
                if (maxspin == 0)
285
 
                        g_object_set (G_OBJECT (column), "visible", false, NULL);
286
 
                g_object_set (G_OBJECT (renderer), "xalign", 1.0, NULL);
287
 
                /* set this column to a fixed sizing (of 50 pixels) */
288
 
                gtk_tree_view_column_set_spacing (column, 5);
289
 
                gtk_tree_view_append_column (tree, column);
290
 
                column = gtk_tree_view_column_new_with_attributes (_("Value"), renderer, "text", 3, NULL);
291
 
                g_object_set (G_OBJECT (renderer), "xalign", 1.0, NULL);
292
 
                /* set this column to a fixed sizing (of 50 pixels) */
293
 
                gtk_tree_view_column_set_spacing (column, 5);
294
 
                gtk_tree_view_append_column (tree, column);
295
 
                jend = radii_list.end ();
296
 
                char *ion, *cn, *spin;
297
 
                for (j = radii_list.begin (); j != jend; j++) {
298
 
                        if ((*j)->charge > 1)
299
 
                                ion = g_strdup_printf ("%s<sup>%d+</sup><sub> </sub>",elt->GetSymbol (),(*j)->charge);
300
 
                        else if ((*j)->charge < -1)
301
 
                                ion = g_strdup_printf ("%s<sup>%d\xE2\x88\x92</sup><sub> </sub>",elt->GetSymbol (),-(*j)->charge);
302
 
                        else if ((*j)->charge == 1)
303
 
                                ion = g_strdup_printf ("%s<sup>+</sup><sub> </sub>",elt->GetSymbol ());
304
 
                        else
305
 
                                ion = g_strdup_printf ("%s<sup>\xE2\x88\x92</sup><sub> </sub>",elt->GetSymbol ());
306
 
                        cn = g_strdup_printf ("%d", (*j)->cn);
307
 
                        switch ((*j)->spin) {
308
 
                        case GCU_LOW_SPIN:
309
 
                                spin = _("Low");
310
 
                                break;
311
 
                        case GCU_HIGH_SPIN:
312
 
                                spin = _("High");
313
 
                                break;
314
 
                        default:
315
 
                                spin = "";
316
 
                                break;
317
 
                        }
318
 
                        buf = gcu_dimensional_value_get_string (&(*j)->value);
319
 
                        gtk_list_store_append (pclist, &iter);
320
 
                        gtk_list_store_set (pclist, &iter,
321
 
                                          0, ion,
322
 
                                          1, cn,
323
 
                                          2, spin,
324
 
                                          3, buf,
325
 
                                          -1);
326
 
                        g_free (ion);
327
 
                        g_free (cn);
328
 
                        g_free (buf);
329
 
                }
330
 
        }
331
 
}
332
 
 
333
 
GChemTableElt::~GChemTableElt ()
334
 
{
335
 
        reinterpret_cast<GChemTableApp*> (m_App)->ClearPage (m_Z);
336
 
}
337
 
 
338
 
void GChemTableElt::OnFocusIn ()
339
 
{
340
 
        reinterpret_cast<GChemTableApp*> (m_App)->SetCurZ (m_Z);
341
 
}