atomes 1.1.15
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
menu_bar.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
23/*
24* This file: 'menu_bar.c'
25*
26* Contains:
27*
28
29 - The functions to create the menu bar of the OpenGL window
30 - The functions to create the menu items for the menu bar and the pop up menu
31
32*
33* List of functions:
34
35 void append_opengl_item (glwin * view, GMenu * menu, const gchar * name, const gchar * key, int mpop, int item_id,
36 gchar * accel, int image_format, gpointer icon,
37 gboolean custom, GCallback handler, gpointer data,
38 gboolean check, gboolean status, gboolean radio, gboolean sensitive);
39 void menu_bar_attach_color_palettes (glwin * view, GtkWidget * menu_bar);
40 void update_menu_bar (glwin * view);
41
42 G_MODULE_EXPORT void to_opengl_advanced (GSimpleAction * action, GVariant * parameter, gpointer data);
43 G_MODULE_EXPORT void to_render_gl_image (GSimpleAction * action, GVariant * parameter, gpointer data);
44
45 GtkWidget * opengl_window_create_menu_bar (glwin * view);
46
47 GMenu * prepare_opengl_menu (glwin * view, int popm);
48 GMenu * prepare_model_menu (glwin * view, int popm);
49 GMenu * prepare_coord_menu (glwin * view, int popm);
50 GMenu * opengl_menu_bar (glwin * view);
51
52*/
53
54#include "global.h"
55#include "interface.h"
56#include "project.h"
57#include "calc.h"
58#include "glview.h"
59#include "initcoord.h"
60#include "submenus.h"
61#include "color_box.h"
62
63#ifdef GTK4
64extern GtkWidget * color_palette (glwin * view, int ideo, int spec, int geo);
65extern G_MODULE_EXPORT void opengl_advanced (GtkWidget * widg, gpointer data);
66extern G_MODULE_EXPORT void render_gl_image (GtkWidget * widg, gpointer data);
67extern G_MODULE_EXPORT void to_coord_properties (GSimpleAction * action, GVariant * parameter, gpointer data);
68extern G_MODULE_EXPORT void view_shortcuts (GSimpleAction * action, GVariant * parameter, gpointer data);
69GSimpleActionGroup * view_pop_actions;
70
80G_MODULE_EXPORT void to_opengl_advanced (GSimpleAction * action, GVariant * parameter, gpointer data)
81{
82 opengl_advanced (NULL, data);
83}
84
94G_MODULE_EXPORT void to_render_gl_image (GSimpleAction * action, GVariant * parameter, gpointer data)
95{
96 render_gl_image (NULL, data);
97}
98
124void append_opengl_item (glwin * view, GMenu * menu, const gchar * name, const gchar * key, int mpop, int item_id,
125 gchar * accel, int image_format, gpointer icon,
126 gboolean custom, GCallback handler, gpointer data,
127 gboolean check, gboolean status, gboolean radio, gboolean sensitive)
128{
129 gchar * str_a, * str_b, * str_c;
130 str_a = g_strdup_printf ("set-%s", key);
131 str_b = g_strdup_printf ("%s.%d.%d", str_a, item_id, mpop);
132 str_c = (sensitive) ? g_strdup_printf ("gl-%d.%s", view -> action_id, (radio) ? str_a : str_b) : g_strdup_printf ("None");
133 append_menu_item (menu, name, (const gchar *) str_c, accel, (custom) ? (const gchar *) str_b : NULL, image_format, icon, check, status, radio, (radio) ? (const gchar *)str_b : NULL);
134 if (handler)
135 {
136 if (! radio || (radio && status))
137 {
138 if (! opengl_project)
139 {
140 widget_add_action (view -> action_group, (radio) ? (const gchar *)str_a : (const gchar *)str_b, handler, data,
141 check, status, radio, (const gchar *)str_b);
142 }
143 else
144 {
145 widget_add_action (view_pop_actions, (radio) ? (const gchar *)str_a : (const gchar *)str_b, handler, data,
146 check, status, radio, (const gchar *)str_b);
147 }
148 }
149 }
150 g_free (str_a);
151 g_free (str_b);
152 g_free (str_c);
153}
154
163GMenu * prepare_opengl_menu (glwin * view, int popm)
164{
165 GMenu * menu = g_menu_new ();
166 append_submenu (menu, "Style", menu_style(view, popm));
167 GMenuItem * item = g_menu_item_new ("Color Scheme(s)", (get_project_by_id(view -> proj) -> nspec) ? NULL : "None");
168 g_menu_item_set_submenu (item, (GMenuModel*)menu_map(view, popm));
169 g_menu_append_item (menu, item);
170 append_submenu (menu, "Render", menu_render(view, popm));
171 append_submenu (menu, "Quality", menu_quality(view, popm));
172 append_opengl_item (view, menu, "Material And Lights", "material", popm, popm, NULL, IMG_NONE, NULL, FALSE, G_CALLBACK(to_opengl_advanced), (gpointer)view, FALSE, FALSE, FALSE, TRUE);
173 append_opengl_item (view, menu, "Render Image", "image", popm, popm, "<CTRL>I", IMG_FILE, PACKAGE_IMG, FALSE, G_CALLBACK(to_render_gl_image), (gpointer)view, FALSE, FALSE, FALSE, TRUE);
174 return menu;
175}
176
185GMenu * prepare_model_menu (glwin * view, int popm)
186{
187 GMenu * menu = g_menu_new ();
188 append_submenu (menu, "Atom(s)", menu_atoms(view, popm, 0));
189 append_submenu (menu, "Bond(s)", menu_bonds(view, popm, 0));
190 append_submenu (menu, "Clone(s)", menu_clones(view, popm));
191 g_menu_append_item (menu, menu_box_axis (view, popm, 0));
192 return menu;
193}
194
203GMenu * prepare_coord_menu (glwin * view, int popm)
204{
205 GMenu * menu = g_menu_new ();
206 append_submenu (menu, "Coordination", menu_coord (view, popm));
207 append_submenu (menu, "Polyhedra", menu_poly (view, popm));
208 if (view -> rings)
209 {
210 append_submenu (menu, "Rings(s)", menu_rings (view, popm));
211 }
212 else
213 {
214 append_menu_item (menu, "Ring(s)", "None", NULL, NULL, IMG_NONE, NULL, FALSE, FALSE, FALSE, NULL);
215 }
216 if (view -> chains)
217 {
218 append_submenu (menu, "Chain(s)", add_menu_coord (view, popm, 9));
219 }
220 else
221 {
222 append_menu_item (menu, "Chain(s)", "None", NULL, NULL, IMG_NONE, NULL, FALSE, FALSE, FALSE, NULL);
223 }
224 if (view -> adv_bonding[0])
225 {
226 append_submenu (menu, "Fragment(s)", add_menu_coord (view, popm, 2));
227 }
228 else
229 {
230 append_menu_item (menu, "Fragment(s)", "None", NULL, NULL, IMG_NONE, NULL, FALSE, FALSE, FALSE, NULL);
231 }
232 if (view -> adv_bonding[1])
233 {
234 append_submenu (menu, "Molecule(s)", add_menu_coord (view, popm, 3));
235 }
236 else
237 {
238 append_menu_item (menu, "Molecule(s)", "None", NULL, NULL, IMG_NONE, NULL, FALSE, FALSE, FALSE, NULL);
239 }
240 append_opengl_item (view, menu, "Advanced", "adv-all", popm, popm, "<CTRL>E", IMG_STOCK, (gpointer)DPROPERTIES, FALSE, G_CALLBACK(to_coord_properties), & view -> colorp[30][0], FALSE, FALSE, FALSE, TRUE);
241 return menu;
242}
243
252GMenu * menu_shortcuts (glwin * view, int popm)
253{
254 GMenu * menu = g_menu_new ();
255 append_opengl_item (view, menu, "Shortcuts", "shortcuts", popm, popm, NULL, IMG_NONE, NULL, FALSE, G_CALLBACK(view_shortcuts), (gpointer)view, FALSE, FALSE, FALSE, TRUE);
256 return menu;
257}
258
266GMenu * opengl_menu_bar (glwin * view)
267{
268 GMenu * menu = g_menu_new ();
269 append_submenu (menu, "OpenGL", prepare_opengl_menu(view, 0));
270 if (get_project_by_id(view -> proj) -> natomes)
271 {
272 append_submenu (menu, "Model", prepare_model_menu(view, 0));
273 append_submenu (menu, "Chemistry", prepare_coord_menu(view, 0));
274 }
275 else
276 {
277 append_menu_item (menu, "Model", "None", NULL, NULL, IMG_NONE, NULL, FALSE, FALSE, FALSE, NULL);
278 append_menu_item (menu, "Chemistry", "None", NULL, NULL, IMG_NONE, NULL, FALSE, FALSE, FALSE, NULL);
279 }
280 append_submenu (menu, "Tools", menu_tools(view, 0));
281 append_submenu (menu, "View", menu_view(view, 0));
282 append_submenu (menu, "Animate", menu_anim(view, 0));
283 append_submenu (menu, "Help", menu_shortcuts(view, 0));
284 return menu;
285}
286
295void menu_bar_attach_color_palettes (glwin * view, GtkWidget * menu_bar)
296{
297 /* Here we need to attached color palettes for:
298 - Box
299 - Atoms
300 - Clones
301 - Total coordination(s)
302 - Partial coordination(s)
303 - Fragment(s) and molecule(s)
304 - Ring(s)
305 - Background
306 This is a work in progress since the 'gtk_popover_menu_bar_add_child' to use to insert widget is bugged:
307 https://gitlab.gnome.org/GNOME/gtk/-/issues/5955
308 */
309 int i, j, k, l, m;
310 gchar * str;
311 project * this_proj = get_project_by_id (view -> proj);
312 // Box
313 if (! gtk_popover_menu_bar_add_child ((GtkPopoverMenuBar *)menu_bar, color_palette (view, -1, -1, -1), "set-box-color.0"))
314 {
315 g_debug ("Color palette error: box - custom= set-box-color.0");
316 }
317 // Atom(s) and clone(s)
318 for (i=0; i<2; i++)
319 {
320 for (j=0; j<this_proj -> nspec; j++)
321 {
322 str = g_strdup_printf ("set-%s.%d", (! i) ? "atom-color" : "clone-color", j);
323 if (! gtk_popover_menu_bar_add_child ((GtkPopoverMenuBar *)menu_bar, color_palette (view, i*this_proj -> nspec+j, -1, -1), (const gchar *)str))
324 {
325 g_debug ("Color palette error: %s - %d - custom= %s", (! i) ? "atom-color" : "clone-color", j+1, str);
326 }
327 g_free (str);
328 }
329 }
330 // Coordinations
331 for (i=0; i<2; i++)
332 {
333 if (this_proj -> coord -> ntg[i])
334 {
335 for (j=0; j<this_proj -> nspec; j++)
336 {
337 for (k=0; k<this_proj -> coord -> ntg[i][j]; k++)
338 {
339 m = 0;
340 for (l=0; l<j; l++)
341 {
342 m += this_proj -> coord -> ntg[i][l];
343 }
344 if (i)
345 {
346 str = g_strdup_printf ("set-%s-c.%d", exact_name (env_name (this_proj, k, j, 1, NULL)), m);
347 }
348 else
349 {
350 str = g_strdup_printf ("set-%d-c.%d", this_proj -> coord -> geolist[i][j][k], m);
351 }
352 m += (i) ? this_proj -> coord -> totcoord[0] : 0;
353 if (! gtk_popover_menu_bar_add_child ((GtkPopoverMenuBar *)menu_bar, color_palette (view, 2*this_proj -> nspec+m, -1, -1), (const gchar *)str))
354 {
355 g_debug ("Color palette error: %s - spec= %d - coord= %d, custom= %s", (! i) ? "total-coord" : "partial-coord", j+1, k+1, str);
356 }
357 g_free (str);
358 }
359 }
360 }
361 }
362 // Fragment(s) and molecule(s)
363 for (i=2; i<4; i++)
364 {
365 for (j=0; j<this_proj -> coord -> totcoord[i]; j++)
366 {
367 str = g_strdup_printf ("set-%s-%d", (i == 2) ? "fcol" : "mcol", j);
368 k = 2*this_proj -> nspec + this_proj -> coord -> totcoord[0] + this_proj -> coord -> totcoord[1] + j;
369 if (i == 3) k += this_proj -> coord -> totcoord[2];
370 if (! gtk_popover_menu_bar_add_child ((GtkPopoverMenuBar *)menu_bar, color_palette (view, k, i, 0), (const gchar *)str))
371 {
372 g_debug ("Color palette error: %s - %d, custom= %s", (i == 2) ? "fragment" : "molecule", j+1, str);
373 }
374 g_free (str);
375 }
376 }
377 // Rings
378 for (i=4; i<9; i++)
379 {
380 for (j=0; j<this_proj -> coord -> totcoord[i]; j++)
381 {
382 str = g_strdup_printf ("set-rcol-%d-%d", i, j);
383 if (! gtk_popover_menu_bar_add_child ((GtkPopoverMenuBar *)menu_bar, color_palette (view, -3, i-4, 0), (const gchar *)str))
384 {
385 g_debug ("Color palette error: rings - %d - %d, custom= %s", i, j+1, str);
386 }
387 g_free (str);
388 }
389 }
390 // Background
391 if (! gtk_popover_menu_bar_add_child ((GtkPopoverMenuBar *)menu_bar, color_palette (view, -2, -1, -1), "set-back-color.0"))
392 {
393 g_debug ("Color palette error: background - custom= set-back-color.0");
394 }
395}
396
404GtkWidget * opengl_window_create_menu_bar (glwin * view)
405{
406 view -> menu_bar = destroy_this_widget (view -> menu_bar);
407 if (view -> action_group) g_object_unref (view -> action_group);
408 view -> action_group = g_simple_action_group_new ();
409 opengl_project = NULL;
410
411 GtkWidget * menu_bar = gtk_popover_menu_bar_new_from_model ((GMenuModel *)opengl_menu_bar(view));
412 menu_bar_attach_color_palettes (view, menu_bar);
413 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, view -> menu_box, menu_bar, FALSE, FALSE, 0);
415 gchar * str = g_strdup_printf ("gl-%d", view -> action_id);
416 gtk_widget_insert_action_group (view -> menu_box, str, G_ACTION_GROUP(view -> action_group));
417 g_free (str);
418 show_the_widgets (menu_bar);
419 return menu_bar;
420}
421
429void update_menu_bar (glwin * view)
430{
431 view -> menu_bar = opengl_window_create_menu_bar (view);
432}
433#endif
Variable declarations for the MD input preparation assistants.
integer function chains()
Definition chains.F90:54
Structure definitions for color management Function declarations for color management.
color colorp[64]
gchar * PACKAGE_IMG
Definition global.c:81
int activev
Definition global.c:160
Global variable declarations Global convenience function declarations Global data structure defin...
@ IMG_NONE
Definition global.h:260
@ IMG_STOCK
Definition global.h:264
@ IMG_FILE
Definition global.h:263
project * proj
void opengl_project_changed(int id)
change the OpenGL project
Definition update_p.c:245
void widget_add_action(GSimpleActionGroup *action_group, const gchar *act, GCallback handler, gpointer data, gboolean check, gboolean status, gboolean radio, const gchar *stat)
add an action to an action group
Definition gui.c:641
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
#define DPROPERTIES
Definition global.h:206
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:299
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2034
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
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...
action
Definition glview.h:189
G_MODULE_EXPORT void opengl_advanced(GtkWidget *widg, gpointer data)
create OpenGL rendering advanced window
Definition w_advance.c:1477
G_MODULE_EXPORT void view_shortcuts(GtkWidget *widg, gpointer data)
OpenGL window shortcuts callback GTK3.
Definition glwindow.c:455
G_MODULE_EXPORT void render_gl_image(GtkWidget *widg, gpointer data)
render image from the OpenGL window
Definition glwindow.c:429
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)
Function declarations to handle the atomic coordination data.
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.
GMenu * menu_anim(glwin *view, int popm)
create the 'Animate' submenu elements
Definition m_anim.c:139
GMenu * menu_atoms(glwin *view, int popm, int at)
create the 'Atom(s)' submenu elements
Definition m_atoms.c:797
GMenu * menu_bonds(glwin *view, int popm, int at)
create the 'Bond(s)' submenu GTK4
Definition m_bonds.c:367
GMenuItem * menu_box_axis(glwin *view, int popm, int ab)
create the 'Model -> Box' and 'View -> Axis' submenus GTK4
Definition m_box.c:470
GMenu * menu_clones(glwin *view, int popm)
create the 'Clone(s)' submenu GTK4
Definition m_clones.c:180
GMenu * menu_coord(glwin *view, int popm)
create the 'Coordination' submenu GTK4
Definition m_coord.c:689
GMenu * menu_rings(glwin *view, int popm)
create the 'Ring(s)' submenu GTK4
Definition m_coord.c:705
G_MODULE_EXPORT void to_coord_properties(GSimpleAction *action, GVariant *parameter, gpointer data)
open advancedd coordination properties GTK4 callback
Definition m_coord.c:557
GMenu * add_menu_coord(glwin *view, int popm, int id)
create a coordination type submenu
Definition m_coord.c:652
GMenu * menu_map(glwin *view, int popm)
create the 'OpenGL -> Color Scheme(s)' submenu - GTK4
Definition m_map.c:1272
GMenu * menu_poly(glwin *view, int popm)
create the 'Chemistry -> Polyehdra' submenu - GTK4
Definition m_poly.c:490
GMenu * menu_quality(glwin *view, int popm)
create the 'OpenGL -> Quality' menu item - GTK4
Definition m_quality.c:167
GMenu * menu_render(glwin *view, int popm)
create the 'OpenGL -> Render' submenu - GTK4
Definition m_render.c:182
GMenu * menu_view(glwin *view, int popm)
create the 'View' submenu - GTK4
Definition m_rep.c:579
GMenu * menu_style(glwin *view, int popm)
create the 'OpenGL -> Style' submenu - GTK4
Definition m_style.c:433
GMenu * menu_tools(glwin *view, int popm)
create the 'Tools' submenu - GTK4
Definition m_tools.c:770
Function declarations for reading atomes project file Function declarations for saving atomes proje...
Definition glwin.h:875
Function declarations for the creation of the OpenGL window menus.
GMenu * prepare_model_menu(glwin *view, int popm)
GMenu * prepare_coord_menu(glwin *view, int popm)
GMenu * prepare_opengl_menu(glwin *view, int popm)
GMenu * menu_shortcuts(glwin *view, int popm)
int status
Definition w_advance.c:160