atomes 1.2.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
w_bonds.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-2025 by CNRS and University of Strasbourg */
15
22/*
23* This file: 'w_bonds.c'
24*
25* Contains:
26*
27
28 - The functions to create the bond (legnth/radius) edition window(s)
29
30*
31* List of functions:
32
33 void bonds_input_win (GtkWidget * win, project * this_proj, int nspec, int aoc, double ** val)
34
35 G_MODULE_EXPORT void update_bond_parameter (GtkEntry * res, gpointer data);
36 G_MODULE_EXPORT void set_bond_parameter (GSimpleAction * action, GVariant * parameter, gpointer data);
37 G_MODULE_EXPORT void set_bond_parameter (GtkWidget * widg, gpointer data);
38 G_MODULE_EXPORT void window_bonds (GSimpleAction * action, GVariant * parameter, gpointer data);
39 G_MODULE_EXPORT void window_bonds (GtkWidget * widg, gpointer data);
40
41*/
42
43#include "global.h"
44#include "interface.h"
45#include "glview.h"
46#include "glwindow.h"
47#include "color_box.h"
48
49extern gchar * label_cutrab (project * this_proj, glwin * view, int id);
50
59G_MODULE_EXPORT void update_bond_parameter (GtkEntry * res, gpointer data)
60{
61 int id = GPOINTER_TO_INT(data);
62 const gchar * n = entry_get_text (res);
63 double v = string_to_double ((gpointer)n);
64 int j, k, l, m;
65 int a, b, s;
66 s = opengl_project -> nspec;
67#ifdef GTK3
68 // GTK3 Menu Action To Check
69 int c;
70 gchar * str;
71#endif
72 switch (id)
73 {
74 case -5:
75 if (v > 0.0) opengl_project -> modelgl -> anim -> last -> img -> xyz -> length = v;
76 v = opengl_project -> modelgl -> anim -> last -> img -> xyz -> length;
77#ifdef GTK3
78 // GTK3 Menu Action To Check
79 str = g_strdup_printf ("_Axis length [ %f Å ]", v);
80 gtk_menu_item_set_label (GTK_MENU_ITEM(opengl_project -> modelgl -> ogl_box_axis[1][7]), str);
81 g_free (str);
82#endif
83 if (opengl_project -> modelgl -> axis_win -> length)
84 {
85 update_entry_double (GTK_ENTRY(opengl_project -> modelgl -> axis_win -> length), v);
86 }
87 opengl_project -> modelgl -> create_shaders[MAXIS] = TRUE;
88 break;
89 case -4:
90 if (opengl_project -> modelgl -> anim -> last -> img -> xyz -> axis == CYLINDERS)
91 {
92 if (v > 0.0) opengl_project -> modelgl -> anim -> last -> img -> xyz -> rad = v;
93 v = opengl_project -> modelgl -> anim -> last -> img -> xyz -> rad;
94#ifdef GTK3
95 // GTK3 Menu Action To Check
96 str = g_strdup_printf ("_Radius [ %f Å ]", v);
97 gtk_menu_item_set_label (GTK_MENU_ITEM(opengl_project -> modelgl -> ogl_box_axis[1][6]), str);
98 g_free (str);
99#endif
100 if (opengl_project -> modelgl -> axis_win)
101 {
102 if (opengl_project -> modelgl -> axis_win -> radius && GTK_IS_WIDGET(opengl_project -> modelgl -> axis_win -> radius))
103 {
104 update_entry_double (GTK_ENTRY(opengl_project -> modelgl -> axis_win -> radius), v);
105 }
106 }
107 }
108 else
109 {
110 if (v > 0.0) opengl_project -> modelgl -> anim -> last -> img -> xyz -> line = v;
111 v = opengl_project -> modelgl -> anim -> last -> img -> xyz -> line;
112#ifdef GTK3
113 str = g_strdup_printf ("_Width [ %f pts ]", v);
114 gtk_menu_item_set_label (GTK_MENU_ITEM(opengl_project -> modelgl -> ogl_box_axis[1][4]), str);
115 g_free (str);
116#endif
117 }
118 if (opengl_project -> modelgl -> axis_win)
119 {
120 if (opengl_project -> modelgl -> axis_win -> width && GTK_IS_WIDGET(opengl_project -> modelgl -> axis_win -> width))
121 {
122 update_entry_double (GTK_ENTRY(opengl_project -> modelgl -> axis_win -> width), v);
123 }
124 }
125 opengl_project -> modelgl -> create_shaders[MAXIS] = TRUE;
126 break;
127 case -3:
128 if (opengl_project -> modelgl -> anim -> last -> img -> abc -> box == CYLINDERS)
129 {
130 if (v > 0.0) opengl_project -> modelgl -> anim -> last -> img -> abc -> rad = v;
131 v = opengl_project -> modelgl -> anim -> last -> img -> abc -> rad;
132#ifdef GTK3
133 // GTK3 Menu Action To Check
134 str = g_strdup_printf ("_Radius [ %f Å ]", v);
135 gtk_menu_item_set_label (GTK_MENU_ITEM(opengl_project -> modelgl -> ogl_box_axis[0][6]), str);
136 g_free (str);
137#endif
138 if (opengl_project -> modelgl -> box_win)
139 {
140 if (opengl_project -> modelgl -> box_win -> radius && GTK_IS_WIDGET(opengl_project -> modelgl -> box_win -> radius))
141 {
142 update_entry_double (GTK_ENTRY(opengl_project -> modelgl -> box_win -> radius), v);
143 }
144 }
145 }
146 else
147 {
148 if (v > 0.0) opengl_project -> modelgl -> anim -> last -> img -> abc -> line = v;
149 v = opengl_project -> modelgl -> anim -> last -> img -> abc -> line;
150#ifdef GTK3
151 // GTK3 Menu Action To Check
152 str = g_strdup_printf ("_Width [ %f pts ]", v);
153 gtk_menu_item_set_label (GTK_MENU_ITEM(opengl_project -> modelgl -> ogl_box_axis[0][4]), str);
154 g_free (str);
155#endif
156 if (opengl_project -> modelgl -> box_win)
157 {
158 if (opengl_project -> modelgl -> box_win -> width && GTK_IS_WIDGET(opengl_project -> modelgl -> box_win -> width))
159 {
160 update_entry_double (GTK_ENTRY(opengl_project -> modelgl -> box_win -> width), v);
161 }
162 }
163 }
164 opengl_project -> modelgl -> create_shaders[MDBOX] = TRUE;
165 break;
166 case -2:
167 if (v > 0.0)
168 {
169 opengl_project -> modelgl -> anim -> last -> img -> radall[1] = v;
170 }
171 v = opengl_project -> modelgl -> anim -> last -> img -> radall[1];
172#ifdef GTK3
173 // GTK3 Menu Action To Check
174 str = g_strdup_printf ("Cylinder(s) [ %f Å ]", v);
175 gtk_menu_item_set_label (GTK_MENU_ITEM(opengl_project -> modelgl -> ogl_bonds[8]), str);
176 g_free (str);
177#endif
179 break;
180 case -1:
181 if (v > 0.0)
182 {
183 opengl_project -> modelgl -> anim -> last -> img -> radall[0] = v;
184 }
185 v = opengl_project -> modelgl -> anim -> last -> img -> radall[0];
186#ifdef GTK3
187 // GTK3 Menu Action To Check
188 str = g_strdup_printf ("Cylinder(s) [ %f Å ]", v);
189 gtk_menu_item_set_label (GTK_MENU_ITEM(opengl_project -> modelgl -> ogl_bonds[1]), str);
190 g_free (str);
191#endif
193 break;
194 default:
195 k = s*(s + 1)/2;
196 if (id < k)
197 {
198 j = id;
199 m = 0;
200#ifdef GTK3
201 // GTK3 Menu Action To Check
202 c = 0;
203#endif
204 }
205 else
206 {
207 j = id - k;
208 m = s;
209#ifdef GTK3
210 // GTK3 Menu Action To Check
211 c = 1;
212#endif
213 }
214 if (j < s)
215 {
216 a = j + m;
217 b = j + m;
218 }
219 else
220 {
221 j -= s;
222 for (k=0; k<s-1; k++)
223 {
224 for (l=k+1; l<s; l++)
225 {
226 if (j == 0)
227 {
228 a = k + m;
229 b = l + m;
230 }
231 j -= 1;
232 }
233 }
234 }
235#ifdef DEBUG
236 g_debug ("UPDATE_BONDS:: id= %d, a= %d, b=%d, a+2s= %d, b+2s= %d, val= %f", id, a, b, a+2*s, b+2*s, v);
237#endif
238 if (opengl_project -> modelgl -> anim -> last -> img -> style == WIREFRAME)
239 {
240 if (v > 0.0)
241 {
242 opengl_project -> modelgl -> anim -> last -> img -> linerad[a][b]
243 = opengl_project -> modelgl -> anim -> last -> img -> linerad[b][a] = v;
244 }
245 v = opengl_project -> modelgl -> anim -> last -> img -> linerad[a][b];
246#ifdef GTK3
247 // GTK3 Menu Action To Check
248 gtk_menu_item_set_label (GTK_MENU_ITEM(opengl_project -> modelgl -> ogl_bonds[5+8*c]),
250#endif
251 }
252 else
253 {
254 if (v > 0.0)
255 {
256 opengl_project -> modelgl -> anim -> last -> img -> bondrad[a][b]
257 = opengl_project -> modelgl -> anim -> last -> img -> bondrad[b][a] = v;
258 }
259 v = opengl_project -> modelgl -> anim -> last -> img -> bondrad[a][b];
260#ifdef GTK3
261 // GTK3 Menu Action To Check
262 gtk_menu_item_set_label (GTK_MENU_ITEM(opengl_project -> modelgl -> ogl_bonds[3+8*c]),
264#endif
265 }
267 break;
268 }
270 update (opengl_project -> modelgl);
271}
272
284void bonds_input_win (GtkWidget * win, project * this_proj, int nspec, int aoc, double ** val)
285{
286 int i, j, k, l, m, n;
287 gchar * dim[2]={" pts"," Å "};
288 GtkWidget * vbox = dialog_get_content_area (win);
289 GtkWidget * hbo;
290 GtkWidget * rad;
291 gchar * str;
292 if (this_proj -> modelgl -> anim -> last -> img -> style == WIREFRAME)
293 {
294 n = 0;
295 }
296 else
297 {
298 n = 1;
299 }
300 for (i=0, k=aoc*nspec; i<nspec; i++, k++)
301 {
302 j = i + aoc * nspec * (nspec + 1) / 2;
303 hbo = create_hbox (0);
304 gtk_widget_set_size_request (hbo, 250, -1);
305 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbo, TRUE, TRUE, 0);
306 str = g_strdup_printf (" %s - %s", this_proj -> chemistry -> label[i], this_proj -> chemistry -> label[i]);
307 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbo, markup_label(str, 100, -1, 0.2, 0.5), FALSE, FALSE, 0);
308 g_free (str);
309 rad = create_entry (G_CALLBACK(update_bond_parameter), 120, 15, FALSE, GINT_TO_POINTER(j));
310 update_entry_double (GTK_ENTRY(rad), val[k][k]);
311 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbo, rad, FALSE, FALSE, 0);
312 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbo, markup_label(dim[n], 40, -1, 0.0, 0.5), FALSE, FALSE, 0);
313 }
314 k = j+1;
315 for (i=0; i<nspec-1; i++)
316 {
317 for (j=i+1; j<nspec; j++, k++)
318 {
319 l = i + aoc * nspec;
320 m = j + aoc * nspec;
321 hbo = create_hbox (0);
322 gtk_widget_set_size_request (hbo, 250, -1);
323 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbo, TRUE, TRUE, 0);
324 str = g_strdup_printf (" %s - %s", this_proj -> chemistry -> label[i], this_proj -> chemistry -> label[j]);
325 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbo, markup_label(str, 100, -1, 0.2, 0.5), FALSE, FALSE, 0);
326 g_free (str);
327 rad = create_entry (G_CALLBACK(update_bond_parameter), 120, 15, FALSE, GINT_TO_POINTER(k));
328 update_entry_double (GTK_ENTRY(rad), val[l][m]);
329 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbo, rad, FALSE, FALSE, 0);
330 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbo, markup_label(dim[n], 40, -1, 0.0, 0.5), FALSE, FALSE, 0);
331 }
332 }
334}
335
336#ifdef GTK4
346G_MODULE_EXPORT void set_bond_parameter (GSimpleAction * action, GVariant * parameter, gpointer data)
347#else
356G_MODULE_EXPORT void set_bond_parameter (GtkWidget * widg, gpointer data)
357#endif
358{
359 tint * the_data = (tint *)data;
360 gchar * title[2][2] = {{"Adjust atomic bond radius(ii)", "Adjust clone bond radius(ii)"},
361 {"Adjust atomic line width(s)", "Adjust clone line width(s)"}};
362
363 int p = the_data -> a;
365 int s = opengl_project -> nspec;
366 double ** val;
367 int id = the_data -> b;
368 int jd = the_data -> c;
369 if (jd)
370 {
371 val = opengl_project -> modelgl -> anim -> last -> img -> linerad;
372 }
373 else
374 {
375 val = opengl_project -> modelgl -> anim -> last -> img -> bondrad;
376 }
377 GtkWidget * win = dialogmodal (title[jd][id], GTK_WINDOW(opengl_project -> modelgl -> win));
378 bonds_input_win (win, opengl_project, s, id, val);
379 run_this_gtk_dialog (win, G_CALLBACK(run_destroy_dialog), NULL);
380#ifdef GTK4
381 update_menu_bar (opengl_project -> modelgl);
382#endif
383}
384
385#ifdef GTK4
395G_MODULE_EXPORT void window_bonds (GSimpleAction * action, GVariant * parameter, gpointer data)
396#else
405G_MODULE_EXPORT void window_bonds (GtkWidget * widg, gpointer data)
406#endif
407{
408 int id;
409 tint * bid = (tint *)data;
410 gchar * obj[4] = {"box", "axis", "bond", "clone bond"};
411 gchar * Nobj[4] = {"Box", "Axis", "Bond", "Clone bond"};
412 gchar * str;
413 switch (bid -> b)
414 {
415 case 0:
416 id = -5;
417 str = g_strdup_printf ("Adjust axis length");
418 break;
419 case 1:
420 id = -3 - bid -> c;
421 str = g_strdup_printf ("Adjust %s line width", obj[bid -> c]);
422 break;
423 case 4:
424 id = -3 - bid -> c;
425 str = g_strdup_printf ("Adjust %s cylinders radius", obj[bid -> c]);
426 break;
427 default:
428 id = - bid -> b + 1;
429 str = g_strdup_printf ("Adjust %s cylinders radius", obj[bid -> b]);
430 break;
431 }
432 opengl_project_changed (bid -> a);
433 GtkWidget * win = dialogmodal (str, GTK_WINDOW(opengl_project -> modelgl -> win));
434 g_free (str);
435 GtkWidget * vbox = dialog_get_content_area (win);
436 GtkWidget * hbox = create_hbox (0);
437 gtk_widget_set_size_request (hbox, 300, -1);
438 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
439 switch (bid -> b)
440 {
441 case 0:
442 str = g_strdup_printf ("Axis length");
443 break;
444 case 1:
445 str = g_strdup_printf ("%s line width", Nobj[bid -> c]);
446 break;
447 case 4:
448 str = g_strdup_printf ("%s cylinders radius", Nobj[bid -> c]);
449 break;
450 default:
451 str = g_strdup_printf ("%s cylinders radius", Nobj[bid -> b]);
452 break;
453 }
454 GtkWidget * label = gtk_label_new (str);
455 g_free (str);
456 gtk_widget_set_size_request (label, 150, -1);
457 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, label, FALSE, FALSE, 0);
458 GtkWidget * rad = create_entry (G_CALLBACK(update_bond_parameter), 120, -1, FALSE, GINT_TO_POINTER(id));
459 switch (bid -> b)
460 {
461 case 0:
462 update_entry_double (GTK_ENTRY(rad), opengl_project -> modelgl -> anim -> last -> img -> xyz -> length);
463 break;
464 case 1:
465 update_entry_double (GTK_ENTRY(rad), (bid -> c) ? opengl_project -> modelgl -> anim -> last -> img -> xyz -> line : opengl_project -> modelgl -> anim -> last -> img -> abc -> line);
466 break;
467 case 4:
468 update_entry_double (GTK_ENTRY(rad), (bid -> c) ? opengl_project -> modelgl -> anim -> last -> img -> xyz -> rad : opengl_project -> modelgl -> anim -> last -> img -> abc -> rad);
469 break;
470 default:
471 update_entry_double (GTK_ENTRY(rad), opengl_project -> modelgl -> anim -> last -> img -> radall[bid -> b-2]);
472 break;
473 }
474 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, rad, FALSE, FALSE, 0);
475 switch (bid -> b)
476 {
477 case 1:
478 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(" [pts]", 40, -1, 0.0, 0.5), FALSE, FALSE, 0);
479 break;
480 default:
481 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(" [&#xC5;]", 30, -1, 0.0, 0.5), FALSE, FALSE, 0);
482 break;
483 }
484 gtk_widget_set_size_request (win, 350, 100);
486 run_this_gtk_dialog (win, G_CALLBACK(run_destroy_dialog), NULL);
487#ifdef GTK4
488 update_menu_bar (opengl_project -> modelgl);
489#endif
490}
integer(kind=c_int) function chemistry()
Definition chemistry.F90:22
Structure definitions for color management Function declarations for color management.
void label(cairo_t *cr, double val, int axe, int p, project *this_proj)
draw axis label
Definition labels.c:56
float val
Definition dlp_init.c:117
void init_default_shaders(glwin *view)
re-initialize the default OpenGL shaders
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:501
GtkWidget * create_entry(GCallback handler, int dim, int cdim, gboolean key_release, gpointer data)
Create a GtkEntry.
Definition gtk-misc.c:1375
void update_entry_double(GtkEntry *entry, double doubleval)
update the content of a GtkEntry as double
Definition gtk-misc.c:643
GtkWidget * dialogmodal(gchar *str, GtkWindow *parent)
Create a new dialog modal window.
Definition gtk-misc.c:520
const gchar * entry_get_text(GtkEntry *entry)
get the text in a GtkEntry
Definition gtk-misc.c:607
void opengl_project_changed(int id)
change the OpenGL project
Definition update_p.c:245
GtkWidget * dialog_get_content_area(GtkWidget *widg)
prepare GtkWidget to insert content in a GtkDialog window
Definition gtk-misc.c:835
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
create a GtkLabel with pango markup
Definition gtk-misc.c:1646
project * opengl_project
Definition project.c:54
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:308
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:823
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:2237
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:182
void update(glwin *view)
update the rendering of the OpenGL window
Definition glview.c:450
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
action
Definition glview.h:198
@ CYLINDERS
Definition glview.h:186
@ WIREFRAME
Definition glview.h:183
@ MAXIS
Definition glwin.h:94
@ MDBOX
Definition glwin.h:93
Function declarations for the creation of the OpenGL window.
Messaging function declarations.
Definition glwin.h:333
Definition glwin.h:351
Definition glwin.h:965
Definition global.h:106
int b
Definition tab-1.c:95
int c
Definition tab-1.c:95
int a
Definition tab-1.c:95
G_MODULE_EXPORT void set_bond_parameter(GtkWidget *widg, gpointer data)
update bond parameter callback - creating the dialog GTK3
Definition w_bonds.c:356
void bonds_input_win(GtkWidget *win, project *this_proj, int nspec, int aoc, double **val)
prepare bond property entry list
Definition w_bonds.c:284
G_MODULE_EXPORT void update_bond_parameter(GtkEntry *res, gpointer data)
update bond parameter callback
Definition w_bonds.c:59
gchar * label_cutrab(project *this_proj, glwin *view, int id)
prepare the text of a menu item in the 'Model -> Bond(s)' submenu
Definition m_bonds.c:67
G_MODULE_EXPORT void window_bonds(GtkWidget *widg, gpointer data)
create bond(s) configuration window(s) callback GTK3
Definition w_bonds.c:405
GtkWidget * res[2]
Definition w_encode.c:212
GtkWidget * hbox
Definition workspace.c:71
GtkWidget * img
Definition workspace.c:70
GtkWidget * vbox
Definition workspace.c:72