4
* Gnome Chemistry Utils
5
* programs/gchemtable-elt.cc
7
* Copyright (C) 2005-2006 Jean Bréfort <jean.brefort@normalesup.org>
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.
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.
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
26
#include "gchemtable-elt.h"
27
#include "gchemtable-app.h"
28
#include <gcu/element.h>
29
#include <glib/gi18n.h>
32
extern void on_show_curve (GObject *obj, char const* name);
33
static void on_focus_in (GChemTableElt *dlg)
38
GChemTableElt::GChemTableElt (GChemTableApp *App, int Z): Dialog (App, GLADEDIR"/eltpage.glade", "eltdlg")
40
Element *elt = Element::GetElement (Z);
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);
49
buf = g_strdup_printf ("%d", Z);
50
w = glade_xml_get_widget (xml, "z");
51
gtk_label_set_text (GTK_LABEL (w), buf);
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);
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);
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 ();
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 (),
99
// electronic properties page
100
w = glade_xml_get_widget (xml, "pauling-en");
101
GcuElectronegativity en;
102
en.scale = "Pauling";
104
if (elt->GetElectronegativity (&en)) {
105
buf = gcu_value_get_string (&en.value);
106
gtk_label_set_text (GTK_LABEL (w), buf);
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
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))) {
120
gtk_table_resize (table, 4, n);
121
buf = g_strdup_printf (_("%d:"), n);
122
w = gtk_label_new (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);
136
val = glade_xml_get_widget (xml, "ei-value");
137
button = glade_xml_get_widget (xml, "ei-btn");
139
buf = gcu_dimensional_value_get_string (value);
140
gtk_label_set_markup (GTK_LABEL (val), 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
148
gtk_widget_show_all (GTK_WIDGET (table));
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");
155
// electronic affinities
157
table = GTK_TABLE (glade_xml_get_widget (xml, "ae-table"));
158
while ((value = elt->GetElectronAffinity (n))) {
160
gtk_table_resize (table, 4, n);
161
buf = g_strdup_printf (_("%d:"), n);
162
w = gtk_label_new (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.
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");
178
buf = gcu_dimensional_value_get_string (value);
179
gtk_label_set_markup (GTK_LABEL (val), buf);
183
gtk_widget_show_all (GTK_WIDGET (table));
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");
191
// First covalent radius
194
r.type = GCU_COVALENT;
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);
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");
208
w = glade_xml_get_widget (xml, "covalent-radius");
209
gtk_label_set_text (GTK_LABEL (w), _("n.a."));
210
gtk_widget_hide (button);
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);
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");
222
w = glade_xml_get_widget (xml, "vdw-radius");
223
gtk_label_set_text (GTK_LABEL (w), _("n.a."));
224
gtk_widget_hide (button);
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);
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");
236
w = glade_xml_get_widget (xml, "metallic-radius");
237
gtk_label_set_text (GTK_LABEL (w), _("n.a."));
238
gtk_widget_hide (button);
240
GcuAtomicRadius const **radii = elt->GetRadii ();
241
list <GcuAtomicRadius const*> radii_list;
242
list <GcuAtomicRadius const*>::iterator j, jend;
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)))))
252
radii_list.insert (j, *radii);
253
if ((*radii)->spin > maxspin)
254
maxspin = (*radii)->spin;
258
if (radii_list.size () == 0) {
259
w = gtk_label_new (_("n.a."));
261
gtk_box_pack_start (GTK_BOX (glade_xml_get_widget (xml, "ionic-radii")),
263
gtk_widget_hide (glade_xml_get_widget (xml, "radii-scrolled"));
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);
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);
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 ());
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) {
318
buf = gcu_dimensional_value_get_string (&(*j)->value);
319
gtk_list_store_append (pclist, &iter);
320
gtk_list_store_set (pclist, &iter,
333
GChemTableElt::~GChemTableElt ()
335
reinterpret_cast<GChemTableApp*> (m_App)->ClearPage (m_Z);
338
void GChemTableElt::OnFocusIn ()
340
reinterpret_cast<GChemTableApp*> (m_App)->SetCurZ (m_Z);