atomes 1.1.14
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-2024 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 = atof(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 -> axis_length = v;
76 v = opengl_project -> modelgl -> anim -> last -> img -> axis_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 opengl_project -> modelgl -> create_shaders[MAXIS] = TRUE;
84 break;
85 case -4:
86 if (opengl_project -> modelgl -> anim -> last -> img -> box_axis[AXIS] == CYLINDERS)
87 {
88 if (v > 0.0) opengl_project -> modelgl -> anim -> last -> img -> box_axis_rad[AXIS] = v;
89 v = opengl_project -> modelgl -> anim -> last -> img -> box_axis_rad[AXIS];
90#ifdef GTK3
91 // GTK3 Menu Action To Check
92 str = g_strdup_printf ("_Radius [ %f Å ]", v);
93 gtk_menu_item_set_label (GTK_MENU_ITEM(opengl_project -> modelgl -> ogl_box_axis[1][6]), str);
94 g_free (str);
95#endif
96 }
97 else
98 {
99 if (v > 0.0) opengl_project -> modelgl -> anim -> last -> img -> box_axis_line[AXIS] = v;
100 v = opengl_project -> modelgl -> anim -> last -> img -> box_axis_line[AXIS];
101#ifdef GTK3
102 str = g_strdup_printf ("_Width [ %f pts ]", v);
103 gtk_menu_item_set_label (GTK_MENU_ITEM(opengl_project -> modelgl -> ogl_box_axis[1][4]), str);
104 g_free (str);
105#endif
106 }
107 opengl_project -> modelgl -> create_shaders[MAXIS] = TRUE;
108 break;
109 case -3:
110 if (opengl_project -> modelgl -> anim -> last -> img -> box_axis[BOX] == CYLINDERS)
111 {
112 if (v > 0.0) opengl_project -> modelgl -> anim -> last -> img -> box_axis_rad[BOX] = v;
113 v = opengl_project -> modelgl -> anim -> last -> img -> box_axis_rad[BOX];
114#ifdef GTK3
115 // GTK3 Menu Action To Check
116 str = g_strdup_printf ("_Radius [ %f Å ]", v);
117 gtk_menu_item_set_label (GTK_MENU_ITEM(opengl_project -> modelgl -> ogl_box_axis[0][6]), str);
118 g_free (str);
119#endif
120 }
121 else
122 {
123 if (v > 0.0) opengl_project -> modelgl -> anim -> last -> img -> box_axis_line[BOX] = v;
124 v = opengl_project -> modelgl -> anim -> last -> img -> box_axis_line[BOX];
125#ifdef GTK3
126 // GTK3 Menu Action To Check
127 str = g_strdup_printf ("_Width [ %f pts ]", v);
128 gtk_menu_item_set_label (GTK_MENU_ITEM(opengl_project -> modelgl -> ogl_box_axis[0][4]), str);
129 g_free (str);
130#endif
131 }
132 opengl_project -> modelgl -> create_shaders[MDBOX] = TRUE;
133 break;
134 case -2:
135 if (v > 0.0)
136 {
137 opengl_project -> modelgl -> anim -> last -> img -> radall[1] = v;
138 }
139 v = opengl_project -> modelgl -> anim -> last -> img -> radall[1];
140#ifdef GTK3
141 // GTK3 Menu Action To Check
142 str = g_strdup_printf ("Cylinder(s) [ %f Å ]", v);
143 gtk_menu_item_set_label (GTK_MENU_ITEM(opengl_project -> modelgl -> ogl_bonds[8]), str);
144 g_free (str);
145#endif
147 break;
148 case -1:
149 if (v > 0.0)
150 {
151 opengl_project -> modelgl -> anim -> last -> img -> radall[0] = v;
152 }
153 v = opengl_project -> modelgl -> anim -> last -> img -> radall[0];
154#ifdef GTK3
155 // GTK3 Menu Action To Check
156 str = g_strdup_printf ("Cylinder(s) [ %f Å ]", v);
157 gtk_menu_item_set_label (GTK_MENU_ITEM(opengl_project -> modelgl -> ogl_bonds[1]), str);
158 g_free (str);
159#endif
161 break;
162 default:
163 k = s*(s + 1)/2;
164 if (id < k)
165 {
166 j = id;
167 m = 0;
168#ifdef GTK3
169 // GTK3 Menu Action To Check
170 c = 0;
171#endif
172 }
173 else
174 {
175 j = id - k;
176 m = s;
177#ifdef GTK3
178 // GTK3 Menu Action To Check
179 c = 1;
180#endif
181 }
182 if (j < s)
183 {
184 a = j + m;
185 b = j + m;
186 }
187 else
188 {
189 j -= s;
190 for (k=0; k<s-1; k++)
191 {
192 for (l=k+1; l<s; l++)
193 {
194 if (j == 0)
195 {
196 a = k + m;
197 b = l + m;
198 }
199 j -= 1;
200 }
201 }
202 }
203#ifdef DEBUG
204 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);
205#endif
206 if (opengl_project -> modelgl -> anim -> last -> img -> style == WIREFRAME)
207 {
208 if (v > 0.0)
209 {
210 opengl_project -> modelgl -> anim -> last -> img -> linerad[a][b]
211 = opengl_project -> modelgl -> anim -> last -> img -> linerad[b][a] = v;
212 }
213 v = opengl_project -> modelgl -> anim -> last -> img -> linerad[a][b];
214#ifdef GTK3
215 // GTK3 Menu Action To Check
216 gtk_menu_item_set_label (GTK_MENU_ITEM(opengl_project -> modelgl -> ogl_bonds[5+8*c]),
218#endif
219 }
220 else
221 {
222 if (v > 0.0)
223 {
224 opengl_project -> modelgl -> anim -> last -> img -> bondrad[a][b]
225 = opengl_project -> modelgl -> anim -> last -> img -> bondrad[b][a] = v;
226 }
227 v = opengl_project -> modelgl -> anim -> last -> img -> bondrad[a][b];
228#ifdef GTK3
229 // GTK3 Menu Action To Check
230 gtk_menu_item_set_label (GTK_MENU_ITEM(opengl_project -> modelgl -> ogl_bonds[3+8*c]),
232#endif
233 }
235 break;
236 }
238 update (opengl_project -> modelgl);
239}
240
252void bonds_input_win (GtkWidget * win, project * this_proj, int nspec, int aoc, double ** val)
253{
254 int i, j, k, l, m, n;
255 gchar * dim[2]={" pts"," Å "};
256 GtkWidget * vbox = dialog_get_content_area (win);
257 GtkWidget * hbo;
258 GtkWidget * rad;
259 gchar * str;
260 if (this_proj -> modelgl -> anim -> last -> img -> style == WIREFRAME)
261 {
262 n = 0;
263 }
264 else
265 {
266 n = 1;
267 }
268 for (i=0, k=aoc*nspec; i<nspec; i++, k++)
269 {
270 j = i + aoc * nspec * (nspec + 1) / 2;
271 hbo = create_hbox (0);
272 gtk_widget_set_size_request (hbo, 250, -1);
273 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbo, TRUE, TRUE, 0);
274 str = g_strdup_printf (" %s - %s", this_proj -> chemistry -> label[i], this_proj -> chemistry -> label[i]);
275 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbo, markup_label(str, 100, -1, 0.2, 0.5), FALSE, FALSE, 0);
276 g_free (str);
277 rad = create_entry (G_CALLBACK(update_bond_parameter), 120, 15, FALSE, (gpointer)GINT_TO_POINTER(j));
278 update_entry_double (GTK_ENTRY(rad), val[k][k]);
279 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbo, rad, FALSE, FALSE, 0);
280 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbo, markup_label(dim[n], 40, -1, 0.0, 0.5), FALSE, FALSE, 0);
281 }
282 k = j+1;
283 for (i=0; i<nspec-1; i++)
284 {
285 for (j=i+1; j<nspec; j++, k++)
286 {
287 l = i + aoc * nspec;
288 m = j + aoc * nspec;
289 hbo = create_hbox (0);
290 gtk_widget_set_size_request (hbo, 250, -1);
291 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbo, TRUE, TRUE, 0);
292 str = g_strdup_printf (" %s - %s", this_proj -> chemistry -> label[i], this_proj -> chemistry -> label[j]);
293 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbo, markup_label(str, 100, -1, 0.2, 0.5), FALSE, FALSE, 0);
294 g_free (str);
295 rad = create_entry (G_CALLBACK(update_bond_parameter), 120, 15, FALSE, (gpointer)GINT_TO_POINTER(k));
296 update_entry_double (GTK_ENTRY(rad), val[l][m]);
297 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbo, rad, FALSE, FALSE, 0);
298 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbo, markup_label(dim[n], 40, -1, 0.0, 0.5), FALSE, FALSE, 0);
299 }
300 }
302}
303
304#ifdef GTK4
314G_MODULE_EXPORT void set_bond_parameter (GSimpleAction * action, GVariant * parameter, gpointer data)
315#else
324G_MODULE_EXPORT void set_bond_parameter (GtkWidget * widg, gpointer data)
325#endif
326{
327 tint * the_data = (tint *)data;
328 gchar * title[2][2] = {{"Adjust atomic bond radius(ii)", "Adjust clone bond radius(ii)"},
329 {"Adjust atomic line width(s)", "Adjust clone line width(s)"}};
330
331 int p = the_data -> a;
333 int s = opengl_project -> nspec;
334 double ** val;
335 int id = the_data -> b;
336 int jd = the_data -> c;
337 if (jd)
338 {
339 val = opengl_project -> modelgl -> anim -> last -> img -> linerad;
340 }
341 else
342 {
343 val = opengl_project -> modelgl -> anim -> last -> img -> bondrad;
344 }
345 GtkWidget * win = dialogmodal (title[jd][id], GTK_WINDOW(opengl_project -> modelgl -> win));
346 bonds_input_win (win, opengl_project, s, id, val);
347 run_this_gtk_dialog (win, G_CALLBACK(run_destroy_dialog), NULL);
348#ifdef GTK4
349 update_menu_bar (opengl_project -> modelgl);
350#endif
351}
352
353#ifdef GTK4
363G_MODULE_EXPORT void window_bonds (GSimpleAction * action, GVariant * parameter, gpointer data)
364#else
373G_MODULE_EXPORT void window_bonds (GtkWidget * widg, gpointer data)
374#endif
375{
376 int id;
377 tint * bid = (tint *)data;
378 gchar * obj[4] = {"box", "axis", "bond", "clone bond"};
379 gchar * Nobj[4] = {"Box", "Axis", "Bond", "Clone bond"};
380 gchar * str;
381 switch (bid -> b)
382 {
383 case 0:
384 id = -5;
385 str = g_strdup_printf ("Adjust axis length");
386 break;
387 case 1:
388 id = -3 - bid -> c;
389 str = g_strdup_printf ("Adjust %s line width", obj[bid -> c]);
390 break;
391 case 4:
392 id = -3 - bid -> c;
393 str = g_strdup_printf ("Adjust %s cylinders radius", obj[bid -> c]);
394 break;
395 default:
396 id = - bid -> b + 1;
397 str = g_strdup_printf ("Adjust %s cylinders radius", obj[bid -> b]);
398 break;
399 }
400 opengl_project_changed (bid -> a);
401 GtkWidget * win = dialogmodal (str, GTK_WINDOW(opengl_project -> modelgl -> win));
402 g_free (str);
403 GtkWidget * vbox = dialog_get_content_area (win);
404 GtkWidget * hbox = create_hbox (0);
405 gtk_widget_set_size_request (hbox, 300, -1);
406 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
407 switch (bid -> b)
408 {
409 case 0:
410 str = g_strdup_printf ("Axis length");
411 break;
412 case 1:
413 str = g_strdup_printf ("%s line width", Nobj[bid -> c]);
414 break;
415 case 4:
416 str = g_strdup_printf ("%s cylinders radius", Nobj[bid -> c]);
417 break;
418 default:
419 str = g_strdup_printf ("%s cylinders radius", Nobj[bid -> b]);
420 break;
421 }
422 GtkWidget * label = gtk_label_new (str);
423 g_free (str);
424 gtk_widget_set_size_request (label, 150, -1);
425 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, label, FALSE, FALSE, 0);
426 GtkWidget * rad = create_entry (G_CALLBACK(update_bond_parameter), 120, -1, FALSE, GINT_TO_POINTER(id));
427 switch (bid -> b)
428 {
429 case 0:
430 update_entry_double (GTK_ENTRY(rad), opengl_project -> modelgl -> anim -> last -> img -> axis_length);
431 break;
432 case 1:
433 update_entry_double (GTK_ENTRY(rad), opengl_project -> modelgl -> anim -> last -> img -> box_axis_line[bid -> c]);
434 break;
435 case 4:
436 update_entry_double (GTK_ENTRY(rad), opengl_project -> modelgl -> anim -> last -> img -> box_axis_rad[bid -> c]);
437 break;
438 default:
439 update_entry_double (GTK_ENTRY(rad), opengl_project -> modelgl -> anim -> last -> img -> radall[bid -> b-2]);
440 break;
441 }
442 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, rad, FALSE, FALSE, 0);
443 switch (bid -> b)
444 {
445 case 1:
446 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(" [pts]", 40, -1, 0.0, 0.5), FALSE, FALSE, 0);
447 break;
448 default:
449 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(" [&#xC5;]", 30, -1, 0.0, 0.5), FALSE, FALSE, 0);
450 break;
451 }
452 gtk_widget_set_size_request (win, 350, 100);
454 run_this_gtk_dialog (win, G_CALLBACK(run_destroy_dialog), NULL);
455#ifdef GTK4
456 update_menu_bar (opengl_project -> modelgl);
457#endif
458}
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
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:472
GtkWidget * create_entry(GCallback handler, int dim, int cdim, gboolean key_release, gpointer data)
Create a GtkEntry.
Definition gtk-misc.c:1294
void update_entry_double(GtkEntry *entry, double doubleval)
update the content of a GtkEntry as double
Definition gtk-misc.c:613
GtkWidget * dialogmodal(gchar *str, GtkWindow *parent)
Create a new dialog modal window.
Definition gtk-misc.c:490
const gchar * entry_get_text(GtkEntry *entry)
get the text in a GtkEntry
Definition gtk-misc.c:577
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:805
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
Definition gtk-misc.c:1565
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:279
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:793
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:2078
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:169
void update(glwin *view)
update the rendering of the OpenGL window
Definition glview.c:439
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
action
Definition glview.h:189
@ CYLINDERS
Definition glview.h:177
@ WIREFRAME
Definition glview.h:174
#define BOX
Definition glwin.h:54
#define AXIS
Definition glwin.h:55
@ 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:875
Definition global.h:98
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:324
void bonds_input_win(GtkWidget *win, project *this_proj, int nspec, int aoc, double **val)
prepare bond property entry list
Definition w_bonds.c:252
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:373
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