atomes 1.1.14
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
m_clones.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_clones.c'
24*
25* Contains:
26*
27
28 - The functions to create the 'Model -> Clone(s)' submenu
29
30*
31* List of functions:
32
33 G_MODULE_EXPORT void show_hide_clones (GtkWidget * widg, gpointer data);
34 G_MODULE_EXPORT void show_hide_clones (GSimpleAction * action, GVariant * parameter, gpointer data);
35
36 GtkWidget * create_clone_widget (char * name, gboolean clone, GtkWidget * menu, glwin * view);
37 GtkWidget * menu_clones (glwin * view, int id);
38
39 GMenu * menu_clones (glwin * view, int popm);
40
41*/
42
43#include "global.h"
44#include "glview.h"
45#include "glwindow.h"
46#include "submenus.h"
47
48#ifdef GTK3
57G_MODULE_EXPORT void show_hide_clones (GtkWidget * widg, gpointer data)
58{
59 glwin * view = (glwin *)data;
60 gboolean j;
61 j = gtk_check_menu_item_get_active ((GtkCheckMenuItem *)widg);
62 if (widg != view -> ogl_clones[0])
63 {
64 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)view -> ogl_clones[0], j);
65 }
66 view -> anim -> last -> img -> draw_clones = j;
67 widget_set_sensitive (view -> ogl_atoms[5], j);
68 widget_set_sensitive (view -> ogl_atoms[7], j);
69 widget_set_sensitive (view -> ogl_bonds[9], j);
70 widget_set_sensitive (view -> ogl_bonds[11], j);
71 widget_set_sensitive (view -> ogl_bonds[13], j);
72 widget_set_sensitive (view -> ogl_clones[1], j);
73 widget_set_sensitive (view -> ogl_clones[2], j);
74 widget_set_sensitive (view -> ogl_clones[3], j);
75 widget_set_sensitive (view -> ogl_clones[4], j);
76 int i;
77 for (i=0; i<get_project_by_id(view -> proj) -> nspec; i++)
78 {
79 widget_set_sensitive (view -> ogl_spec[1][i], j);
80 widget_set_sensitive (view -> ogl_lab[1][i], j);
81 }
83 update (view);
84}
85
96GtkWidget * create_clone_widget (char * name, gboolean clone, GtkWidget * menu, glwin * view)
97{
98 GtkWidget * clone_widget = gtk3_menu_item (menu, name, IMG_NONE, NULL, G_CALLBACK(show_hide_clones), view, FALSE, 0, 0, TRUE, FALSE, clone);
99 widget_set_sensitive (clone_widget, view -> allbonds[1]);
100 return clone_widget;
101}
102
111GtkWidget * menu_clones (glwin * view, int id)
112{
113 GtkWidget * menu = gtk_menu_new ();
114 if (id == 0)
115 {
116 view -> ogl_clones[0] = create_clone_widget ("Show/Hide", view -> anim -> last -> img -> draw_clones, menu, view);
117 }
118 else
119 {
120 create_clone_widget ("Show/Hide", view -> anim -> last -> img -> draw_clones, menu, view);
121 }
122 gtk_menu_shell_append ((GtkMenuShell *)menu, menu_item_new_with_submenu ("Atom(s)", TRUE, menu_atoms (view, id, 1)));
123 if ((id == 0) || (view -> anim -> last -> img -> style != SPHERES && view -> anim -> last -> img -> style != PUNT))
124 {
125 gtk_menu_shell_append ((GtkMenuShell *)menu, menu_item_new_with_submenu ("Bond(s)", TRUE, menu_bonds (view, id, 1)));
126 }
127 return menu;
128}
129#else
139G_MODULE_EXPORT void show_hide_clones (GSimpleAction * action, GVariant * parameter, gpointer data)
140{
141 glwin * view = (glwin *)data;
142 const gchar * name = g_action_get_name ((GAction *)action);
143 if (g_strcmp0(name, "set-show-clones.1.1") == 0)
144 {
145 g_action_group_activate_action ((GActionGroup *)view -> action_group, "set-show-clones.0.0", NULL);
146 }
147 else
148 {
149 GVariant * state;
150 gboolean show;
151 if (action)
152 {
153 state = g_action_get_state (G_ACTION (action));
154 show = ! g_variant_get_boolean (state);
155 }
156 else
157 {
158 show = ! view -> anim -> last -> img -> draw_clones;
159 }
160 view -> anim -> last -> img -> draw_clones = show;
162 update (view);
163 // Update the menu bar is reqiured to udpate the clone(s) submenus
164 update_menu_bar (view);
165 if (action)
166 {
167 g_variant_unref (state);
168 }
169 }
170}
171
180GMenu * menu_clones (glwin * view, int popm)
181{
182 GMenu * menu = g_menu_new ();
183 append_opengl_item (view, menu, "Show/Hide", "show-clones", popm, popm, NULL, IMG_NONE, NULL, FALSE,
184 G_CALLBACK(show_hide_clones), (gpointer)view, TRUE, view -> anim -> last -> img -> draw_clones, FALSE, (view -> allbonds[1]) ? TRUE : FALSE);
185 append_submenu (menu, "Atom(s)", menu_atoms(view, popm, 1));
186 if (view -> anim -> last -> img -> style != SPHERES && view -> anim -> last -> img -> style != PUNT)
187 {
188 append_submenu (menu, "Bonds(s)", menu_bonds(view, popm, 1));
189 }
190 return menu;
191}
192#endif
void init_default_shaders(glwin *view)
re-initialize the default OpenGL shaders
Global variable declarations Global convenience function declarations Global data structure defin...
@ IMG_NONE
Definition global.h:232
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:602
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:186
GtkWidget * menu_item_new_with_submenu(gchar *name, gboolean active, GtkWidget *sub_menu)
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...
action
Definition glview.h:189
@ SPHERES
Definition glview.h:176
@ PUNT
Definition glview.h:178
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)
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
G_MODULE_EXPORT void show_hide_clones(GSimpleAction *action, GVariant *parameter, gpointer data)
show/hide clones menu item callback
Definition m_clones.c:139
GMenu * menu_clones(glwin *view, int popm)
create the 'Clone(s)' submenu GTK4
Definition m_clones.c:180
Definition glwin.h:875
Function declarations for the creation of the OpenGL window menus.
GtkWidget * img
Definition workspace.c:70