atomes 1.1.15
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-2024 by CNRS and University of Strasbourg */
15
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 adjust_occupancy (GtkButton * but, gpointer data);
72 G_MODULE_EXPORT void crystal_window (GSimpleAction * action, GVariant * parameter, gpointer data);
73 G_MODULE_EXPORT void crystal_window (GtkWidget * widg, gpointer data);
74
75 GtkWidget * prepare_lattice_grid (int type, builder_edition * cbuilder, glwin * glview);
76 GtkWidget * sg_info (int sg, gpointer data);
77 GtkWidget * create_bl_combo (int cs, gpointer data);
78 GtkWidget * builder_win (project * this_proj, gpointer data);
79
80 GtkTreeModel * so_combo_tree (space_group * spg);
81 GtkTreeModel * sg_combo_tree (int csid, int bvid);
82 GtkTreeModel * la_combo_tree ();
83
84*/
85
86#include "global.h"
87#include "interface.h"
88#include "glview.h"
89#include "cbuild_edit.h"
90#include "bind.h"
91#include "project.h"
92#include "workspace.h"
93#include "readers.h"
94
95extern G_MODULE_EXPORT void show_sg_info (GtkButton * but, gpointer data);
96
97extern void get_origin (space_group * spg);
98extern int test_lattice (builder_edition * cbuilder, cell_info * cif_cell);
99extern int build_crystal (gboolean visible, project * this_proj, gboolean to_wrap, gboolean show_clones, cell_info * cell, GtkWidget * widg);
100
101gchar * crystal_sytems[7] = {"Triclinic", "Monoclinic", "Othorhombic", "Tetragonal", "Trigonal", "Hexagonal", "Cubic"};
102gchar * bravais_keys[7][4] = {{"Primitive", NULL, NULL, NULL},
103 {"Primitive", "Base-centered", NULL, NULL},
104 {"Primitive", "Base-centered", "Body-centered", "Face-centered"},
105 {"Primitive", "Body-centered", NULL, NULL},
106 {"Hexagonal axes", "Rhombohedral axes", NULL, NULL},
107 {"Hexagonal", NULL, NULL, NULL},
108 {"Primitive", "Body-centered", "Face-centered", NULL}};
109
110gchar * latt_info[7]={"<i>a</i> &#x2260; <i>b</i> &#x2260; <i>c</i>\n&#x3B1; &#x2260; &#x3B2; &#x2260; &#x263;", // Triclinic
111 "<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
112 "<i>a</i> &#x2260; <i>b</i> &#x2260; <i>c</i>\n&#x3B1; = &#x3B2; = &#x263; = 90°", // Orthorhombic
113 "<i>a</i> = <i>b</i> &#x2260; <i>c</i>\n&#x3B1; = &#x3B2; = &#x263; = 90°", // Tetragonal
114 "<i>a</i> = <i>b</i> = <i>c</i>\n&#x3B1; = &#x3B2; = &#x3B3; &#x2260; 90°", // Trigonal R
115 "<i>a</i> = <i>b</i> &#x2260; <i>c</i>\n&#x3B1; = &#x3B2; = 90° and &#x263; = 120°", // Hexagonal
116 "<i>a</i> = <i>b</i> = <i>c</i>\n&#x3B1; = &#x3B2; = &#x263; = 90°"}; // Cubic
117int nsg_bv[7]={2, 13, 59, 68, 25, 27, 36};
118int min_bv[7]={0, 2, 15, 74, 142, 167, 194};
119
127int get_crystal_id (int spg)
128{
129 if (spg < 3)
130 {
131 return 0;
132 }
133 else if (spg < 16)
134 {
135 return 1;
136 }
137 else if (spg < 75)
138 {
139 return 2;
140 }
141 else if (spg < 143)
142 {
143 return 3;
144 }
145 else if (spg < 168)
146 {
147 if (groups[spg-1][0] == 'R')
148 {
149 return 4;
150 }
151 else
152 {
153 return 5;
154 }
155 }
156 else if (spg < 195)
157 {
158 return 5;
159 }
160 else
161 {
162 return 6;
163 }
164}
165
174{
175 if (spg < 3)
176 {
177 return 0;
178 }
179 else if (spg < 16)
180 {
181 if (groups[spg-1][0] == 'P')
182 {
183 return 1;
184 }
185 else
186 {
187 return 2;
188 }
189 }
190 else if (spg < 75)
191 {
192 if (groups[spg-1][0] == 'P')
193 {
194 return 3;
195 }
196 else if (groups[spg-1][0] == 'I')
197 {
198 return 4;
199 }
200 else if (groups[spg-1][0] == 'A' || groups[spg-1][0] == 'C')
201 {
202 return 5;
203 }
204 else
205 {
206 return 6;
207 }
208 }
209 else if (spg < 143)
210 {
211 if (groups[spg-1][0] == 'P')
212 {
213 return 7;
214 }
215 else
216 {
217 return 8;
218 }
219 }
220 else if (spg < 168)
221 {
222 if (groups[spg-1][0] == 'R')
223 {
224 return 9;
225 }
226 else
227 {
228 return 10;
229 }
230 }
231 else if (spg < 195)
232 {
233 return 10;
234 }
235 else
236 {
237 if (groups[spg-1][0] == 'P')
238 {
239 return 11;
240 }
241 else if (groups[spg-1][0] == 'I')
242 {
243 return 12;
244 }
245 else
246 {
247 return 13;
248 }
249 }
250}
251
259gchar * frac_string (gchar * init)
260{
261 gchar * end = substitute_string (init, "1/2", "&#189;");
262 end = substitute_string (end, "1/4", "&#188;");
263 end = substitute_string (end, "3/4", "&#190;");
264 end = substitute_string (end, "1/3", "&#8531;");
265 end = substitute_string (end, "2/3", "&#8532;");
266 end = substitute_string (end, "1/6", "&#8537;");
267 end = substitute_string (end, "5/6", "&#8538;");
268 end = substitute_string (end, "1/8", "&#8539;");
269 end = substitute_string (end, "3/8", "&#8540;");
270 end = substitute_string (end, "5/8", "&#8541;");
271 end = substitute_string (end, "7/8", "&#8542;");
272 return g_strdup_printf ("%s", end);
273}
274
282gchar * get_num_string (gchar * str)
283{
284 str = replace_markup (str, "65", "6<sub>5</sub>");
285 str = replace_markup (str, "64", "6<sub>4</sub>");
286 str = replace_markup (str, "63", "6<sub>3</sub>");
287 str = replace_markup (str, "62", "6<sub>2</sub>");
288 str = replace_markup (str, "61", "6<sub>1</sub>");
289 str = replace_markup (str, "43", "4<sub>3</sub>");
290 str = replace_markup (str, "42", "4<sub>2</sub>");
291 str = replace_markup (str, "41", "4<sub>1</sub>");
292 str = replace_markup (str, "32", "3<sub>2</sub>");
293 str = replace_markup (str, "31", "3<sub>1</sub>");
294 return substitute_string (str, "21", "2<sub>1</sub>");
295}
296
305gchar * get_so_string (space_group * spg, int id)
306{
307 gchar * str = replace_markup (spg -> settings[id].name, "s", "/");
308 str = get_num_string (str);
309 str = substitute_string (str, "_", NULL);
310 if (spg -> settings[id].origin)
311 {
312 str = g_strdup_printf ("%s (%d)", str, spg -> settings[id].origin);
313 }
314 return str;
315}
316
324GtkTreeModel * so_combo_tree (space_group * spg)
325{
326 GtkTreeIter iter;
327 GtkTreeStore * store;
328 int i;
329 store = gtk_tree_store_new (1, G_TYPE_STRING);
330 if (! spg) return GTK_TREE_MODEL (store);
331 if (spg -> nums > 1)
332 {
333 for (i=0; i<spg -> nums; i++)
334 {
335 gtk_tree_store_append (store, &iter, NULL);
336 gtk_tree_store_set (store, & iter, 0, get_so_string (spg, i), -1);
337 }
338 }
339 else
340 {
341 gtk_tree_store_append (store, &iter, NULL);
342 gtk_tree_store_set (store, & iter, 0, groups[spg -> id-1], -1);
343 }
344 return GTK_TREE_MODEL (store);
345}
346
355GtkTreeModel * sg_combo_tree (int csid, int bvid)
356{
357 GtkTreeIter iter;
358 GtkTreeStore * store;
359 int i;
360 gboolean doit;
361 gchar * str;
362 store = gtk_tree_store_new (1, G_TYPE_STRING);
363 for (i=min_bv[csid]; i<min_bv[csid]+nsg_bv[csid]; i++)
364 {
365 doit = FALSE;
366 if (! bvid || csid == 5)
367 {
368 doit = TRUE;
369 }
370 else
371 {
372 if (csid == 1 || csid == 3)
373 {
374 if ((bvid == 1 && groups[i][0] == 'P') || (bvid == 2 && groups[i][0] != 'P')) doit = TRUE;
375 }
376 else if (csid == 2)
377 {
378 if ((bvid == 1 && groups[i][0] == 'P') || (bvid == 2 && groups[i][0] == 'A') || (bvid == 2 && groups[i][0] == 'C') ||
379 (bvid == 3 && groups[i][0] == 'I') || (bvid == 4 && groups[i][0] == 'F'))
380 {
381 doit = TRUE;
382 }
383 }
384 else if (csid == 4)
385 {
386 if ((bvid == 1 && groups[i][0] == 'P') || (bvid == 2 && groups[i][0] == 'R')) doit = TRUE;
387 }
388 else if (csid == 6)
389 {
390 if ((bvid == 1 && groups[i][0] == 'P') || (bvid == 2 && groups[i][0] == 'I') || (bvid == 3 && groups[i][0] == 'F'))
391 {
392 doit = TRUE;
393 }
394 }
395 }
396 if (doit)
397 {
398 gtk_tree_store_append (store, &iter, NULL);
399 str = g_strdup_printf ("%3d: %s", i+1, groups[i]);
400 gtk_tree_store_set (store, & iter, 0, str, -1);
401 g_free (str);
402 }
403 }
404 return GTK_TREE_MODEL (store);
405}
406
412GtkTreeModel * la_combo_tree ()
413{
414 GtkTreeIter iter;
415 GtkTreeStore *store;
416 gchar * lat[2]={"<b><i>a</i></b>, <b><i>b</i></b>, <b><i>c</i></b>, &#x3B1; &#x3B2; &#x263;", "Vectors"};
417 int i;
418 store = gtk_tree_store_new (1, G_TYPE_STRING);
419 for (i=0; i<2; i++)
420 {
421 gtk_tree_store_append (store, &iter, NULL);
422 gtk_tree_store_set (store, & iter, 0, lat[i], -1);
423 }
424 return GTK_TREE_MODEL (store);
425}
426
434int get_sg_num (GtkComboBox * box)
435{
436 GValue val = {0, };
437 GtkTreeModel * cmodel = gtk_combo_box_get_model (box);
438 GtkTreeIter iter;
439 gchar * str = NULL;
440 gchar * num = NULL;
441 int i = 0;
442 if (gtk_combo_box_get_active_iter (box, & iter))
443 {
444 gtk_tree_model_get_value (cmodel, & iter, 0, & val);
445 str = g_strdup_printf ("%s", (char *)g_value_get_string (& val));
446 if (str)
447 {
448 num = g_strdup_printf ("%c%c%c", str[0], str[1], str[2]);
449 i = (int) string_to_double ((gpointer)num);
450 g_free (str);
451 g_free (num);
452 }
453 }
454 return i;
455}
456
465{
466 int i, j, k;
467 j = get_sg_num (GTK_COMBO_BOX(cbuilder -> sg_combo));
468 k = get_crystal_id (j);
469 box_info * box = & cbuilder -> cell.box[0];
470 switch (k)
471 {
472 case 1:
473 box -> param[1][0] = 90.0;
474 box -> vect[0][1] = box -> vect[0][2] = 0.0;
475 box -> vect[2][0] = box -> vect[2][1] = 0.0;
476 break;
477 case 2:
478 box -> param[1][0] = box -> param[1][1] = box -> param[1][2] = 90.0;
479 box -> vect[0][1] = box -> vect[0][2] = 0.0;
480 box -> vect[1][0] = box -> vect[1][2] = 0.0;
481 box -> vect[2][0] = box -> vect[2][1] = 0.0;
482 break;
483 case 3:
484 box -> param[0][1] = box -> param[0][0];
485 box -> param[1][0] = box -> param[1][1] = box -> param[1][2] = 90.0;
486 break;
487 case 4:
488 box -> param[0][1] = box -> param[0][0];
489 if (cbuilder -> cell.sp_group -> name[0] == 'R')
490 {
491 box -> param[1][0] = box -> param[1][1] = box -> param[1][2] = 0.0;
492 }
493 else
494 {
495 box -> param[1][0] = box -> param[1][1] = 90.0;
496 box -> param[1][2] = 120.0;
497 }
498 box -> vect[1][1] = box -> vect[0][0];
499 box -> vect[0][1] = box -> vect[0][2] = 0.0;
500 box -> vect[1][0] = box -> vect[1][2] = 0.0;
501 break;
502 case 5:
503 box -> param[0][1] = box -> param[0][0];
504 box -> param[1][0] = box -> param[1][1] = 90.0;
505 box -> param[1][2] = 120.0;
506 box -> vect[0][1] = box -> vect[0][2] = 0.0;
507 box -> vect[1][0] = box -> vect[1][2] = 0.0;
508 break;
509 case 6:
510 box -> param[0][1] = box -> param[0][2] = box -> param[0][0];
511 box -> param[1][0] = box -> param[1][1] = box -> param[1][2] = 90.0;
512 box -> vect[1][1] = box -> vect[2][2] = box -> vect[0][0];
513 box -> vect[0][1] = box -> vect[0][2] = 0.0;
514 box -> vect[1][0] = box -> vect[1][2] = 0.0;
515 box -> vect[2][0] = box -> vect[2][1] = 0.0;
516 break;
517 default:
518 break;
519 }
520 if (cbuilder -> cell.ltype)
521 {
522 for (i=0; i<3; i++)
523 {
524 for (j=0; j<3; j++)
525 {
526 if (cbuilder -> ventry[i][j])
527 {
528 if (GTK_IS_WIDGET(cbuilder -> ventry[i][j]))
529 {
530 update_entry_double (GTK_ENTRY(cbuilder -> ventry[i][j]), box -> vect[i][j]);
531 }
532 }
533 }
534 }
535 }
536 else
537 {
538 for (i=0; i<2; i++)
539 {
540 for (j=0; j<3; j++)
541 {
542 if (cbuilder -> bentry[i][j])
543 {
544 if (GTK_IS_WIDGET(cbuilder -> bentry[i][j]))
545 {
546 update_entry_double (GTK_ENTRY(cbuilder -> bentry[i][j]), box -> param[i][j]);
547 }
548 }
549 }
550 }
551 if (cbuilder -> bentry[0][1])
552 {
553 if (GTK_IS_WIDGET(cbuilder -> bentry[0][1]))
554 {
555 widget_set_sensitive (cbuilder -> bentry[0][1], (k > 2) ? 0 : 1);
556 if (k > 2) update_entry_text (GTK_ENTRY(cbuilder -> bentry[0][1]), "");
557 }
558 }
559 if (cbuilder -> bentry[0][2])
560 {
561 if (GTK_IS_WIDGET(cbuilder -> bentry[0][2]))
562 {
563 widget_set_sensitive (cbuilder -> bentry[0][2], (k > 5 || (k == 4 && cbuilder -> cell.sp_group -> name[0] == 'R')) ? 0 : 1);
564 if (k > 5 || (k == 4 && cbuilder -> cell.sp_group -> name[0] == 'R')) update_entry_text (GTK_ENTRY(cbuilder -> bentry[0][2]), "");
565 }
566 }
567 for (i=0; i<3; i++)
568 {
569 if (cbuilder -> bentry[1][i])
570 {
571 if (GTK_IS_WIDGET(cbuilder -> bentry[1][i]))
572 {
573 widget_set_sensitive (cbuilder -> bentry[1][i], (k > 1) || (k == 1 && ! i) ? 0 : 1);
574 if (k == 4 && cbuilder -> cell.sp_group -> name[0] == 'R')
575 {
576 if (! i)
577 {
578 widget_set_sensitive (cbuilder -> bentry[1][i], 1);
579 }
580 else
581 {
582 update_entry_text (GTK_ENTRY(cbuilder -> bentry[1][i]), "");
583 }
584 }
585 }
586 }
587 }
588 }
589}
590
599G_MODULE_EXPORT void update_cb_vect (GtkEntry * entry, gpointer data)
600{
601 tint * id = (tint *)data;
602 const gchar * m = entry_get_text (entry);
603 double v = string_to_double ((gpointer)m);
604 get_project_by_id(id -> a) -> modelgl -> builder_win -> cell.box[0].vect[id -> b][id -> c] = v;
605 update_entry_double (entry, v);
606}
607
616G_MODULE_EXPORT void update_cb_box (GtkEntry * entry, gpointer data)
617{
618 tint * id = (tint *)data;
619 const gchar * m = entry_get_text (entry);
620 double v = string_to_double ((gpointer)m);
621 if (v >= 0.0)
622 {
623 get_project_by_id(id -> a) -> modelgl -> builder_win -> cell.box[0].param[id -> b][id -> c] = v;
624 }
625 update_entry_double (entry, v);
626}
627
637GtkWidget * prepare_lattice_grid (int type, builder_edition * cbuilder, glwin * glview)
638{
639 GtkWidget * table = gtk_grid_new ();
640 int i, j, k;
641 k = 0;
642 for (i=0; i<3; i++)
643 {
644 for (j=0; j<3; j++, k++)
645 {
646 if (i < 2) cbuilder -> cell.box[0].param[i][j] = 0.0;
647 cbuilder -> cell.box[0].vect[i][j] = 0.0;
648 t_box[k].a = i;
649 t_box[k].b = j;
650 }
651 }
652 cbuilder -> cell.ltype = type;
653 if (cbuilder -> cell.ltype)
654 {
655 k = 0;
656 for (i=0; i<4; i++)
657 {
658 if (i > 0)
659 {
660 gtk_grid_attach (GTK_GRID (table), markup_label(vect_name[i-1], 20, -1, 0.0, 0.5), 0, i, 1, 1);
661 }
662 for (j=0; j<4; j++)
663 {
664 if (j > 0)
665 {
666 if (i == 0)
667 {
668 gtk_grid_attach (GTK_GRID (table), markup_label(vect_comp[j-1], -1, 20, 0.5, 0.5), j, 0, 1, 1);
669 }
670 else
671 {
672 cbuilder -> ventry[i-1][j-1] = create_entry (G_CALLBACK(update_cb_vect), 100, 15, FALSE, & cbuilder -> pointers[i][j]);
673 update_entry_double (GTK_ENTRY(cbuilder -> ventry[i-1][j-1]), cbuilder -> cell.box[0].vect[i-1][j-1]);
674 gtk_grid_attach (GTK_GRID (table), cbuilder -> ventry[i-1][j-1], j, i, 1, 1);
675 k ++;
676 }
677 }
678 }
679 }
680 }
681 else
682 {
683 k = 0;
684 for (i=0; i<2; i++)
685 {
686 //gtk_grid_attach (GTK_GRID (table), markup_label(box_p[i], -1, 50, 0.5, 0.5), 1, i+2*i, 1, 1);
687 gtk_grid_attach (GTK_GRID (table), markup_label(" ", 20, -1, 0.5, 0.5), 0, i, 1, 1);
688 for (j=0; j<3; j++, k++)
689 {
690 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);
691 cbuilder -> bentry[i][j] = create_entry (G_CALLBACK(update_cb_box), 100, 15, FALSE, & cbuilder -> pointers[i][j]);
692 update_entry_double (GTK_ENTRY(cbuilder -> bentry[i][j]), cbuilder -> cell.box[0].param[i][j]);
693 gtk_grid_attach (GTK_GRID (table), cbuilder -> bentry[i][j], j+1, i+2*i+1, 1, 1);
694 }
695 }
696 adjust_lattice_parameters (cbuilder);
697 }
698 return table;
699}
700
709G_MODULE_EXPORT void set_lattice (GtkComboBox * box, gpointer data)
710{
711 tint * id = (tint *) data;
712 glwin * view = get_project_by_id(id -> a) -> modelgl;
713 builder_edition * cbuilder = view -> builder_win;
714 cbuilder -> lattice_grid = destroy_this_widget (cbuilder -> lattice_grid);
715 cbuilder -> lattice_grid = prepare_lattice_grid (gtk_combo_box_get_active (box), cbuilder, view);
716 add_box_child_start (GTK_ORIENTATION_VERTICAL, cbuilder -> lattice_box, cbuilder -> lattice_grid, FALSE, FALSE, 5);
717 show_the_widgets (cbuilder -> lattice_grid);
718}
719
728G_MODULE_EXPORT void set_so (GtkComboBox * box, gpointer data)
729{
730 tint * id = (tint *) data;
731 builder_edition * cbuilder = get_project_by_id(id -> a) -> modelgl -> builder_win;
732 int i = gtk_combo_box_get_active(box);
733 gchar * str = g_strdup_printf ("(%s,%s,%s)", cbuilder -> cell.sp_group -> settings[i].pos[0],
734 cbuilder -> cell.sp_group -> settings[i].pos[1],
735 cbuilder -> cell.sp_group -> settings[i].pos[2]);
736 cbuilder -> so_info = destroy_this_widget(cbuilder -> so_info);
737 cbuilder -> so_info = markup_label(frac_string(str), -1, -1, 0.5, 0.5);
738 g_free (str);
739 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> so_box, cbuilder -> so_info, FALSE, FALSE, 10);
740 show_the_widgets (cbuilder -> so_info);
741 cbuilder -> cell.sp_group -> sid = i;
742 get_origin (cbuilder -> cell.sp_group);
743}
744
753GtkWidget * sg_info (int sg, gpointer data)
754{
755 gchar * str = g_strdup_printf ("%s group info", groups[sg]);
756 GtkWidget * mlab = markup_label(str, -1, -1, 0.5, 0.5);
757 GtkWidget * mbut = create_button (NULL, IMG_NONE, NULL, 50, -1, GTK_RELIEF_NORMAL, G_CALLBACK(show_sg_info), data);
759 show_the_widgets (mbut);
760 return mbut;
761}
762
771int read_space_group (builder_edition * cbuilder, int spg)
772{
773 // Read file
774 gchar * sgfile = substitute_string(groups[spg], "<sub>", NULL);
775 sgfile = substitute_string(sgfile, "</sub>", NULL);
776 sgfile = substitute_string(sgfile, "/", "s");
777#ifdef G_OS_WIN32
778 sgfile = g_strdup_printf ("%s\\space_groups\\%d-%s.sgl", PACKAGE_LIB_DIR, spg+1, sgfile);
779#else
780 sgfile = g_strdup_printf ("%s/space_groups/%d-%s.sgl", PACKAGE_LIB_DIR, spg+1, sgfile);
781#endif
782 int res;
783 if (cbuilder)
784 {
785 cbuilder -> cell.sp_group = read_sg_xml_file (sgfile);
786 res = (cbuilder -> cell.sp_group) ? 1 : 0;
787 }
788 else if (this_reader)
789 {
790 this_reader -> lattice.sp_group = read_sg_xml_file (sgfile);
791 res = (this_reader -> lattice.sp_group) ? 1 : 0;
792 }
793 g_free (sgfile);
794 return res;
795}
796
804int get_group_id_from_name (gchar * sg_name)
805{
806 int i;
807 for (i=0; i<230; i++)
808 {
809 if (g_strcmp0(groups[i], sg_name) == 0) return i+1;
810 }
811 return 0;
812}
813
822{
823 GtkTreeModel * model = so_combo_tree (cbuilder -> cell.sp_group);
824 gtk_combo_box_set_model (GTK_COMBO_BOX(cbuilder -> so_combo), model);
825 g_object_unref (model);
826 gtk_combo_box_set_active (GTK_COMBO_BOX(cbuilder -> so_combo), 0);
827
828 GList * cell_list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(cbuilder -> so_combo));
829 if (cell_list && cell_list -> data)
830 {
831 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cbuilder -> so_combo), cell_list -> data, "markup", 0, NULL);
832 }
833 widget_set_sensitive (cbuilder -> so_combo, cbuilder -> cell.sp_group -> nums-1);
834 if (cbuilder -> cell.sp_group) get_origin (cbuilder -> cell.sp_group);
835}
836
845{
846 if (cbuilder -> bv_img) cbuilder -> bv_img = destroy_this_widget(cbuilder -> bv_img);
847 cbuilder -> bv_img = gtk_image_new_from_file (bravais_img[get_bravais_img_id(cbuilder -> cell.sp_group -> id)]);
848#ifdef GTK4
849 gtk_widget_set_size_request (cbuilder -> bv_img, 200, 200);
850 gtk_widget_set_hexpand (cbuilder -> bv_img, TRUE);
851 gtk_widget_set_vexpand (cbuilder -> bv_img, TRUE);
852#endif
853 add_box_child_start (GTK_ORIENTATION_VERTICAL, cbuilder -> bv_box[1], cbuilder -> bv_img, FALSE, FALSE, 5);
854}
855
864{
865 if (cbuilder -> ltc_cons) cbuilder -> ltc_cons = destroy_this_widget(cbuilder -> ltc_cons);
866 gchar * str = g_strdup_printf ("<b>%s</b>", latt_info[get_crystal_id (cbuilder -> cell.sp_group -> id)]);
867 cbuilder -> ltc_cons = markup_label(str, 150, -1, 0.0, 0.5);
868 g_free (str);
869 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> ltc_box, cbuilder -> ltc_cons, FALSE, FALSE, 5);
870}
871
880G_MODULE_EXPORT void set_sg (GtkComboBox * box, gpointer data)
881{
882 tint * id = (tint *) data;
883 builder_edition * cbuilder = get_project_by_id(id -> a) -> modelgl -> builder_win;
884 int i = get_sg_num(box);
885 if (i)
886 {
887 cbuilder -> sg_but = destroy_this_widget(cbuilder -> sg_but);
888 if (read_space_group (cbuilder, i-1))
889 {
890 cbuilder -> sg_but = sg_info (i-1, data);
891 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> sg_box, cbuilder -> sg_but, FALSE, FALSE, 10);
892 if (cbuilder -> bv_box[0]) adjust_lattice_constraints (cbuilder);
893 if (cbuilder -> bv_box[1]) adjust_bv_img (cbuilder);
894 show_the_widgets (cbuilder -> bh_box);
895 if (cbuilder -> so_combo) adjust_so_combo (cbuilder);
896 if (cbuilder -> lattice_grid) adjust_lattice_parameters (cbuilder);
897 }
898 else
899 {
900 // Error reading file
901 show_error ("Cannot read space group *.sgl file ?!\nPlease check the program library !", 0, cbuilder -> win);
902 }
903 }
904}
905
915void adjust_sg_combo (builder_edition * cbuilder, int cs, int bl)
916{
917 GtkTreeModel * model = sg_combo_tree (cs, bl);
918 gtk_combo_box_set_model (GTK_COMBO_BOX(cbuilder -> sg_combo), model);
919 g_object_unref (model);
920 gtk_combo_box_set_active (GTK_COMBO_BOX(cbuilder -> sg_combo), 0);
921 GList * cell_list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(cbuilder -> sg_combo));
922 if (cell_list && cell_list -> data)
923 {
924 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cbuilder -> sg_combo), cell_list -> data, "markup", 0, NULL);
925 }
926 adjust_lattice_parameters (cbuilder);
927}
928
937G_MODULE_EXPORT void set_bl (GtkComboBox * box, gpointer data)
938{
939 builder_edition * cbuilder = (builder_edition *)data;
940 int i, j;
941 i = gtk_combo_box_get_active (GTK_COMBO_BOX(cbuilder -> cs_combo));
942 j = gtk_combo_box_get_active (box);
943 adjust_sg_combo (cbuilder, i, j);
944}
945
954GtkWidget * create_bl_combo (int cs, gpointer data)
955{
956 GtkWidget * cbox = create_combo();
957 int i;
958 combo_text_append (cbox, "All");
959 for (i=0; i<4; i++)
960 {
961 if (bravais_keys[cs][i]) combo_text_append (cbox, bravais_keys[cs][i]);
962 }
963 i = (cs == 0 || cs == 5) ? 0 : 1;
965 gtk_combo_box_set_active (GTK_COMBO_BOX(cbox), ! i);
966 g_signal_connect (G_OBJECT(cbox), "changed", G_CALLBACK(set_bl), data);
967 gtk_widget_set_size_request (cbox, 150, 25);
968 return cbox;
969}
970
979G_MODULE_EXPORT void set_cs (GtkComboBox * box, gpointer data)
980{
981 builder_edition * cbuilder = (builder_edition *)data;
982 int i = gtk_combo_box_get_active (box);
983 cbuilder -> bl_combo = destroy_this_widget(cbuilder -> bl_combo);
984 cbuilder -> bl_combo = create_bl_combo (i, data);
985 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> bl_box, cbuilder -> bl_combo, FALSE, FALSE, 0);
986 adjust_sg_combo (cbuilder, i, 0);
987 show_the_widgets (cbuilder -> bl_combo);
988}
989
990#ifdef GTK4
999G_MODULE_EXPORT void set_wr (GtkCheckButton * but, gpointer data)
1000#else
1009G_MODULE_EXPORT void set_wr (GtkToggleButton * but, gpointer data)
1010#endif
1011{
1012 builder_edition * cbuilder = (builder_edition * )data;
1013#ifdef GTK4
1014 cbuilder -> wrap = gtk_check_button_get_active (but);
1015#else
1016 cbuilder -> wrap = gtk_toggle_button_get_active (but);
1017#endif
1018}
1019
1020#ifdef GTK4
1029G_MODULE_EXPORT void set_shc (GtkCheckButton * but, gpointer data)
1030#else
1039G_MODULE_EXPORT void set_shc (GtkToggleButton * but, gpointer data)
1040#endif
1041{
1042 builder_edition * cbuilder = (builder_edition * )data;
1043#ifdef GTK4
1044 cbuilder -> clones = gtk_check_button_get_active (but);
1045#else
1046 cbuilder -> clones = gtk_toggle_button_get_active (but);
1047#endif
1048}
1049
1058G_MODULE_EXPORT void add_cryst_cell (GtkSpinButton * res, gpointer data)
1059{
1060 tint * bid = (tint *)data;
1061 builder_edition * cbuilder = get_project_by_id(bid -> a) -> modelgl -> builder_win;
1062 cbuilder -> cell.cextra[bid -> b] = gtk_spin_button_get_value_as_int(res);
1063}
1064
1073G_MODULE_EXPORT void apply_build (GtkButton * but, gpointer data)
1074{
1075 int id = GPOINTER_TO_INT(data);
1076 project * this_proj = get_project_by_id(id);
1077 if (test_lattice(this_proj -> modelgl -> builder_win, NULL))
1078 {
1079 build_crystal (TRUE, this_proj, this_proj -> modelgl -> builder_win -> wrap, this_proj -> modelgl -> builder_win -> clones,
1080 & this_proj -> modelgl -> builder_win -> cell, this_proj -> modelgl -> builder_win -> win);
1081 }
1082}
1083
1092G_MODULE_EXPORT void close_build (GtkButton * but, gpointer data)
1093{
1094 int id = GPOINTER_TO_INT(data);
1095 project * this_proj = get_project_by_id(id);
1096 this_proj -> modelgl -> search_widg[7] = free_this_search_data (this_proj -> modelgl -> search_widg[7]);
1097 this_proj -> modelgl -> builder_win -> win = destroy_this_widget(this_proj -> modelgl -> builder_win -> win);
1098 g_free (this_proj -> modelgl -> builder_win);
1099 this_proj -> modelgl -> builder_win = NULL;
1100}
1101
1102#ifdef GTK4
1111G_MODULE_EXPORT gboolean delete_build (GtkWindow * widg, gpointer data)
1112#else
1122G_MODULE_EXPORT gboolean delete_build (GtkWidget * widg, GdkEvent * event, gpointer data)
1123#endif
1124{
1125 close_build (NULL, data);
1126 return TRUE;
1127}
1128
1130
1131#ifdef GTK4
1140G_MODULE_EXPORT void toggle_occ (GtkCheckButton * but, gpointer data)
1141#else
1150G_MODULE_EXPORT void toggle_occ (GtkToggleButton * but, gpointer data)
1151#endif
1152{
1153 dint * cid = (dint *)data;
1154 get_project_by_id(cid -> a) -> modelgl -> builder_win -> occupancy = cid -> b;
1155}
1156
1157#ifdef GTK4
1166G_MODULE_EXPORT void toggle_overlap (GtkCheckButton * Button, gpointer data)
1167#else
1176G_MODULE_EXPORT void toggle_overlap (GtkToggleButton * Button, gpointer data)
1177#endif
1178{
1179 builder_edition * cbuilder = (builder_edition * )data;
1180#ifdef GTK4
1181 cbuilder -> overlapping = gtk_check_button_get_active (Button);
1182#else
1183 cbuilder -> overlapping = gtk_toggle_button_get_active (Button);
1184#endif
1185}
1186
1195G_MODULE_EXPORT void adjust_occupancy (GtkButton * but, gpointer data)
1196{
1197 project * this_proj = (project *)data;
1198 builder_edition * cbuilder = this_proj -> modelgl -> builder_win;
1199 GtkWidget * info = dialogmodal ("Occupancy set-up", GTK_WINDOW(cbuilder -> win));
1200 GtkWidget * vbox, * hbox;
1202 gchar * boccup[5] = {"<b>Random for the initial cell only</b>",
1203 "<b>Random cell by cell</b>",
1204 "<b>Completely random</b>",
1205 "<b>Successively</b>",
1206 "<b>Alternatively</b>"};
1207 gchar * occup[5] = {"<i>Sites are filled randomly in the initial cell only,\n"
1208 " then the initial cell is simply replicated.</i>",
1209 "<i>Sites are filled randomly for each cell, cell by cell separately.</i>",
1210 "<i>Sites are filled randomly for the entire network,\n"
1211 " the final crystal is considered as a whole.</i>",
1212 "<i>Sites are filled successively: all object(s) A, then all object(s) B ... </i>",
1213 "<i>Sites are filled alternatively: object A, object B, object A ...</i>"};
1214 GtkWidget * occ_but[5];
1215 int i;
1216 for (i=0; i<5; i++)
1217 {
1218 hbox = create_hbox(0);
1219 occp[i].a = this_proj -> id;
1220 occp[i].b = i;
1221 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1222#ifdef GTK4
1223 occ_but[i] = check_button (boccup[i], -1, 25, FALSE, G_CALLBACK(toggle_occ), & occp[i]);
1224 if (i)
1225 {
1226 gtk_check_button_set_group ((GtkCheckButton *)occ_but[i], (GtkCheckButton *)occ_but[0]);
1227 }
1228#else
1229 if (! i)
1230 {
1231 occ_but[i] = radio_button (boccup[i], -1, 25, FALSE, G_CALLBACK(toggle_occ), & occp[i]);
1232 }
1233 else
1234 {
1235 occ_but[i] = gtk_radio_button_new_from_widget (GTK_RADIO_BUTTON(occ_but[0]));
1236 add_container_child (CONTAINER_BUT, occ_but[i], markup_label(boccup[i], -1, 25, 0.0, 0.5));
1237 }
1238#endif
1239 if (i) g_signal_connect (G_OBJECT(occ_but[i]), "toggled", G_CALLBACK(toggle_occ), & occp[i]);
1240#ifdef GTK4
1241 gtk_button_set_has_frame (GTK_BUTTON(occ_but[i]), FALSE);
1242#endif
1243 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, occ_but[i], FALSE, FALSE, 5);
1244 hbox = create_hbox(0);
1245 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1246 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label (occup[i], 200, -1, 0.5, 0.5), FALSE, FALSE, 50);
1247 }
1248 i = cbuilder -> occupancy;
1249#ifdef GTK4
1250 gtk_check_button_set_active (GTK_CHECK_BUTTON(occ_but[i]), TRUE);
1251#else
1252 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(occ_but[i]), TRUE);
1253#endif
1254 hbox = create_hbox(0);
1255 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 5);
1256 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);
1257 hbox = create_hbox(0);
1258 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1259 gchar * overlap = "<i>Instead of ensuring that sites are filled by a single object,\n"
1260 "this allows object(s) to share the same crystalline position. \n"
1261 "The option above describes how filled and empty positions alternate.</i>";
1262 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label (overlap, 200, -1, 0.5, 0.5), FALSE, FALSE, 50);
1263
1264 show_the_widgets (info);
1265 run_this_gtk_dialog (info, G_CALLBACK(run_destroy_dialog), NULL);
1266}
1267
1276GtkWidget * builder_win (project * this_proj, gpointer data)
1277{
1278 int i, j;
1279 gchar * str = (! this_proj -> natomes) ? g_strdup_printf ("Crystal builder - %s", this_proj -> name) : g_strdup_printf ("Crystal builder");
1280 builder_edition * cbuilder = this_proj -> modelgl -> builder_win;
1281 GtkWidget * win = create_win (str, this_proj -> modelgl -> win, FALSE, FALSE);
1282 g_free (str);
1283 GtkWidget * vbox = create_vbox (BSEP);
1285
1286 cbuilder -> bh_box = create_hbox(0);
1287 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, cbuilder -> bh_box, FALSE, FALSE, 0);
1288 for (i=0; i<2; i++)
1289 {
1290 cbuilder -> bv_box[i] = create_vbox (BSEP);
1291 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> bh_box, cbuilder -> bv_box[i], FALSE, FALSE, 0);
1292 }
1293
1294 // Crystal system
1295 GtkWidget * hbox = create_hbox(0);
1296 add_box_child_start (GTK_ORIENTATION_VERTICAL, cbuilder -> bv_box[0], hbox, FALSE, FALSE, 0);
1297 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label("Crystal system:", 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1298 cbuilder -> cs_combo = create_combo();
1299
1300 for (i=0; i<7;i++) combo_text_append (cbuilder -> cs_combo, crystal_sytems[i]);
1301 gtk_combo_box_set_active (GTK_COMBO_BOX(cbuilder -> cs_combo), 0);
1302 gtk_widget_set_size_request (cbuilder -> cs_combo, 150, 25);
1303 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, cbuilder -> cs_combo, FALSE, FALSE, 0);
1304 g_signal_connect (G_OBJECT(cbuilder -> cs_combo), "changed", G_CALLBACK(set_cs), (gpointer)cbuilder);
1305
1306 // Bravais lattice
1307 cbuilder -> bl_box = create_hbox(0);
1308 add_box_child_start (GTK_ORIENTATION_VERTICAL, cbuilder -> bv_box[0], cbuilder -> bl_box, FALSE, FALSE, 0);
1309 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> bl_box, markup_label("Bravais lattice:", 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1310 cbuilder -> bl_combo = create_bl_combo (0, (gpointer)cbuilder);
1311 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> bl_box, cbuilder -> bl_combo, FALSE, FALSE, 0);
1312
1313 cbuilder -> ltc_box = create_hbox (0);
1314 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> ltc_box, markup_label("Lattice constraints: ", 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1315 str = g_strdup_printf ("<b>%s</b>", latt_info[get_crystal_id (1)]);
1316 cbuilder -> ltc_cons = markup_label(str, 150, -1, 0.0, 0.5);
1317 g_free (str);
1318 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> ltc_box, cbuilder -> ltc_cons, FALSE, FALSE, 5);
1319 add_box_child_start (GTK_ORIENTATION_VERTICAL, cbuilder -> bv_box[0], cbuilder -> ltc_box, FALSE, FALSE, 5);
1320
1321 // cbuilder -> bv_img = gtk_image_new_from_file (bravais_img[get_bravais_img_id(1)]);
1322 // add_box_child_start (GTK_ORIENTATION_VERTICAL, cbuilder -> bv_box[1], cbuilder -> bv_img, FALSE, FALSE, 5);
1323
1324 // Space group
1325 cbuilder -> sg_box = create_hbox(0);
1326 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, cbuilder -> sg_box, FALSE, FALSE, 0);
1327 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> sg_box, markup_label("Space group:", 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1328 GtkTreeModel * model = sg_combo_tree (0, 0);
1329 cbuilder -> sg_combo = gtk_combo_box_new_with_model (model);
1330 g_object_unref (model);
1331 GtkCellRenderer * renderer = gtk_cell_renderer_combo_new ();
1332 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cbuilder -> sg_combo), renderer, TRUE);
1333 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (cbuilder -> sg_combo), renderer, "text", 0, NULL);
1334 g_signal_connect (G_OBJECT(cbuilder -> sg_combo), "changed", G_CALLBACK(set_sg), data);
1335 gtk_widget_set_size_request (cbuilder -> sg_combo, 150, 25);
1336 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> sg_box, cbuilder -> sg_combo, FALSE, FALSE, 0);
1337 gtk_combo_box_set_active (GTK_COMBO_BOX(cbuilder -> sg_combo), 0);
1338 GList * cell_list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(cbuilder -> sg_combo));
1339 if (cell_list && cell_list -> data)
1340 {
1341 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cbuilder -> sg_combo), cell_list -> data, "markup", 0, NULL);
1342 }
1343
1344 // Space group option
1345 cbuilder -> so_box = create_hbox(0);
1346 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, cbuilder -> so_box, FALSE, FALSE, 0);
1347 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> so_box, markup_label("Settings:", 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1348 model = so_combo_tree (cbuilder -> cell.sp_group);
1349 cbuilder -> so_combo = gtk_combo_box_new_with_model (model);
1350 g_object_unref (model);
1351 renderer = gtk_cell_renderer_combo_new ();
1352 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cbuilder -> so_combo), renderer, TRUE);
1353 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (cbuilder -> so_combo), renderer, "text", 0, NULL);
1354 gtk_widget_set_size_request (cbuilder -> so_combo, 150, 25);
1355 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> so_box, cbuilder -> so_combo, FALSE, FALSE, 0);
1356 gtk_combo_box_set_active (GTK_COMBO_BOX(cbuilder -> so_combo), 0);
1357 widget_set_sensitive (cbuilder -> so_combo, 0);
1358 g_signal_connect (G_OBJECT(cbuilder -> so_combo), "changed", G_CALLBACK(set_so), data);
1359 cell_list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(cbuilder -> so_combo));
1360 if (cell_list && cell_list -> data)
1361 {
1362 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cbuilder -> so_combo), cell_list -> data, "markup", 0, NULL);
1363 }
1364
1365 for (i=0; i<3; i++)
1366 {
1367 cbuilder -> cell.cextra[i] = 1;
1368 for (j=0; j<3; j++)
1369 {
1370 cbuilder -> pointers[i][j].a = this_proj -> id;
1371 cbuilder -> pointers[i][j].b = i;
1372 cbuilder -> pointers[i][j].c = j;
1373 }
1374 }
1375 if (cbuilder -> cell.sp_group) get_origin (cbuilder -> cell.sp_group);
1376 // Lattice parameters
1377 hbox = create_hbox(0);
1378 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1379 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label("Lattice parameters:", 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1380 cbuilder -> lattice_box = create_vbox (BSEP);
1381 GtkTreeModel * lmodel = la_combo_tree ();
1382 cbuilder -> la_combo = gtk_combo_box_new_with_model (lmodel);
1383 g_object_unref (lmodel);
1384 renderer = gtk_cell_renderer_combo_new ();
1385 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cbuilder -> la_combo), renderer, TRUE);
1386 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (cbuilder -> la_combo), renderer, "text", 0, NULL);
1387 gtk_widget_set_size_request (cbuilder -> la_combo, 150, 25);
1388 g_signal_connect (G_OBJECT(cbuilder -> la_combo), "changed", G_CALLBACK(set_lattice), data);
1389 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, cbuilder -> la_combo, FALSE, FALSE, 0);
1390 gtk_combo_box_set_active (GTK_COMBO_BOX(cbuilder -> la_combo), 0);
1391 cell_list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(cbuilder -> la_combo));
1392 if (cell_list && cell_list -> data)
1393 {
1394 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cbuilder -> la_combo), cell_list -> data, "markup", 0, NULL);
1395 }
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 }
1460 show_the_widgets (this_proj -> modelgl -> builder_win -> win);
1461}
1462
1463#ifdef GTK4
1473G_MODULE_EXPORT void crystal_window (GSimpleAction * action, GVariant * parameter, gpointer data)
1474#else
1483G_MODULE_EXPORT void crystal_window (GtkWidget * widg, gpointer data)
1484#endif
1485{
1487}
void prepare_atom_edition(gpointer data, gboolean visible)
prepare atom edition
Definition atom_edit.c:459
atom_search * allocate_atom_search(int proj, int action, int searchid, int tsize)
allocate atom search data structure
Definition atom_edit.c:392
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:372
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 build_crystal(gboolean visible, project *this_proj, gboolean to_wrap, gboolean show_clones, cell_info *cell, GtkWidget *widg)
build crystal
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 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]
gchar * bravais_keys[7][4]
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
void adjust_so_combo(builder_edition *cbuilder)
adjust the space group setting combo box to use pango markup
gchar * crystal_sytems[7]
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:3584
gchar * replace_markup(char *init, char *key, char *rep)
replace pattern in string
Definition w_library.c:339
space_group * read_sg_xml_file(const char *filetoread)
read space group data from XML file
Definition cbuild_sg.c:652
gchar * param[2]
float val
Definition dlp_init.c:117
char * box_prop[2][3]
Definition edit_menu.c:73
char * vect_name[3]
Definition edit_menu.c:81
dint t_box[9]
Definition edit_menu.c:94
gchar * PACKAGE_LIB_DIR
Definition global.c:78
gchar * bravais_img[14]
Definition global.c:138
double string_to_double(gpointer string)
convert string to double
Definition global.c:624
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:492
@ IMG_NONE
Definition global.h:260
@ IMG_STOCK
Definition global.h:264
GtkWidget * create_entry(GCallback handler, int dim, int cdim, gboolean key_release, gpointer data)
Create a GtkEntry.
Definition gtk-misc.c:1314
void update_entry_double(GtkEntry *entry, double doubleval)
update the content of a GtkEntry as double
Definition gtk-misc.c:633
GtkWidget * create_scroll(GtkWidget *box, int dimx, int dimy, int shadow)
create a scroll window
Definition gtk-misc.c:1960
GtkWidget * dialogmodal(gchar *str, GtkWindow *parent)
Create a new dialog modal window.
Definition gtk-misc.c:510
GtkWidget * create_win(gchar *str, GtkWidget *parent, gboolean modal, gboolean resiz)
create a new GtkWindow
Definition gtk-misc.c:445
const gchar * entry_get_text(GtkEntry *entry)
get the text in a GtkEntry
Definition gtk-misc.c:597
#define BSEP
Definition global.h:245
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:2387
GtkWidget * radio_button(gchar *text, int dimx, int dimy, gboolean state, GCallback handler, gpointer data)
create a radio button
Definition gtk-misc.c:1834
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:1772
#define APPLY
Definition global.h:220
GtkWidget * check_button(gchar *text, int dimx, int dimy, gboolean state, GCallback handler, gpointer data)
create a check button
Definition gtk-misc.c:1799
@ CONTAINER_WIN
Definition global.h:250
@ CONTAINER_BUT
Definition global.h:253
@ CONTAINER_SCR
Definition global.h:251
#define DPROPERTIES
Definition global.h:206
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:1863
GtkWidget * create_combo()
create a GtkCombox widget, note deprecated in GTK4
Definition gtk-misc.c:923
GtkWidget * dialog_get_content_area(GtkWidget *widg)
prepare GtkWidget to insert content in a GtkDialog window
Definition gtk-misc.c:825
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
Definition gtk-misc.c:1585
GtkWidget * cbox(GtkWidget *box, char *lab)
Definition gtk-misc.c:1931
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:299
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:206
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:813
void combo_text_append(GtkWidget *combo, gchar *text)
append text in GtkComboBox widget
Definition gtk-misc.c:900
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:2102
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2034
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:277
void update_entry_text(GtkEntry *entry, gchar *text)
update the content of a GtkEntry as string
Definition gtk-misc.c:671
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:226
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:801
#define FCLOSE
Definition global.h:211
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:173
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:285
action
Definition glview.h:189
@ INSERT
Definition glview.h:227
void show_error(char *error, int val, GtkWidget *win)
show error message
Definition interface.c:293
Messaging function declarations.
char * vect_comp[3]
Definition edit_menu.c:82
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:71
Functions declaration to read atomic coordinates.
Definition global.h:97
int b
Definition global.h:99
int a
Definition global.h:98
Definition glwin.h:875
Definition global.h:104
int b
Definition tab-1.c:95
int c
Definition tab-1.c:95
int a
Definition tab-1.c:95
gchar * settings[3][10]
Definition w_advance.c:119
GtkWidget * res[2]
Definition w_encode.c:212
GtkWidget * hbox
Definition workspace.c:71
GtkWidget * vbox
Definition workspace.c:72
Function declarations for workspace managment.