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