atomes 1.1.16
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
m_poly.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_poly.c'
24*
25* Contains:
26*
27
28 - The functions to create the 'Chemistry -> Polyhedra' submenus
29
30*
31* List of functions:
32
33 G_MODULE_EXPORT void show_hide_poly (GSimpleAction * action, GVariant * parameter, gpointer data);
34 G_MODULE_EXPORT void show_hide_poly (GtkWidget * widg, gpointer data);
35 G_MODULE_EXPORT void cloned_poly (GSimpleAction * action, GVariant * parameter, gpointer data);
36 G_MODULE_EXPORT void cloned_poly (GtkWidget * widg, gpointer data);
37
38 GtkWidget * mpoly (glwin * view, int jd, int id);
39 GtkWidget * menupoly (glwin * view, int jd, int id, gchar * poln);
40 GtkWidget * menu_poly (glwin * view, int id);
41
42 GMenu * menu_show_coord_poly (glwin * view, int popm, int id);
43 GMenu * menu_show_rings_poly (glwin * view, int popm, int id);
44 GMenu * add_menu_poly (glwin * view, int popm, int aid);
45 GMenu * menu_poly_rings (glwin * view, int popm);
46 GMenu * menu_poly (glwin * view, int popm);
47
48*/
49
50#include "global.h"
51#include "interface.h"
52#include "glview.h"
53#include "glwindow.h"
54
55extern G_MODULE_EXPORT void coord_properties (GtkWidget * widg, gpointer data);
56
57#ifdef GTK4
58extern G_MODULE_EXPORT void to_coord_properties (GSimpleAction * action, GVariant * parameter, gpointer data);
59
69G_MODULE_EXPORT void show_hide_poly (GSimpleAction * action, GVariant * parameter, gpointer data)
70#else
79G_MODULE_EXPORT void show_hide_poly (GtkWidget * widg, gpointer data)
80#endif
81{
82 qint * obj = (qint *)data;
83 int i, j;
84 gboolean doit = TRUE;
85 gboolean show;
86 project * this_proj = get_project_by_id(obj -> a);
87 int s = obj -> b;
88 int c = obj -> c;
89 int g = obj -> d;
90 j = c;
91 if (g < 2)
92 {
93 for (i=0; i<s; i++)
94 {
95 j += this_proj -> coord -> ntg[g][i];
96 }
97 }
98#ifdef DEBUG
99 g_debug ("SHOW_HIDE_POLY:: p= %d, s= %d, c= %d, g= %d", this_proj -> id, s, c, g);
100#endif
101#ifdef GTK4
102 GVariant * state;
103 if (action)
104 {
105 state = g_action_get_state (G_ACTION (action));
106 show = ! g_variant_get_boolean (state);
107 const gchar * poly = g_action_get_name ((GAction *)action);
108 int lgt = strlen (poly);
109 gchar * name = g_strdup_printf ("%c%c", poly[lgt-2], poly[lgt-1]);
110 if (g_strcmp0(name, ".1") == 0)
111 {
112 g_free (name);
113 name = g_strdup_printf ("%.*s.0", lgt-2, poly);
114 g_action_group_activate_action ((GActionGroup *)this_proj -> modelgl -> action_group, (const gchar *)name, NULL);
115 g_free (name);
116 doit = FALSE;
117 }
118 }
119 else
120 {
121 show = this_proj -> modelgl -> anim -> last -> img -> show_poly[g][j];
122 }
123#else
124 show = gtk_check_menu_item_get_active ((GtkCheckMenuItem *)widg);
125#endif
126#ifdef GTK3
127 // GTK3 Menu Action To Check
128 if (is_coord_in_menu(g, this_proj))
129 {
130 for (i=0; i<2; i++)
131 {
132 if (widg != this_proj -> modelgl -> ogl_poly[i][g][j])
133 {
134 if (GTK_IS_WIDGET(this_proj -> modelgl -> ogl_poly[i][g][j]))
135 {
136 if (gtk_check_menu_item_get_active ((GtkCheckMenuItem *)this_proj -> modelgl -> ogl_poly[i][g][j]) != show)
137 {
138 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)this_proj -> modelgl -> ogl_poly[i][g][j], show);
139 }
140 }
141 }
142 }
143 }
144#endif
145 if (doit)
146 {
147 this_proj -> modelgl -> anim -> last -> img -> show_poly[g][j] = show;
148 int shaders[2] = {POLYS, RINGS};
149 re_create_md_shaders (2, shaders, this_proj);
150 update (this_proj -> modelgl);
151#ifdef GTK4
152 if (action)
153 {
154 g_action_change_state (G_ACTION (action), g_variant_new_boolean (show));
155 g_variant_unref (state);
156 }
157#endif
158 }
159}
160
161#ifdef GTK4
171G_MODULE_EXPORT void cloned_poly (GSimpleAction * action, GVariant * parameter, gpointer data)
172#else
181G_MODULE_EXPORT void cloned_poly (GtkWidget * widg, gpointer data)
182#endif
183{
184 glwin * view = (glwin *)data;
185 gboolean doit = TRUE;
186 gboolean show;
187#ifdef GTK4
188 const gchar * name = g_action_get_name ((GAction *)action);
189 if (g_strcmp0(name, "set-cloned-poly.1.1") == 0)
190 {
191 g_action_group_activate_action ((GActionGroup *)view -> action_group, "set-cloned-poly.0.0", NULL);
192 doit = FALSE;
193 }
194#endif
195 if (doit)
196 {
197#ifdef GTK4
198 GVariant * state;
199 state = g_action_get_state (G_ACTION (action));
200 show = ! g_variant_get_boolean (state);
201#else
202 show = gtk_check_menu_item_get_active ((GtkCheckMenuItem *)widg);
203 if (widg != view -> ogl_clones[5]) gtk_check_menu_item_set_active ((GtkCheckMenuItem *)view -> ogl_clones[5], show);
204#endif
205 view -> anim -> last -> img -> cloned_poly = show;
206 int shaders[2] = {POLYS, RINGS};
208 update (view);
209#ifdef GTK4
210 g_action_change_state (G_ACTION (action), g_variant_new_boolean (show));
211 g_variant_unref (state);
212#endif
213 }
214}
215
216
217#ifdef GTK3
227GtkWidget * mpoly (glwin * view, int jd, int id)
228{
229 int i, j;
230 project * this_proj = get_project_by_id(view -> proj);
231 GtkWidget * menup = gtk_menu_new ();
232 if (is_coord_in_menu(id, this_proj))
233 {
234 GtkWidget * pshow = create_menu_item (FALSE, "Show/Hide");
235 GtkWidget * widg;
236 gtk_menu_shell_append ((GtkMenuShell *)menup, pshow);
237 GtkWidget * menus = gtk_menu_new ();
238 gtk_menu_item_set_submenu ((GtkMenuItem *)pshow, menus);
239 j = (id < 2) ? this_proj -> nspec : this_proj -> coord -> totcoord[id];
240 for (i=0; i<j; i++)
241 {
242 if (id < 2)
243 {
244 if (GTK_IS_WIDGET(view -> oglmpv[jd][id][i]))
245 {
246 widg = gtk_widget_get_parent (view -> oglmpv[jd][id][i]);
247 if (GTK_IS_WIDGET(widg))
248 {
249 g_object_ref (view -> oglmpv[jd][id][i]);
250 gtk_container_remove (GTK_CONTAINER(widg), view -> oglmpv[jd][id][i]);
251 }
252 gtk_menu_shell_append ((GtkMenuShell *)menus, view -> oglmpv[jd][id][i]);
253 }
254 }
255 else
256 {
257 if (GTK_IS_WIDGET(view -> ogl_poly[jd][id][i]))
258 {
259 widg = gtk_widget_get_parent (view -> ogl_poly[jd][id][i]);
260 if (GTK_IS_WIDGET(widg))
261 {
262 g_object_ref (view -> ogl_poly[jd][id][i]);
263 gtk_container_remove (GTK_CONTAINER(widg), view -> ogl_poly[jd][id][i]);
264 }
265 gtk_menu_shell_append ((GtkMenuShell *)menus, view -> ogl_poly[jd][id][i]);
266 }
267 }
268 }
269 }
270 add_advanced_item (menup, G_CALLBACK(coord_properties), (gpointer)& view -> colorp[id][0], FALSE, 0, 0);
271 return menup;
272}
273
284GtkWidget * menupoly (glwin * view, int jd, int id, gchar * poln)
285{
286 int i;
287 GtkWidget * item;
288 if (id > 1)
289 {
290 GtkWidget * menui = gtk_menu_new ();
291 if (view -> rings)
292 {
293 for (i=0; i<5; i++)
294 {
295 if (view -> ring_max[i])
296 {
297 if (jd == 0)
298 {
299 view -> ogl_rings[7+i] = create_menu_item (TRUE, rings_type[i]);
300 gtk_menu_item_set_submenu ((GtkMenuItem *)view -> ogl_rings[7+i], mpoly(view, jd, 4+i));
301 gtk_menu_shell_append ((GtkMenuShell *)menui, view -> ogl_rings[7+i]);
302 }
303 else
304 {
305 item = create_menu_item (TRUE, rings_type[i]);
306 gtk_menu_shell_append ((GtkMenuShell *)menui, item);
307 gtk_menu_item_set_submenu ((GtkMenuItem *)item, mpoly(view, jd, 4+i));
308 }
309 }
310 }
311 }
312 return menui;
313 }
314 else
315 {
316 GtkWidget * poly = create_menu_item (TRUE, poln);
317 gtk_menu_item_set_submenu ((GtkMenuItem *)poly, mpoly (view, jd, id));
318 return poly;
319 }
320}
321
330GtkWidget * menu_poly (glwin * view, int id)
331{
332 GtkWidget * menup = gtk_menu_new ();
333 gtk_menu_shell_append ((GtkMenuShell *)menup, menupoly(view, id, 0, "Total Coordination(s)"));
334 gtk_menu_shell_append ((GtkMenuShell *)menup, menupoly(view, id, 1, "Partial Coordination(s)"));
335 if (id == 0)
336 {
337 gtk_menu_shell_append ((GtkMenuShell *)menup, view -> ogl_rings[6]);
338 widget_set_sensitive (view -> ogl_rings[6], view -> rings);
339 view -> ogl_clones[5] = gtk3_menu_item (menup, "Cloned Polyhedra", IMG_NONE, NULL, G_CALLBACK(cloned_poly), view, FALSE, 0, 0, TRUE, FALSE, view -> anim -> last -> img -> cloned_poly);
340 }
341 else
342 {
343 GtkWidget * item = create_menu_item (FALSE, "Ring(s)");
344 gtk_menu_item_set_submenu ((GtkMenuItem *)item, menupoly(view, id, 2, NULL));
345 gtk_menu_shell_append ((GtkMenuShell *)menup, item);
346 widget_set_sensitive (item, view -> rings);
347 GtkWidget * cloned_p = gtk3_menu_item (menup, "Cloned Polyhedra", IMG_NONE, NULL, G_CALLBACK(cloned_poly), view, FALSE, 0, 0, TRUE, FALSE, view -> anim -> last -> img -> cloned_poly);
348 widget_set_sensitive ((cloned_p), get_project_by_id(view -> proj) -> cell.pbc);
349 }
350 return menup;
351}
352#else
362GMenu * menu_show_coord_poly (glwin * view, int popm, int id)
363{
364 GMenu * menu = g_menu_new ();
365 GMenu * menus;
366 project * this_proj = get_project_by_id (view -> proj);
367 gchar * stra, * strb;
368 int i, j, k;
369 for (i=0; i<this_proj -> nspec; i++)
370 {
371 j = 0;
372 menus = g_menu_new ();
373 if (this_proj -> coord)
374 {
375 if (this_proj -> coord -> ntg[id])
376 {
377 for (k=0; k<i; k++)
378 {
379 j += this_proj -> coord -> ntg[id][k];
380 }
381 for (k=0; k < this_proj -> coord -> ntg[id][i]; k++)
382 {
383 if (id)
384 {
385 stra = exact_name (env_name (this_proj, k, i, 1, NULL));
386 }
387 else
388 {
389 stra = g_strdup_printf ("%d", this_proj -> coord -> geolist[id][i][k]);
390 }
391 strb = g_strdup_printf ("%s-%d-p", stra, id);
392 append_opengl_item (view, menus, stra, strb, popm, k+j, NULL, IMG_NONE, NULL, FALSE, G_CALLBACK(show_hide_poly), & view -> gcid[id][k+j][id],
393 TRUE, view -> anim -> last -> img -> show_poly[id][k+j], FALSE, TRUE);
394 g_free (stra);
395 g_free (strb);
396 }
397 }
398 }
399 append_submenu (menu, this_proj -> chemistry -> label[i], menus);
400 g_object_unref (menus);
401 }
402 return menu;
403}
404
414GMenu * menu_show_rings_poly (glwin * view, int popm, int id)
415{
416 GMenu * menu = g_menu_new ();
417 project * this_proj = get_project_by_id (view -> proj);
418 if (this_proj -> coord)
419 {
420 int i;
421 gchar * stra, * strb;
422 for (i=0; i<this_proj -> coord -> totcoord[id]; i++)
423 {
424 stra = g_strdup_printf ("%d", this_proj -> coord -> geolist[id][0][i]);
425 strb = g_strdup_printf ("%d-%s-p", id, stra);
426 append_opengl_item (view, menu, stra, strb, popm, i, NULL, IMG_NONE, NULL, FALSE, G_CALLBACK(show_hide_poly), & view -> gcid[id][i][id],
427 TRUE, view -> anim -> last -> img -> show_poly[id][i], FALSE, TRUE);
428 g_free (stra);
429 g_free (strb);
430 }
431 }
432 return menu;
433}
434
444GMenu * add_menu_poly (glwin * view, int popm, int aid)
445{
446 GMenu * menu = g_menu_new ();
447 if (aid < 2)
448 {
449 append_submenu (menu, "Show/Hide", menu_show_coord_poly (view, popm, aid));
450 }
451 else
452 {
453 append_submenu (menu, "Show/Hide", menu_show_rings_poly (view, popm, aid));
454 }
455 append_opengl_item (view, menu, "Advanced", "adv-p", popm, aid, NULL, IMG_STOCK, (gpointer)DPROPERTIES, FALSE,
456 G_CALLBACK(to_coord_properties), & view -> colorp[aid][0], FALSE, FALSE, FALSE, TRUE);
457 return menu;
458}
459
468GMenu * menu_poly_rings (glwin * view, int popm)
469{
470 GMenu * menu = g_menu_new ();
471 int i;
472 for (i=0; i<5; i++)
473 {
474 if (view -> ring_max[i])
475 {
476 append_submenu (menu, rings_type[i], add_menu_poly(view, popm, 4+i));
477 }
478 }
479 return menu;
480}
481
490GMenu * menu_poly (glwin * view, int popm)
491{
492 GMenu * menu = g_menu_new ();
493 append_submenu (menu, "Total Coordination(s)", add_menu_poly (view, popm, 0));
494 append_submenu (menu, "Partial Coordination(s)", add_menu_poly (view, popm, 1));
495 if (view -> rings)
496 {
497 append_submenu (menu, "Rings(s)", menu_poly_rings (view, popm));
498 }
499 else
500 {
501 append_menu_item (menu, "Ring(s)", "None", NULL, NULL, IMG_NONE, NULL, FALSE, FALSE, FALSE, NULL);
502 }
503 append_opengl_item (view, menu, "Cloned Polyhedra", "cloned-poly", popm, popm, NULL, IMG_NONE, NULL, FALSE,
504 G_CALLBACK(cloned_poly), view, TRUE, view -> anim -> last -> img -> cloned_poly, FALSE, view -> allbonds[1]);
505 return menu;
506}
507#endif
integer(kind=c_int) function chemistry()
Definition chemistry.F90:22
color colorp[64]
void label(cairo_t *cr, double val, int axe, int p, project *this_proj)
draw axis label
Definition labels.c:56
char * rings_type[5]
Definition global.c:143
Global variable declarations Global convenience function declarations Global data structure defin...
@ IMG_NONE
Definition global.h:260
@ IMG_STOCK
Definition global.h:264
GtkWidget * gtk3_menu_item(GtkWidget *menu, gchar *name, int icon_format, gpointer item_icon, GCallback handler, gpointer data, gboolean accel, guint key, GdkModifierType mod, gboolean check, gboolean radio, gboolean status)
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
GtkWidget * add_advanced_item(GtkWidget *menu, GCallback handler, gpointer data, gboolean accel, guint key, GdkModifierType mod)
#define DPROPERTIES
Definition global.h:206
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)
void append_menu_item(GMenu *menu, const gchar *label, const gchar *action, const gchar *accel, const gchar *custom, int format, const gchar *icon, gboolean check, gboolean status, gboolean radio, const gchar *rstatus)
create a menu item, then append it to a menu
Definition gui.c:758
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
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...
void re_create_md_shaders(int nshaders, int shaders[nshaders], project *this_proj)
re-initialize some MD dependent OpenGL shaders
action
Definition glview.h:189
gboolean is_coord_in_menu(int id, project *this_proj)
is this coordination in a menu ?
Definition m_coord.c:74
shaders
The different types of shaders in the atomes program.
Definition glwin.h:88
@ POLYS
Definition glwin.h:92
@ RINGS
Definition glwin.h:96
GtkWidget * menupoly(glwin *view, int jd, int id, gchar *poln)
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)
gchar * env_name(project *this_proj, int g, int s, int f, GtkTextBuffer *buffer)
ouput the name of a coordination sphere
Definition interface.c:889
gchar * exact_name(gchar *name)
short cut to print string without spaces
Definition interface.c:370
Messaging function declarations.
G_MODULE_EXPORT void to_coord_properties(GSimpleAction *action, GVariant *parameter, gpointer data)
open advancedd coordination properties GTK4 callback
Definition m_coord.c:557
G_MODULE_EXPORT void show_hide_poly(GtkWidget *widg, gpointer data)
show / hide polyhedra callback - GTK3
Definition m_poly.c:79
G_MODULE_EXPORT void coord_properties(GtkWidget *widg, gpointer data)
create the environments configuration window
Definition w_coord.c:1469
G_MODULE_EXPORT void cloned_poly(GtkWidget *widg, gpointer data)
cloned polyehdra callback - GTK3
Definition m_poly.c:181
GMenu * add_menu_poly(glwin *view, int popm, int aid)
create the 'Show/Hide' polyhedra subemnus - GTK4
Definition m_poly.c:444
GMenu * menu_poly_rings(glwin *view, int popm)
create the 'Polyhedra -> Ring(s)' submenu - GTK4
Definition m_poly.c:468
GMenu * menu_poly(glwin *view, int popm)
create the 'Chemistry -> Polyehdra' submenu - GTK4
Definition m_poly.c:490
GMenu * menu_show_coord_poly(glwin *view, int popm, int id)
create the 'Polyedra -> Coordination -> Show/Hide' submenus - GTK4
Definition m_poly.c:362
GMenu * menu_show_rings_poly(glwin *view, int popm, int id)
create the 'Rings(s) -> Show/Hide' subemnus - GTK4
Definition m_poly.c:414
Definition glwin.h:875
Definition global.h:112
int b
Definition tab-1.c:95
int c
Definition tab-1.c:95
int d
Definition tab-1.c:95
int a
Definition tab-1.c:95
GtkWidget * img
Definition workspace.c:70