atomes 1.2.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
m_axis.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-2025 by CNRS and University of Strasbourg */
15
22/*
23* This file: 'm_axis.c'
24*
25* Contains:
26*
27
28 - The functions to create the 'View -> Axis' submenu
29
30*
31* List of functions:
32
33 void menu_axis (GtkWidget * menu_ab, glwin * view, int id);
34 void menu_axis (GMenu * menu_ab, glwin * view, int popm);
35
36 G_MODULE_EXPORT void set_axis_template_pos (GtkWidget * widg, gpointer data);
37 G_MODULE_EXPORT void change_axis_pos_radio (GSimpleAction * action, GVariant * parameter, gpointer data);
38
39 GtkWidget * axis_position_submenu (glwin * view, int id);
40
41 GMenu * position_submenu (glwin * view, int popm, int pos);
42 GMenu * axis_position_submenu (glwin * view, int popm);
43
44*/
45
46#include "global.h"
47#include "glview.h"
48#include "glwindow.h"
49#include "submenus.h"
50
51extern G_MODULE_EXPORT void axis_advanced (GtkWidget * widg, gpointer data);
52extern GtkWidget * create_layout_widget (gchar * str, GtkWidget * menu, int vab, gpointer data);
53
54#ifdef GTK4
64G_MODULE_EXPORT void to_axis_advanced (GSimpleAction * action, GVariant * parameter, gpointer data)
65{
66 axis_advanced (NULL, data);
67}
68#endif
69
70#ifdef GTK3
79G_MODULE_EXPORT void set_axis_template_pos (GtkWidget * widg, gpointer data)
80{
81/* TOP_RIGHT = 0,
82 TOP_LEFT = 1,
83 BOTTOM_RIGHT = 2,
84 BOTTOM_LEFT = 3,
85 CENTER = 4 */
86 tint * the_data = (tint *)data;
87 project * this_proj = get_project_by_id(the_data -> a);
88 int i = this_proj -> modelgl -> anim -> last -> img -> xyz -> t_pos;
89 int j = the_data -> b;
90 if (gtk_check_menu_item_get_active ((GtkCheckMenuItem *)widg) && i != j)
91 {
92 this_proj -> modelgl -> anim -> last -> img -> xyz -> t_pos = NONE;
93 if (i != CUSTOM)
94 {
95 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)this_proj -> modelgl -> ogl_box_axis[1][8+i], FALSE);
96 }
97 if (widg != this_proj -> modelgl -> ogl_box_axis[1][8+j])
98 {
99 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)this_proj -> modelgl -> ogl_box_axis[1][8+j], TRUE);
100 }
101 this_proj -> modelgl -> anim -> last -> img -> xyz -> t_pos = j;
102 this_proj -> modelgl -> create_shaders[MAXIS] = TRUE;
103 update (this_proj -> modelgl);
104 if (this_proj -> modelgl -> axis_win)
105 {
106 if (this_proj -> modelgl -> axis_win -> templates && GTK_IS_WIDGET(this_proj -> modelgl -> axis_win -> templates))
107 {
108 combo_set_active (this_proj -> modelgl -> axis_win -> templates, j);
109 }
110 }
111 }
112 else if (i == j && ! gtk_check_menu_item_get_active ((GtkCheckMenuItem *)widg))
113 {
114 if (i != CUSTOM)
115 {
116 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)this_proj -> modelgl -> ogl_box_axis[1][8+i], TRUE);
117 }
118 }
119}
120
129GtkWidget * axis_position_submenu (glwin * view, int id)
130{
131 int i, j, k;
132 GtkWidget * menup = gtk_menu_new ();
133 GtkWidget * ud, * udm, * widg;
134 gchar * udlab[2] = {"Top", "Bottom"};
135 gchar * lrlab[2] = {"Right Corner", "Left Corner"};
136
137 i = 0;
138 for (j=0; j<2; j++)
139 {
140 ud = create_menu_item (FALSE, udlab[j]);
141 gtk_menu_shell_append ((GtkMenuShell *)menup, ud);
142 udm = gtk_menu_new ();
143 gtk_menu_item_set_submenu ((GtkMenuItem *)ud, udm);
144 for (k=0; k<2; k++)
145 {
146 if (id == 0)
147 {
148 view -> ogl_box_axis[1][8+i] = gtk3_menu_item (udm, lrlab[k], IMG_NONE, NULL, G_CALLBACK(set_axis_template_pos), & view -> colorp[i][0],
149 FALSE, 0, 0, TRUE, TRUE, (view -> anim -> last -> img -> xyz -> t_pos == i) ? TRUE: FALSE);
150 if (view -> anim -> last -> img -> xyz -> axis == NONE) widget_set_sensitive (view -> ogl_box_axis[1][8+i], 0);
151 }
152 else
153 {
154 widg = gtk3_menu_item (udm, lrlab[k], IMG_NONE, NULL, G_CALLBACK(set_axis_template_pos), & view -> colorp[i][0],
155 FALSE, 0, 0, TRUE, TRUE, (view -> anim -> last -> img -> xyz -> t_pos == i) ? TRUE: FALSE);
156 if (view -> anim -> last -> img -> xyz -> axis == NONE) widget_set_sensitive (widg, 0);
157 }
158 i += 1;
159 }
160 }
161 if (id == 0)
162 {
163 view -> ogl_box_axis[1][8+i] = gtk3_menu_item (menup, "Center", IMG_NONE, NULL, G_CALLBACK(set_axis_template_pos), & view -> colorp[i][0],
164 FALSE, 0, 0, TRUE, TRUE, (view -> anim -> last -> img -> xyz -> t_pos == i) ? TRUE: FALSE);
165 if (view -> anim -> last -> img -> xyz -> axis == NONE) widget_set_sensitive (view -> ogl_box_axis[1][8+i], 0);
166 }
167 else
168 {
169 widg = gtk3_menu_item (menup, "Center", IMG_NONE, NULL, G_CALLBACK(set_axis_template_pos), & view -> colorp[i][0],
170 FALSE, 0, 0, TRUE, TRUE, (view -> anim -> last -> img -> xyz -> t_pos == i) ? TRUE: FALSE);
171 if (view -> anim -> last -> img -> xyz -> axis == NONE) widget_set_sensitive (widg, 0);
172 }
173 return menup;
174}
175
185void menu_axis (GtkWidget * menu_ab, glwin * view, int id)
186{
187 GtkWidget * widg = create_menu_item (FALSE, "Length");
188 gtk_menu_shell_append ((GtkMenuShell *)menu_ab, widg);
189 GtkWidget * menul = gtk_menu_new ();
190 gtk_menu_item_set_submenu ((GtkMenuItem *)widg, menul);
191
192 gchar * str = g_strdup_printf (" Length [ %f Å ]", view -> anim -> last -> img -> xyz -> length);
193 if (id == 0)
194 {
195 view -> ogl_box_axis[1][7] = create_layout_widget (str, menul, view -> anim -> last -> img -> xyz -> axis, & view -> colorp[0][AXIS]);
196 if (view -> anim -> last -> img -> xyz -> axis == NONE)
197 {
198 widget_set_sensitive (view -> ogl_box_axis[1][7], 0);
199 }
200 }
201 else
202 {
203 widg = create_layout_widget (str, menul, view -> anim -> last -> img -> xyz -> axis, & view -> colorp[0][AXIS]);
204 if (view -> anim -> last -> img -> xyz -> axis == NONE)
205 {
206 widget_set_sensitive (widg, 0);
207 }
208 }
209 g_free (str);
210 gtk_menu_shell_append ((GtkMenuShell *)menu_ab, menu_item_new_with_submenu ("Position", TRUE, axis_position_submenu(view, id)));
211 add_advanced_item (menu_ab, G_CALLBACK(axis_advanced), (gpointer)view, FALSE, 0, 0);
212}
213#else
223G_MODULE_EXPORT void change_axis_pos_radio (GSimpleAction * action, GVariant * parameter, gpointer data)
224{
225 /* TOP_RIGHT = 0,
226 TOP_LEFT = 1,
227 BOTTOM_RIGHT = 2,
228 BOTTOM_LEFT = 3,
229 CENTER = 4 */
230 tint * the_data = (tint *)data;
231 glwin * view = get_project_by_id(the_data -> a) -> modelgl;
232 const gchar * pos = g_variant_get_string (parameter, NULL);
233 int lgt = strlen (pos);
234 gchar * name = g_strdup_printf ("%c%c", pos[lgt-2], pos[lgt-1]);
235 if (g_strcmp0(name, ".1") == 0)
236 {
237 g_free (name);
238 name = g_strdup_printf ("%.*s.0", lgt-2, pos);
239 g_action_group_activate_action ((GActionGroup *)view -> action_group, "set-axis-pos", g_variant_new_string((const gchar *)name));
240 g_free (name);
241 }
242 else
243 {
244 int i;
245 gchar * pos_name = NULL;
246 for (i=0; i<5; i++)
247 {
248 pos_name = g_strdup_printf ("set-axis-pos.%d.0", i);
249 if (g_strcmp0(pos, (const gchar *)pos_name) == 0)
250 {
251 view -> anim -> last -> img -> xyz -> t_pos = i;
252 g_free (pos_name);
253 pos_name = NULL;
254 break;
255 }
256 g_free (pos_name);
257 pos_name = NULL;
258 }
259 g_action_change_state (G_ACTION (action), parameter);
260 view -> create_shaders[MAXIS] = TRUE;
261 update (view);
262 g_action_change_state (G_ACTION (action), parameter);
263 if (view -> axis_win)
264 {
265 if (view -> axis_win -> templates && GTK_IS_WIDGET(view -> axis_win -> templates))
266 {
267 combo_set_active (view -> axis_win -> templates, i);
268 }
269 }
270 }
271}
272
282GMenu * position_submenu (glwin * view, int popm, int pos)
283{
284 GMenu * menu = g_menu_new ();
285 gchar * lrlab[2] = {"Right Corner", "Left Corner"};
286 int i, j;
287 i = pos*2;
288 for (j=0; j<2; j++)
289 {
290 append_opengl_item (view, menu, lrlab[j], "axis-pos", popm, i, NULL, IMG_NONE, NULL, FALSE,
291 G_CALLBACK(change_axis_pos_radio), & view -> colorp[i][0],
292 FALSE, (view -> anim -> last -> img -> xyz -> t_pos == i) ? TRUE: FALSE, TRUE, TRUE);
293 i ++;
294 }
295 return menu;
296}
297
306GMenu * axis_position_submenu (glwin * view, int popm)
307{
308 int i;
309 GMenu * menu = g_menu_new ();
310 gchar * udlab[2] = {"Top", "Bottom"};
311 for (i=0; i<2; i++)
312 {
313 append_submenu (menu, udlab[i], position_submenu(view, popm, i));
314 }
315 append_opengl_item (view, menu, "Center", "axis-pos", popm, 4, NULL, IMG_NONE, NULL, FALSE,
316 G_CALLBACK(change_axis_pos_radio), & view -> colorp[4][0],
317 FALSE, (view -> anim -> last -> img -> xyz -> t_pos == 4) ? TRUE: FALSE, TRUE, TRUE);
318 return menu;
319}
320
330void menu_axis (GMenu * menu_ab, glwin * view, int popm)
331{
332 GMenuItem * item = g_menu_item_new ("Length", (view -> anim -> last -> img -> xyz -> axis) != NONE ? NULL : "None");
333 g_menu_item_set_attribute (item, "custom", "s", "axis-length", NULL);
334 g_menu_item_set_submenu (item, (GMenuModel *)axis_box_param (view, popm, AXIS, NONE));
335 g_menu_append_item (menu_ab, item);
336 append_submenu (menu_ab, "Position", axis_position_submenu(view, popm));
337 append_opengl_item (view, menu_ab, "Advanced", "axis-advanced", popm, popm, NULL, IMG_STOCK, DPROPERTIES, FALSE,
338 G_CALLBACK(to_axis_advanced), (gpointer)view, FALSE, FALSE, FALSE, TRUE);
339}
340#endif
color colorp[64]
Global variable declarations Global convenience function declarations Global data structure defin...
@ IMG_NONE
Definition global.h:262
@ IMG_STOCK
Definition global.h:266
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)
void combo_set_active(GtkWidget *combo, int pos)
set the active item's position
Definition gtk-misc.c:932
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:732
GtkWidget * add_advanced_item(GtkWidget *menu, GCallback handler, gpointer data, gboolean accel, guint key, GdkModifierType mod)
#define DPROPERTIES
Definition global.h:208
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:215
GtkWidget * create_menu_item(gboolean add_mnemo, gchar *action)
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:450
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
@ CUSTOM
Definition glview.h:219
action
Definition glview.h:198
@ NONE
Definition glview.h:181
#define AXIS
Definition glwin.h:55
@ MAXIS
Definition glwin.h:94
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 * position_submenu(glwin *view, int popm, int pos)
create elements of the 'Axis -> Position' submenu GTK4
Definition m_axis.c:282
GMenu * axis_position_submenu(glwin *view, int popm)
create the 'Axis -> Position' submenu GTK4
Definition m_axis.c:306
G_MODULE_EXPORT void axis_advanced(GtkWidget *widg, gpointer data)
create the axis advanced parameters window
Definition w_axis.c:786
GtkWidget * create_layout_widget(gchar *str, GtkWidget *menu, int vab, gpointer data)
G_MODULE_EXPORT void change_axis_pos_radio(GSimpleAction *action, GVariant *parameter, gpointer data)
handle change axis position signal GTK4
Definition m_axis.c:223
void menu_axis(GMenu *menu_ab, glwin *view, int popm)
create the 'Axis' submenu GTK4
Definition m_axis.c:330
GMenu * axis_box_param(glwin *view, int popm, int ab, int style)
create the box/axis '-> Length/Width/Radius' submenus GTK4
Definition m_box.c:563
Definition glwin.h:333
Definition glwin.h:965
Definition global.h:106
Function declarations for the creation of the OpenGL window menus.
int b
Definition tab-1.c:95
int a
Definition tab-1.c:95
GtkWidget * img
Definition workspace.c:70