atomes 1.1.15
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
m_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: 'm_bonds.c'
24*
25* Contains:
26*
27
28 - The functions to create the 'Model -> Bond(s)' submenu
29
30*
31* List of functions:
32
33 gchar * label_cutrab (project * this_proj, glwin * view, int id);
34
35 GtkWidget * create_bond_menu_item (gchar * str, GtkWidget * menu);
36 GtkWidget * create_bond_layout_widget (gchar * str, GtkWidget * widg, int va, tint * data);
37 GtkWidget * menu_bonds (glwin * view, int id, int at);
38
39 GMenu * create_bond_layout_section (glwin * view, gchar * str, gchar * key, int popm, int id, GCallback handler, gpointer data, gboolean sensitive);
40 GMenu * menu_bonds (glwin * view, int popm, int at);
41
42*/
43
44#include "global.h"
45#include "glview.h"
46#include "glwindow.h"
47
48#ifdef GTK4
49extern G_MODULE_EXPORT void window_bonds (GSimpleAction * action, GVariant * parameter, gpointer data);
50extern G_MODULE_EXPORT void window_cuts (GSimpleAction * action, GVariant * parameter, gpointer data);
51extern G_MODULE_EXPORT void set_bond_parameter (GSimpleAction * action, GVariant * parameter, gpointer data);
52#else
53extern G_MODULE_EXPORT void window_bonds (GtkWidget * widg, gpointer data);
54extern G_MODULE_EXPORT void window_cuts (GtkWidget * widg, gpointer data);
55extern G_MODULE_EXPORT void set_bond_parameter (GtkWidget * widg, gpointer data);
56#endif
57
67gchar * label_cutrab (project * this_proj, glwin * view, int id)
68{
69 int i, j, k, m;
70 gchar * mot;
71 gchar * tmp;
72 gchar * str;
73 chemical_data * chem = this_proj -> chemistry;
74
75 k = 0;
76 m = this_proj -> nspec;
77 for (i=0; i < m; i++)
78 {
79 if (id == 0)
80 {
81 str = g_strdup_printf ("%s-%s [ %f Å ]", chem -> label[i], chem -> label[i], chem -> cutoffs[i][i]);
82 }
83 else
84 {
85 if (id == 1)
86 {
87 str = g_strdup_printf ("%s-%s [ %f Å ]", chem -> label[i], chem -> label[i], view -> anim -> last -> img -> bondrad[i][i]);
88 }
89 else if (id == 2)
90 {
91 str = g_strdup_printf ("%s-%s [ %f Å ]", chem -> label[i], chem -> label[i], view -> anim -> last -> img -> bondrad[i+m][i+m]);
92 }
93 else if (id == 3)
94 {
95 str = g_strdup_printf ("%s-%s [ %f pts ]", chem -> label[i], chem -> label[i], view -> anim -> last -> img -> linerad[i][i]);
96 }
97 else
98 {
99 str = g_strdup_printf ("%s-%s [ %f pts ]", chem -> label[i], chem -> label[i], view -> anim -> last -> img -> linerad[i+m][i+m]);
100 }
101 }
102 if (i == 0)
103 {
104 mot = g_strdup_printf ("%s", str);
105 }
106 else
107 {
108 tmp = g_strdup_printf ("%s", mot);
109 g_free (mot);
110 mot = g_strdup_printf ("%s\n%s", tmp, str);
111 g_free (tmp);
112 }
113 g_free (str);
114 k+=1;
115 }
116 for (i=0; i < m-1; i++)
117 {
118 for (j=i+1; j < m; j++)
119 {
120 if (id == 0)
121 {
122 str = g_strdup_printf ("%s-%s [ %f Å ]", chem -> label[i], chem -> label[j], chem -> cutoffs[i][j]);
123 }
124 else
125 {
126 if (id == 1)
127 {
128 str = g_strdup_printf ("%s-%s [ %f Å ]", chem -> label[i], chem -> label[j], view -> anim -> last -> img -> bondrad[i][j]);
129 }
130 else if (id == 2)
131 {
132 str = g_strdup_printf ("%s-%s [ %f Å ]", chem -> label[i], chem -> label[j], view -> anim -> last -> img -> bondrad[i+m][j+m]);
133 }
134 else if (id == 3)
135 {
136 str = g_strdup_printf ("%s-%s [ %f pts ]", chem -> label[i], chem -> label[j], view -> anim -> last -> img -> linerad[i][j]);
137 }
138 else
139 {
140 str = g_strdup_printf ("%s-%s [ %f pts ]", chem -> label[i], chem -> label[j], view -> anim -> last -> img -> linerad[i+m][j+m]);
141 }
142 }
143
144 if (k == 0)
145 {
146 mot = g_strdup_printf ("%s", str);
147 }
148 else
149 {
150 tmp = g_strdup_printf ("%s", mot);
151 g_free (mot);
152 mot = g_strdup_printf ("%s\n%s", tmp, str);
153 g_free (tmp);
154 }
155 g_free (str);
156 k += 1;
157 }
158 }
159 if (id == 0)
160 {
161 str = g_strdup_printf ("Total [ %f Å ]", chem -> grtotcutoff);
162 tmp = g_strdup_printf ("%s", mot);
163 g_free (mot);
164 mot = g_strdup_printf ("%s\n%s", tmp, str);
165 g_free (tmp);
166 g_free (str);
167 }
168 return mot;
169}
170
171#ifdef GTK3
180GtkWidget * create_bond_menu_item (gchar * str, GtkWidget * menu)
181{
182 GtkWidget * layout = create_menu_item (FALSE, str);
183 gtk_menu_shell_append ((GtkMenuShell *)menu, layout);
184 return layout;
185}
186
197GtkWidget * create_bond_layout_widget (gchar * str, GtkWidget * widg, int va, tint * data)
198{
199 GtkWidget * menu = gtk_menu_new ();
200 gtk_menu_item_set_submenu ((GtkMenuItem *)widg, menu);
201 GtkWidget * layout = create_menu_item (FALSE, str);
202 gtk_menu_shell_append ((GtkMenuShell *)menu, layout);
203 switch (va)
204 {
205 case 0:
206 g_signal_connect (G_OBJECT (layout), "activate", G_CALLBACK(window_bonds), data);
207 break;
208 case 1:
209 g_signal_connect (G_OBJECT (layout), "activate", G_CALLBACK(set_bond_parameter), data);
210 break;
211 default:
212 g_signal_connect (G_OBJECT (layout), "activate", G_CALLBACK(window_cuts), data);
213 break;
214 }
215 return layout;
216}
217
227GtkWidget * menu_bonds (glwin * view, int id, int at)
228{
229 GtkWidget * widg;
230 gchar * str;
231 int i;
232
233 GtkWidget * menub = gtk_menu_new ();
234 i = view -> anim -> last -> img -> style;
235
236 if (id == 0)
237 {
238 if (at == 0)
239 {
240 str = g_strdup_printf ("Cylinder(s) [ %f Å ]", view -> anim -> last -> img -> radall[0]);
241 }
242 else
243 {
244 str = g_strdup_printf ("Cylinder(s) [ %f Å ]", view -> anim -> last -> img -> radall[1]);
245 }
246 view -> ogl_bonds[8*at] = create_bond_menu_item ("Radius", menub);
247 view -> ogl_bonds[1+8*at] = create_bond_layout_widget (str, view -> ogl_bonds[8*at], 0, & view -> colorp[2+at][0]);
248 g_free (str);
249 if (at == 1 && ! view -> anim -> last -> img -> draw_clones)
250 {
251 widget_set_sensitive (view -> ogl_bonds[1+8*at], 0);
252 }
253 }
254 else if (i == CYLINDERS)
255 {
256 if (at == 0)
257 {
258 str = g_strdup_printf ("Cylinder(s) [ %f Å ]", view -> anim -> last -> img -> radall[0]);
259 }
260 else
261 {
262 str = g_strdup_printf ("Cylinder(s) [ %f Å ]", view -> anim -> last -> img -> radall[1]);
263 }
264 widg = create_bond_menu_item ("Cylinder Radius(ii)", menub);
265 widg = create_bond_layout_widget (str, widg, 0, & view -> colorp[2+at][0]);
266 g_free (str);
267 if (at == 1 && ! view -> anim -> last -> img -> draw_clones)
268 {
269 widget_set_sensitive (widg, 0);
270 }
271 }
272
273 if (id == 0)
274 {
275 str = label_cutrab (get_project_by_id(view -> proj), view, 1+at);
276 view -> ogl_bonds[2+8*at] = create_bond_menu_item ("Radius(ii)", menub);
277 view -> ogl_bonds[3+8*at] = create_bond_layout_widget (str, view -> ogl_bonds[2+8*at], 1, & view -> colorp[at][0]);
278 g_free (str);
279 if (at == 1 && ! view -> anim -> last -> img -> draw_clones)
280 {
281 widget_set_sensitive (view -> ogl_bonds[3+8*at], 0);
282 }
283 }
284 else if (i == BALL_AND_STICK)
285 {
286 str = label_cutrab (get_project_by_id(view -> proj), view, 1+at);
287 widg = create_bond_menu_item ("Radius(ii)", menub);
288 widg = create_bond_layout_widget (str, widg, 1, & view -> colorp[at][0]);
289 g_free (str);
290 if (at == 1 && ! view -> anim -> last -> img -> draw_clones)
291 {
292 widget_set_sensitive (widg, 0);
293 }
294 }
295
296 if (id == 0)
297 {
298 str = label_cutrab (get_project_by_id(view -> proj), view, 3+at);
299 view -> ogl_bonds[4+8*at] = create_bond_menu_item ("Line Width(s)", menub);
300 view -> ogl_bonds[5+8*at] = create_bond_layout_widget (str, view -> ogl_bonds[4+8*at], 1, & view -> colorp[at][1]);
301 g_free (str);
302 if (at == 1 && ! view -> anim -> last -> img -> draw_clones)
303 {
304 widget_set_sensitive (view -> ogl_bonds[5+8*at], 0);
305 }
306 }
307 else if (i == WIREFRAME)
308 {
309 str = label_cutrab (get_project_by_id(view -> proj), view, 3+at);
310 widg = create_bond_menu_item ("Line Width(s)", menub);;
311 widg = create_bond_layout_widget (str, widg, 1, & view -> colorp[at][1]);
312 g_free (str);
313 if (at == 1 && ! view -> anim -> last -> img -> draw_clones)
314 {
315 widget_set_sensitive (widg, 0);
316 }
317 }
318
319 if (at == 0)
320 {
321 str = label_cutrab (get_project_by_id(view -> proj), view, 0);
322 if (id == 0)
323 {
324 view -> ogl_bonds[6] = create_bond_menu_item ("Cutoff(s)", menub);
325 view -> ogl_bonds[7] = create_bond_layout_widget (str, view -> ogl_bonds[6], 2, & view -> colorp[at][0]);
326 }
327 else
328 {
329 widg = create_bond_menu_item ("Cutoff(s)", menub);
330 widg = create_bond_layout_widget (str, widg, 2, & view -> colorp[at][0]);
331 }
332 g_free (str);
333 }
334 return menub;
335}
336#else
351GMenu * create_bond_layout_section (glwin * view, gchar * str, gchar * key, int popm, int id, GCallback handler, gpointer data, gboolean sensitive)
352{
353 GMenu * menu = g_menu_new ();
354 append_opengl_item (view, menu, str, key, popm, id, NULL, IMG_NONE, NULL, FALSE, handler, data, FALSE, FALSE, FALSE, sensitive);
355 return menu;
356}
357
367GMenu * menu_bonds (glwin * view, int popm, int at)
368{
369 gchar * str;
370 gboolean sensitive = (at == 1 && ! view -> anim -> last -> img -> draw_clones) ? FALSE : TRUE;
371 GMenu * menu = g_menu_new ();
372 switch (view -> anim -> last -> img -> style)
373 {
374 case CYLINDERS:
375 if (at == 0)
376 {
377 str = g_strdup_printf ("Cylinder(s) [ %f Å ]", view -> anim -> last -> img -> radall[0]);
378 }
379 else
380 {
381 str = g_strdup_printf ("Cylinder(s) [ %f Å ]", view -> anim -> last -> img -> radall[1]);
382 }
383 append_submenu (menu, "Cylinder Radius(ii)", create_bond_layout_section (view, str, (at) ? "clone-cyl-rad" : "atom-cyl-rad", popm, at, G_CALLBACK(window_bonds), & view -> colorp[2+at][0], sensitive));
384 g_free (str);
385 break;
386 case BALL_AND_STICK:
387 str = label_cutrab (get_project_by_id(view -> proj), view, 1+at);
388 append_submenu (menu, "Radius(ii)", create_bond_layout_section (view, str, (at) ? "clone-rad" : "atom-rad", popm, at+1, G_CALLBACK(set_bond_parameter), & view -> colorp[at][0], sensitive));
389 g_free (str);
390 break;
391 case WIREFRAME:
392 str = label_cutrab (get_project_by_id(view -> proj), view, 3+at);
393 append_submenu (menu, "Line Width(s)", create_bond_layout_section (view, str, (at) ? "clone-line" : "atom-line", popm, at+2, G_CALLBACK(set_bond_parameter), & view -> colorp[at][1], sensitive));
394 g_free (str);
395 break;
396 }
397
398 if (! at)
399 {
400 str = label_cutrab (get_project_by_id(view -> proj), view, 0);
401 append_submenu (menu, "Cutoff(s)", create_bond_layout_section (view, str, "bond-cutoffs", popm, at+3, G_CALLBACK(window_cuts), & view -> colorp[at][0], sensitive));
402 g_free (str);
403 }
404 return menu;
405}
406#endif
gchar * mot[2][2]
Definition popup.c:3293
integer(kind=c_int) function chemistry()
Definition chemistry.F90:22
color colorp[64]
PangoLayout * layout
Definition curve.c:79
void label(cairo_t *cr, double val, int axe, int p, project *this_proj)
draw axis label
Definition labels.c:56
Global variable declarations Global convenience function declarations Global data structure defin...
@ IMG_NONE
Definition global.h:260
project * proj
void append_submenu(GMenu *menu, const gchar *label, GMenu *submenu)
append a GMenuItem with a subenu to a GMenu, and use markup for the GMenuItem
Definition gui.c:728
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_menu_item(gboolean add_mnemo, gchar *action)
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...
action
Definition glview.h:189
@ BALL_AND_STICK
Definition glview.h:173
@ CYLINDERS
Definition glview.h:177
@ WIREFRAME
Definition glview.h:174
Function declarations for the creation of the OpenGL window.
void append_opengl_item(glwin *view, GMenu *menu, const gchar *name, gchar *key, int mpop, int item_id, gchar *accel, int image_format, gpointer icon, gboolean custom, GCallback handler, gpointer data, gboolean check, gboolean status, gboolean radio, gboolean sensitive)
G_MODULE_EXPORT void window_cuts(GtkWidget *widg, gpointer data)
adjust bond cutoffs window callback GTK3
Definition w_cutoffs.c:272
GMenu * create_bond_layout_section(glwin *view, gchar *str, gchar *key, int popm, int id, GCallback handler, gpointer data, gboolean sensitive)
create a bond menu item GTK4
Definition m_bonds.c:351
GMenu * menu_bonds(glwin *view, int popm, int at)
create the 'Bond(s)' submenu GTK4
Definition m_bonds.c:367
G_MODULE_EXPORT void set_bond_parameter(GtkWidget *widg, gpointer data)
update bond parameter callback - creating the dialog GTK3
Definition w_bonds.c:324
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
Definition glwin.h:875
Definition global.h:104
GtkWidget * img
Definition workspace.c:70