atomes 1.3.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-2026 by CNRS and University of Strasbourg */
15
21
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 int get_filled_id (int sid);
34 int get_style_id (int sid);
35
36 void clean_atom_style (project * this_proj);
37 void update_menus (glwin * view);
38 void set_this_style (glwin * view, int style);
39
40 G_MODULE_EXPORT void set_style (GtkWidget * widg, gpointer data);
41 G_MODULE_EXPORT void change_style_radio (GSimpleAction * action, GVariant * parameter, gpointer data);
42
43 GtkWidget * create_style_menu (char * name, int val, int style, int vbl, int filled, guint accel, GtkWidget * menu, tint * data);
44 GtkWidget * menu_style (glwin * view, int id);
45
46 GMenu * menu_style (glwin * view, int popm);
47
48*/
49
50#include "global.h"
51#include "bind.h"
52#include "project.h"
53#include "glview.h"
54#include "glwindow.h"
55#include "preferences.h"
56
57extern gchar * label_atpts (project * this_proj, glwin * view, int id);
58
59char * text_styles[OGL_STYLES] = {i18n("Balls and Sticks"),
60 i18n("Wireframes"),
61 i18n("Spacefilled"),
62 i18n("Spheres"),
63 i18n("Cylinders"),
64 i18n("Dots")};
65
66char * text_filled[FILLED_STYLES] = {i18n("Covalent Radii"),
67 i18n("Ionic Radii"),
68 i18n("van der Waals Radii"),
69 i18n("In Crystal Radii")};
70
78void clean_atom_style (project * this_proj)
79{
80 int i, j;
81 for (i=0; i<this_proj -> steps; i++)
82 {
83 for (j=0; j<this_proj -> natomes; j++)
84 {
85 this_proj -> atoms[i][j].style = NONE;
86 }
87 }
88}
89
90#ifdef GTK3
91// GTK3 Menu Action To Check
99void update_menus (glwin * view)
100{
101 int i, j;
102 int s = view -> anim -> last -> img -> style;
103 gchar * str;
104 for (i=0; i<2; i++)
105 {
106 for (j=0; j<6; j+=2)
107 {
108 hide_the_widgets (view -> ogl_bonds[j+8*i]);
109 if (j<4)
110 {
111 hide_the_widgets (view -> ogl_atoms[4*i+j]);
112 }
113 }
114 }
115 switch (s)
116 {
117 case CYLINDERS:
118 for (i=0; i<2; i++) show_the_widgets (view -> ogl_bonds[8*i]);
119 break;
120 case WIREFRAME:
121 for (i=0; i<2; i++)
122 {
123 show_the_widgets (view -> ogl_bonds[4+8*i]);
124 str = label_atpts (get_project_by_id(view -> proj), view, 1+2*i);
125 gtk_menu_item_set_label (GTK_MENU_ITEM(view -> ogl_atoms[4*i+1]), str);
126 g_free (str);
127 show_the_widgets (view -> ogl_atoms[4*i+2]);
128 }
129 break;
130 case SPACEFILL:
131 for (i=0; i<2; i++)
132 {
133 str = label_atpts (get_project_by_id(view -> proj), view, 4);
134 gtk_menu_item_set_label (GTK_MENU_ITEM(view -> ogl_atoms[4*i+1]), str);
135 g_free (str);
136 show_the_widgets (view -> ogl_atoms[4*i]);
137 }
138 break;
139 case PUNT:
140 for (i=0; i<2; i++)
141 {
142 str = label_atpts (get_project_by_id(view -> proj), view, 2*i+1);
143 gtk_menu_item_set_label (GTK_MENU_ITEM(view -> ogl_atoms[4*i+1]), str);
144 g_free (str);
145 show_the_widgets (view -> ogl_atoms[4*i+2]);
146 }
147 break;
148 case SPHERES:
149 for (i=0; i<2; i++)
150 {
151 str = label_atpts (get_project_by_id(view -> proj), view, 2*i);
152 gtk_menu_item_set_label (GTK_MENU_ITEM(view -> ogl_atoms[4*i+1]), str);
153 g_free (str);
154 show_the_widgets (view -> ogl_atoms[4*i]);
155 }
156 break;
157 default:
158 for (i=0; i<2; i++)
159 {
160 show_the_widgets (view -> ogl_bonds[2+8*i]);
161 if (view -> ogl_atoms[4*i+1])
162 {
163 if (GTK_IS_WIDGET(view -> ogl_atoms[4*i+1]))
164 {
165 str = label_atpts (get_project_by_id(view -> proj), view, 2*i);
166 gtk_menu_item_set_label (GTK_MENU_ITEM(view -> ogl_atoms[4*i+1]), str);
167 g_free (str);
168 show_the_widgets (view -> ogl_atoms[4*i]);
169 }
170 }
171 }
172 break;
173 }
174}
175#endif
176
184int get_filled_id (int sid)
185{
186 return (sid >= OGL_STYLES) ? sid - OGL_STYLES : NONE;
187}
188
196int get_style_id (int sid)
197{
198 return (sid >= OGL_STYLES) ? SPACEFILL : sid;
199}
200
209G_MODULE_EXPORT void set_style (GtkWidget * widg, gpointer data)
210{
211 tint * the_data = (tint *)data;
212 project * this_proj = get_project_by_id(the_data -> a);
213 int s = the_data -> b;
214 int st = get_style_id (s);
215 int ft = get_filled_id (s);
216 int old_style = this_proj -> modelgl -> anim -> last -> img -> style;
217 int old_filled = this_proj -> modelgl -> anim -> last -> img -> filled_type;
218 int i, j, k, l, m;
219#ifdef GTK3
220 if ((old_style != st || old_filled != ft) && gtk_check_menu_item_get_active ((GtkCheckMenuItem *)widg))
221#else
222 if (old_style != st || old_filled != ft)
223#endif
224 {
225 i = old_style;
226 j = old_filled;
227 this_proj -> modelgl -> anim -> last -> img -> style = NONE;
228 this_proj -> modelgl -> anim -> last -> img -> filled_type = NONE;
229#ifdef GTK3
230 if (old_style == SPACEFILL)
231 {
232 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)this_proj -> modelgl -> filled_styles[j], FALSE);
233 }
234 else
235 {
236 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)this_proj -> modelgl -> ogl_styles[i], FALSE);
237 }
238#endif
239 if (s >= OGL_STYLES)
240 {
241 j = this_proj -> nspec;
242 k = (ft) ? 9 + ft : 2;
243 l = (ft) ? 12 + ft : 7;
244 for (i=0; i<j; i++)
245 {
246 m = (int)this_proj -> chemistry -> chem_prop[CHEM_Z][i];
247 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]);
248 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]);
249 }
250#ifdef GTK3
251 if (widg != this_proj -> modelgl -> filled_styles[ft])
252 {
253 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)this_proj -> modelgl -> filled_styles[ft], TRUE);
254 }
255#endif
256 this_proj -> modelgl -> anim -> last -> img -> filled_type = ft;
257 this_proj -> modelgl -> anim -> last -> img -> style = SPACEFILL;
258 }
259 else
260 {
261#ifdef GTK3
262 if (widg != this_proj -> modelgl -> ogl_styles[st])
263 {
264 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)this_proj -> modelgl -> ogl_styles[st], TRUE);
265 }
266#endif
267 this_proj -> modelgl -> anim -> last -> img -> style = st;
268 }
269 clean_atom_style (this_proj);
270 if (st == WIREFRAME || st == PUNT)
271 {
272 j = 0;
273 }
274 else
275 {
276 j = 1;
277 }
278#ifdef GTK3
279 update_menus (this_proj -> modelgl);
280#endif
281 init_default_shaders (this_proj -> modelgl);
282 }
283}
284
293void set_this_style (glwin * view, int style)
294{
295 if (get_project_by_id(view -> proj) -> natomes)
296 {
297#ifdef GTK4
298 gchar * str = g_strdup_printf ("set-style.%d.0", style);
299 activate_glwin_action (str, "set-style", view);
300 g_free (str);
301#else
302 // GTK3 Menu Action To Check
303 if (style < OGL_STYLES)
304 {
305 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)view -> ogl_styles[style], TRUE);
306 set_style (view -> ogl_styles[style], & view -> colorp[style][0]);
307 }
308 else
309 {
310 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)view -> filled_styles[style-OGL_STYLES], TRUE);
311 set_style (view -> filled_styles[style-OGL_STYLES], & view -> colorp[style][0]);
312 }
313#endif
314 }
315}
316
317#ifdef GTK3
332GtkWidget * create_style_menu (char * name, int val, int style, int vbl, int filled, guint accel, GtkWidget * menu, tint * data)
333{
334 GtkWidget * style_widget = gtk3_menu_item (menu, name, IMG_NONE, NULL, G_CALLBACK(set_style), data, (accel != -1) ? TRUE : FALSE, accel,
335 0, TRUE, TRUE, (style == val && filled == vbl) ? TRUE : FALSE);
336 return style_widget;
337}
338
347GtkWidget * menu_style (glwin * view, int id)
348{
349 int i, j;
350 GtkWidget * widg;
351 GtkWidget * menus = gtk_menu_new ();
352 guint accels[OGL_STYLES-1]={GDK_KEY_b, GDK_KEY_w, GDK_KEY_s, GDK_KEY_c, GDK_KEY_d};
353 guint accelf[FILLED_STYLES]={GDK_KEY_o, GDK_KEY_i, GDK_KEY_v, GDK_KEY_r};
354 if (id == 0)
355 {
356 for (i=0; i<OGL_STYLES; i++)
357 {
358 if (i != SPACEFILL)
359 {
360 view -> ogl_styles[i] = create_style_menu (_(text_styles[i]),
361 i,
362 view -> anim -> last -> img -> style,
363 i,
364 i,
365 accels[(i < SPACEFILL) ? i : i-1],
366 menus,
367 & view -> colorp[i][0]);
368 }
369 else
370 {
371 widg = create_menu_item (FALSE, _("Spacefilled"));
372 gtk_menu_shell_append ((GtkMenuShell *)menus, widg);
373 GtkWidget * menuf = gtk_menu_new ();
374 gtk_menu_item_set_submenu ((GtkMenuItem *)widg, menuf);
375 for (j=0; j < FILLED_STYLES; j++)
376 {
377 view -> filled_styles[j] = create_style_menu (_(text_filled[j]),
378 SPACEFILL,
379 view -> anim -> last -> img -> style,
380 j,
381 view -> anim -> last -> img -> filled_type,
382 accelf[j],
383 menuf,
384 & view -> colorp[OGL_STYLES + j][0]);
385 }
386 }
387 }
388 }
389 else
390 {
391 for (i=0; i<OGL_STYLES; i++)
392 {
393 if (i != SPACEFILL)
394 {
395 widg = create_style_menu (_(text_styles[i]),
396 i,
397 view -> anim -> last -> img -> style,
398 i,
399 i,
400 accels[(i < SPACEFILL) ? i : i-1],
401 menus,
402 & view -> colorp[i][0]);
403 }
404 else
405 {
406 widg = create_menu_item (FALSE, _("Spacefilled"));
407 gtk_menu_shell_append ((GtkMenuShell *)menus, widg);
408 GtkWidget * menuf = gtk_menu_new ();
409 gtk_menu_item_set_submenu ((GtkMenuItem *)widg, menuf);
410 for (j=0; j < FILLED_STYLES; j++)
411 {
412 widg = create_style_menu (_(text_filled[j]),
413 SPACEFILL,
414 view -> anim -> last -> img -> style,
415 j,
416 view -> anim -> last -> img -> filled_type,
417 accelf[j],
418 menuf,
419 & view -> colorp[OGL_STYLES + j][0]);
420 }
421
422 }
423 }
424 }
425 return menus;
426}
427#else
437G_MODULE_EXPORT void change_style_radio (GSimpleAction * action, GVariant * parameter, gpointer data)
438{
439 glwin * view = (glwin *)data;
440 const gchar * style = g_variant_get_string (parameter, NULL);
441 int lgt = strlen (style);
442 gchar * name = g_strdup_printf ("%c%c", style[lgt-2], style[lgt-1]);
443 if (g_strcmp0(name, ".1") == 0)
444 {
445 g_free (name);
446 name = g_strdup_printf ("%.*s.0", lgt-2, style);
447 g_action_group_activate_action ((GActionGroup *)view -> action_group, "set-style", g_variant_new_string((const gchar *)name));
448 g_free (name);
449 }
450 else
451 {
452 gchar * style_name = NULL;
453 int i;
454 for (i=0; i<OGL_STYLES+FILLED_STYLES; i++)
455 {
456 style_name = g_strdup_printf ("set-style.%d.0", i);
457 if (g_strcmp0(style, (const gchar *)style_name) == 0)
458 {
459 set_style (NULL, & view -> colorp[i][0]);
460 g_free (style_name);
461 style_name = NULL;
462 break;
463 }
464 g_free (style_name);
465 style_name = NULL;
466 }
467 g_action_change_state (G_ACTION (action), parameter);
468 }
469}
470
479GMenu * menu_style (glwin * view, int popm)
480{
481 int i, j, k;
482 GMenu * menu = g_menu_new ();
483 gchar * accels[OGL_STYLES-1]={"b", "w", "s", "c", "d"};
484 gchar * accelf[FILLED_STYLES]={"o", "i", "v", "r"};
485
486 for (i=0; i<OGL_STYLES; i++, k++)
487 {
488 if (i != SPACEFILL)
489 {
490 append_opengl_item (view, menu, _(text_styles[i]), "style", popm, i,
491 accels[(i < SPACEFILL) ? i : i-1], IMG_NONE, NULL, FALSE,
492 G_CALLBACK(change_style_radio), (gpointer)view,
493 FALSE, (view -> anim -> last -> img -> style == i) ? TRUE : FALSE, TRUE, TRUE);
494 }
495 else
496 {
497 GMenu * menus = g_menu_new ();
498 for (j=0; j < FILLED_STYLES; j++)
499 {
500 append_opengl_item (view, menus, _(text_filled[j]), "style", popm, j+OGL_STYLES,
501 accelf[j], IMG_NONE, NULL, FALSE,
502 G_CALLBACK(change_style_radio), (gpointer)view,
503 FALSE, (view -> anim -> last -> img -> style == SPACEFILL && view -> anim -> last -> img -> filled_type == j) ? TRUE : FALSE, TRUE, TRUE);
504 }
505 append_submenu (menu, _("Spacefilled"), menus);
506 }
507 }
508 return menu;
509}
510#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
#define i18n(String)
Definition global.c:80
Global variable declarations Global convenience function declarations Global data structure defin...
@ IMG_NONE
Definition global.h:276
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:714
GtkWidget * create_menu_item(gboolean add_mnemo, gchar *action)
void hide_the_widgets(GtkWidget *widg)
hide GtkWidget
Definition gtk-misc.c:224
#define CHEM_Z
Definition global.h:316
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:202
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
char * text_filled[FILLED_STYLES]
Definition m_style.c:66
#define OGL_STYLES
Definition glwin.h:107
char * text_styles[OGL_STYLES]
Definition m_style.c:59
void activate_glwin_action(gchar *action_string, gchar *action_name, glwin *view)
the keyboard shortcut actions for the OpenGL window
Definition glwindow.c:824
G_MODULE_EXPORT void set_style(GtkWidget *widg, gpointer data)
set style callback
Definition m_style.c:209
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)
int get_filled_id(int sid)
retrieve filled ID number in FILLED_STYLES based on style ID
Definition m_style.c:184
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:209
int get_style_id(int sid)
retrieve style ID number in OGL_STYLES based on style ID
Definition m_style.c:196
void clean_atom_style(project *this_proj)
clean all atom(s) possible alternative rendering styles
Definition m_style.c:78
G_MODULE_EXPORT void change_style_radio(GSimpleAction *action, GVariant *parameter, gpointer data)
change style callback GTK4
Definition m_style.c:437
GMenu * menu_style(glwin *view, int popm)
create the 'OpenGL -> Style' submenu - GTK4
Definition m_style.c:479
void set_this_style(glwin *view, int style)
set general style for atom(s) and bond(s)
Definition m_style.c:293
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:967
Definition global.h:118
GtkWidget * img
Definition workspace.c:70