atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
cbuild_edit.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: 'cbuild_edit.c'
24*
25* Contains:
26*
27
28 - The functions to create the crystal builder window
29
30*
31* List of functions:
32
33 int get_crystal_id (int spg);
34 int get_bravais_img_id (int spg);
35 int get_sg_num (GtkComboBox * box);
36 int read_space_group (builder_edition * cbuilder, int spg);
37 int get_group_id_from_name (gchar * sg_name);
38
39 G_MODULE_EXPORT gboolean delete_build (GtkWindow * widg, gpointer data);
40 G_MODULE_EXPORT gboolean delete_build (GtkWidget * widg, GdkEvent * event, gpointer data);
41
42 gchar * frac_string (gchar * init);
43 gchar * get_num_string (gchar * str);
44 gchar * get_so_string (space_group * spg, int id);
45
46 void adjust_lattice_parameters (builder_edition * cbuilder);
47 void adjust_so_combo (builder_edition * cbuilder);
48 void adjust_bv_img (builder_edition * cbuilder);
49 void adjust_lattice_constraints (builder_edition * cbuilder);
50 void adjust_sg_combo (builder_edition * cbuilder, int cs, int bl);
51 void prepare_crystal_builder (gpointer data);
52
53 G_MODULE_EXPORT void update_cb_vect (GtkEntry * entry, gpointer data);
54 G_MODULE_EXPORT void update_cb_box (GtkEntry * entry, gpointer data);
55 G_MODULE_EXPORT void set_lattice (GtkComboBox * box, gpointer data);
56 G_MODULE_EXPORT void set_so (GtkComboBox * box, gpointer data);
57 G_MODULE_EXPORT void set_sg (GtkComboBox * box, gpointer data);
58 G_MODULE_EXPORT void set_bl (GtkComboBox * box, gpointer data);
59 G_MODULE_EXPORT void set_cs (GtkComboBox * box, gpointer data);
60 G_MODULE_EXPORT void set_wr (GtkCheckButton * but, gpointer data);
61 G_MODULE_EXPORT void set_wr (GtkToggleButton * but, gpointer data);
62 G_MODULE_EXPORT void set_shc (GtkCheckButton * but, gpointer data);
63 G_MODULE_EXPORT void set_shc (GtkToggleButton * but, gpointer data);
64 G_MODULE_EXPORT void add_cryst_cell (GtkSpinButton * res, gpointer data);
65 G_MODULE_EXPORT void apply_build (GtkButton * but, gpointer data);
66 G_MODULE_EXPORT void close_build (GtkButton * but, gpointer data);
67 G_MODULE_EXPORT void toggle_occ (GtkCheckButton * but, gpointer data);
68 G_MODULE_EXPORT void toggle_occ (GtkToggleButton * but, gpointer data);
69 G_MODULE_EXPORT void toggle_overlap (GtkCheckButton * Button, gpointer data);
70 G_MODULE_EXPORT void toggle_overlap (GtkToggleButton * Button, gpointer data);
71 G_MODULE_EXPORT void on_rounding_changed (GtkComboBox * box, gpointer data);
72 G_MODULE_EXPORT void adjust_occupancy (GtkButton * but, gpointer data);
73 G_MODULE_EXPORT void crystal_window (GSimpleAction * action, GVariant * parameter, gpointer data);
74 G_MODULE_EXPORT void crystal_window (GtkWidget * widg, gpointer data);
75
76 GtkWidget * prepare_lattice_grid (int type, builder_edition * cbuilder, glwin * glview);
77 GtkWidget * sg_info (int sg, gpointer data);
78 GtkWidget * create_bl_combo (int cs, gpointer data);
79 GtkWidget * builder_win (project * this_proj, gpointer data);
80
81 GtkTreeModel * so_combo_tree (space_group * spg);
82 GtkTreeModel * sg_combo_tree (int csid, int bvid);
83 GtkTreeModel * la_combo_tree ();
84
85*/
86
87#include "global.h"
88#include "interface.h"
89#include "glview.h"
90#include "cbuild_edit.h"
91#include "bind.h"
92#include "project.h"
93#include "workspace.h"
94#include "readers.h"
95
96extern G_MODULE_EXPORT void show_sg_info (GtkButton * but, gpointer data);
97
98extern void get_origin (space_group * spg);
99extern int test_lattice (builder_edition * cbuilder, cell_info * cif_cell);
100extern int build_crystal (gboolean visible, project * this_proj, int c_step, gboolean to_wrap, gboolean show_clones, cell_info * cell, GtkWidget * widg);
101
102gchar * latt_info[7]={"<i>a</i> &#x2260; <i>b</i> &#x2260; <i>c</i>\n&#x3B1; &#x2260; &#x3B2; &#x2260; &#x263;", // Triclinic
103 i18n("<i>a</i> &#x2260; <i>b</i> &#x2260; <i>c</i>\n&#x3B1; = &#x3B2; = 90° &#x2260; &#x263;\n\tor\n&#x3B1; = &#x263; = 90° &#x2260; &#x3B2;"), // Monoclinic
104 "<i>a</i> &#x2260; <i>b</i> &#x2260; <i>c</i>\n&#x3B1; = &#x3B2; = &#x263; = 90°", // Orthorhombic
105 "<i>a</i> = <i>b</i> &#x2260; <i>c</i>\n&#x3B1; = &#x3B2; = &#x263; = 90°", // Tetragonal
106 "<i>a</i> = <i>b</i> = <i>c</i>\n&#x3B1; = &#x3B2; = &#x3B3; &#x2260; 90°", // Trigonal R
107 i18n("<i>a</i> = <i>b</i> &#x2260; <i>c</i>\n&#x3B1; = &#x3B2; = 90° and &#x263; = 120°"), // Hexagonal
108 "<i>a</i> = <i>b</i> = <i>c</i>\n&#x3B1; = &#x3B2; = &#x263; = 90°"}; // Cubic
109int nsg_bv[7]={2, 13, 59, 68, 25, 27, 36};
110int min_bv[7]={0, 2, 15, 74, 142, 167, 194};
111
119int get_crystal_id (int spg)
120{
121 if (spg < 3)
122 {
123 return 0;
124 }
125 else if (spg < 16)
126 {
127 return 1;
128 }
129 else if (spg < 75)
130 {
131 return 2;
132 }
133 else if (spg < 143)
134 {
135 return 3;
136 }
137 else if (spg < 168)
138 {
139 if (groups[spg-1][0] == 'R')
140 {
141 return 4;
142 }
143 else
144 {
145 return 5;
146 }
147 }
148 else if (spg < 195)
149 {
150 return 5;
151 }
152 else
153 {
154 return 6;
155 }
156}
157
166{
167 if (spg < 3)
168 {
169 return 0;
170 }
171 else if (spg < 16)
172 {
173 if (groups[spg-1][0] == 'P')
174 {
175 return 1;
176 }
177 else
178 {
179 return 2;
180 }
181 }
182 else if (spg < 75)
183 {
184 if (groups[spg-1][0] == 'P')
185 {
186 return 3;
187 }
188 else if (groups[spg-1][0] == 'I')
189 {
190 return 4;
191 }
192 else if (groups[spg-1][0] == 'A' || groups[spg-1][0] == 'C')
193 {
194 return 5;
195 }
196 else
197 {
198 return 6;
199 }
200 }
201 else if (spg < 143)
202 {
203 if (groups[spg-1][0] == 'P')
204 {
205 return 7;
206 }
207 else
208 {
209 return 8;
210 }
211 }
212 else if (spg < 168)
213 {
214 if (groups[spg-1][0] == 'R')
215 {
216 return 9;
217 }
218 else
219 {
220 return 10;
221 }
222 }
223 else if (spg < 195)
224 {
225 return 10;
226 }
227 else
228 {
229 if (groups[spg-1][0] == 'P')
230 {
231 return 11;
232 }
233 else if (groups[spg-1][0] == 'I')
234 {
235 return 12;
236 }
237 else
238 {
239 return 13;
240 }
241 }
242}
243
251gchar * frac_string (gchar * init)
252{
253 gchar * end = substitute_string (init, "1/2", "&#189;");
254 end = substitute_string (end, "1/4", "&#188;");
255 end = substitute_string (end, "3/4", "&#190;");
256 end = substitute_string (end, "1/3", "&#8531;");
257 end = substitute_string (end, "2/3", "&#8532;");
258 end = substitute_string (end, "1/6", "&#8537;");
259 end = substitute_string (end, "5/6", "&#8538;");
260 end = substitute_string (end, "1/8", "&#8539;");
261 end = substitute_string (end, "3/8", "&#8540;");
262 end = substitute_string (end, "5/8", "&#8541;");
263 end = substitute_string (end, "7/8", "&#8542;");
264 return g_strdup_printf ("%s", end);
265}
266
274gchar * get_num_string (gchar * str)
275{
276 str = replace_markup (str, "65", "6<sub>5</sub>");
277 str = replace_markup (str, "64", "6<sub>4</sub>");
278 str = replace_markup (str, "63", "6<sub>3</sub>");
279 str = replace_markup (str, "62", "6<sub>2</sub>");
280 str = replace_markup (str, "61", "6<sub>1</sub>");
281 str = replace_markup (str, "43", "4<sub>3</sub>");
282 str = replace_markup (str, "42", "4<sub>2</sub>");
283 str = replace_markup (str, "41", "4<sub>1</sub>");
284 str = replace_markup (str, "32", "3<sub>2</sub>");
285 str = replace_markup (str, "31", "3<sub>1</sub>");
286 return substitute_string (str, "21", "2<sub>1</sub>");
287}
288
297gchar * get_so_string (space_group * spg, int id)
298{
299 gchar * str = replace_markup (spg -> settings[id].name, "s", "/");
300 str = get_num_string (str);
301 str = substitute_string (str, "_", NULL);
302 if (spg -> settings[id].origin)
303 {
304 str = g_strdup_printf ("%s (%d)", str, spg -> settings[id].origin);
305 }
306 return str;
307}
308
316GtkTreeModel * so_combo_tree (space_group * spg)
317{
318 GtkTreeIter iter;
319 GtkTreeStore * store;
320 int i;
321 store = gtk_tree_store_new (1, G_TYPE_STRING);
322 if (! spg) return GTK_TREE_MODEL (store);
323 if (spg -> nums > 1)
324 {
325 for (i=0; i<spg -> nums; i++)
326 {
327 gtk_tree_store_append (store, &iter, NULL);
328 gtk_tree_store_set (store, & iter, 0, get_so_string (spg, i), -1);
329 }
330 }
331 else
332 {
333 gtk_tree_store_append (store, &iter, NULL);
334 gtk_tree_store_set (store, & iter, 0, groups[spg -> id-1], -1);
335 }
336 return GTK_TREE_MODEL (store);
337}
338
347GtkTreeModel * sg_combo_tree (int csid, int bvid)
348{
349 GtkTreeIter iter;
350 GtkTreeStore * store;
351 int i;
352 gboolean doit;
353 gchar * str;
354 store = gtk_tree_store_new (1, G_TYPE_STRING);
355 for (i=min_bv[csid]; i<min_bv[csid]+nsg_bv[csid]; i++)
356 {
357 doit = FALSE;
358 if (! bvid || csid == 5)
359 {
360 doit = TRUE;
361 }
362 else
363 {
364 if (csid == 1 || csid == 3)
365 {
366 if ((bvid == 1 && groups[i][0] == 'P') || (bvid == 2 && groups[i][0] != 'P')) doit = TRUE;
367 }
368 else if (csid == 2)
369 {
370 if ((bvid == 1 && groups[i][0] == 'P') || (bvid == 2 && groups[i][0] == 'A') || (bvid == 2 && groups[i][0] == 'C') ||
371 (bvid == 3 && groups[i][0] == 'I') || (bvid == 4 && groups[i][0] == 'F'))
372 {
373 doit = TRUE;
374 }
375 }
376 else if (csid == 4)
377 {
378 if ((bvid == 1 && groups[i][0] == 'P') || (bvid == 2 && groups[i][0] == 'R')) doit = TRUE;
379 }
380 else if (csid == 6)
381 {
382 if ((bvid == 1 && groups[i][0] == 'P') || (bvid == 2 && groups[i][0] == 'I') || (bvid == 3 && groups[i][0] == 'F'))
383 {
384 doit = TRUE;
385 }
386 }
387 }
388 if (doit)
389 {
390 gtk_tree_store_append (store, &iter, NULL);
391 str = g_strdup_printf ("%3d: %s", i+1, groups[i]);
392 gtk_tree_store_set (store, & iter, 0, str, -1);
393 g_free (str);
394 }
395 }
396 return GTK_TREE_MODEL (store);
397}
398
404GtkTreeModel * la_combo_tree ()
405{
406 GtkTreeIter iter;
407 GtkTreeStore *store;
408 gchar * lat[2]={"<b><i>a</i></b>, <b><i>b</i></b>, <b><i>c</i></b>, &#x3B1; &#x3B2; &#x263;", i18n("Vectors")};
409 int i;
410 store = gtk_tree_store_new (1, G_TYPE_STRING);
411 for (i=0; i<2; i++)
412 {
413 gtk_tree_store_append (store, &iter, NULL);
414 gtk_tree_store_set (store, & iter, 0, (i) ? _(lat[i]) : lat[i], -1);
415 }
416 return GTK_TREE_MODEL (store);
417}
418
426int get_sg_num (GtkComboBox * box)
427{
428 GValue val = {0, };
429 GtkTreeModel * cmodel = gtk_combo_box_get_model (box);
430 GtkTreeIter iter;
431 gchar * str = NULL;
432 gchar * num = NULL;
433 int i = 0;
434 if (gtk_combo_box_get_active_iter (box, & iter))
435 {
436 gtk_tree_model_get_value (cmodel, & iter, 0, & val);
437 str = g_strdup_printf ("%s", (char *)g_value_get_string (& val));
438 if (str)
439 {
440 num = g_strdup_printf ("%c%c%c", str[0], str[1], str[2]);
441 i = (int) string_to_double ((gpointer)num);
442 g_free (str);
443 g_free (num);
444 }
445 }
446 return i;
447}
448
457{
458 int i, j, k;
459 j = get_sg_num (GTK_COMBO_BOX(cbuilder -> sg_combo));
460 k = get_crystal_id (j);
461 box_info * box = & cbuilder -> cell.box[0];
462 switch (k)
463 {
464 case 1:
465 box -> param[1][0] = 90.0;
466 box -> vect[0][1] = box -> vect[0][2] = 0.0;
467 box -> vect[2][0] = box -> vect[2][1] = 0.0;
468 break;
469 case 2:
470 box -> param[1][0] = box -> param[1][1] = box -> param[1][2] = 90.0;
471 box -> vect[0][1] = box -> vect[0][2] = 0.0;
472 box -> vect[1][0] = box -> vect[1][2] = 0.0;
473 box -> vect[2][0] = box -> vect[2][1] = 0.0;
474 break;
475 case 3:
476 box -> param[0][1] = box -> param[0][0];
477 box -> param[1][0] = box -> param[1][1] = box -> param[1][2] = 90.0;
478 break;
479 case 4:
480 box -> param[0][1] = box -> param[0][0];
481 if (cbuilder -> cell.sp_group -> name[0] == 'R')
482 {
483 box -> param[1][0] = box -> param[1][1] = box -> param[1][2] = 0.0;
484 }
485 else
486 {
487 box -> param[1][0] = box -> param[1][1] = 90.0;
488 box -> param[1][2] = 120.0;
489 }
490 box -> vect[1][1] = box -> vect[0][0];
491 box -> vect[0][1] = box -> vect[0][2] = 0.0;
492 box -> vect[1][0] = box -> vect[1][2] = 0.0;
493 break;
494 case 5:
495 box -> param[0][1] = box -> param[0][0];
496 box -> param[1][0] = box -> param[1][1] = 90.0;
497 box -> param[1][2] = 120.0;
498 box -> vect[0][1] = box -> vect[0][2] = 0.0;
499 box -> vect[1][0] = box -> vect[1][2] = 0.0;
500 break;
501 case 6:
502 box -> param[0][1] = box -> param[0][2] = box -> param[0][0];
503 box -> param[1][0] = box -> param[1][1] = box -> param[1][2] = 90.0;
504 box -> vect[1][1] = box -> vect[2][2] = box -> vect[0][0];
505 box -> vect[0][1] = box -> vect[0][2] = 0.0;
506 box -> vect[1][0] = box -> vect[1][2] = 0.0;
507 box -> vect[2][0] = box -> vect[2][1] = 0.0;
508 break;
509 default:
510 break;
511 }
512 if (cbuilder -> cell.ltype)
513 {
514 for (i=0; i<3; i++)
515 {
516 for (j=0; j<3; j++)
517 {
518 if (cbuilder -> ventry[i][j])
519 {
520 if (GTK_IS_WIDGET(cbuilder -> ventry[i][j]))
521 {
522 update_entry_double (GTK_ENTRY(cbuilder -> ventry[i][j]), box -> vect[i][j]);
523 }
524 }
525 }
526 }
527 }
528 else
529 {
530 for (i=0; i<2; i++)
531 {
532 for (j=0; j<3; j++)
533 {
534 if (cbuilder -> bentry[i][j])
535 {
536 if (GTK_IS_WIDGET(cbuilder -> bentry[i][j]))
537 {
538 update_entry_double (GTK_ENTRY(cbuilder -> bentry[i][j]), box -> param[i][j]);
539 }
540 }
541 }
542 }
543 if (cbuilder -> bentry[0][1])
544 {
545 if (GTK_IS_WIDGET(cbuilder -> bentry[0][1]))
546 {
547 widget_set_sensitive (cbuilder -> bentry[0][1], (k > 2) ? 0 : 1);
548 if (k > 2) update_entry_text (GTK_ENTRY(cbuilder -> bentry[0][1]), "");
549 }
550 }
551 if (cbuilder -> bentry[0][2])
552 {
553 if (GTK_IS_WIDGET(cbuilder -> bentry[0][2]))
554 {
555 widget_set_sensitive (cbuilder -> bentry[0][2], (k > 5 || (k == 4 && cbuilder -> cell.sp_group -> name[0] == 'R')) ? 0 : 1);
556 if (k > 5 || (k == 4 && cbuilder -> cell.sp_group -> name[0] == 'R')) update_entry_text (GTK_ENTRY(cbuilder -> bentry[0][2]), "");
557 }
558 }
559 for (i=0; i<3; i++)
560 {
561 if (cbuilder -> bentry[1][i])
562 {
563 if (GTK_IS_WIDGET(cbuilder -> bentry[1][i]))
564 {
565 widget_set_sensitive (cbuilder -> bentry[1][i], (k > 1) || (k == 1 && ! i) ? 0 : 1);
566 if (k == 4 && cbuilder -> cell.sp_group -> name[0] == 'R')
567 {
568 if (! i)
569 {
570 widget_set_sensitive (cbuilder -> bentry[1][i], 1);
571 }
572 else
573 {
574 update_entry_text (GTK_ENTRY(cbuilder -> bentry[1][i]), "");
575 }
576 }
577 }
578 }
579 }
580 }
581}
582
591G_MODULE_EXPORT void update_cb_vect (GtkEntry * entry, gpointer data)
592{
593 tint * id = (tint *)data;
594 const gchar * m = entry_get_text (entry);
595 double v = string_to_double ((gpointer)m);
596 get_project_by_id(id -> a) -> modelgl -> builder_win -> cell.box[0].vect[id -> b][id -> c] = v;
597 update_entry_double (entry, v);
598}
599
608G_MODULE_EXPORT void update_cb_box (GtkEntry * entry, gpointer data)
609{
610 tint * id = (tint *)data;
611 const gchar * m = entry_get_text (entry);
612 double v = string_to_double ((gpointer)m);
613 if (v >= 0.0)
614 {
615 get_project_by_id(id -> a) -> modelgl -> builder_win -> cell.box[0].param[id -> b][id -> c] = v;
616 }
617 update_entry_double (entry, v);
618}
619
629GtkWidget * prepare_lattice_grid (int type, builder_edition * cbuilder, glwin * glview)
630{
631 GtkWidget * table = gtk_grid_new ();
632 int i, j, k;
633 k = 0;
634 for (i=0; i<3; i++)
635 {
636 for (j=0; j<3; j++, k++)
637 {
638 if (i < 2) cbuilder -> cell.box[0].param[i][j] = 0.0;
639 cbuilder -> cell.box[0].vect[i][j] = 0.0;
640 t_box[k].a = i;
641 t_box[k].b = j;
642 }
643 }
644 cbuilder -> cell.ltype = type;
645 if (cbuilder -> cell.ltype)
646 {
647 k = 0;
648 for (i=0; i<4; i++)
649 {
650 if (i > 0)
651 {
652 gtk_grid_attach (GTK_GRID (table), markup_label(vect_name[i-1], 20, -1, 0.0, 0.5), 0, i, 1, 1);
653 }
654 for (j=0; j<4; j++)
655 {
656 if (j > 0)
657 {
658 if (i == 0)
659 {
660 gtk_grid_attach (GTK_GRID (table), markup_label(vect_comp[j-1], -1, 20, 0.5, 0.5), j, 0, 1, 1);
661 }
662 else
663 {
664 cbuilder -> ventry[i-1][j-1] = create_entry (G_CALLBACK(update_cb_vect), 100, 15, FALSE, & cbuilder -> pointers[i][j]);
665 update_entry_double (GTK_ENTRY(cbuilder -> ventry[i-1][j-1]), cbuilder -> cell.box[0].vect[i-1][j-1]);
666 gtk_grid_attach (GTK_GRID (table), cbuilder -> ventry[i-1][j-1], j, i, 1, 1);
667 k ++;
668 }
669 }
670 }
671 }
672 }
673 else
674 {
675 k = 0;
676 for (i=0; i<2; i++)
677 {
678 //gtk_grid_attach (GTK_GRID (table), markup_label(box_p[i], -1, 50, 0.5, 0.5), 1, i+2*i, 1, 1);
679 gtk_grid_attach (GTK_GRID (table), markup_label(" ", 20, -1, 0.5, 0.5), 0, i, 1, 1);
680 for (j=0; j<3; j++, k++)
681 {
682 gtk_grid_attach (GTK_GRID (table), markup_label(box_prop[i][j], -1, -1, 0.5, 0.5), j+1, i+2*i, 1, 1);
683 cbuilder -> bentry[i][j] = create_entry (G_CALLBACK(update_cb_box), 100, 15, FALSE, & cbuilder -> pointers[i][j]);
684 update_entry_double (GTK_ENTRY(cbuilder -> bentry[i][j]), cbuilder -> cell.box[0].param[i][j]);
685 gtk_grid_attach (GTK_GRID (table), cbuilder -> bentry[i][j], j+1, i+2*i+1, 1, 1);
686 }
687 }
688 adjust_lattice_parameters (cbuilder);
689 }
690 return table;
691}
692
701G_MODULE_EXPORT void set_lattice (GtkComboBox * box, gpointer data)
702{
703 tint * id = (tint *) data;
704 glwin * view = get_project_by_id(id -> a) -> modelgl;
705 builder_edition * cbuilder = view -> builder_win;
706 cbuilder -> lattice_grid = destroy_this_widget (cbuilder -> lattice_grid);
707 cbuilder -> lattice_grid = prepare_lattice_grid (combo_get_active ((GtkWidget *)box), cbuilder, view);
708 add_box_child_start (GTK_ORIENTATION_VERTICAL, cbuilder -> lattice_box, cbuilder -> lattice_grid, FALSE, FALSE, 5);
709 show_the_widgets (cbuilder -> lattice_grid);
710}
711
720G_MODULE_EXPORT void set_so (GtkComboBox * box, gpointer data)
721{
722 tint * id = (tint *) data;
723 builder_edition * cbuilder = get_project_by_id(id -> a) -> modelgl -> builder_win;
724 int i = combo_get_active ((GtkWidget *)box);
725 gchar * str = g_strdup_printf ("(%s,%s,%s)", cbuilder -> cell.sp_group -> settings[i].pos[0],
726 cbuilder -> cell.sp_group -> settings[i].pos[1],
727 cbuilder -> cell.sp_group -> settings[i].pos[2]);
728 cbuilder -> so_info = destroy_this_widget(cbuilder -> so_info);
729 cbuilder -> so_info = markup_label(frac_string(str), -1, -1, 0.5, 0.5);
730 g_free (str);
731 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> so_box, cbuilder -> so_info, FALSE, FALSE, 10);
732 show_the_widgets (cbuilder -> so_info);
733 cbuilder -> cell.sp_group -> sid = i;
734 get_origin (cbuilder -> cell.sp_group);
735}
736
745GtkWidget * sg_info (int sg, gpointer data)
746{
747 gchar * str = g_strdup_printf (_("%s group info"), groups[sg]);
748 GtkWidget * mlab = markup_label(str, -1, -1, 0.5, 0.5);
749 GtkWidget * mbut = create_button (NULL, IMG_NONE, NULL, 50, -1, GTK_RELIEF_NORMAL, G_CALLBACK(show_sg_info), data);
751 show_the_widgets (mbut);
752 return mbut;
753}
754
763int read_space_group (builder_edition * cbuilder, int spg)
764{
765 // Read file
766 gchar * sgfile = substitute_string(groups[spg], "<sub>", NULL);
767 sgfile = substitute_string(sgfile, "</sub>", NULL);
768 sgfile = substitute_string(sgfile, "/", "s");
769#ifdef G_OS_WIN32
770 sgfile = g_strdup_printf ("%s\\space_groups\\%d-%s.sgl", PACKAGE_LIB_DIR, spg+1, sgfile);
771#else
772 sgfile = g_strdup_printf ("%s/space_groups/%d-%s.sgl", PACKAGE_LIB_DIR, spg+1, sgfile);
773#endif
774 int res;
775 if (cbuilder)
776 {
777 cbuilder -> cell.sp_group = read_sg_xml_file (sgfile);
778 res = (cbuilder -> cell.sp_group) ? 1 : 0;
779 }
780 else if (this_reader)
781 {
782 this_reader -> lattice.sp_group = read_sg_xml_file (sgfile);
783 res = (this_reader -> lattice.sp_group) ? 1 : 0;
784 }
785 g_free (sgfile);
786 return res;
787}
788
796int get_group_id_from_name (gchar * sg_name)
797{
798 int i;
799 for (i=0; i<230; i++)
800 {
801 if (g_strcmp0(groups[i], sg_name) == 0) return i+1;
802 }
803 return 0;
804}
805
814{
815 GtkTreeModel * model = so_combo_tree (cbuilder -> cell.sp_group);
816 gtk_combo_box_set_model (GTK_COMBO_BOX(cbuilder -> so_combo), model);
817 g_object_unref (model);
818 combo_set_active (cbuilder -> so_combo, 0);
819 combo_set_markup (cbuilder -> so_combo);
820 widget_set_sensitive (cbuilder -> so_combo, cbuilder -> cell.sp_group -> nums-1);
821 if (cbuilder -> cell.sp_group) get_origin (cbuilder -> cell.sp_group);
822}
823
832{
833 if (cbuilder -> bv_img) cbuilder -> bv_img = destroy_this_widget(cbuilder -> bv_img);
834 cbuilder -> bv_img = gtk_image_new_from_file (bravais_img[get_bravais_img_id(cbuilder -> cell.sp_group -> id)]);
835#ifdef GTK4
836 gtk_widget_set_size_request (cbuilder -> bv_img, 200, 200);
837 gtk_widget_set_hexpand (cbuilder -> bv_img, TRUE);
838 gtk_widget_set_vexpand (cbuilder -> bv_img, TRUE);
839#endif
840 add_box_child_start (GTK_ORIENTATION_VERTICAL, cbuilder -> bv_box[1], cbuilder -> bv_img, FALSE, FALSE, 5);
841}
842
851{
852 if (cbuilder -> ltc_cons) cbuilder -> ltc_cons = destroy_this_widget(cbuilder -> ltc_cons);
853 int i = get_crystal_id (cbuilder -> cell.sp_group -> id);
854 gchar * str = g_strdup_printf ("<b>%s</b>", (i == 1 || i == 5) ? _(latt_info[i]) : latt_info[i]);
855 cbuilder -> ltc_cons = markup_label(str, 150, -1, 0.0, 0.5);
856 g_free (str);
857 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> ltc_box, cbuilder -> ltc_cons, FALSE, FALSE, 5);
858}
859
868G_MODULE_EXPORT void set_sg (GtkComboBox * box, gpointer data)
869{
870 tint * id = (tint *) data;
871 builder_edition * cbuilder = get_project_by_id(id -> a) -> modelgl -> builder_win;
872 int i = get_sg_num(box);
873 if (i)
874 {
875 cbuilder -> sg_but = destroy_this_widget(cbuilder -> sg_but);
876 if (read_space_group (cbuilder, i-1))
877 {
878 cbuilder -> sg_but = sg_info (i-1, data);
879 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> sg_box, cbuilder -> sg_but, FALSE, FALSE, 10);
880 if (cbuilder -> bv_box[0]) adjust_lattice_constraints (cbuilder);
881 if (cbuilder -> bv_box[1]) adjust_bv_img (cbuilder);
882 show_the_widgets (cbuilder -> bh_box);
883 if (cbuilder -> so_combo) adjust_so_combo (cbuilder);
884 if (cbuilder -> lattice_grid) adjust_lattice_parameters (cbuilder);
885 }
886 else
887 {
888 // Error reading file
889 show_error (_("Cannot read space group *.sgl file ?!\nPlease check the program library !"), 0, cbuilder -> win);
890 }
891 }
892}
893
903void adjust_sg_combo (builder_edition * cbuilder, int cs, int bl)
904{
905 GtkTreeModel * model = sg_combo_tree (cs, bl);
906 gtk_combo_box_set_model (GTK_COMBO_BOX(cbuilder -> sg_combo), model);
907 g_object_unref (model);
908 combo_set_active (cbuilder -> sg_combo, 0);
909 combo_set_markup (cbuilder -> sg_combo);
910 adjust_lattice_parameters (cbuilder);
911}
912
921G_MODULE_EXPORT void set_bl (GtkComboBox * box, gpointer data)
922{
923 builder_edition * cbuilder = (builder_edition *)data;
924 int i, j;
925 i = combo_get_active (cbuilder -> cs_combo);
926 j = combo_get_active ((GtkWidget *)box);
927 adjust_sg_combo (cbuilder, i, j);
928}
929
938GtkWidget * create_bl_combo (int cs, gpointer data)
939{
940 gchar * bravais_keys[7][4] = {{i18n("Primitive "), NULL, NULL, NULL},
941 {i18n("Primitive "), i18n("Base-centered"), NULL, NULL},
942 {i18n("Primitive "), i18n("Base-centered"), i18n("Body-centered"), i18n("Face-centered")},
943 {i18n("Primitive "), i18n("Body-centered"), NULL, NULL},
944 {i18n("Hexagonal Axes"), i18n("Rhombohedral Axes"), NULL, NULL},
945 {i18n("Hexagonal"), NULL, NULL, NULL},
946 {i18n("Primitive"), i18n("Body-centered"), i18n("Face-centered"), NULL}};
947 GtkWidget * cbox = create_combo();
948 int i;
949 combo_text_append (cbox, _("All"));
950 for (i=0; i<4; i++)
951 {
952 if (bravais_keys[cs][i]) combo_text_append (cbox, _(bravais_keys[cs][i]));
953 }
954 i = (cs == 0 || cs == 5) ? 0 : 1;
956 combo_set_active (cbox, ! i);
957 g_signal_connect (G_OBJECT(cbox), "changed", G_CALLBACK(set_bl), data);
958 gtk_widget_set_size_request (cbox, 150, 25);
959 return cbox;
960}
961
970G_MODULE_EXPORT void set_cs (GtkComboBox * box, gpointer data)
971{
972 builder_edition * cbuilder = (builder_edition *)data;
973 int i = combo_get_active ((GtkWidget *)box);
974 cbuilder -> bl_combo = destroy_this_widget(cbuilder -> bl_combo);
975 cbuilder -> bl_combo = create_bl_combo (i, data);
976 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> bl_box, cbuilder -> bl_combo, FALSE, FALSE, 0);
977 adjust_sg_combo (cbuilder, i, 0);
978 show_the_widgets (cbuilder -> bl_combo);
979}
980
981#ifdef GTK4
990G_MODULE_EXPORT void set_wr (GtkCheckButton * but, gpointer data)
991#else
1000G_MODULE_EXPORT void set_wr (GtkToggleButton * but, gpointer data)
1001#endif
1002{
1003 builder_edition * cbuilder = (builder_edition * )data;
1004 cbuilder -> wrap = button_get_status ((GtkWidget *)but);
1005}
1006
1007#ifdef GTK4
1016G_MODULE_EXPORT void set_shc (GtkCheckButton * but, gpointer data)
1017#else
1026G_MODULE_EXPORT void set_shc (GtkToggleButton * but, gpointer data)
1027#endif
1028{
1029 builder_edition * cbuilder = (builder_edition * )data;
1030 cbuilder -> clones = button_get_status ((GtkWidget *)but);
1031}
1032
1041G_MODULE_EXPORT void add_cryst_cell (GtkSpinButton * res, gpointer data)
1042{
1043 tint * bid = (tint *)data;
1044 builder_edition * cbuilder = get_project_by_id(bid -> a) -> modelgl -> builder_win;
1045 cbuilder -> cell.cextra[bid -> b] = gtk_spin_button_get_value_as_int(res);
1046}
1047
1056G_MODULE_EXPORT void apply_build (GtkButton * but, gpointer data)
1057{
1058 int id = GPOINTER_TO_INT(data);
1059 project * this_proj = get_project_by_id(id);
1060 if (test_lattice(this_proj -> modelgl -> builder_win, NULL))
1061 {
1062 crystal_dist_chk = TRUE;
1063 crystal_crowded = FALSE;
1064 crystal_low_warning = TRUE;
1065 build_crystal (TRUE, this_proj, 0, this_proj -> modelgl -> builder_win -> wrap, this_proj -> modelgl -> builder_win -> clones,
1066 & this_proj -> modelgl -> builder_win -> cell, this_proj -> modelgl -> builder_win -> win);
1067 }
1068}
1069
1078G_MODULE_EXPORT void close_build (GtkButton * but, gpointer data)
1079{
1080 int id = GPOINTER_TO_INT(data);
1081 project * this_proj = get_project_by_id(id);
1082 this_proj -> modelgl -> search_widg[7] = free_this_search_data (this_proj -> modelgl -> search_widg[7]);
1083 this_proj -> modelgl -> builder_win -> win = destroy_this_widget(this_proj -> modelgl -> builder_win -> win);
1084 g_free (this_proj -> modelgl -> builder_win);
1085 this_proj -> modelgl -> builder_win = NULL;
1086}
1087
1088#ifdef GTK4
1097G_MODULE_EXPORT gboolean delete_build (GtkWindow * widg, gpointer data)
1098#else
1108G_MODULE_EXPORT gboolean delete_build (GtkWidget * widg, GdkEvent * event, gpointer data)
1109#endif
1110{
1111 close_build (NULL, data);
1112 return TRUE;
1113}
1114
1116
1117#ifdef GTK4
1126G_MODULE_EXPORT void toggle_occ (GtkCheckButton * but, gpointer data)
1127#else
1136G_MODULE_EXPORT void toggle_occ (GtkToggleButton * but, gpointer data)
1137#endif
1138{
1139 dint * cid = (dint *)data;
1140 get_project_by_id(cid -> a) -> modelgl -> builder_win -> occupancy = cid -> b;
1141}
1142
1143#ifdef GTK4
1152G_MODULE_EXPORT void toggle_overlap (GtkCheckButton * Button, gpointer data)
1153#else
1162G_MODULE_EXPORT void toggle_overlap (GtkToggleButton * Button, gpointer data)
1163#endif
1164{
1165 builder_edition * cbuilder = (builder_edition * )data;
1166 cbuilder -> overlapping = button_get_status ((GtkWidget *)Button);
1167}
1168
1177G_MODULE_EXPORT void on_rounding_changed (GtkComboBox * box, gpointer data)
1178{
1179 builder_edition * cbuilder = (builder_edition *)data;
1180 cbuilder -> rounding = combo_get_active ((GtkWidget *)box);
1181}
1182
1191G_MODULE_EXPORT void adjust_occupancy (GtkButton * but, gpointer data)
1192{
1193 project * this_proj = (project *)data;
1194 builder_edition * cbuilder = this_proj -> modelgl -> builder_win;
1195 GtkWidget * info = dialogmodal ("Occupancy set-up", GTK_WINDOW(cbuilder -> win));
1196 GtkWidget * vbox, * hbox;
1198 gchar * boccup[5] = {i18n("<b>Random for the initial cell only</b>"),
1199 i18n("<b>Random cell by cell</b>"),
1200 i18n("<b>Completely random</b>"),
1201 i18n("<b>Successively</b>"),
1202 i18n("<b>Alternatively</b>")};
1203 gchar * occup[5] = {i18n("<i>Sites are filled randomly in the initial cell only,\n"
1204 "then the initial cell is simply replicated.</i>"),
1205 i18n("<i>Sites are filled randomly for each cell, cell by cell separately.</i>"),
1206 i18n("<i>Sites are filled randomly for the entire network,\n"
1207 "the final crystal is considered as a whole.</i>"),
1208 i18n("<i>Sites are filled successively: all object(s) A, then all object(s) B ... </i>"),
1209 i18n("<i>Sites are filled alternatively: object A, object B, object A ...</i>")};
1210
1211 GtkWidget * occ_but[5];
1212 int i;
1213 for (i=0; i<5; i++)
1214 {
1215 hbox = create_hbox(0);
1216 occp[i].a = this_proj -> id;
1217 occp[i].b = i;
1218 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1219#ifdef GTK4
1220 occ_but[i] = check_button (_(boccup[i]), -1, 25, FALSE, G_CALLBACK(toggle_occ), & occp[i]);
1221 if (i)
1222 {
1223 gtk_check_button_set_group ((GtkCheckButton *)occ_but[i], (GtkCheckButton *)occ_but[0]);
1224 }
1225#else
1226 if (! i)
1227 {
1228 occ_but[i] = radio_button (_(boccup[i]), -1, 25, FALSE, G_CALLBACK(toggle_occ), & occp[i]);
1229 }
1230 else
1231 {
1232 occ_but[i] = gtk_radio_button_new_from_widget (GTK_RADIO_BUTTON(occ_but[0]));
1233 add_container_child (CONTAINER_BUT, occ_but[i], markup_label(_(boccup[i]), -1, 25, 0.0, 0.5));
1234 }
1235#endif
1236 if (i) g_signal_connect (G_OBJECT(occ_but[i]), "toggled", G_CALLBACK(toggle_occ), & occp[i]);
1237#ifdef GTK4
1238 gtk_button_set_has_frame (GTK_BUTTON(occ_but[i]), FALSE);
1239#endif
1240 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, occ_but[i], FALSE, FALSE, 5);
1241 hbox = create_hbox(0);
1242 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1243 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label (_(occup[i]), 200, -1, 0.5, 0.5), FALSE, FALSE, 50);
1244 }
1245 i = cbuilder -> occupancy;
1246 button_set_status (occ_but[i], TRUE);
1247 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, check_button (_("<b>Allow overlapping</b>"), -1, 25, cbuilder -> overlapping, G_CALLBACK(toggle_overlap), (gpointer)cbuilder), FALSE, FALSE, 0);
1248 hbox = create_hbox(0);
1249 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1250 gchar * overlap = _("<i>Instead of ensuring that sites are filled by a single object,\n"
1251 "this allows object(s) to share the same crystalline position. \n"
1252 "The option above describes how filled and empty positions alternate.</i>\n");
1253 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label (overlap, 200, -1, 0.5, 0.5), FALSE, FALSE, 50);
1254
1255 // Rounding occupancy here
1256 hbox = create_hbox(0);
1257 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 10);
1258 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label (_("<b>Occupancy rounding:</b>"), 200, -1, 0.5, 0.5), FALSE, FALSE, 0);
1259 GtkWidget * rounding = create_combo ();
1260 gtk_widget_set_size_request (rounding, -1, 30);
1261 for (i=0; i<3; i++) combo_text_append (rounding, _(cif_occupancies[i]));
1262 combo_set_active (rounding, cbuilder -> rounding);
1263 g_signal_connect(G_OBJECT(rounding), "changed", G_CALLBACK(on_rounding_changed), & cbuilder);
1264 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, rounding, FALSE, FALSE, 10);
1265 gchar * str = g_strdup_printf (_("\t<b>Lowest integer: </b>\n"
1266 "\t\t Occupancy %s\n\t\t\t ex:\t ⌊8.75⌋ = 8\n"
1267 "\t<b>Highest integer: </b>\n"
1268 "\t\t Occupancy %s\n\t\t\t ex:\t ⌈5.39⌉ = 6\n"
1269 "\t<b>Nearest integer: </b>\n"
1270 "\t\t Occupancy %s\n\t\t\t ex:\t ⌊6.82⌉ = 7\t\t and\t ⌊4.31⌉ = 4\n"
1271 "\n\t\t%s\n"), _(cif_occ[0]), _(cif_occ[1]), _(cif_occ[2]), _(cif_sites[0]));
1272 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, markup_label (str, 450, -1, 0.5, 0.5), FALSE, FALSE, 5);
1273 g_free (str);
1274
1275 show_the_widgets (info);
1276 run_this_gtk_dialog (info, G_CALLBACK(run_destroy_dialog), NULL);
1277}
1278
1287GtkWidget * builder_win (project * this_proj, gpointer data)
1288{
1289 int i, j;
1290 gchar * crystal_systems[7] = {i18n("Triclinic"), i18n("Monoclinic"), i18n("Othorhombic"), i18n("Tetragonal"), i18n("Trigonal"), i18n("Hexagonal"), i18n("Cubic")};
1291 gchar * str = (! this_proj -> natomes) ? g_strdup_printf (_("Crystal builder - %s"), this_proj -> name) : g_strdup_printf (_("Crystal builder"));
1292 builder_edition * cbuilder = this_proj -> modelgl -> builder_win;
1293 GtkWidget * win = create_win (str, this_proj -> modelgl -> win, FALSE, FALSE);
1294 g_free (str);
1295 GtkWidget * vbox = create_vbox (BSEP);
1297
1298 cbuilder -> bh_box = create_hbox(0);
1299 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, cbuilder -> bh_box, FALSE, FALSE, 0);
1300 for (i=0; i<2; i++)
1301 {
1302 cbuilder -> bv_box[i] = create_vbox (BSEP);
1303 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> bh_box, cbuilder -> bv_box[i], FALSE, FALSE, 0);
1304 }
1305
1306 // Crystal system
1307 GtkWidget * hbox = create_hbox(0);
1308 add_box_child_start (GTK_ORIENTATION_VERTICAL, cbuilder -> bv_box[0], hbox, FALSE, FALSE, 0);
1309 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(_("Crystal system:"), 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1310 cbuilder -> cs_combo = create_combo();
1311
1312 for (i=0; i<7;i++) combo_text_append (cbuilder -> cs_combo, _(crystal_systems[i]));
1313 combo_set_active (cbuilder -> cs_combo, 0);
1314 gtk_widget_set_size_request (cbuilder -> cs_combo, 150, 25);
1315 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, cbuilder -> cs_combo, FALSE, FALSE, 0);
1316 g_signal_connect (G_OBJECT(cbuilder -> cs_combo), "changed", G_CALLBACK(set_cs), (gpointer)cbuilder);
1317
1318 // Bravais lattice
1319 cbuilder -> bl_box = create_hbox(0);
1320 add_box_child_start (GTK_ORIENTATION_VERTICAL, cbuilder -> bv_box[0], cbuilder -> bl_box, FALSE, FALSE, 0);
1321 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> bl_box, markup_label(_("Bravais lattice:"), 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1322 cbuilder -> bl_combo = create_bl_combo (0, (gpointer)cbuilder);
1323 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> bl_box, cbuilder -> bl_combo, FALSE, FALSE, 0);
1324
1325 cbuilder -> ltc_box = create_hbox (0);
1326 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> ltc_box, markup_label(_("Lattice constraints: "), 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1327 i = get_crystal_id (1);
1328 str = g_strdup_printf ("<b>%s</b>", (i == 1 || i == 5) ? _(latt_info[i]) : latt_info[i]);
1329 cbuilder -> ltc_cons = markup_label(str, 150, -1, 0.0, 0.5);
1330 g_free (str);
1331 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> ltc_box, cbuilder -> ltc_cons, FALSE, FALSE, 5);
1332 add_box_child_start (GTK_ORIENTATION_VERTICAL, cbuilder -> bv_box[0], cbuilder -> ltc_box, FALSE, FALSE, 5);
1333
1334 // cbuilder -> bv_img = gtk_image_new_from_file (bravais_img[get_bravais_img_id(1)]);
1335 // add_box_child_start (GTK_ORIENTATION_VERTICAL, cbuilder -> bv_box[1], cbuilder -> bv_img, FALSE, FALSE, 5);
1336
1337 // Space group
1338 cbuilder -> sg_box = create_hbox(0);
1339 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, cbuilder -> sg_box, FALSE, FALSE, 0);
1340 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> sg_box, markup_label(_("Space group:"), 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1341 GtkTreeModel * model = sg_combo_tree (0, 0);
1342 cbuilder -> sg_combo = gtk_combo_box_new_with_model (model);
1343 g_object_unref (model);
1344 GtkCellRenderer * renderer = gtk_cell_renderer_combo_new ();
1345 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cbuilder -> sg_combo), renderer, TRUE);
1346 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (cbuilder -> sg_combo), renderer, "text", 0, NULL);
1347 g_signal_connect (G_OBJECT(cbuilder -> sg_combo), "changed", G_CALLBACK(set_sg), data);
1348 gtk_widget_set_size_request (cbuilder -> sg_combo, 150, 25);
1349 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> sg_box, cbuilder -> sg_combo, FALSE, FALSE, 0);
1350 combo_set_active (cbuilder -> sg_combo, 0);
1351 combo_set_markup (cbuilder -> sg_combo);
1352 // Space group option
1353 cbuilder -> so_box = create_hbox(0);
1354 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, cbuilder -> so_box, FALSE, FALSE, 0);
1355 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> so_box, markup_label(_("Settings:"), 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1356 model = so_combo_tree (cbuilder -> cell.sp_group);
1357 cbuilder -> so_combo = gtk_combo_box_new_with_model (model);
1358 g_object_unref (model);
1359 renderer = gtk_cell_renderer_combo_new ();
1360 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cbuilder -> so_combo), renderer, TRUE);
1361 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (cbuilder -> so_combo), renderer, "text", 0, NULL);
1362 gtk_widget_set_size_request (cbuilder -> so_combo, 150, 25);
1363 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> so_box, cbuilder -> so_combo, FALSE, FALSE, 0);
1364 combo_set_active (cbuilder -> so_combo, 0);
1365 widget_set_sensitive (cbuilder -> so_combo, 0);
1366 g_signal_connect (G_OBJECT(cbuilder -> so_combo), "changed", G_CALLBACK(set_so), data);
1367 combo_set_markup (cbuilder -> so_combo);
1368
1369 for (i=0; i<3; i++)
1370 {
1371 cbuilder -> cell.cextra[i] = 1;
1372 for (j=0; j<3; j++)
1373 {
1374 cbuilder -> pointers[i][j].a = this_proj -> id;
1375 cbuilder -> pointers[i][j].b = i;
1376 cbuilder -> pointers[i][j].c = j;
1377 }
1378 }
1379 if (cbuilder -> cell.sp_group) get_origin (cbuilder -> cell.sp_group);
1380 // Lattice parameters
1381 hbox = create_hbox(0);
1382 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1383 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(_("Lattice parameters:"), 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1384 cbuilder -> lattice_box = create_vbox (BSEP);
1385 GtkTreeModel * lmodel = la_combo_tree ();
1386 cbuilder -> la_combo = gtk_combo_box_new_with_model (lmodel);
1387 g_object_unref (lmodel);
1388 renderer = gtk_cell_renderer_combo_new ();
1389 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cbuilder -> la_combo), renderer, TRUE);
1390 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (cbuilder -> la_combo), renderer, "text", 0, NULL);
1391 gtk_widget_set_size_request (cbuilder -> la_combo, 150, 25);
1392 g_signal_connect (G_OBJECT(cbuilder -> la_combo), "changed", G_CALLBACK(set_lattice), data);
1393 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, cbuilder -> la_combo, FALSE, FALSE, 0);
1394 combo_set_active (cbuilder -> la_combo, 0);
1395 combo_set_markup (cbuilder -> la_combo);
1396 hbox = create_hbox(0);
1397 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 5);
1398 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, cbuilder -> lattice_box, FALSE, FALSE, 50);
1399
1400 hbox = create_hbox(0);
1401 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1402 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(_("Cell(s):"), 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1403 hbox = create_hbox(0);
1404 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1405 GtkWidget * ax_cell[3];
1406 for (i=0; i<3; i++)
1407 {
1408 ax_cell[i] = spin_button (G_CALLBACK(add_cryst_cell), cbuilder -> cell.cextra[i], 1, 1000, 1, 0, 100, & cbuilder -> pointers[i][0]);
1409 str = g_strdup_printf ("%s x ", box_prop[0][i]);
1410 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(str, 50, -1, 1.0, 0.5), FALSE, FALSE, 5);
1411 g_free (str);
1412 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, ax_cell[i], FALSE, FALSE, 0);
1413 }
1414
1415 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, check_button (_(" Wrap all atoms in the unit cell after building"), -1, -1, FALSE, G_CALLBACK(set_wr), (gpointer)cbuilder), FALSE, FALSE, 10);
1416 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, check_button (_(" Show/Hide clones after building"), -1, -1, FALSE, G_CALLBACK(set_shc), (gpointer)cbuilder), FALSE, FALSE, 0);
1417
1418 hbox = create_hbox (0);
1419 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 10);
1420 this_proj -> modelgl -> search_widg[7] = allocate_atom_search (this_proj -> id, INSERT, 7, 0);
1421 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(_("Add object(s):"), 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1422 cbuilder -> add_combo = create_action_combo (5, this_proj);
1423 gtk_widget_set_size_request (cbuilder -> add_combo, 110, -1);
1424 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, cbuilder -> add_combo, FALSE, FALSE, 5);
1425 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, create_button (_("Occupancy"), IMG_STOCK, DPROPERTIES, -1, -1, GTK_RELIEF_NORMAL, G_CALLBACK(adjust_occupancy), this_proj), FALSE, FALSE, 5);
1426
1427 GtkWidget * cbscroll = create_scroll (vbox, 400, 200, GTK_SHADOW_NONE);
1428 add_container_child (CONTAINER_SCR, cbscroll, create_atoms_tree (this_proj -> modelgl -> search_widg[7], this_proj, 0));
1429
1430 hbox = create_hbox (5);
1431 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, TRUE, FALSE, 5);
1432 cbuilder -> pbut = create_button ((this_proj -> natomes) ? _("Build (new project)") : _("Build"), IMG_STOCK, APPLY, -1, -1, GTK_RELIEF_NORMAL, G_CALLBACK(apply_build), GINT_TO_POINTER(this_proj -> id));
1433 add_box_child_end (hbox, cbuilder -> pbut, FALSE, FALSE, 5);
1434 GtkWidget * but = create_button (_("Close"), IMG_STOCK, FCLOSE, -1, -1, GTK_RELIEF_NORMAL, G_CALLBACK(close_build), GINT_TO_POINTER(this_proj -> id));
1435 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, but, FALSE, FALSE, 5);
1436 add_gtk_close_event (win, G_CALLBACK(delete_build), GINT_TO_POINTER(this_proj -> id));
1437
1438 return win;
1439}
1440
1448void prepare_crystal_builder (gpointer data)
1449{
1450 tint * id = (tint *) data;
1451 project * this_proj = get_project_by_id(id -> a);
1452 if (this_proj -> modelgl -> builder_win == NULL)
1453 {
1454 // close_edit (NULL, GINT_TO_POINTER(this_proj -> id));
1455 prepare_atom_edition (data, FALSE);
1456 this_proj -> modelgl -> builder_win = g_malloc0(sizeof*this_proj -> modelgl -> builder_win);
1457 this_proj -> modelgl -> builder_win -> cell.box = g_malloc0(sizeof*this_proj -> modelgl -> builder_win -> cell.box);
1458 this_proj -> modelgl -> builder_win -> win = builder_win (this_proj, data);
1459 this_proj -> modelgl -> builder_win -> rounding = 2;
1460 }
1461 show_the_widgets (this_proj -> modelgl -> builder_win -> win);
1462}
1463
1464#ifdef GTK4
1474G_MODULE_EXPORT void crystal_window (GSimpleAction * action, GVariant * parameter, gpointer data)
1475#else
1484G_MODULE_EXPORT void crystal_window (GtkWidget * widg, gpointer data)
1485#endif
1486{
1488}
void prepare_atom_edition(gpointer data, gboolean visible)
prepare atom edition
Definition atom_edit.c:460
atom_search * allocate_atom_search(int proj, int action, int searchid, int tsize)
allocate atom search data structure
Definition atom_edit.c:393
G_MODULE_EXPORT void close_build(GtkWidget *widg, gpointer data)
GtkWidget * create_action_combo(int id, project *this_proj)
create action combo box
Binding to the Fortran90 subroutines.
gchar * substitute_string(gchar *init, gchar *o_motif, gchar *n_motif)
substitute all patterns in string
Definition w_library.c:375
gboolean crystal_low_warning
gboolean crystal_crowded
int occupancy(double occ, int cif_occ)
handle occupancy integer rouding
gboolean crystal_dist_chk
void adjust_sg_combo(builder_edition *cbuilder, int cs, int bl)
adjust the space group combo box to use pango markup
void adjust_bv_img(builder_edition *cbuilder)
adjust the bravais lattice image
G_MODULE_EXPORT void toggle_overlap(GtkToggleButton *Button, gpointer data)
adjust overlapping toggle callback GTK3
G_MODULE_EXPORT void adjust_occupancy(GtkButton *but, gpointer data)
adjust occupancy create dialog callback
G_MODULE_EXPORT void toggle_occ(GtkToggleButton *but, gpointer data)
occupancy toggle callback GTK3
G_MODULE_EXPORT void set_wr(GtkToggleButton *but, gpointer data)
wrap or not atomic coordinates after crystal building toggle callback GTK3
G_MODULE_EXPORT void apply_build(GtkButton *but, gpointer data)
build crystall callback
G_MODULE_EXPORT void set_sg(GtkComboBox *box, gpointer data)
change space group
G_MODULE_EXPORT void show_sg_info(GtkButton *but, gpointer data)
G_MODULE_EXPORT void set_cs(GtkComboBox *box, gpointer data)
change the crystal system
G_MODULE_EXPORT void add_cryst_cell(GtkSpinButton *res, gpointer data)
add cell callback spin
GtkWidget * create_bl_combo(int cs, gpointer data)
create the bravais lattice combo box
G_MODULE_EXPORT void set_so(GtkComboBox *box, gpointer data)
set space group setting
GtkWidget * sg_info(int sg, gpointer data)
create the space group information button
void adjust_lattice_constraints(builder_edition *cbuilder)
adjust lattice constraints
GtkTreeModel * la_combo_tree()
create the lattice system combo box tree model
int min_bv[7]
gchar * get_num_string(gchar *str)
get description string for entry string
gchar * latt_info[7]
gchar * frac_string(gchar *init)
get pango string for fraction string
int get_crystal_id(int spg)
get the bravais lattice id from space group id
G_MODULE_EXPORT void set_bl(GtkComboBox *box, gpointer data)
change bravais lattice
int build_crystal(gboolean visible, project *this_proj, int c_step, gboolean to_wrap, gboolean show_clones, cell_info *cell, GtkWidget *widg)
build crystal
int read_space_group(builder_edition *cbuilder, int spg)
read space group N°spg data from file
G_MODULE_EXPORT void set_shc(GtkToggleButton *but, gpointer data)
show / hide clones after crystal building toggle callback GTK3
G_MODULE_EXPORT void close_build(GtkButton *but, gpointer data)
close crystal builder and free associated data pointers
int get_bravais_img_id(int spg)
get bravais image from space group id
int nsg_bv[7]
void get_origin(space_group *spg)
get space group origin matrices
void adjust_lattice_parameters(builder_edition *cbuilder)
adjust lattice parameters depending on space group
G_MODULE_EXPORT void update_cb_box(GtkEntry *entry, gpointer data)
update lattice box parameter callback
G_MODULE_EXPORT void set_lattice(GtkComboBox *box, gpointer data)
change the lattice system
G_MODULE_EXPORT void crystal_window(GtkWidget *widg, gpointer data)
create the crystal build window callback GTK3
G_MODULE_EXPORT gboolean delete_build(GtkWidget *widg, GdkEvent *event, gpointer data)
crystal builder delete event callback GTK3
int get_group_id_from_name(gchar *sg_name)
get space group id from name
dint occp[5]
G_MODULE_EXPORT void update_cb_vect(GtkEntry *entry, gpointer data)
update lattice vector callback
int get_sg_num(GtkComboBox *box)
get space group number from active iter in tree model of combo box
void prepare_crystal_builder(gpointer data)
create the crystal builder
int test_lattice(builder_edition *cbuilder, cell_info *cif_cell)
test lattice parameters
GtkTreeModel * sg_combo_tree(int csid, int bvid)
create the space group combo box tree model
GtkWidget * builder_win(project *this_proj, gpointer data)
create crystal builder window
GtkWidget * prepare_lattice_grid(int type, builder_edition *cbuilder, glwin *glview)
prepare the lattice parameters grid widget
GtkTreeModel * so_combo_tree(space_group *spg)
create the space group setting combo box tree model
gchar * get_so_string(space_group *spg, int id)
get space group setting descrption string
G_MODULE_EXPORT void on_rounding_changed(GtkComboBox *box, gpointer data)
changed rounding method for occupancy
void adjust_so_combo(builder_edition *cbuilder)
adjust the space group setting combo box to use pango markup
Function declarations for the crystal builder.
gchar * groups[230]
Definition cbuild_sg.c:43
GtkWidget * create_atoms_tree(atom_search *asearch, project *this_proj, int na)
create atom search tree view
Definition w_search.c:3572
gchar * replace_markup(char *init, char *key, char *rep)
replace pattern in string
Definition w_library.c:340
space_group * read_sg_xml_file(const char *filetoread)
read space group data from XML file
Definition cbuild_sg.c:661
gchar * param[2]
float val
Definition dlp_init.c:117
char * box_prop[2][3]
Definition edit_menu.c:74
char * vect_name[3]
Definition edit_menu.c:77
dint t_box[9]
Definition edit_menu.c:90
gchar * PACKAGE_LIB_DIR
Definition global.c:89
#define i18n(String)
Definition global.c:80
gchar * bravais_img[14]
Definition global.c:142
double string_to_double(gpointer string)
convert string to double
Definition global.c:611
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
@ IMG_NONE
Definition global.h:276
@ IMG_STOCK
Definition global.h:280
int combo_get_active(GtkWidget *combo)
retrieve the active item's position
Definition gtk-misc.c:935
GtkWidget * create_entry(GCallback handler, int dim, int cdim, gboolean key_release, gpointer data)
Create a GtkEntry.
Definition gtk-misc.c:1401
void update_entry_double(GtkEntry *entry, double doubleval)
update the content of a GtkEntry as double
Definition gtk-misc.c:688
GtkWidget * create_scroll(GtkWidget *box, int dimx, int dimy, int shadow)
create a scroll window
Definition gtk-misc.c:2139
GtkWidget * dialogmodal(gchar *str, GtkWindow *parent)
Create a new dialog modal window.
Definition gtk-misc.c:552
GtkWidget * create_win(gchar *str, GtkWidget *parent, gboolean modal, gboolean resiz)
create a new GtkWindow
Definition gtk-misc.c:486
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
const gchar * entry_get_text(GtkEntry *entry)
get the text in a GtkEntry
Definition gtk-misc.c:652
#define BSEP
Definition global.h:261
void add_gtk_close_event(GtkWidget *widg, GCallback handler, gpointer data)
add a close event signal and callback to a GtkWidget
Definition gtk-misc.c:2557
void button_set_status(GtkWidget *button, int status)
set status of check / toggle button
Definition gtk-misc.c:1916
GtkWidget * radio_button(gchar *text, int dimx, int dimy, gboolean state, GCallback handler, gpointer data)
create a radio button
Definition gtk-misc.c:1970
GtkWidget * spin_button(GCallback handler, double value, double start, double end, double step, int digits, int dim, gpointer data)
create a spin button
Definition gtk-misc.c:1877
#define APPLY
Definition global.h:236
GtkWidget * check_button(gchar *text, int dimx, int dimy, gboolean state, GCallback handler, gpointer data)
create a check button
Definition gtk-misc.c:1937
@ CONTAINER_WIN
Definition global.h:266
@ CONTAINER_BUT
Definition global.h:269
@ CONTAINER_SCR
Definition global.h:267
#define DPROPERTIES
Definition global.h:222
GtkWidget * create_button(gchar *text, int image_format, gchar *image, int dimx, int dimy, int relief, GCallback handler, gpointer data)
create a simple button
Definition gtk-misc.c:1999
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
GtkWidget * cbox(GtkWidget *box, char *lab)
box creating routine, to help design faster elements for the GUI
Definition gtk-misc.c:2102
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 widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:247
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:849
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
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2213
void add_box_child_end(GtkWidget *widg, GtkWidget *child, gboolean expand, gboolean fill, int padding)
Add a GtkWidget in a GtkBox at the end position.
Definition gtk-misc.c:318
void update_entry_text(GtkEntry *entry, gchar *text)
update the content of a GtkEntry as string
Definition gtk-misc.c:726
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:267
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:837
int button_get_status(GtkWidget *button)
get status of check / toggle button
Definition gtk-misc.c:1899
#define FCLOSE
Definition global.h:227
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
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
atom_search * free_this_search_data(atom_search *this_search)
free atom search data structure
Definition popup.c:282
action
Definition glview.h:198
@ INSERT
Definition glview.h:237
gchar * cif_occ[3]
Definition interface.c:542
gchar * cif_sites[2]
Definition interface.c:545
void show_error(char *error, int val, GtkWidget *win)
show error message
Definition interface.c:299
gchar * cif_occupancies[3]
Definition interface.c:524
Messaging function declarations.
char * vect_comp[3]
Definition edit_menu.c:78
integer(kind=c_int) function lattice(totl, lid, vectors, vmod, angles, lat, cfrac, apbc)
Definition lattice.F90:162
Function declarations for reading atomes project file Function declarations for saving atomes proje...
coord_file * this_reader
Definition read_coord.c:73
Functions declaration to read atomic coordinates.
Definition glwin.h:350
Definition global.h:111
Definition glwin.h:967
Definition global.h:118
GtkWidget * res[2]
Definition w_encode.c:342
GtkWidget * hbox
Definition workspace.c:71
GtkWidget * vbox
Definition workspace.c:72
Function declarations for workspace managment.