atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
interface.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2026 by CNRS and University of Strasbourg */
15
21
22/*
23* This file: 'interface.c'
24*
25* Contains:
26*
27
28 - General messaging functions
29
30*
31* List of functions:
32
33 int dummy_ask_ (char * question);
34 int iask (char * question, char * lab, int id, GtkWidget * win);
35
36 gboolean ask_yes_no (gchar * title, gchar * text, int type, GtkWidget * widg);
37
38 G_MODULE_EXPORT gboolean leaving_question (GtkWindow * widget, gpointer data);
39 G_MODULE_EXPORT gboolean leaving_question (GtkWidget * widget, GdkEvent * event, gpointer data);
40
41 gchar * exact_name (gchar * name);
42 gchar * cask (char * question, char * lab, int id, char * old, GtkWidget * win);
43 gchar * textcolor (int i);
44 gchar * env_name (project * this_proj, int g, int s, int f, GtkTextBuffer * buffer);
45
46 void show_web (GtkWidget * dialog, int id);
47 void show_info (char * information, int val, GtkWidget * win);
48 void show_warning (char * warning, GtkWidget * win);
49 void show_warning_ (char * warning, char * sub, char * tab);
50 void show_error (char * error, int val, GtkWidget * win);
51 void show_error_with_trace (gchar * error, atomes_error * this_error, int act, int val, GtkWidget * win);
52 void show_error_ (char * error, char * sub, char * tab);
53 void init_data_ (int * nats, int * nspc, int * stps, int * cid);
54 void print_info (gchar * str, gchar * stag, GtkTextBuffer * buffer);
55 void lattice_info_ (int * bid, double * volume, double * density,
56 double dvects[3][3], double rvects[3][3], double mod[3], double ang[3],
57 double f_to_c[3][3], double c_to_f[3][3]);
58 void send_chem_info_ (int prop[active_project -> nspec]);
59 void update_after_calc (int calc);
60
61 G_MODULE_EXPORT void create_about_dialog (GtkWidget * widg, gpointer data);
62 G_MODULE_EXPORT void run_yes_no (GtkDialog * dial, gint response_id, gpointer data);
63 G_MODULE_EXPORT void on_answer_changed (GtkWidget * widg, gpointer data);
64 G_MODULE_EXPORT void run_iask (GtkDialog * iask, gint response_id, gpointer data);
65 G_MODULE_EXPORT void run_cask (GtkDialog * cask, gint response_id, gpointer data);
66
67 GtkWidget * addweb (int id);
68 GtkWidget * show_pop (char * pop, GtkWidget * pwin);
69
70*/
71
72#include "global.h"
73#include "bind.h"
74#include "callbacks.h"
75#include "project.h"
76#include "curve.h"
77#include "affero.h"
78
79extern gchar * substitute_string (gchar * init, gchar * o_motif, gchar * n_motif);
80
81GtkWidget * answer;
82
83/* Old version to make url/email in about dialog clickable */
84/* void about_dialog_handle_url (GtkAboutDialog * dialog, const gchar * link, gpointer data)
85{
86 GtkWidget * error_dialog;
87 gchar * url, * escaped;
88 g_return_if_fail (GTK_IS_ABOUT_DIALOG (dialog));
89 g_return_if_fail (link != NULL);
90
91/ * simple check if this is an email address * /
92 if (! g_str_has_prefix (link, "mailto:") && strchr (link, '@') != NULL)
93 {
94 escaped = g_uri_escape_string (link, NULL, FALSE);
95 url = g_strdup_printf ("mailto:%s", escaped);
96 g_free (escaped);
97 }
98 else
99 {
100 url = g_strdup_printf ("%s", link);
101 }
102
103#ifdef G_OS_WIN32
104 HINSTANCE h;
105 h = ShellExecute (NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
106 if ((int)h <= 32)
107#else
108#ifdef GTK4
109 // gtk_show_uri (GTK_WINDOW (dialog), url, gtk_event_controller_get_current_event_time ( , ));
110#else
111 GError * error = NULL;
112 gtk_show_uri_on_window (GTK_WINDOW (dialog), url, gtk_get_current_event_time (), & error);
113 if (error != NULL)
114#endif
115#endif
116 {
117 gchar * uri = g_strdup_printf (_("Failed to open link:\n%s"), url);
118 error_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
119 GTK_DIALOG_DESTROY_WITH_PARENT,
120 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
121 _("Impossible to open link: "));
122 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", uri);
123 run_this_gtk_dialog (error_dialog, G_CALLBACK(run_destroy_dialog), NULL);
124 g_free (uri);
125 }
126 g_free (url);
127} */
128
136GtkWidget * addweb (int id)
137{
138 GtkWidget * web;
139 const gchar * contact = i18n(" Please contact me at:\n");
140 const gchar * seb = " Dr. Sébastien Le Roux ";
141 GtkWidget * eseb;
142 GtkWidget * vbox;
143 GtkWidget * hbox;
144 const gchar * or = i18n("\n Or check the website for information\n");
145 if (id)
146 {
147 web = gtk_link_button_new_with_label (ATOMES_URL, _("Visit the project's website"));
148 }
149 gchar * mailto = g_strdup_printf ("mailo:%s", PACKAGE_BUGREPORT);
150 gchar * mailsh = g_strdup_printf ("<%s>",PACKAGE_BUGREPORT);
151 eseb = gtk_link_button_new_with_label (mailto, mailsh);
152 g_free (mailto);
153 g_free (mailsh);
155 if (id) add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, gtk_label_new (_(contact)), FALSE, FALSE, 0);
156 hbox = create_hbox (0);
157 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
158 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, gtk_label_new (seb), FALSE, FALSE, 10);
159 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, eseb, FALSE, FALSE, 0);
160 if (id)
161 {
162 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, gtk_label_new (_(or)), FALSE, FALSE, 0);
163 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, web, FALSE, FALSE, 0);
164 }
165 return (vbox);
166}
167
176G_MODULE_EXPORT void create_about_dialog (GtkWidget * widg, gpointer data)
177{
178 GtkWidget * aboutdialog;
179#ifdef GTK4
180 GdkPaintable * atomes_logo = gtk_image_get_paintable (GTK_IMAGE(gtk_image_new_from_file(PACKAGE_LAGPL)));
181#else
182 GdkPixbuf * atomes_logo = gdk_pixbuf_new_from_file (PACKAGE_LAGPL, NULL);
183#endif
184 gchar * str;
185 const gchar * authors[] = {"Dr. Sébastien Le Roux <sebastien.leroux@ipcms.unistra.fr>",
186 "", NULL};
187 /*"Collaborations:",
188 "",
189 "Dr. Noël Jakse <noel.jakse@grenoble-inp.fr> : dynamic structure factor", NULL}; */
190 const gchar * weblabel = "https://atomes.ipcms.fr";
191 const gchar * comments = i18n("Visualization, analyzis, creation/edition and post-processing of atomic scale models !");
192 const gchar * copyrights = "Copyright © 2026 \nDr. Sébastien Le Roux";
193
194 // gtk_about_dialog_set_url_hook (about_dialog_handle_url, NULL, NULL);
195 // gtk_about_dialog_set_email_hook (about_dialog_handle_url, NULL, NULL);
196
197 aboutdialog = gtk_about_dialog_new ();
198 gtk_about_dialog_set_logo (GTK_ABOUT_DIALOG(aboutdialog), atomes_logo);
199 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(aboutdialog), VERSION);
200 str = g_strdup_printf ("%s", PACKAGE);
201 gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG(aboutdialog), str);
202 g_free (str);
203 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(aboutdialog), _(comments));
204 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(aboutdialog), g_strdup_printf("%s", ATOMES_URL));
205 gtk_about_dialog_set_website_label (GTK_ABOUT_DIALOG(aboutdialog), weblabel);
206 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(aboutdialog), authors);
207 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(aboutdialog), copyrights);
208 gtk_about_dialog_set_license (GTK_ABOUT_DIALOG(aboutdialog), affero_license);
209 gtk_about_dialog_set_license_type (GTK_ABOUT_DIALOG(aboutdialog), GTK_LICENSE_CUSTOM);
210 gtk_about_dialog_set_wrap_license (GTK_ABOUT_DIALOG(aboutdialog), FALSE);
211 run_this_gtk_dialog (aboutdialog, G_CALLBACK(destroy_this_dialog), NULL);
212}
213
222void show_web (GtkWidget * dialog, int id)
223{
224 GtkWidget * box = dialog_get_content_area (dialog);
225 GtkWidget * theweb = addweb (id);
226 show_the_widgets (theweb);
227 add_box_child_start (GTK_ORIENTATION_VERTICAL, box, theweb, FALSE, FALSE, 0);
229}
230
240void show_info (char * information, int val, GtkWidget * win)
241{
242 gchar * info=NULL;
243 if (val < 0)
244 {
245 info = g_strdup_printf ("%s\n%s", information, ifbug);
246 }
247 else
248 {
249 info = g_strdup_printf ("%s", information);
250 }
251
252 GtkWidget * dialog = message_dialogmodal (info, _("Information"), GTK_MESSAGE_INFO, GTK_BUTTONS_OK, win);
253 if (val != 0) show_web (dialog, (val < 0) ? 0 : val);
254 run_this_gtk_dialog (dialog, G_CALLBACK(run_destroy_dialog), NULL);
255 g_free (info);
256}
257
266void show_warning (char * warning, GtkWidget * win)
267{
268 GtkWidget * dialog = message_dialogmodal (warning, _("Warning"), GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, win);
269 run_this_gtk_dialog (dialog, G_CALLBACK(run_destroy_dialog), NULL);
270}
271
281void show_warning_ (char * warning, char * sub, char * tab)
282{
283 /* This function is called from fortran 90 */
284 gchar * wtot=NULL;
285 wtot = g_strdup_printf ("%s\n%s\n%s", warning, sub, tab);
286 show_warning (wtot, MainWindow);
287 g_free (wtot);
288}
289
299void show_error (char * error, int val, GtkWidget * win)
300{
301 gchar * etot=NULL;
302 if (val)
303 {
304 etot = g_strdup_printf ("%s", error);
305 }
306 else
307 {
308 etot = g_strdup_printf ("%s\n%s", error, ifbug);
309 }
310 GtkWidget * dialog = message_dialogmodal (etot, _("Error"), GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, win);
311 show_web (dialog, val);
312 g_warning ("%s", etot);
313 run_this_gtk_dialog (dialog, G_CALLBACK(run_destroy_dialog), NULL);
314 g_free (etot);
315}
316
328void show_error_with_trace (gchar * error, atomes_error * this_error, int act, int val, GtkWidget * win)
329{
330 GtkWidget * dialog = message_dialogmodal (error, _("Error"), GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, win);
331 GtkWidget * exp_trace = create_expander (_("Details"), NULL);
332 gchar * trace;
333 if (this_error -> error_trace)
334 {
335 trace = g_strdup_printf (_("\n\tError %s %s, at:\n"
336 "<span font_desc=\"monospace 10\">\t\tFile : <b>%s</b>\n"
337 "\t\tFunction: <b>%s()</b>\n"
338 "\t\tLine : <b>%d</b></span>\n\n"
339 "\tBacktrace:\n%s\t\t →\t\t <i>call to</i>\t<span font_desc=\"monospace 10\"><b>%s()</b></span>\n"),
340 (! act) ? _("reading") : _("saving"),
341 _(this_error -> error_signal.message),
342 this_error -> error_file,
343 this_error -> error_func,
344 this_error -> error_line,
345 this_error -> error_trace,
346 this_error -> error_func);
347 }
348 else
349 {
350 trace = g_strdup_printf (_("\n\tError %s %s, at:\n"
351 "<span font_desc=\"monospace 10\">\t\tFile : <b>%s</b>\n"
352 "\t\tFunction: <b>%s()</b>\n"
353 "\t\tLine : <b>%d</b></span>\n"),
354 (! act) ? _("reading") : _("saving"),
355 _(this_error -> error_signal.message),
356 this_error -> error_file,
357 this_error -> error_func,
358 this_error -> error_line);
359 }
360 GtkWidget * trace_label = markup_label (trace, -1, -1, 0.0, 0.5);
361 gtk_label_set_selectable(GTK_LABEL(trace_label), TRUE);
362 g_free (trace);
363 add_container_child (CONTAINER_EXP, exp_trace, trace_label);
364 GtkWidget * content_area = gtk_message_dialog_get_message_area(GTK_MESSAGE_DIALOG(dialog));
365 add_box_child_start (GTK_ORIENTATION_VERTICAL, content_area, exp_trace, FALSE, FALSE, 0);
366 if (! val)
367 {
368 add_box_child_start (GTK_ORIENTATION_VERTICAL, content_area, markup_label (_(ifbug), -1, -1, 0.0, 0.5), FALSE, FALSE, 0);
369 }
370 show_web (dialog, val);
371 g_warning ("%s", error);
372 run_this_gtk_dialog (dialog, G_CALLBACK(run_destroy_dialog), NULL);
373}
374
384void show_error_ (char * error, char * sub, char * tab)
385{
386 /* This function is called from fortran 90 */
387 gchar * etot=NULL;
388 etot = g_strdup_printf ("%s\n\t%s\n\t%s", error, sub, tab);
389 show_error (etot, 0, MainWindow);
390 g_free (etot);
391}
392
393gboolean res_yes_no;
394
404G_MODULE_EXPORT void run_yes_no (GtkDialog * dial, gint response_id, gpointer data)
405{
406 res_yes_no = (response_id == GTK_RESPONSE_YES) ? TRUE : FALSE;
407 destroy_this_dialog (dial);
408}
409
420gboolean ask_yes_no (gchar * title, gchar * text, int type, GtkWidget * widg)
421{
422 GtkWidget * dialog = message_dialogmodal (text, title, type, GTK_BUTTONS_YES_NO, widg);
423 run_this_gtk_dialog (dialog, G_CALLBACK(run_yes_no), NULL);
424 return res_yes_no;
425}
426
434gchar * exact_name (gchar * name)
435{
436 return g_strdup_printf("%s", substitute_string (name, " ", NULL));
437}
438
447GtkWidget * show_pop (char * pop, GtkWidget * pwin)
448{
449 GtkWidget * wpop = create_win (_("Information"), pwin, TRUE, FALSE);
450 gtk_widget_set_size_request (wpop, 600, 80);
451#ifdef GTK3
452 gtk_window_set_position (GTK_WINDOW (wpop), GTK_WIN_POS_CENTER);
453#endif
454 GtkWidget * hpop = create_hbox (0);
456 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hpop, stock_image(EXECUTE), TRUE, TRUE, 0);
457 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hpop, gtk_label_new (pop), TRUE, TRUE, 0);
458 show_the_widgets (wpop);
459 return (wpop);
460}
461
462#ifdef GTK4
471G_MODULE_EXPORT gboolean leaving_question (GtkWindow * widget, gpointer data)
472#else
482G_MODULE_EXPORT gboolean leaving_question (GtkWidget * widget, GdkEvent * event, gpointer data)
483#endif
484{
485 if (ask_yes_no (_("Leaving ?!"), _("Are you sure you want to quit ?"), GTK_MESSAGE_QUESTION, MainWindow))
486 {
487 quit_gtk ();
488 }
489 else
490 {
492 }
493 return TRUE;
494}
495
503int dummy_ask_ (char * question)
504{
505 GtkWidget * dask = message_dialogmodal (question, _("Parameter required"), GTK_MESSAGE_INFO, GTK_BUTTONS_YES_NO, MainWindow);
506 run_this_gtk_dialog (dask, G_CALLBACK(run_yes_no), NULL);
507 return (res_yes_no) ? 0 : -1;
508}
509
510extern gchar * field_init[3];
511gchar * coord_type[3]={i18n("Cartesian"),
512 i18n("Atomic units"),
513 i18n("Fractional")};
514gchar * npt_type[4]={"A\tB\tC\t&#x3B1;\t&#x3B2;\t&#x263;",
515 "A\tB\tC\n&#x3B1;\t&#x3B2;\t&#x263;",
516 "a<sub>x</sub>\ta<sub>y</sub>\ta<sub>z</sub>\tb<sub>x</sub>\tb<sub>y</sub>\tb<sub>z</sub>\tc<sub>x</sub>\tc<sub>y</sub>\tc<sub>z</sub>",
517 "a<sub>x</sub>\ta<sub>y</sub>\ta<sub>z</sub>\nb<sub>x</sub>\tb<sub>y</sub>\tb<sub>z</sub>\nc<sub>x</sub>\tc<sub>y</sub>\tc<sub>z</sub>"};
518gchar * npt_info[3]={i18n("1 line by step, as many lines as MD steps"),
519 i18n("2 lines by step, twice as many lines as MD steps"),
520 i18n("3 lines by step, three times as many lines as MD steps")};
521gchar * cif_configurations[3]={i18n("Single step chemical reaction"),
522 i18n("MD trajectory"),
523 i18n("Single configuration")};
524gchar * cif_occupancies[3]={i18n("Round up to lowest integer"),
525 i18n("Round up to highest integer"),
526 i18n("Round up to nearest integer")};
527gchar * cif_config_legends={i18n("\t<b>Single step chemical reaction</b>\n"
528 "\t\tConsider each configuration as a step in a chemical reaction:\n"
529 "\t\t\t- Atomic coordinates are sorted based on occupancy or disorder site\n"
530 "\t\t\t- Each describing the proportion of a reactant\n"
531 "\t\t\t- A super lattice is build to respect these proportions\n\n"
532 "\t<b>MD trajectory</b>\n"
533 "\t\tConsider the CIF file a MD trajectory\n\n"
534 "\t\tNumber of atom(s) must not change between configuration(s)\n\n"
535 "\t<b>Single configuration </b>\n"
536 "\t\tSelect a single configuration in the CIF file")};
537gchar * cif_config_leg={i18n("\t<b>MD trajectory</b>\n"
538 "\t\tConsider the CIF file a MD trajectory\n\n"
539 "\t\tNumber of atom(s) must not change between configuration(s)\n\n"
540 "\t<b>Single configuration </b>\n"
541 "\t\tSelect a single configuration in the CIF file")};
542gchar * cif_occ[3]={i18n("to lowest integer: <b>⌊</b>n<sub>sites</sub> x occupancy<b>⌋</b>"),
543 i18n("to highest integer: <b>⌈</b>n<sub>sites</sub> x occupancy<b>⌉</b>"),
544 i18n("to nearest integer: <b>⌊</b>n<sub>sites</sub> x occupancy<b>⌉</b>")};
545gchar * cif_sites[2]={i18n("with n<sub>sites</sub> = f(space group, crystalline positions)"),
546 i18n("with n<sub>sites</sub> = f(symmetry positions, crystalline positions)")};
547
548GtkWidget * answer_info;
549
558G_MODULE_EXPORT void on_answer_changed (GtkWidget * widg, gpointer data)
559{
560 int i, j;
561 i = combo_get_active (widg);
562 j = (! i || i == 2) ? 0 : (i == 1) ? 1 : 2;
563 gtk_label_set_text (GTK_LABEL(answer_info), _(npt_info[j]));
564}
565
567
577G_MODULE_EXPORT void run_iask (GtkDialog * iask, gint response_id, gpointer data)
578{
579 int i = GPOINTER_TO_INT(data);
580 gboolean done = FALSE;
581 const gchar * riask;
582 if (response_id == GTK_RESPONSE_OK)
583 {
584 if (i == 0 || i > 5)
585 {
586 riask = entry_get_text (GTK_ENTRY(answer));
587 res_int = string_to_double ((gpointer)riask);
588 if (i > 5)
589 {
590 if (res_int > 0 && res_int < i+1)
591 {
592 done = TRUE;
593 res_int --;
594 }
595 }
596 else if (res_int > 0)
597 {
598 done = TRUE;
599 }
600 }
601 else
602 {
603 done = TRUE;
605 }
606 }
607 if (done) destroy_this_dialog (iask);
608}
609
620int iask (char * question, char * lab, int id, GtkWidget * win)
621{
622 GtkWidget * iask;
623 GtkWidget * vbox;
624 GtkWidget * hboxa;
625 GtkWidget * quest;
626 int i;
627 iask = message_dialogmodal (question, _("Parameter Required"), GTK_MESSAGE_INFO, GTK_BUTTONS_OK, win);
629 gtk_box_set_spacing (GTK_BOX(vbox), 15);
630 hboxa = create_hbox (0);
631 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hboxa, TRUE, TRUE, 0);
632 quest = markup_label(lab, -1, -1, 0.0, 0.5);
633 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hboxa, quest, TRUE, TRUE, 0);
634
635 if (id == 0 || id > 6)
636 {
637 answer = gtk_entry_new ();
638 gtk_widget_set_size_request (answer, 100, -1);
639 gtk_entry_set_alignment (GTK_ENTRY(answer), 1.0);
640 }
641 else
642 {
643 if (id < 6)
644 {
645 answer = create_combo ();
646 gtk_widget_set_size_request (answer, -1, 30);
647 switch (id)
648 {
649 case 1:
650 for (i=0; i<3; i++) combo_text_append (answer, _(coord_type[i]));
651 break;
652 case 2:
653 for (i=0; i<NCFORMATS; i++) combo_text_append (answer, _(coord_files[i]));
654 break;
655 case 3:
656 for (i=0; i<3; i++) combo_text_append (answer, _(cif_configurations[i]));
657 break;
658 case 4:
659 for (i=1; i<3; i++) combo_text_append (answer, _(cif_configurations[i]));
660 break;
661 case 5:
662 for (i=0; i<3; i++) combo_text_append (answer, _(cif_occupancies[i]));
663 break;
664 default:
665 // id < 0
666 for (i=0; i<3; i++) combo_text_append (answer, _(field_init[i]));
667 break;
668 }
669 }
670 else
671 {
672 GtkTreeIter iter;
673 GtkTreeStore * store = store = gtk_tree_store_new (1, G_TYPE_STRING);
674 for (i=0; i<4; i++)
675 {
676 gtk_tree_store_append (store, & iter, NULL);
677 gtk_tree_store_set (store, & iter, 0, _(npt_type[i]), -1);
678 }
679 answer = gtk_combo_box_new_with_model (GTK_TREE_MODEL(store));
680 GtkCellRenderer * renderer = gtk_cell_renderer_combo_new ();
681 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (answer), renderer, TRUE);
682 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (answer), renderer, "text", 0, NULL);
683 }
686 }
687 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hboxa, answer, FALSE, FALSE, 10);
688 if (id == 3)
689 {
690 answer_info = markup_label (_(cif_config_legends), 450, -1, 0.5, 0.5);
691 }
692 if (id == 4)
693 {
694 answer_info = markup_label (_(cif_config_leg), 450, -1, 0.5, 0.5);
695 }
696 if (id == 5)
697 {
698 gchar * str = g_strdup_printf (_("\t<b>Lowest integer: </b>\n"
699 "\t\t Occupancy %s\n\t\t\t ex:\t ⌊8.76⌋ = 8\n\n"
700 "\t<b>Highest integer: </b>\n"
701 "\t\t Occupancy %s\n\t\t\t ex:\t ⌈5.39⌉ = 6\n\n"
702 "\t<b>Nearest integer: </b>\n"
703 "\t\t Occupancy %s\n\t\t\t ex:\t ⌊6.82⌉ = 7\t\t and\t ⌊4.31⌉ = 4\n\n"
704 "\t\t%s\n"), _(cif_occ[0]), _(cif_occ[1]), _(cif_occ[2]), _(cif_sites[cif_use_symmetry_positions]));
705 answer_info = markup_label (str, 450, -1, 0.5, 0.5);
706 g_free (str);
707 }
708 if (id == 6)
709 {
710 answer_info = markup_label (_(npt_info[0]), -1, -1, 0.5, 0.5);
711 g_signal_connect(G_OBJECT(answer), "changed", G_CALLBACK(on_answer_changed), NULL);
712 }
713 if (id > 2 && id < 7) add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, answer_info, FALSE, FALSE, 5);
714 run_this_gtk_dialog (iask, G_CALLBACK(run_iask), GINT_TO_POINTER(id));
715 return res_int;
716}
717
718gchar * res_char;
719
729G_MODULE_EXPORT void run_cask (GtkDialog * cask, gint response_id, gpointer data)
730{
731 int i = GPOINTER_TO_INT(data);
732 gboolean done = FALSE;
733 if (i < 0)
734 {
735 while (! done)
736 {
737 if (response_id == GTK_RESPONSE_OK)
738 {
739 res_char = g_strdup_printf ("%s", entry_get_text (GTK_ENTRY(answer)));
740 done = TRUE;
741 }
742 }
743 }
744 else
745 {
746 if (response_id == GTK_RESPONSE_OK)
747 {
748 res_char = g_strdup_printf ("%s", entry_get_text (GTK_ENTRY(answer)));
749 }
750 else
751 {
752 res_char = NULL;
753 }
754 done = TRUE;
755 }
756 if (done) destroy_this_dialog (cask);
757}
758
770gchar * cask (char * question, char * lab, int id, char * old, GtkWidget * win)
771{
772 GtkWidget * cask;
773 GtkWidget * dialog_ask;
774 GtkWidget * hboxa;
775 GtkWidget * quest;
776 res_char = NULL;
777 cask = message_dialogmodal (question, _("Parameter required"), GTK_MESSAGE_INFO, GTK_BUTTONS_OK, win);
778 dialog_ask = dialog_get_content_area (cask);
779 gtk_box_set_spacing (GTK_BOX(dialog_ask), 15);
780
781 hboxa = create_hbox (0);
782 add_box_child_start (GTK_ORIENTATION_VERTICAL, dialog_ask, hboxa, TRUE, TRUE, 0);
783 show_the_widgets (hboxa);
784 quest = gtk_label_new (lab);
785 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hboxa, quest, TRUE, TRUE, 0);
786 show_the_widgets (quest);
787 answer = gtk_entry_new ();
788 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hboxa, answer, TRUE, TRUE, 0);
789 gtk_widget_set_size_request (answer, 50, -1);
790 gtk_entry_set_alignment (GTK_ENTRY(answer), 1.0);
791 update_entry_text (GTK_ENTRY(answer), old);
792 run_this_gtk_dialog (cask, G_CALLBACK(run_cask), GINT_TO_POINTER(id));
793
794 return (res_char);
795}
796
807void init_data_ (int * nats, int * nspc, int * stps, int * cid)
808{
809 active_project -> natomes = * nats;
810 active_project -> nspec = * nspc;
811 active_project -> steps = * stps;
812 if (active_project -> steps > 1)
813 {
814 active_project -> skt_corr_threshold = (active_project -> steps < 20) ? 1 : 10;
815 active_project -> skt_n_data_sets = min (5, active_project -> steps);
816 active_project -> sqw_n_data_sets = 5;
817 }
819 if (* cid) active_chem = active_project -> chemistry;
820}
821
841void spec_data_ (int * status, int * ind, int * atd, int * nsp,
842 char * lbel, char * el_nme,
843 double * amss, double * rdus,
844 double * nscatt, double * xscatt)
845{
846 int id = * ind;
847 active_chem -> label[id]= g_strdup_printf("%s", lbel);
848 active_chem -> element[id]= g_strdup_printf("%s", el_nme);
849 if (* status)
850 {
851 active_chem -> nsps[id] = * nsp;
852 active_chem -> chem_prop[CHEM_Z][id] = (double) * atd;
853 active_chem -> chem_prop[CHEM_M][id] = * amss;
854 active_chem -> chem_prop[CHEM_R][id] = * rdus;
855 active_chem -> chem_prop[CHEM_N][id] = * nscatt;
856 active_chem -> chem_prop[CHEM_X][id] = * xscatt;
857 }
858}
859
869void print_info (gchar * str, gchar * stag, GtkTextBuffer * buffer)
870{
871 GtkTextIter bEnd;
872 GtkTextTag * tag;
873 gtk_text_buffer_get_end_iter (buffer, &bEnd);
874 if (stag != NULL)
875 {
876 tag = gtk_text_tag_table_lookup (gtk_text_buffer_get_tag_table(buffer), stag);
877 gtk_text_buffer_insert_with_tags (buffer, &bEnd, str, -1, tag, NULL);
878 }
879 else
880 {
881 tag = gtk_text_tag_table_lookup (gtk_text_buffer_get_tag_table(buffer), "default-size");
882 gtk_text_buffer_insert_with_tags (buffer, &bEnd, str, -1, tag, NULL);
883 }
884}
885
893gchar * textcolor (int i)
894{
895 switch (i - i * (i / 9))
896 {
897 case 0:
898 return "red";
899 break;
900 case 1:
901 return "blue";
902 break;
903 case 2:
904 return "cyan";
905 break;
906 case 3:
907 return "green";
908 break;
909 case 4:
910 return "light_green";
911 break;
912 case 5:
913 return "yellow";
914 break;
915 case 6:
916 return "orange";
917 break;
918 case 7:
919 return "violet";
920 break;
921 case 8:
922 return "pink";
923 break;
924 }
925 return NULL;
926}
927
945void lattice_info_ (int * bid, double * volume, double * density,
946 double dvects[3][3], double rvects[3][3], double mod[3], double ang[3],
947 double f_to_c[3][3], double c_to_f[3][3])
948{
949 int i, j;
950 for ( i=0; i<3; i++)
951 {
952 for (j=0; j<3; j++)
953 {
954 active_cell -> box[* bid].vect[i][j] = dvects[j][i];
955 active_cell -> box[* bid].rvect[i][j] = rvects[j][i];
956 }
957 active_cell -> box[* bid].param[0][i] = mod[i];
958 active_cell -> box[* bid].param[1][i] = ang[i];
959 }
960 active_cell -> box[* bid].frac_to_cart = mat4(f_to_c[0][0], f_to_c[0][1], f_to_c[0][2], 0.0,
961 f_to_c[1][0], f_to_c[1][1], f_to_c[1][2], 0.0,
962 f_to_c[2][0], f_to_c[2][1], f_to_c[2][2], 0.0,
963 0.0, 0.0, 0.0, 0.0);
964 active_cell -> box[* bid].cart_to_frac = mat4(c_to_f[0][0], c_to_f[0][1], c_to_f[0][2], 0.0,
965 c_to_f[1][0], c_to_f[1][1], c_to_f[1][2], 0.0,
966 c_to_f[2][0], c_to_f[2][1], c_to_f[2][2], 0.0,
967 0.0, 0.0, 0.0, 0.0);
968#ifdef DEBUG
969 // m4_print (active_cell -> box[* bid].frac_to_cart);
970 // m4_print (active_cell -> box[* bid].cart_to_frac);
971#endif
972 active_cell -> box[* bid].vol = * volume;
973 active_cell -> box[* bid].dens = * density;
974 if ((active_cell -> npt && * bid == active_project -> steps-1) || ! active_cell -> npt)
975 {
976 if (active_project -> analysis)
977 {
978 active_project -> analysis[GDR] -> max = fdmax_ (& active_cell -> pbc);
979 active_project -> analysis[SQD] -> min = active_project -> analysis[SKD] -> min = fkmin_ (& active_cell -> pbc);
980 // if (active_project -> analysis[SKT]) active_project -> analysis[SKT] -> min = active_project -> analysis[SKD] -> min;
981 }
982 int i, j;
983 active_cell -> volume = active_cell -> density = 0.0;
984 i = (active_cell -> npt) ? active_project -> steps : 1;
985 for (j=0; j<i; j++)
986 {
987 active_cell -> volume += active_cell -> box[j].vol;
988 active_cell -> density += active_cell -> box[j].dens;
989 }
990 active_cell -> volume /= i;
991 active_cell -> density /= i;
992 }
993}
994
1002void send_chem_info_ (int prop[active_project -> nspec])
1003{
1004 int i;
1005 for (i=0; i<active_project -> nspec; i++)
1006 {
1007 active_chem -> formula[i] = prop[i];
1008 }
1009}
1010
1022gchar * env_name (project * this_proj, int g, int s, int f, GtkTextBuffer * buffer)
1023{
1024 int l, m;
1025 gchar * spec = g_strdup_printf ("%s", exact_name(this_proj -> chemistry -> label[s]));
1026 gchar * stra;
1027 gchar * strb;
1028
1029 m = 0;
1030 for (l=0; l<this_proj -> nspec; l++)
1031 {
1032 m += this_proj -> coord -> partial_geo[s][g][l];
1033 }
1034 if (m > 0)
1035 {
1036 stra = g_strdup_printf ("%s [", spec);
1037 if (buffer != NULL)
1038 {
1039 print_info (spec, textcolor(s), buffer);
1040 print_info ("[", "bold", buffer);
1041 }
1042 for (l=0; l<this_proj -> nspec; l++)
1043 {
1044 m = this_proj -> coord -> partial_geo[s][g][l];
1045 if (m > 1)
1046 {
1047 if (f == 1)
1048 {
1049 strb = g_strdup_printf ("%s%s<sub>%d</sub>", stra, exact_name(this_proj -> chemistry -> label[l]), m);
1050 }
1051 else
1052 {
1053 strb = g_strdup_printf ("%s%s%d", stra, exact_name(this_proj -> chemistry -> label[l]), m);
1054 }
1055 if (buffer != NULL)
1056 {
1057 print_info (exact_name(this_proj -> chemistry -> label[l]), "bold", buffer);
1058 g_free (strb);
1059 strb = g_strdup_printf ("%d", m);
1060 print_info (strb, "sub", buffer);
1061 }
1062 }
1063 else if (m > 0)
1064 {
1065 strb = g_strdup_printf ("%s%s", stra, exact_name(this_proj -> chemistry -> label[l]));
1066 if (buffer != NULL)
1067 {
1068 print_info (exact_name(this_proj -> chemistry -> label[l]), "bold", buffer);
1069 }
1070 }
1071 else
1072 {
1073 strb = g_strdup_printf ("%s", stra);
1074 }
1075 g_free (stra);
1076 stra = g_strdup_printf ("%s", strb);
1077 g_free (strb);
1078 }
1079 strb = g_strdup_printf ("%s]", stra);
1080 if (buffer != NULL)
1081 {
1082 print_info ("]", "bold", buffer);
1083 }
1084 g_free (stra);
1085 }
1086 else
1087 {
1088 strb = g_strdup_printf (_("%s - isolated"), spec);
1089 if (buffer != NULL)
1090 {
1091 print_info (spec, textcolor(s), buffer);
1092 print_info (_(" - isolated"), "bold", buffer);
1093 }
1094 }
1095 if (buffer != NULL)
1096 {
1097 strb = NULL;
1098 }
1099 g_free (spec);
1100 return strb;
1101}
1102
1110void update_after_calc (int calc)
1111{
1112 int i, j;
1113 tint cd;
1114 project * this_proj;
1115 for (i=0; i<nprojects; i++)
1116 {
1117 this_proj = get_project_by_id(i);
1118 if (this_proj -> analysis[calc] -> init_ok)
1119 {
1120 for (j= 0; j < this_proj -> analysis[calc] -> numc; j++)
1121 {
1122 if (this_proj -> analysis[calc] -> curves[j] -> plot != NULL)
1123 {
1124 cd.a = i;
1125 cd.b = calc;
1126 cd.c = j;
1127 update_curve ((gpointer)& cd);
1128 }
1129 }
1130 }
1131 }
1132}
The text of the Affero GPL v3 license.
gchar * affero_license
Definition affero.h:31
Binding to the Fortran90 subroutines.
double fdmax_(int *)
double fkmin_(int *)
void quit_gtk()
Leave the application.
Definition callbacks.c:330
gchar * substitute_string(gchar *init, gchar *o_motif, gchar *n_motif)
substitute all patterns in string
Definition w_library.c:375
Callback declarations for main window.
integer(kind=c_int) function chemistry()
Definition chemistry.F90:22
#define VERSION
Definition config.h:67
#define PACKAGE_BUGREPORT
Definition config.h:49
#define PACKAGE
Definition config.h:46
void update_curve(gpointer data)
update curve rendering
Definition curve.c:635
Variable declarations for the curve widget Functions for interactions with the curve widget.
gchar * text
Definition datab.c:105
float val
Definition dlp_init.c:117
gchar * field_init[3]
Definition dlp_field.c:4457
char * ifbug
Definition global.c:145
gchar * PACKAGE_LAGPL
Definition global.c:109
GtkTextTag * tag
Definition global.c:219
int nprojects
Definition global.c:161
GtkWidget * MainWindow
Definition global.c:207
gchar * ATOMES_URL
Definition global.c:140
GtkWidget * atomes_logo
Definition global.c:214
#define i18n(String)
Definition global.c:80
gboolean cif_use_symmetry_positions
Definition global.c:193
double string_to_double(gpointer string)
convert string to double
Definition global.c:611
GtkWidget * pop
Definition global.c:210
Global variable declarations Global convenience function declarations Global data structure defin...
void run_this_gtk_dialog(GtkWidget *dial, GCallback handler, gpointer data)
run a GTK (3 and 4) basic GtkDialog
Definition gtk-misc.c:533
#define EXECUTE
Definition global.h:232
int combo_get_active(GtkWidget *combo)
retrieve the active item's position
Definition gtk-misc.c:935
#define SQD
Definition global.h:338
GtkWidget * create_win(gchar *str, GtkWidget *parent, gboolean modal, gboolean resiz)
create a new GtkWindow
Definition gtk-misc.c:486
cell_info * active_cell
Definition project.c:50
void combo_set_markup(GtkWidget *combo)
use pango markup in combo widget
Definition gtk-misc.c:970
void combo_set_active(GtkWidget *combo, int pos)
set the active item's position
Definition gtk-misc.c:958
#define CHEM_N
Definition global.h:319
const gchar * entry_get_text(GtkEntry *entry)
get the text in a GtkEntry
Definition gtk-misc.c:652
chemical_data * active_chem
Definition project.c:48
#define BSEP
Definition global.h:261
GtkWidget * stock_image(const gchar *stock_id)
create a GtkImage for the Gtk database
Definition gtk-misc.c:1451
#define CHEM_R
Definition global.h:318
@ CONTAINER_EXP
Definition global.h:271
@ CONTAINER_WIN
Definition global.h:266
#define NCFORMATS
Definition global.h:332
GtkWidget * create_combo()
create a GtkCombox widget, note deprecated in GTK4
Definition gtk-misc.c:1010
GtkWidget * dialog_get_content_area(GtkWidget *widg)
prepare GtkWidget to insert content in a GtkDialog window
Definition gtk-misc.c:861
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
create a GtkLabel with pango markup
Definition gtk-misc.c:1672
void add_box_child_start(int orientation, GtkWidget *widg, GtkWidget *child, gboolean expand, gboolean fill, int padding)
Add a GtkWidget in a GtkBox at the initial position.
Definition gtk-misc.c:340
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2235
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:849
#define CHEM_M
Definition global.h:317
#define SKD
Definition global.h:339
void combo_text_append(GtkWidget *combo, gchar *text)
append text in GtkComboBox widget
Definition gtk-misc.c:987
G_MODULE_EXPORT void run_destroy_dialog(GtkDialog *dialog, gint response_id, gpointer data)
to destroy a GtkDialog when the dialog emit the closing signal
Definition gtk-misc.c:2272
void update_entry_text(GtkEntry *entry, gchar *text)
update the content of a GtkEntry as string
Definition gtk-misc.c:726
#define min(a, b)
Definition global.h:93
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:267
char * coord_files[NCFORMATS+1]
Definition callbacks.c:88
GtkWidget * message_dialogmodal(gchar *message, gchar *title, GtkMessageType mtype, GtkButtonsType buttons, GtkWidget *parent)
create a modal (cannot be ignored) message window
Definition gtk-misc.c:573
#define CHEM_X
Definition global.h:320
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:837
#define CHEM_Z
Definition global.h:316
GtkWidget * create_expander(gchar *name, gchar *file_img)
create GtkExpander
Definition gtk-misc.c:2163
project * active_project
Definition project.c:47
#define GDR
Definition global.h:337
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:202
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
#define max(a, b)
Definition global.h:92
image * plot
Definition ogl_draw.c:72
G_MODULE_EXPORT void on_answer_changed(GtkWidget *widg, gpointer data)
Handling the GtkComboBox in 'int iask'.
Definition interface.c:558
gchar * cif_configurations[3]
Definition interface.c:521
void show_web(GtkWidget *dialog, int id)
add / show web information to widget
Definition interface.c:222
G_MODULE_EXPORT void create_about_dialog(GtkWidget *widg, gpointer data)
create the about dialog
Definition interface.c:176
int iask(char *question, char *lab, int id, GtkWidget *win)
enter an integer value - prepare the dialog
Definition interface.c:620
gchar * res_char
Definition interface.c:718
gchar * cif_occ[3]
Definition interface.c:542
gchar * cask(char *question, char *lab, int id, char *old, GtkWidget *win)
enter a string - prepare the dialog
Definition interface.c:770
void show_warning_(char *warning, char *sub, char *tab)
show warning from Fortran90
Definition interface.c:281
gchar * substitute_string(gchar *init, gchar *o_motif, gchar *n_motif)
substitute all patterns in string
Definition w_library.c:375
gchar * cif_sites[2]
Definition interface.c:545
void show_warning(char *warning, GtkWidget *win)
show warning
Definition interface.c:266
G_MODULE_EXPORT void run_cask(GtkDialog *cask, gint response_id, gpointer data)
enter a string - running the dialog
Definition interface.c:729
gchar * npt_type[4]
Definition interface.c:514
gboolean res_yes_no
Definition interface.c:393
void spec_data_(int *status, int *ind, int *atd, int *nsp, char *lbel, char *el_nme, double *amss, double *rdus, double *nscatt, double *xscatt)
update project data using information from Fortran90
Definition interface.c:841
void show_info(char *information, int val, GtkWidget *win)
add / show information message to widget
Definition interface.c:240
gchar * textcolor(int i)
setup text color keyword
Definition interface.c:893
int res_int
Definition interface.c:566
void show_error(char *error, int val, GtkWidget *win)
show error message
Definition interface.c:299
G_MODULE_EXPORT gboolean leaving_question(GtkWidget *widget, GdkEvent *event, gpointer data)
Leaving atomes ?
Definition interface.c:482
GtkWidget * answer_info
Definition interface.c:548
int dummy_ask_(char *question)
Ask to use dummy atoms or not from Fortran90.
Definition interface.c:503
gchar * cif_config_leg
Definition interface.c:537
void send_chem_info_(int prop[active_project -> nspec])
Definition interface.c:1002
void update_after_calc(int calc)
update all curve plots in the workspace after a calculation
Definition interface.c:1110
gchar * cif_occupancies[3]
Definition interface.c:524
gchar * cif_config_legends
Definition interface.c:527
void show_error_(char *error, char *sub, char *tab)
show error from Fortran90
Definition interface.c:384
GtkWidget * answer
Definition interface.c:81
void show_error_with_trace(gchar *error, atomes_error *this_error, int act, int val, GtkWidget *win)
show error message
Definition interface.c:328
gchar * npt_info[3]
Definition interface.c:518
void init_data_(int *nats, int *nspc, int *stps, int *cid)
update project data using information from Fortran90
Definition interface.c:807
void lattice_info_(int *bid, double *volume, double *density, double dvects[3][3], double rvects[3][3], double mod[3], double ang[3], double f_to_c[3][3], double c_to_f[3][3])
lattice data from Fortran90
Definition interface.c:945
gchar * env_name(project *this_proj, int g, int s, int f, GtkTextBuffer *buffer)
output the name of a coordination sphere
Definition interface.c:1022
G_MODULE_EXPORT void run_iask(GtkDialog *iask, gint response_id, gpointer data)
enter an integer value - running the dialog
Definition interface.c:577
GtkWidget * show_pop(char *pop, GtkWidget *pwin)
display pop information window
Definition interface.c:447
G_MODULE_EXPORT void run_yes_no(GtkDialog *dial, gint response_id, gpointer data)
ask yes or no for something: running dialog
Definition interface.c:404
void print_info(gchar *str, gchar *stag, GtkTextBuffer *buffer)
print information in GtkTextBuffer
Definition interface.c:869
gboolean ask_yes_no(gchar *title, gchar *text, int type, GtkWidget *widg)
ask yes or no for something: prepare dialog
Definition interface.c:420
GtkWidget * addweb(int id)
create a widget to present
Definition interface.c:136
gchar * exact_name(gchar *name)
short cut to print string without spaces
Definition interface.c:434
gchar * coord_type[3]
Definition interface.c:511
void alloc_proj_data(project *this_proj, int cid)
allocate data
Definition open_p.c:224
Function declarations for reading atomes project file Function declarations for saving atomes proje...
Definition glwin.h:350
Definition global.h:118
int b
Definition global.h:120
int c
Definition global.h:121
int a
Definition global.h:119
int status
Definition w_advance.c:173
int element
Definition w_periodic.c:61
GtkWidget * hbox
Definition workspace.c:71
GtkWidget * vbox
Definition workspace.c:72
GtkWidget * lab
Definition workspace.c:73