atomes 1.1.14
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);
68GSimpleActionGroup * view_pop_actions;
69
79G_MODULE_EXPORT void to_opengl_advanced (GSimpleAction * action, GVariant * parameter, gpointer data)
80{
81 opengl_advanced (NULL, data);
82}
83
93G_MODULE_EXPORT void to_render_gl_image (GSimpleAction * action, GVariant * parameter, gpointer data)
94{
95 render_gl_image (NULL, data);
96}
97
123void append_opengl_item (glwin * view, GMenu * menu, const gchar * name, const gchar * key, int mpop, int item_id,
124 gchar * accel, int image_format, gpointer icon,
125 gboolean custom, GCallback handler, gpointer data,
126 gboolean check, gboolean status, gboolean radio, gboolean sensitive)
127{
128 gchar * str_a, * str_b, * str_c;
129 str_a = g_strdup_printf ("set-%s", key);
130 str_b = g_strdup_printf ("%s.%d.%d", str_a, item_id, mpop);
131 str_c = (sensitive) ? g_strdup_printf ("gl-%d.%s", view -> action_id, (radio) ? str_a : str_b) : g_strdup_printf ("None");
132 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);
133 if (handler)
134 {
135 if (! radio || (radio && status))
136 {
137 if (! opengl_project)
138 {
139 widget_add_action (view -> action_group, (radio) ? (const gchar *)str_a : (const gchar *)str_b, handler, data,
140 check, status, radio, (const gchar *)str_b);
141 }
142 else
143 {
144 widget_add_action (view_pop_actions, (radio) ? (const gchar *)str_a : (const gchar *)str_b, handler, data,
145 check, status, radio, (const gchar *)str_b);
146 }
147 }
148 }
149 g_free (str_a);
150 g_free (str_b);
151 g_free (str_c);
152}
153
162GMenu * prepare_opengl_menu (glwin * view, int popm)
163{
164 GMenu * menu = g_menu_new ();
165 append_submenu (menu, "Style", menu_style(view, popm));
166 GMenuItem * item = g_menu_item_new ("Color Scheme(s)", (get_project_by_id(view -> proj) -> nspec) ? NULL : "None");
167 g_menu_item_set_submenu (item, (GMenuModel*)menu_map(view, popm));
168 g_menu_append_item (menu, item);
169 append_submenu (menu, "Render", menu_render(view, popm));
170 append_submenu (menu, "Quality", menu_quality(view, popm));
171 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);
172 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);
173 return menu;
174}
175
184GMenu * prepare_model_menu (glwin * view, int popm)
185{
186 GMenu * menu = g_menu_new ();
187 append_submenu (menu, "Atom(s)", menu_atoms(view, popm, 0));
188 append_submenu (menu, "Bond(s)", menu_bonds(view, popm, 0));
189 append_submenu (menu, "Clone(s)", menu_clones(view, popm));
190 g_menu_append_item (menu, menu_box_axis (view, popm, 0));
191 return menu;
192}
193
202GMenu * prepare_coord_menu (glwin * view, int popm)
203{
204 GMenu * menu = g_menu_new ();
205 append_submenu (menu, "Coordination", menu_coord (view, popm));
206 append_submenu (menu, "Polyhedra", menu_poly (view, popm));
207 if (view -> rings)
208 {
209 append_submenu (menu, "Rings(s)", menu_rings (view, popm));
210 }
211 else
212 {
213 append_menu_item (menu, "Ring(s)", "None", NULL, NULL, IMG_NONE, NULL, FALSE, FALSE, FALSE, NULL);
214 }
215 if (view -> chains)
216 {
217 append_submenu (menu, "Chain(s)", add_menu_coord (view, popm, 9));
218 }
219 else
220 {
221 append_menu_item (menu, "Chain(s)", "None", NULL, NULL, IMG_NONE, NULL, FALSE, FALSE, FALSE, NULL);
222 }
223 if (view -> adv_bonding[0])
224 {
225 append_submenu (menu, "Fragment(s)", add_menu_coord (view, popm, 2));
226 }
227 else
228 {
229 append_menu_item (menu, "Fragment(s)", "None", NULL, NULL, IMG_NONE, NULL, FALSE, FALSE, FALSE, NULL);
230 }
231 if (view -> adv_bonding[1])
232 {
233 append_submenu (menu, "Molecule(s)", add_menu_coord (view, popm, 3));
234 }
235 else
236 {
237 append_menu_item (menu, "Molecule(s)", "None", NULL, NULL, IMG_NONE, NULL, FALSE, FALSE, FALSE, NULL);
238 }
239 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);
240 return menu;
241}
242
250GMenu * opengl_menu_bar (glwin * view)
251{
252 GMenu * menu = g_menu_new ();
253 append_submenu (menu, "OpenGL", prepare_opengl_menu(view, 0));
254 if (get_project_by_id(view -> proj) -> natomes)
255 {
256 append_submenu (menu, "Model", prepare_model_menu(view, 0));
257 append_submenu (menu, "Chemistry", prepare_coord_menu(view, 0));
258 }
259 else
260 {
261 append_menu_item (menu, "Model", "None", NULL, NULL, IMG_NONE, NULL, FALSE, FALSE, FALSE, NULL);
262 append_menu_item (menu, "Chemistry", "None", NULL, NULL, IMG_NONE, NULL, FALSE, FALSE, FALSE, NULL);
263 }
264 append_submenu (menu, "Tools", menu_tools(view, 0));
265 append_submenu (menu, "View", menu_view(view, 0));
266 append_submenu (menu, "Animate", menu_anim(view, 0));
267 return menu;
268}
269
278void menu_bar_attach_color_palettes (glwin * view, GtkWidget * menu_bar)
279{
280 /* Here we need to attached color palettes for:
281 - Box
282 - Atoms
283 - Clones
284 - Total coordination(s)
285 - Partial coordination(s)
286 - Fragment(s) and molecule(s)
287 - Ring(s)
288 - Background
289 This is a work in progress since the 'gtk_popover_menu_bar_add_child' to use to insert widget is bugged:
290 https://gitlab.gnome.org/GNOME/gtk/-/issues/5955
291 */
292 int i, j, k, l, m;
293 gchar * str;
294 project * this_proj = get_project_by_id (view -> proj);
295 // Box
296 if (! gtk_popover_menu_bar_add_child ((GtkPopoverMenuBar *)menu_bar, color_palette (view, -1, -1, -1), "set-box-color.0"))
297 {
298 g_debug ("Color palette error: box - custom= set-box-color.0");
299 }
300 // Atom(s) and clone(s)
301 for (i=0; i<2; i++)
302 {
303 for (j=0; j<this_proj -> nspec; j++)
304 {
305 str = g_strdup_printf ("set-%s.%d", (! i) ? "atom-color" : "clone-color", j);
306 if (! gtk_popover_menu_bar_add_child ((GtkPopoverMenuBar *)menu_bar, color_palette (view, i*this_proj -> nspec+j, -1, -1), (const gchar *)str))
307 {
308 g_debug ("Color palette error: %s - %d - custom= %s", (! i) ? "atom-color" : "clone-color", j+1, str);
309 }
310 g_free (str);
311 }
312 }
313 // Coordinations
314 for (i=0; i<2; i++)
315 {
316 if (this_proj -> coord -> ntg[i])
317 {
318 for (j=0; j<this_proj -> nspec; j++)
319 {
320 for (k=0; k<this_proj -> coord -> ntg[i][j]; k++)
321 {
322 m = 0;
323 for (l=0; l<j; l++)
324 {
325 m += this_proj -> coord -> ntg[i][l];
326 }
327 if (i)
328 {
329 str = g_strdup_printf ("set-%s-c.%d", exact_name (env_name (this_proj, k, j, 1, NULL)), m);
330 }
331 else
332 {
333 str = g_strdup_printf ("set-%d-c.%d", this_proj -> coord -> geolist[i][j][k], m);
334 }
335 m += (i) ? this_proj -> coord -> totcoord[0] : 0;
336 if (! gtk_popover_menu_bar_add_child ((GtkPopoverMenuBar *)menu_bar, color_palette (view, 2*this_proj -> nspec+m, -1, -1), (const gchar *)str))
337 {
338 g_debug ("Color palette error: %s - spec= %d - coord= %d, custom= %s", (! i) ? "total-coord" : "partial-coord", j+1, k+1, str);
339 }
340 g_free (str);
341 }
342 }
343 }
344 }
345 // Fragment(s) and molecule(s)
346 for (i=2; i<4; i++)
347 {
348 for (j=0; j<this_proj -> coord -> totcoord[i]; j++)
349 {
350 str = g_strdup_printf ("set-%s-%d", (i == 2) ? "fcol" : "mcol", j);
351 k = 2*this_proj -> nspec + this_proj -> coord -> totcoord[0] + this_proj -> coord -> totcoord[1] + j;
352 if (i == 3) k += this_proj -> coord -> totcoord[2];
353 if (! gtk_popover_menu_bar_add_child ((GtkPopoverMenuBar *)menu_bar, color_palette (view, k, i, 0), (const gchar *)str))
354 {
355 g_debug ("Color palette error: %s - %d, custom= %s", (i == 2) ? "fragment" : "molecule", j+1, str);
356 }
357 g_free (str);
358 }
359 }
360 // Rings
361 for (i=4; i<9; i++)
362 {
363 for (j=0; j<this_proj -> coord -> totcoord[i]; j++)
364 {
365 str = g_strdup_printf ("set-rcol-%d-%d", i, j);
366 if (! gtk_popover_menu_bar_add_child ((GtkPopoverMenuBar *)menu_bar, color_palette (view, -3, i-4, 0), (const gchar *)str))
367 {
368 g_debug ("Color palette error: rings - %d - %d, custom= %s", i, j+1, str);
369 }
370 g_free (str);
371 }
372 }
373 // Background
374 if (! gtk_popover_menu_bar_add_child ((GtkPopoverMenuBar *)menu_bar, color_palette (view, -2, -1, -1), "set-back-color.0"))
375 {
376 g_debug ("Color palette error: background - custom= set-back-color.0");
377 }
378}
379
387GtkWidget * opengl_window_create_menu_bar (glwin * view)
388{
389 view -> menu_bar = destroy_this_widget (view -> menu_bar);
390 if (view -> action_group) g_object_unref (view -> action_group);
391 view -> action_group = g_simple_action_group_new ();
392 opengl_project = NULL;
393
394 GtkWidget * menu_bar = gtk_popover_menu_bar_new_from_model ((GMenuModel *)opengl_menu_bar(view));
395 menu_bar_attach_color_palettes (view, menu_bar);
397 gchar * str = g_strdup_printf ("gl-%d", view -> action_id);
398 gtk_widget_insert_action_group (menu_bar, str, G_ACTION_GROUP(view -> action_group));
399 g_free (str);
400
401
402 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, view -> menu_box, menu_bar, FALSE, FALSE, 0);
403
404 show_the_widgets (menu_bar);
405 return menu_bar;
406}
407
415void update_menu_bar (glwin * view)
416{
417 view -> menu_bar = opengl_window_create_menu_bar (view);
418}
419#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]
int activev
Definition global.c:160
Global variable declarations Global convenience function declarations Global data structure defin...
@ IMG_NONE
Definition global.h:232
@ IMG_STOCK
Definition global.h:236
@ IMG_FILE
Definition global.h:235
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:515
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:602
#define DPROPERTIES
Definition global.h:178
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 * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2010
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:632
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:169
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 render_gl_image(GtkWidget *widg, gpointer data)
render image from the OpenGL window
Definition glwindow.c:331
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)
int status
Definition w_advance.c:160