4
4
* Gnome Chemistry Utils
5
* programs/gchemtable-app.cc
7
* Copyright (C) 2005-2010 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
5
* programs/gchemtable-app.cc
7
* Copyright (C) 2005-2011 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 3 of the
12
12
* License, or (at your option) any later version.
14
14
* This program is distributed in the hope that it will be useful,
27
27
#include "gchemtable-curve.h"
28
28
#include "gchemtable-data.h"
29
29
#include "gchemtable-elt.h"
30
#include <gcugtk/filechooser.h>
31
#include <gcugtk/message.h>
32
#include <gcugtk/ui-builder.h>
30
33
#include <gcu/chemistry.h>
31
34
#include <gcu/element.h>
32
#include <gcu/filechooser.h>
33
#include <gcu/ui-builder.h>
35
36
#include <glib/gi18n.h>
36
#include <gtk/gtkaboutdialog.h>
37
#include <gtk/gtkmain.h>
38
#include <gtk/gtkstock.h>
39
#include <gtk/gtkuimanager.h>
40
#include <gtk/gtkwindow.h>
41
38
#include <gio/gio.h>
102
99
App->SetColorScheme ("block");
105
static void on_about_activate_url (G_GNUC_UNUSED GtkAboutDialog *about, const gchar *url, gpointer data)
107
reinterpret_cast <Application *> (data)->OnWeb (url);
110
102
static void on_help (G_GNUC_UNUSED GtkWidget *widget, GChemTableApp *app)
115
static void on_web (G_GNUC_UNUSED GtkWidget *widget, GChemTableApp *app)
120
static void on_mail (G_GNUC_UNUSED GtkWidget *widget, GChemTableApp *app)
125
static void on_live_assistance (G_GNUC_UNUSED GtkWidget *widget, GChemTableApp *app)
127
app->OnLiveAssistance ();
130
static void on_bug (G_GNUC_UNUSED GtkWidget *widget, GChemTableApp *app)
107
static void on_web (GtkWidget *widget, GChemTableApp *app)
109
app->OnWeb (gtk_widget_get_screen (widget));
112
static void on_mail (GtkWidget *widget, GChemTableApp *app)
114
app->OnMail (gtk_widget_get_screen (widget));
117
static void on_live_assistance (GtkWidget *widget, GChemTableApp *app)
119
app->OnLiveAssistance (gtk_widget_get_screen (widget));
122
static void on_bug (GtkWidget *widget, GChemTableApp *app)
124
app->OnBug (gtk_widget_get_screen (widget));
135
127
static void on_about (G_GNUC_UNUSED GtkWidget *widget, GChemTableApp *app)
256
static void get_state_color (int Z, GdkColor *color, GChemTableApp *App)
248
static void get_state_color (int Z, GdkRGBA *rgba, GChemTableApp *App)
258
App->GetStateColor (Z, color);
250
App->GetStateColor (Z, rgba);
261
253
static void on_changed_temp (GtkRange *range, GChemTableApp *app)
268
260
app->SetFamily (gtk_combo_box_get_active (box));
271
static void get_family_color (int Z, GdkColor *color, GChemTableApp *App)
273
App->GetFamilyColor (Z, color);
276
static void get_acidity_color (int Z, GdkColor *color, GChemTableApp *App)
278
App->GetAcidityColor (Z, color);
281
static void get_electroneg_color (int Z, GdkColor *color, GChemTableApp *App)
283
App->GetElectronegColor (Z, color);
286
static void get_radius_color (int Z, GdkColor *color, GChemTableApp *App)
288
App->GetRadiusColor (Z, color);
291
static void get_block_color (int Z, GdkColor *color, GChemTableApp *App)
293
App->GetBlockColor (Z, color);
263
static void get_family_color (int Z, GdkRGBA *rgba, GChemTableApp *App)
265
App->GetFamilyColor (Z, rgba);
268
static void get_acidity_color (int Z, GdkRGBA *rgba, GChemTableApp *App)
270
App->GetAcidityColor (Z, rgba);
273
static void get_electroneg_color (int Z, GdkRGBA *rgba, GChemTableApp *App)
275
App->GetElectronegColor (Z, rgba);
278
static void get_radius_color (int Z, GdkRGBA *rgba, GChemTableApp *App)
280
App->GetRadiusColor (Z, rgba);
283
static void get_block_color (int Z, GdkRGBA *rgba, GChemTableApp *App)
285
App->GetBlockColor (Z, rgba);
296
288
static void on_destroy (GChemTableApp *App)
299
291
gtk_main_quit ();
302
GChemTableApp::GChemTableApp (): Application ("gchemtable")
294
GChemTableApp::GChemTableApp (): gcugtk::Application ("gchemtable")
298
gcu::Element::LoadAllData ();
306
299
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
307
300
gtk_window_set_title (GTK_WINDOW (window), _("Periodic table of the elements"));
308
301
gtk_window_set_icon_name (GTK_WINDOW (window), GetIconName ().c_str ());
310
303
G_CALLBACK (on_destroy),
313
g_object_set (G_OBJECT(window), "allow-shrink", FALSE, NULL);
315
vbox = (GtkVBox*)gtk_vbox_new(FALSE, 0);
306
grid = gtk_grid_new ();
307
g_object_set (G_OBJECT (grid), "orientation", GTK_ORIENTATION_VERTICAL, NULL);
317
309
GtkUIManager *ui_manager = gtk_ui_manager_new ();
318
310
GtkActionGroup *action_group = gtk_action_group_new ("MenuActions");
328
320
exit (EXIT_FAILURE);
330
322
GtkWidget *bar = gtk_ui_manager_get_widget (ui_manager, "/MainMenu");
331
gtk_box_pack_start (GTK_BOX (vbox), bar, FALSE, FALSE, 0);
323
gtk_container_add (GTK_CONTAINER (grid), bar);
332
324
periodic = GCU_PERIODIC (gcu_periodic_new());
333
g_object_set(G_OBJECT(periodic),
334
"color-style", GCU_PERIODIC_COLOR_DEFAULT,
335
"can_unselect", true,
325
g_object_set (G_OBJECT(periodic),
327
"color-style", GCU_PERIODIC_COLOR_DEFAULT,
328
"can_unselect", true,
337
331
g_signal_connect(G_OBJECT(periodic), "element_changed", (GCallback)on_changed, this);
338
gtk_box_pack_end (GTK_BOX(vbox), GTK_WIDGET(GCU_PERIODIC(periodic)), true, true, 0);
339
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(vbox));
332
gtk_container_add (GTK_CONTAINER (grid), GTK_WIDGET (periodic));
333
gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (grid));
340
334
gtk_widget_show_all(window);
341
335
g_object_unref (ui_manager);
342
336
for (int i = 0; i < 118; i++)
345
gcu::Element::LoadAllData ();
339
gcu_periodic_set_tips (periodic, GCU_PERIODIC_TIP_STANDARD);
346
340
colorschemes["none"] = GCU_PERIODIC_COLOR_NONE;
347
341
colorschemes["default"] = GCU_PERIODIC_COLOR_DEFAULT;
349
UIBuilder *builder = new UIBuilder (UIDIR"/state-thermometer.ui", GETTEXT_PACKAGE);
343
gcugtk::UIBuilder *builder = new gcugtk::UIBuilder (UIDIR"/state-thermometer.ui", GETTEXT_PACKAGE);
350
344
GtkWidget *thermometer = builder->GetRefdWidget ("state-thermometer");
351
345
colorschemes["state"] = gcu_periodic_add_color_scheme (periodic, (GcuPeriodicColorFunc) get_state_color, thermometer, this);
352
346
gtk_widget_show_all (thermometer);
355
349
temperature = gtk_range_get_value (GTK_RANGE (thermometer));
358
builder = new UIBuilder (UIDIR"/family.ui", GETTEXT_PACKAGE);
352
builder = new gcugtk::UIBuilder (UIDIR"/family.ui", GETTEXT_PACKAGE);
359
353
GtkWidget *familywidget = builder->GetRefdWidget ("family-legend");
360
colorschemes["family"] = gcu_periodic_add_color_scheme (periodic, (GcuPeriodicColorFunc) get_family_color, familywidget, this);
354
colorschemes["family"] = gcu_periodic_add_color_scheme (periodic, (GcuPeriodicColorFunc) get_family_color, familywidget, this);
361
355
gtk_widget_show_all (familywidget);
362
356
familywidget = builder->GetWidget ("family-box");
363
357
gtk_combo_box_set_active (GTK_COMBO_BOX(familywidget), 0);
365
359
g_signal_connect (G_OBJECT (familywidget), "changed", G_CALLBACK (on_changed_family), this);
368
builder = new UIBuilder (UIDIR"/acidity.ui", GETTEXT_PACKAGE);
362
builder = new gcugtk::UIBuilder (UIDIR"/acidity.ui", GETTEXT_PACKAGE);
369
363
GtkWidget *aciditylegend = builder->GetRefdWidget ("acidity-legend");
370
364
colorschemes["acidity"] = gcu_periodic_add_color_scheme (periodic, (GcuPeriodicColorFunc) get_acidity_color, aciditylegend, this);
371
365
gtk_widget_show_all (aciditylegend);
376
370
colorschemes["radius"] = gcu_periodic_add_color_scheme (periodic, (GcuPeriodicColorFunc) get_radius_color, NULL, this);
378
builder = new UIBuilder (UIDIR"/block.ui", GETTEXT_PACKAGE);
372
builder = new gcugtk::UIBuilder (UIDIR"/block.ui", GETTEXT_PACKAGE);
379
373
GtkWidget *blocklegend = builder->GetRefdWidget ("block-legend");
380
374
colorschemes["block"] = gcu_periodic_add_color_scheme (periodic, (GcuPeriodicColorFunc) get_block_color, blocklegend, this);
381
375
gtk_widget_show_all (blocklegend);
402
396
const gchar * license =
403
397
"This program is free software; you can redistribute it and/or\n"
404
398
"modify it under the terms of the GNU General Public License as\n"
405
"published by the Free Software Foundation; either version 2 of the\n"
399
"published by the Free Software Foundation; either version 3 of the\n"
406
400
"License, or (at your option) any later version.\n\n"
407
401
"This program is distributed in the hope that it will be useful,\n"
408
402
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
412
406
"along with this program; if not, write to the Free Software\n"
413
407
"Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301\n"
416
gtk_about_dialog_set_url_hook (on_about_activate_url, this, NULL);
418
410
/* Note to translators: replace the following string with the appropriate credits for you lang */
419
411
const gchar * translator_credits = _("translator_credits");
475
467
gcu_periodic_set_colors (periodic);
478
void GChemTableApp::GetStateColor (int Z, GdkColor *color)
470
void GChemTableApp::GetStateColor (int Z, GdkRGBA *rgba)
480
color->red= color->green = color->blue = 0;
472
rgba->red= rgba->green = rgba->blue = 0.;
481
473
Element *elt = Element::GetElement (Z);
482
474
Value const *value = elt->GetProperty ("meltingpoint");
485
477
double t = value->GetAsDouble ();
486
478
if (t > temperature) {
487
color->blue = 0xffff;
490
482
value = elt->GetProperty ("boilingpoint");
493
485
t = value->GetAsDouble ();
494
486
if (t > temperature) {
495
color->green = 0xffff;
501
void GChemTableApp::GetFamilyColor (int Z, GdkColor *color)
493
void GChemTableApp::GetFamilyColor (int Z, GdkRGBA *rgba)
503
color->red= color->green = color->blue = 0;
495
rgba->red= rgba->green = rgba->blue = 0;
504
496
Element *elt = Element::GetElement (Z);
505
497
std::string &value = elt->GetStringProperty ("family");
506
498
if (!value.length())
521
513
if (value == "Alkali_Earth") {
523
color->blue = 0x8eff;
527
519
if (value == "Alkaline_Earth") {
529
color->blue = 0xffff;
533
525
if (value == "Non-Metal") {
534
526
if (family & 0x20)
535
color->green = 0xffff;
539
531
if (value == "Metalloids") {
541
color->green = 0x8eff;
545
537
if (value == "Transition") {
546
538
if (family & 0x80) {
548
color->green = 0xffff;
553
545
if (value == "Other_Metal") {
554
546
if (family & 0x100) {
556
color->green = 0x8eff;
561
553
if (value == "Halogene") {
567
559
if (value == "Noblegas") {
568
560
if (family & 0x10)
573
565
if (value == "Rare_Earth") {
574
566
if (family & 0x40) {
576
color->blue = 0xffff;
582
void GChemTableApp::GetAcidityColor (int Z, GdkColor *color)
574
void GChemTableApp::GetAcidityColor (int Z, GdkRGBA *rgba)
584
color->red= color->green = color->blue = 0;
576
rgba->red= rgba->green = rgba->blue = 0.;
585
577
Element *elt = Element::GetElement (Z);
586
578
int value = elt->GetIntegerProperty ("acidicbehaviour");
587
579
if (value == GCU_ERROR)
603
color->blue = 0xffff;
607
color->green = 0xffff;
612
color->blue = 0xffff;
617
void GChemTableApp::GetElectronegColor (int Z, GdkColor *color)
609
void GChemTableApp::GetElectronegColor (int Z, GdkRGBA *rgba)
623
color->red= color->green = color->blue = 0;
615
rgba->red= rgba->green = rgba->blue = 0;
624
616
Element *elt = Element::GetElement (Z);
625
617
Value const *value = elt->GetProperty ("electronegativityPauling");
631
623
limit = 0.5 * (max - min);
633
625
if (en < limit) {
635
color->blue = static_cast<guint16> ((en - min) * 0xffff / (limit - min));
627
rgba->blue = (en - min) / (limit - min);
637
color->blue = 0xffff;
638
color->red= static_cast<guint16> ((en - max) * 0xffff / (limit - max));
630
rgba->red= (en - max) / (limit - max);
643
void GChemTableApp::GetRadiusColor (int Z, GdkColor *color)
635
void GChemTableApp::GetRadiusColor (int Z, GdkRGBA *rgba)
649
color->red = color->green = color->blue = 0;
641
rgba->red = rgba->green = rgba->blue = 0.;
650
642
Element *elt = Element::GetElement (Z);
651
643
Value const *value = elt->GetProperty ("radiusCovalent");
657
649
limit = 0.5 * (max - min);
659
651
if (radius < limit) {
661
color->blue = static_cast<guint16> ((radius - min) * 0xffff / (limit - min));
653
rgba->blue = (radius - min) / (limit - min);
663
color->blue = 0xffff;
664
color->red= static_cast<guint16> ((radius - max) * 0xffff / (limit - max));
656
rgba->red= (radius - max) / (limit - max);
669
void GChemTableApp::GetBlockColor (int Z, GdkColor *color)
661
void GChemTableApp::GetBlockColor (int Z, GdkRGBA *rgba)
671
color->red= color->green = color->blue = 0;
663
rgba->red= rgba->green = rgba->blue = 0.;
672
664
Element *elt = Element::GetElement (Z);
673
665
std::string &value = elt->GetStringProperty ("periodTableBlock");
674
666
if (!value.length())
677
669
if (value == "s") {
678
color->blue = 0x8eff;
682
674
if (value == "p") {
687
679
if (value == "d") {
688
color->green = 0x8eff;
692
684
if (value == "f") {
693
color->blue = 0x8eff;
722
714
l.push_front ("application/postscript");
723
715
l.push_front ("application/pdf");
724
716
l.push_front ("image/svg+xml");
725
FileChooser (this, true, l, reinterpret_cast <Document *> (curve), _("Save as image"), GetImageSizeWidget ());
717
gcugtk::FileChooser (this, true, l, reinterpret_cast <Document *> (curve), _("Save as image"), GetImageSizeWidget ());
728
720
bool GChemTableApp::FileProcess (const gchar* filename, const gchar* mime_type, bool bSave, G_GNUC_UNUSED GtkWindow *window, Document *Doc)
736
728
char *unescaped = g_uri_unescape_string (filename, NULL);
737
729
gchar * message = g_strdup_printf (_("File %s\nexists, overwrite?"), unescaped);
738
730
g_free (unescaped);
739
GtkDialog* Box = GTK_DIALOG (gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "%s", message));
740
gtk_window_set_icon_name (GTK_WINDOW (Box), "gspectrum");
741
result = gtk_dialog_run (Box);
742
gtk_widget_destroy (GTK_WIDGET (Box));
731
gcugtk::Message *box = new gcugtk::Message (this, message, GTK_MESSAGE_QUESTION,
732
GTK_BUTTONS_YES_NO, window);
733
result = box->Run ();
743
734
g_free (message);
745
736
if (result == GTK_RESPONSE_YES) {