atomes 1.2.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
m_style.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_style.c'
24*
25* Contains:
26*
27
28 - The functions to create the 'OpenGL -> Style' submenu
29
30*
31* List of functions:
32
33 void clean_atom_style (project * this_proj);
34 void update_menus (glwin * view);
35
36 G_MODULE_EXPORT void set_style (GtkWidget * widg, gpointer data);
37 G_MODULE_EXPORT void change_style_radio (GSimpleAction * action, GVariant * parameter, gpointer data);
38
39 GtkWidget * create_style_menu (char * name, int val, int style, int vbl, int filled, guint accel, GtkWidget * menu, tint * data);
40 GtkWidget * menu_style (glwin * view, int id);
41
42 GMenu * menu_style (glwin * view, int popm);
43
44*/
45
46#include "global.h"
47#include "bind.h"
48#include "project.h"
49#include "glview.h"
50#include "glwindow.h"
51#include "preferences.h"
52
53extern gchar * label_atpts (project * this_proj, glwin * view, int id);
54
55char * text_styles[OGL_STYLES] = {"Ball and stick",
56 "Wireframe",
57 "Spacefilled",
58 "Spheres",
59 "Cylinders",
60 "Dots"};
61
62char * text_filled[FILLED_STYLES] = {"Covalent radius",
63 "Ionic radius",
64 "van Der Waals radius",
65 "In crystal radius"};
66
74void clean_atom_style (project * this_proj)
75{
76 int i, j;
77 for (i=0; i<this_proj -> steps; i++)
78 {
79 for (j=0; j<this_proj -> natomes; j++)
80 {
81 this_proj -> atoms[i][j].style = NONE;
82 }
83 }
84}
85
86#ifdef GTK3
87// GTK3 Menu Action To Check
95void update_menus (glwin * view)
96{
97 int i, j;
98 int s = view -> anim -> last -> img -> style;
99 gchar * str;
100 for (i=0; i<2; i++)
101 {
102 for (j=0; j<6; j+=2)
103 {
104 hide_the_widgets (view -> ogl_bonds[j+8*i]);
105 if (j<4) hide_the_widgets (view -> ogl_atoms[4*i+j]);
106 }
107 }
108 switch (s)
109 {
110 case CYLINDERS:
111 for (i=0; i<2; i++) show_the_widgets (view -> ogl_bonds[8*i]);
112 break;
113 case WIREFRAME:
114 for (i=0; i<2; i++)
115 {
116 show_the_widgets (view -> ogl_bonds[4+8*i]);
117 str = label_atpts (get_project_by_id(view -> proj), view, 1+2*i);
118 gtk_menu_item_set_label (GTK_MENU_ITEM(view -> ogl_atoms[4*i+1]), str);
119 g_free (str);
120 show_the_widgets (view -> ogl_atoms[4*i+2]);
121 }
122 break;
123 case SPACEFILL:
124 for (i=0; i<2; i++)
125 {
126 str = label_atpts (get_project_by_id(view -> proj), view, 4);
127 gtk_menu_item_set_label (GTK_MENU_ITEM(view -> ogl_atoms[4*i+1]), str);
128 g_free (str);
129 show_the_widgets (view -> ogl_atoms[4*i]);
130 }
131 break;
132 case PUNT:
133 for (i=0; i<2; i++)
134 {
135 str = label_atpts (get_project_by_id(view -> proj), view, 2*i+1);
136 gtk_menu_item_set_label (GTK_MENU_ITEM(view -> ogl_atoms[4*i+1]), str);
137 g_free (str);
138 show_the_widgets (view -> ogl_atoms[4*i+2]);
139 }
140 break;
141 case SPHERES:
142 for (i=0; i<2; i++)
143 {
144 str = label_atpts (get_project_by_id(view -> proj), view, 2*i);
145 gtk_menu_item_set_label (GTK_MENU_ITEM(view -> ogl_atoms[4*i+1]), str);
146 g_free (str);
147 show_the_widgets (view -> ogl_atoms[4*i]);
148 }
149 break;
150 default:
151 for (i=0; i<2; i++)
152 {
153 show_the_widgets (view -> ogl_bonds[2+8*i]);
154 str = label_atpts (get_project_by_id(view -> proj), view, 2*i);
155 gtk_menu_item_set_label (GTK_MENU_ITEM(view -> ogl_atoms[4*i+1]), str);
156 g_free (str);
157 show_the_widgets (view -> ogl_atoms[4*i]);
158 }
159 break;
160 }
161}
162#endif
163
172G_MODULE_EXPORT void set_style (GtkWidget * widg, gpointer data)
173{
174 tint * the_data = (tint *)data;
175 project * this_proj = get_project_by_id(the_data -> a);
176 int s = the_data -> b;
177 int st = (s >= OGL_STYLES) ? SPACEFILL : s;
178 int ft = (s >= OGL_STYLES) ? s - OGL_STYLES * (s/OGL_STYLES) : NONE;
179 int old_style = this_proj -> modelgl -> anim -> last -> img -> style;
180 int old_filled = this_proj -> modelgl -> anim -> last -> img -> filled_type;
181 int i, j, k, l, m;
182#ifdef GTK3
183 if ((old_style != st || old_filled != ft) && gtk_check_menu_item_get_active ((GtkCheckMenuItem *)widg))
184#else
185 if (old_style != st || old_filled != ft)
186#endif
187 {
188 i = old_style;
189 j = old_filled;
190 this_proj -> modelgl -> anim -> last -> img -> style = NONE;
191 this_proj -> modelgl -> anim -> last -> img -> filled_type = NONE;
192#ifdef GTK3
193 if (old_style == SPACEFILL)
194 {
195 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)this_proj -> modelgl -> filled_styles[j], FALSE);
196 }
197 else
198 {
199 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)this_proj -> modelgl -> ogl_styles[i], FALSE);
200 }
201#endif
202 if (s >= OGL_STYLES)
203 {
204 j = this_proj -> nspec;
205 k = (ft) ? 9 + ft : 2;
206 l = (ft) ? 12 + ft : 7;
207 for (i=0; i<j; i++)
208 {
209 m = (int)this_proj -> chemistry -> chem_prop[CHEM_Z][i];
210 this_proj -> modelgl -> anim -> last -> img -> atomicrad[i] = (default_o_at_rs[2]) ? default_at_rs[2] : get_radius (2, ft, m, default_atomic_rad[k]);
211 this_proj -> modelgl -> anim -> last -> img -> atomicrad[i+j] = (default_o_at_rs[7]) ? default_at_rs[7] : get_radius (7, ft, m, default_atomic_rad[l]);
212 }
213#ifdef GTK3
214 if (widg != this_proj -> modelgl -> filled_styles[ft])
215 {
216 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)this_proj -> modelgl -> filled_styles[ft], TRUE);
217 }
218#endif
219 this_proj -> modelgl -> anim -> last -> img -> filled_type = ft;
220 this_proj -> modelgl -> anim -> last -> img -> style = SPACEFILL;
221 }
222 else
223 {
224#ifdef GTK3
225 if (widg != this_proj -> modelgl -> ogl_styles[st])
226 {
227 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)this_proj -> modelgl -> ogl_styles[st], TRUE);
228 }
229#endif
230 this_proj -> modelgl -> anim -> last -> img -> style = st;
231 }
232 clean_atom_style (this_proj);
233 if (st == WIREFRAME || st == PUNT)
234 {
235 j = 0;
236 }
237 else
238 {
239 j = 1;
240 }
241#ifdef GTK3
242 for (i=0; i<OGL_RENDERS; i++)
243 {
244 widget_set_sensitive (this_proj -> modelgl -> ogl_render[i], j);
245 }
246 update_menus (this_proj -> modelgl);
247#else
248
249#endif
250 init_default_shaders (this_proj -> modelgl);
251 }
252 /*else if (st != SPACEFILL && old_style != NONE && ! gtk_check_menu_item_get_active ((GtkCheckMenuItem *)widg))
253 {
254 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)this_proj -> modelgl -> ogl_styles[st], TRUE);
255 }
256 else if (old_style != NONE && old_filled != NONE && ! gtk_check_menu_item_get_active ((GtkCheckMenuItem *)widg))
257 {
258 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)this_proj -> modelgl -> filled_styles[ft], TRUE);
259 }*/
260}
261
262#ifdef GTK3
277GtkWidget * create_style_menu (char * name, int val, int style, int vbl, int filled, guint accel, GtkWidget * menu, tint * data)
278{
279 GtkWidget * style_widget = gtk3_menu_item (menu, name, IMG_NONE, NULL, G_CALLBACK(set_style), data, (accel != -1) ? TRUE : FALSE, accel,
280 0, TRUE, TRUE, (style == val && filled == vbl) ? TRUE : FALSE);
281 return style_widget;
282}
283
292GtkWidget * menu_style (glwin * view, int id)
293{
294 int i, j;
295 GtkWidget * widg;
296 GtkWidget * menus = gtk_menu_new ();
297 guint accels[OGL_STYLES-1]={GDK_KEY_b, GDK_KEY_w, GDK_KEY_s, GDK_KEY_c, GDK_KEY_d};
298 guint accelf[FILLED_STYLES]={GDK_KEY_o, GDK_KEY_i, GDK_KEY_v, GDK_KEY_r};
299 if (id == 0)
300 {
301 for (i=0; i<OGL_STYLES; i++)
302 {
303 if (i != SPACEFILL)
304 {
305 view -> ogl_styles[i] = create_style_menu (text_styles[i],
306 i,
307 view -> anim -> last -> img -> style,
308 i,
309 i,
310 accels[(i < SPACEFILL) ? i : i-1],
311 menus,
312 & view -> colorp[i][0]);
313 }
314 else
315 {
316 widg = create_menu_item (FALSE, "Spacefilled");
317 gtk_menu_shell_append ((GtkMenuShell *)menus, widg);
318 GtkWidget * menuf = gtk_menu_new ();
319 gtk_menu_item_set_submenu ((GtkMenuItem *)widg, menuf);
320 for (j=0; j < FILLED_STYLES; j++)
321 {
322 view -> filled_styles[j] = create_style_menu (text_filled[j],
323 SPACEFILL,
324 view -> anim -> last -> img -> style,
325 j,
326 view -> anim -> last -> img -> filled_type,
327 accelf[j],
328 menuf,
329 & view -> colorp[OGL_STYLES + j][0]);
330 }
331 }
332 }
333 }
334 else
335 {
336 for (i=0; i<OGL_STYLES; i++)
337 {
338 if (i != SPACEFILL)
339 {
340 widg = create_style_menu (text_styles[i],
341 i,
342 view -> anim -> last -> img -> style,
343 i,
344 i,
345 accels[(i < SPACEFILL) ? i : i-1],
346 menus,
347 & view -> colorp[i][0]);
348 }
349 else
350 {
351 widg = create_menu_item (FALSE, "Spacefilled");
352 gtk_menu_shell_append ((GtkMenuShell *)menus, widg);
353 GtkWidget * menuf = gtk_menu_new ();
354 gtk_menu_item_set_submenu ((GtkMenuItem *)widg, menuf);
355 for (j=0; j < FILLED_STYLES; j++)
356 {
357 widg = create_style_menu (text_filled[j],
358 SPACEFILL,
359 view -> anim -> last -> img -> style,
360 j,
361 view -> anim -> last -> img -> filled_type,
362 accelf[j],
363 menuf,
364 & view -> colorp[OGL_STYLES + j][0]);
365 }
366
367 }
368 }
369 }
370 return menus;
371}
372#else
382G_MODULE_EXPORT void change_style_radio (GSimpleAction * action, GVariant * parameter, gpointer data)
383{
384 glwin * view = (glwin *)data;
385 const gchar * style = g_variant_get_string (parameter, NULL);
386 int lgt = strlen (style);
387 gchar * name = g_strdup_printf ("%c%c", style[lgt-2], style[lgt-1]);
388 if (g_strcmp0(name, ".1") == 0)
389 {
390 g_free (name);
391 name = g_strdup_printf ("%.*s.0", lgt-2, style);
392 g_action_group_activate_action ((GActionGroup *)view -> action_group, "set-style", g_variant_new_string((const gchar *)name));
393 g_free (name);
394 }
395 else
396 {
397 gchar * style_name = NULL;
398 int i;
399 for (i=0; i<OGL_STYLES+FILLED_STYLES; i++)
400 {
401 style_name = g_strdup_printf ("set-style.%d.0", i);
402 if (g_strcmp0(style, (const gchar *)style_name) == 0)
403 {
404 if (i < SPACEFILL)
405 {
406 set_style (NULL, & view -> colorp[i][0]);
407 }
408 else if (i < SPACEFILL + FILLED_STYLES)
409 {
410 i -= SPACEFILL;
411 set_style (NULL, & view -> colorp[OGL_STYLES+i][0]);
412 }
413 else
414 {
415 i -= FILLED_STYLES;
416 set_style (NULL, & view -> colorp[i][0]);
417 }
418 g_free (style_name);
419 style_name = NULL;
420 break;
421 }
422 g_free (style_name);
423 style_name = NULL;
424 }
425 g_action_change_state (G_ACTION (action), parameter);
426 }
427}
428
437GMenu * menu_style (glwin * view, int popm)
438{
439 int i, j, k;
440 GMenu * menu = g_menu_new ();
441 gchar * accels[OGL_STYLES-1]={"b", "w", "s", "c", "d"};
442 gchar * accelf[FILLED_STYLES]={"o", "i", "v", "r"};
443
444 k = 0;
445 for (i=0; i<OGL_STYLES; i++, k++)
446 {
447 if (i != SPACEFILL)
448 {
449 append_opengl_item (view, menu, text_styles[i], "style", popm, k,
450 accels[(i < SPACEFILL) ? i : i-1], IMG_NONE, NULL, FALSE,
451 G_CALLBACK(change_style_radio), (gpointer)view,
452 FALSE, (view -> anim -> last -> img -> style == i) ? TRUE : FALSE, TRUE, TRUE);
453 }
454 else
455 {
456 GMenu * menus = g_menu_new ();
457 for (j=0; j < FILLED_STYLES; j++, k++)
458 {
459 append_opengl_item (view, menus, text_filled[j], "style", popm, k,
460 accelf[j], IMG_NONE, NULL, FALSE,
461 G_CALLBACK(change_style_radio), (gpointer)view,
462 FALSE, (view -> anim -> last -> img -> style == SPACEFILL && view -> anim -> last -> img -> filled_type == j) ? TRUE : FALSE, TRUE, TRUE);
463 }
464 append_submenu (menu, "Spacefilled", menus);
465 }
466 }
467 return menu;
468}
469#endif
Binding to the Fortran90 subroutines.
integer(kind=c_int) function chemistry()
Definition chemistry.F90:22
color colorp[64]
int atoms[NUM_STYLES][2]
float val
Definition dlp_init.c:117
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:262
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:732
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)
void hide_the_widgets(GtkWidget *widg)
hide GtkWidget
Definition gtk-misc.c:198
#define CHEM_Z
Definition global.h:299
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:182
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:198
@ SPHERES
Definition glview.h:185
@ SPACEFILL
Definition glview.h:184
@ CYLINDERS
Definition glview.h:186
@ WIREFRAME
Definition glview.h:183
@ NONE
Definition glview.h:181
@ PUNT
Definition glview.h:187
#define FILLED_STYLES
Definition glwin.h:106
#define OGL_RENDERS
Definition glwin.h:57
#define OGL_STYLES
Definition glwin.h:107
void update_menus(glwin *view)
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)
gchar * label_atpts(project *this_proj, glwin *view, int id)
prepare the text of a menu item in the 'Model -> Atom(s)' submenu
Definition m_atoms.c:73
G_MODULE_EXPORT void set_style(GtkWidget *widg, gpointer data)
set style callback
Definition m_style.c:172
void clean_atom_style(project *this_proj)
clean all atom(s) possible alternative rendering styles
Definition m_style.c:74
char * text_filled[FILLED_STYLES]
Definition m_style.c:62
G_MODULE_EXPORT void change_style_radio(GSimpleAction *action, GVariant *parameter, gpointer data)
change style callback GTK4
Definition m_style.c:382
GMenu * menu_style(glwin *view, int popm)
create the 'OpenGL -> Style' submenu - GTK4
Definition m_style.c:437
char * text_styles[OGL_STYLES]
Definition m_style.c:55
double precision, dimension(:), allocatable s
double * default_at_rs
float get_radius(int object, int col, int z, element_radius *rad_list)
retrieve the radius/width of a species depending on style
gboolean * default_o_at_rs
element_radius * default_atomic_rad[16]
Preference variable declarations.
Function declarations for reading atomes project file Function declarations for saving atomes proje...
Definition glwin.h:965
Definition global.h:106
int b
Definition tab-1.c:95
int a
Definition tab-1.c:95
GtkWidget * img
Definition workspace.c:70