atomes 1.1.15
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
m_edit.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_edit.c'
24*
25* Contains:
26*
27
28 - The functions to create the 'Tools -> Edit' submenu
29
30*
31* List of functions:
32
33 G_MODULE_EXPORT void wrapping_coord (GSimpleAction * action, GVariant * parameter, gpointer data);
34 G_MODULE_EXPORT void wrapping_coord (GtkWidget * widg, gpointer data);
35 G_MODULE_EXPORT void to_run_rebuild (GSimpleAction * action, GVariant * parameter, gpointer data);
36
37 GtkWidget * menu_cell_edit (glwin * view , int id, int j);
38 GtkWidget * menu_edit (glwin * view, int id);
39
40 GMenu * menu_cell_edit (glwin * view, int popm, int sensitive);
41 GMenu * menu_atom_edit (glwin * view, int popm);
42 GMenu * extract_section (glwin * view, int popm);
43 GMenu * menu_edit (glwin * view, int popm);
44
45*/
46
47#include "cell_edit.h"
48#include "atom_edit.h"
49
50#ifdef GTK4
51extern G_MODULE_EXPORT void crystal_window (GSimpleAction * action, GVariant * parameter, gpointer data);
52extern G_MODULE_EXPORT void turn_rebuild (GSimpleAction * action, GVariant * parameter, gpointer data);
53#else
54extern G_MODULE_EXPORT void crystal_window (GtkWidget * widg, gpointer data);
55extern G_MODULE_EXPORT void turn_rebuild (GtkWidget * widg, gpointer data);
56#endif
57
58#ifdef GTK4
68G_MODULE_EXPORT void wrapping_coord (GSimpleAction * action, GVariant * parameter, gpointer data)
69#else
78G_MODULE_EXPORT void wrapping_coord (GtkWidget * widg, gpointer data)
79#endif
80{
81 glwin * view = (glwin *)data;
82 wrapping (view);
83}
84
85#ifdef GTK3
95GtkWidget * menu_cell_edit (glwin * view , int id, int j)
96{
97 int i, k, l;
98 GtkWidget * menu = gtk_menu_new ();
99 if (id == 0)
100 {
101 for (i=0; i<6; i++)
102 {
103 view -> ogl_box[2+i] = create_menu_item (FALSE, edit_names[i]);
104 if (i == 0)
105 {
106 g_signal_connect (G_OBJECT (view -> ogl_box[2+i]), "activate", G_CALLBACK(wrapping_coord), view);
107 }
108 else if (i == 3)
109 {
110 g_signal_connect (G_OBJECT (view -> ogl_box[2+i]), "activate", G_CALLBACK(super_cell), view);
111 }
112 else
113 {
114 k = (i < 3) ? i-1 : i-2;
115 g_signal_connect (G_OBJECT (view -> ogl_box[2+i]), "activate", G_CALLBACK(edition_win), & view -> colorp[k][0]);
116 }
117 if (i > 2) widget_set_sensitive (view -> ogl_box[2+i], j);
118 if (i == 0) widget_set_sensitive (view -> ogl_box[2+i], ! view -> wrapped);
119 if (i == 3)
120 {
121 k = 0;
122 for (l=0; l<3; l++) k += view -> anim -> last -> img-> extra_cell[l];
123 widget_set_sensitive (view -> ogl_box[2+i], k);
124 }
125 gtk_menu_shell_append ((GtkMenuShell *)menu, view -> ogl_box[2+i]);
126 }
127 }
128 else
129 {
130 for (i=0; i<6; i++)
131 {
132 GtkWidget * widg = create_menu_item (FALSE, edit_names[i]);
133 if (i == 0)
134 {
135 g_signal_connect (G_OBJECT (widg), "activate", G_CALLBACK(wrapping_coord), view);
136 }
137 else if (i == 3)
138 {
139 g_signal_connect (G_OBJECT (widg), "activate", G_CALLBACK(super_cell), view);
140 }
141 else
142 {
143 k = (i < 3) ? i-1 : i-2;
144 g_signal_connect (G_OBJECT (widg), "activate", G_CALLBACK(edition_win), & view -> colorp[k][0]);
145 }
146 if (i > 2) widget_set_sensitive (widg, j);
147 if (i == 0) widget_set_sensitive (widg, ! view -> wrapped);
148 if (i == 3)
149 {
150 k = 0;
151 for (l=0; l<3; l++) k += view -> anim -> last -> img-> extra_cell[l];
152 widget_set_sensitive (widg, k);
153 }
154 gtk_menu_shell_append ((GtkMenuShell *)menu, widg);
155 }
156 }
157 return menu;
158}
159
168GtkWidget * menu_edit (glwin * view, int id)
169{
170 int i, j;
171 project * this_proj = get_project_by_id(view -> proj);
172 GtkWidget * menu = gtk_menu_new ();
173 GtkWidget * widg;
174 if (id == 0)
175 {
176 view -> cbuilder = create_menu_item (FALSE, "Crystal Builder");
177 g_signal_connect (G_OBJECT (view -> cbuilder), "activate", G_CALLBACK(crystal_window), & view -> colorp[0][0]);
178 gtk_menu_shell_append ((GtkMenuShell *)menu, view -> cbuilder);
179 }
180 else
181 {
182 widg = create_menu_item (FALSE, "Crystal Builder");
183 g_signal_connect (G_OBJECT (widg), "activate", G_CALLBACK(crystal_window), & view -> colorp[0][0]);
184 gtk_menu_shell_append ((GtkMenuShell *)menu, widg);
185 }
186 j = (this_proj -> cell.ltype && this_proj -> steps == 1) ? 1 : 0;
187 if (id == 0)
188 {
189 view -> ogl_box[1] = menu_item_new_with_submenu ("Cell", (this_proj -> natomes) ? this_proj -> cell.ltype : 0, menu_cell_edit(view, id, j));
190 gtk_menu_shell_append ((GtkMenuShell *)menu, view -> ogl_box[1]);
191 }
192 else
193 {
194 gtk_menu_shell_append ((GtkMenuShell *)menu, menu_item_new_with_submenu ("Cell", (this_proj -> natomes) ? this_proj -> cell.ltype : 0, menu_cell_edit(view, id, j)));
195 }
196
197 GtkWidget * ats = create_menu_item (FALSE, "Atoms");
198 gtk_menu_shell_append ((GtkMenuShell *)menu, ats);
199 GtkWidget * menua = gtk_menu_new ();
200 gtk_menu_item_set_submenu ((GtkMenuItem *)ats, menua);
201 j = (this_proj -> steps == 1) ? 1 : 0;
202 for (i=0; i<5; i++)
203 {
204 widg = create_menu_item (TRUE, action_name[i]);
205 g_signal_connect (G_OBJECT (widg), "activate", G_CALLBACK(action_window), & view -> colorp[i][0]);
206 gtk_menu_shell_append ((GtkMenuShell *)menua, widg);
207 widget_set_sensitive (widg, this_proj -> nspec);
208 widget_set_sensitive (widg, (i == 3) ? j : (this_proj -> natomes) ? j : 0);
209 }
210
211 if (id == 0)
212 {
213 gchar * rtext[2] = {"Extract/Rebuild on Motion", "Extract/Rebuild on Copy"};
214 for (i=0; i<2; i++)
215 {
216 view -> rbuild[i] = gtk3_menu_item (menu, rtext[i], IMG_STOCK, (gpointer)ECUT, G_CALLBACK(turn_rebuild), & view -> colorp[i][0], FALSE, 0, 0, TRUE, FALSE, view -> rebuild[i][0]);
217 widget_set_sensitive (view -> rbuild[i], (this_proj -> steps == 1) ? 1 : 0);
218 }
219 }
220 return menu;
221}
222#else
232GMenu * menu_cell_edit (glwin * view, int popm, int sensitive)
233{
234 GMenu * menu = g_menu_new ();
235 gboolean sens;
236 GCallback edit_handler[3] = {G_CALLBACK(wrapping_coord), G_CALLBACK(super_cell), G_CALLBACK(edition_win)};
237 int i, j, k, l;
238 gchar * act;
239 for (i=0; i<6; i++)
240 {
241 j = (i == 0) ? i : (i == 3) ? 1 : 2;
242 if (i > 2) sens = sensitive;
243 if (i == 0) sens = ! view -> wrapped;
244 if (i == 3)
245 {
246 k = 0;
247 for (l=0; l<3; l++) k += view -> anim -> last -> img-> extra_cell[l];
248 sens = k;
249 }
250 act = g_strdup_printf ("ceed-%d", i);
251 if (i == 0 || i == 3)
252 {
253 append_opengl_item (view, menu, edit_names[i], act, popm, i, NULL, IMG_NONE, NULL, FALSE, edit_handler[j], (gpointer)view, FALSE, FALSE, FALSE, sens);
254 }
255 else
256 {
257 k = (i < 3) ? i-1 : i-2;
258 append_opengl_item (view, menu, edit_names[i], act, popm, i, NULL, IMG_NONE, NULL, FALSE, edit_handler[j], & view -> colorp[k][0], FALSE, FALSE, FALSE, sens);
259 }
260 g_free (act);
261 }
262 return menu;
263}
264
273GMenu * menu_atom_edit (glwin * view, int popm)
274{
275 GMenu * menu = g_menu_new ();
276 gchar * act;
277 int i, j;
278 project * this_proj = get_project_by_id(view -> proj);
279 j = (this_proj -> steps == 1) ? 1 : 0;
280 for (i=0; i<5; i++)
281 {
282 act = g_strdup_printf ("ated-%d", i);
283 append_opengl_item (view, menu, action_name[i], act, popm, 0, NULL, IMG_NONE, NULL, FALSE,
284 G_CALLBACK(action_window), & view -> colorp[i][0], FALSE, FALSE, FALSE, (i == 3) ? j : (this_proj -> natomes) ? j : 0);
285 g_free (act);
286 }
287 return menu;
288}
289
299G_MODULE_EXPORT void to_run_rebuild (GSimpleAction * action, GVariant * parameter, gpointer data)
300{
301 tint * dat =(tint *)data;
302 glwin * view = get_project_by_id(dat -> a) -> modelgl;
303 gboolean doit = TRUE;
304 GVariant * state = g_action_get_state (G_ACTION (action));
305 const gchar * rebuild = g_action_get_name ((GAction *)action);
306 int lgt = strlen (rebuild);
307 gchar * name = g_strdup_printf ("%c%c", rebuild[lgt-2], rebuild[lgt-1]);
308 if (g_strcmp0(name, ".1") == 0)
309 {
310 g_free (name);
311 name = g_strdup_printf ("%.*s.0", lgt-2, rebuild);
312 g_action_group_activate_action ((GActionGroup *)view -> action_group, (const gchar *)name, NULL);
313 g_free (name);
314 doit = FALSE;
315 }
316 if (doit)
317 {
318 turn_rebuild (NULL, NULL, data);
319 g_action_change_state (G_ACTION (action), g_variant_new_boolean (! g_variant_get_boolean (state)));
320 g_variant_unref (state);
321 }
322}
323
332GMenu * extract_section (glwin * view, int popm)
333{
334 int i;
335 project * this_proj = get_project_by_id(view -> proj);
336 GMenu * menu = g_menu_new ();
337 gchar * rtext[2] = {"Extract/Rebuild on Motion", "Extract/Rebuild on Copy"};
338 for (i=0; i<2; i++)
339 {
340 append_opengl_item (view, menu, rtext[i], "aext", popm, i, NULL, IMG_STOCK, (gpointer)ECUT, FALSE, G_CALLBACK(to_run_rebuild), & view -> colorp[i][0],
341 TRUE, view -> rebuild[i][0], FALSE, (this_proj -> steps == 1) ? 1 : 0);
342 }
343 return menu;
344}
345
354GMenu * menu_edit (glwin * view, int popm)
355{
356 project * this_proj = get_project_by_id(view -> proj);
357 GMenu * menu = g_menu_new ();
358 append_opengl_item (view, menu, "Crystal Builder", "cbuilder", popm, popm, NULL, IMG_NONE, NULL, FALSE, G_CALLBACK(crystal_window), & view -> colorp[0][0], FALSE, FALSE, FALSE, TRUE);
359 append_submenu (menu, "Cell", menu_cell_edit(view, popm, (this_proj -> cell.ltype && this_proj -> steps == 1) ? 1 : 0));
360 append_submenu (menu, "Atom(s)", menu_atom_edit(view, popm));
361 if (! popm) g_menu_append_section (menu, NULL, (GMenuModel*)extract_section(view, popm));
362 return menu;
363}
364#endif
gchar * action_name[5]
Definition atom_edit.c:60
G_MODULE_EXPORT void action_window(GtkWidget *widg, gpointer data)
open model edition window callback GTK3
Definition atom_edit.c:535
Function declarations for the mode edition window.
G_MODULE_EXPORT void edition_win(GtkWidget *widg, gpointer data)
create the cell edition window callback GTK3
Definition cell_edit.c:224
gchar * edit_names[7]
Definition cell_edit.c:48
Function declarations for the cell edition window.
void wrapping(glwin *view)
wrapping atomic coordinates
Definition cell_shift.c:498
G_MODULE_EXPORT void super_cell(GtkWidget *widg, gpointer data)
create super cell menu callback GTK3
Definition cell_super.c:322
color colorp[64]
@ 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
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)
#define ECUT
Definition global.h:205
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
action
Definition glview.h:189
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 turn_rebuild(GtkWidget *widg, gpointer data)
rebuild menu items callback GTK3
Definition popup.c:3947
GMenu * extract_section(glwin *view, int popm)
create the 'Extract/Rebuild' menu items GTK4
Definition m_edit.c:332
GMenu * menu_edit(glwin *view, int popm)
create the 'Edit' submenu GTK4
Definition m_edit.c:354
G_MODULE_EXPORT void wrapping_coord(GtkWidget *widg, gpointer data)
wrapp coordinates callback
Definition m_edit.c:78
GMenu * menu_atom_edit(glwin *view, int popm)
create the 'Edit -> Atom(s)' submenu GTK4
Definition m_edit.c:273
G_MODULE_EXPORT void to_run_rebuild(GSimpleAction *action, GVariant *parameter, gpointer data)
Extract/Rebuild menu items callback GTK4.
Definition m_edit.c:299
GMenu * menu_cell_edit(glwin *view, int popm, int sensitive)
create the 'Edit -> Cell' submenu GTK4
Definition m_edit.c:232
G_MODULE_EXPORT void crystal_window(GtkWidget *widg, gpointer data)
create the crystal build window callback GTK3
Definition glwin.h:875
Definition global.h:104
int a
Definition tab-1.c:95
GtkWidget * img
Definition workspace.c:70