atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
tools.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: 'tools.c'
24*
25* Contains:
26*
27
28 - The callbacks for the toolbox dialog
29
30*
31* List of functions:
32
33 gchar * prepare_for_title (gchar * init);
34
35 void fill_tool_model ();
36 void tool_set_visible (GtkTreeViewColumn * col,
37 GtkCellRenderer * renderer,
38 GtkTreeModel * mod,
39 GtkTreeIter * iter,
40 gpointer data);
41 void adjust_tool_model (int calc, int curve, gchar * string_path);
42
43 G_MODULE_EXPORT void toggle_show_hide_curve (GtkCellRendererToggle * cell_renderer,
44 gchar * string_path, gpointer data);
45
46 GtkWidget * create_tool_tree ();
47 GtkWidget * create_curve_tool_box ();
48
49*/
50
51#include "global.h"
52#include "callbacks.h"
53#include "interface.h"
54#include "project.h"
55#include "workspace.h"
56
57extern GtkWidget * create_curve (tint * data);
58extern gchar * substitute_string (gchar * init, gchar * o_motif, gchar * n_motif);
59
60GtkTreeStore * tool_model = NULL;
61GtkWidget * tool_tree = NULL;
62GtkWidget * tool_scroll = NULL;
63
71gchar * prepare_for_title (gchar * init)
72{
73 gchar * str = substitute_string (init, "<sub>", NULL);
74 str = substitute_string (str, "</sub>", NULL);
75 str = substitute_string (str, "<sup>", NULL);
76 str = substitute_string (str, "</sup>", NULL);
77 str = substitute_string (str, "<i>", NULL);
78 str = substitute_string (str, "</i>", NULL);
79 str = substitute_string (str, "<b>", NULL);
80 str = substitute_string (str, "</b>", NULL);
81 str = substitute_string (str, "<u>", NULL);
82 str = substitute_string (str, "</u>", NULL);
83 return str;
84}
85
92{
93 GtkTreeIter calc_level, curve_level;
94 int i, j;
95 gboolean status, append;
96 gchar * str;
97 GtkImage * img;
98
100 {
101 i = (active_project -> steps > 1) ? 45 : 0;
102 gtk_window_set_resizable (GTK_WINDOW (curvetoolbox), TRUE);
103#ifdef GTK4
104 gtk_window_set_default_size (GTK_WINDOW (curvetoolbox), 300, 250+i);
105#else
106 gtk_widget_set_size_request (curvetoolbox, 300, 320+i);
107#endif
108 gtk_window_set_resizable (GTK_WINDOW (curvetoolbox), FALSE);
109 }
110 gtk_tree_store_clear (tool_model);
111 for (i=0; i<NCALCS; i++)
112 {
113 if (i != MSD && i != SKT)
114 {
115 append = TRUE;
116 }
117 else
118 {
119 if (active_project)
120 {
121 append = (active_project -> steps > 1) ? TRUE : FALSE;
122 }
123 else
124 {
125 append = FALSE;
126 }
127 }
128 if (append)
129 {
130 gtk_tree_store_append (tool_model, & calc_level, NULL);
131 img = GTK_IMAGE(gtk_image_new_from_file(graph_img[i]));
132#ifdef GTK4
133 gtk_tree_store_set (tool_model, & calc_level, 0, -1, 1, -1, 2, img, 3, _(graph_name[i]), -1);
134#else
135 GdkPixbuf * pix = gtk_image_get_pixbuf(img);
136 gtk_tree_store_set (tool_model, & calc_level, 0, -1, 1, -1, 2, pix, 3, _(graph_name[i]), -1);
137#endif
138
139 gtk_image_clear (img);
140 if (active_project)
141 {
142 if (active_project -> analysis)
143 {
144 if (active_project -> analysis[i])
145 {
146 if (active_project -> analysis[i] -> numc > 0 && active_project -> analysis[i] -> calc_ok)
147 {
148 for (j=0; j<active_project -> analysis[i] -> numc; j++)
149 {
150 if (active_project -> analysis[i] -> curves[j] -> name && active_project -> analysis[i] -> curves[j] -> ndata)
151 {
152 gtk_tree_store_append (tool_model, & curve_level, & calc_level);
153 status = FALSE;
154 str = g_strdup_printf ("%s", active_project -> analysis[i] -> curves[j] -> name);
155 if (active_project -> analysis[i] -> curves[j] -> window != NULL)
156 {
157 if (GTK_IS_WIDGET(active_project -> analysis[i] -> curves[j] -> window))
158 {
159 if (gtk_widget_get_visible(active_project -> analysis[i] -> curves[j] -> window)) status = TRUE;
160 }
161 }
162 gtk_tree_store_set (tool_model, & curve_level, 0, i, 1, j, 3, str, 4, status, -1);
163 g_free (str);
164 }
165 }
166 }
167 }
168 }
169 }
170 }
171 }
172}
173
174/* void tool_set_visible (GtkTreeViewColumn * col,
175 GtkCellRenderer * renderer,
176 GtkTreeModel * mod,
177 GtkTreeIter * iter,
178 gpointer data)
179
180 \brief show/hide and sensitive/not a GtkCellRenderer
181
182 \param col the column
183 \param renderer the cell renderer
184 \param mod the model
185 \param iter the iter
186 \param data the associated data pointer
187*/
188void tool_set_visible (GtkTreeViewColumn * col,
189 GtkCellRenderer * renderer,
190 GtkTreeModel * mod,
191 GtkTreeIter * iter,
192 gpointer data)
193{
194 int i, j, k;
195 i = GPOINTER_TO_INT(data);
196 gtk_tree_model_get (mod, iter, 0, & j, -1);
197 gboolean vis = ((j < 0 && i == 2) || (j > -1 && i == 0)) ? FALSE : TRUE;
198 gtk_cell_renderer_set_visible (renderer, vis);
199 if (! active_project)
200 {
201 gtk_cell_renderer_set_sensitive (renderer, FALSE);
202 }
203 else if (j > -1 && active_project -> analysis)
204 {
205 if (active_project -> analysis[j])
206 {
207 if (active_project -> analysis[j] -> numc)
208 {
209 gtk_tree_model_get (mod, iter, 1, & k, -1);
210 if (active_project) gtk_cell_renderer_set_sensitive (renderer, active_project -> analysis[j] -> curves[k] -> ndata);
211 if (i == 1)
212 {
213 set_renderer_markup (mod, iter, renderer, 3);
214 }
215 }
216 }
217 }
218 else
219 {
220 gtk_cell_renderer_set_sensitive (renderer, TRUE);
221 }
222}
223
233void adjust_tool_model (int calc, int curve, gchar * string_path)
234{
235 GtkTreeIter iter;
236 GtkTreePath * path = gtk_tree_path_new_from_string (string_path);
237 gtk_tree_model_get_iter (GTK_TREE_MODEL(tool_model), & iter, path);
238 if (calc == SPH || calc == MSD)
239 {
240 int i, j;
241 gtk_tree_model_get (GTK_TREE_MODEL(tool_model), & iter, 0, & i, -1);
242 gtk_tree_model_get (GTK_TREE_MODEL(tool_model), & iter, 1, & j, -1);
243 if (i == calc && j == curve) gtk_tree_store_set (tool_model, & iter, 4, 0, -1);
244 }
245 else
246 {
247 gtk_tree_store_set (tool_model, & iter, 4, 0, -1);
248 }
249}
250
261G_MODULE_EXPORT void toggle_show_hide_curve (GtkCellRendererToggle * cell_renderer,
262 gchar * string_path, gpointer data)
263{
264 int i, j, k;
265 GtkTreeIter iter;
266 GtkTreePath * path = gtk_tree_path_new_from_string (string_path);
267 gtk_tree_model_get_iter (GTK_TREE_MODEL(tool_model), & iter, path);
268 gtk_tree_model_get (GTK_TREE_MODEL(tool_model), & iter, 0, & i, -1);
269 gtk_tree_model_get (GTK_TREE_MODEL(tool_model), & iter, 1, & j, -1);
270 gtk_tree_model_get (GTK_TREE_MODEL(tool_model), & iter, 4, & k, -1);
271#ifdef DEBUG
272 // g_debug ("Show curve:: i= %d, j= %d, k= %d", i, j, k);
273#endif // DEBUG
274 if (! k)
275 {
276 if (active_project -> analysis[i] -> curves[j] -> window == NULL)
277 {
278 active_project -> analysis[i] -> curves[j] -> window = create_curve (& active_project -> analysis[i] -> idcc[j]);
279 active_project -> analysis[i] -> curves[j] -> path = g_strdup_printf ("%s", string_path);
280 }
281 show_the_widgets (active_project -> analysis[i] -> curves[j] -> window);
282 }
283 else
284 {
285 if (active_project -> analysis[i] -> curves[j] -> window != NULL)
286 {
287 hide_the_widgets (active_project -> analysis[i] -> curves[j] -> window);
288 }
289 }
290 gtk_tree_store_set (tool_model, & iter, 4, ! k, -1);
291}
292
298GtkWidget * create_tool_tree ()
299{
300 GtkTreeViewColumn * tool_col[3];
301 GtkCellRenderer * tool_cell[3];
302 gchar * ctitle[3]={i18n("Logo"), i18n("Name"), i18n("Button")};
303 gchar * ctype[3]={"pixbuf", "text", "active"};
304 GType coltype[5]= {G_TYPE_INT, G_TYPE_INT, G_TYPE_OBJECT, G_TYPE_STRING, G_TYPE_BOOLEAN};
305 tool_model = gtk_tree_store_newv (5, coltype);
306 int i;
308 tool_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(tool_model));
309 for (i=0; i<3; i++)
310 {
311 switch (i)
312 {
313 case 0:
314 tool_cell[i] = gtk_cell_renderer_pixbuf_new ();
315 break;
316 case 1:
317 tool_cell[i] = gtk_cell_renderer_text_new ();
318 break;
319 case 2:
320 tool_cell[i] = gtk_cell_renderer_toggle_new ();
321 g_signal_connect (G_OBJECT(tool_cell[i]), "toggled", G_CALLBACK(toggle_show_hide_curve), NULL);
322 break;
323 }
324 tool_col[i] = gtk_tree_view_column_new_with_attributes (_(ctitle[i]), tool_cell[i], ctype[i], i+2, NULL);
325 gtk_tree_view_append_column (GTK_TREE_VIEW(tool_tree), tool_col[i]);
326 gtk_tree_view_column_set_alignment (tool_col[i], 0.5);
327 // if (i == 1) gtk_tree_view_column_set_attributes (tool_col[i], tool_cell[i], "markup", 3, NULL);
328 gtk_tree_view_column_set_cell_data_func (tool_col[i], tool_cell[i], tool_set_visible, GINT_TO_POINTER(i), NULL);
329 }
330 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(tool_tree), FALSE);
331 return tool_tree;
332}
333
340{
341 GtkWidget * ctbox;
342 ctbox = create_win (_("Toolboxes"), MainWindow, FALSE, FALSE);
343#ifdef GTK4
344 gtk_widget_set_size_request (ctbox, 300, 250);
345#else
346 gtk_widget_set_size_request (ctbox, 300, 320);
347#endif
348 // New calculation icon to be added here
349
350 tool_scroll = create_scroll (NULL, -1, -1, GTK_SHADOW_NONE);
354 add_gtk_close_event (ctbox, G_CALLBACK(hide_this_window), NULL);
355 return (ctbox);
356}
Callback declarations for main window.
ColRGBA col
Definition d_measures.c:77
GtkTreePath * path
Definition datab.c:103
gchar * ctitle[MAXDATA][12]
Definition dlp_field.c:924
GtkWidget * MainWindow
Definition global.c:207
#define i18n(String)
Definition global.c:80
GtkWidget * curvetoolbox
Definition global.c:211
Global variable declarations Global convenience function declarations Global data structure defin...
#define SKT
Definition global.h:347
GtkWidget * create_scroll(GtkWidget *box, int dimx, int dimy, int shadow)
create a scroll window
Definition gtk-misc.c:2139
GtkWidget * create_win(gchar *str, GtkWidget *parent, gboolean modal, gboolean resiz)
create a new GtkWindow
Definition gtk-misc.c:486
gchar * graph_img[NCALCS]
Definition gui.c:106
char * graph_name[]
Definition gui.c:123
G_MODULE_EXPORT gboolean hide_this_window(GtkWidget *win, GdkEvent *event, gpointer data)
hide a GtkWindow
Definition gtk-misc.c:2541
#define SPH
Definition global.h:345
void add_gtk_close_event(GtkWidget *widg, GCallback handler, gpointer data)
add a close event signal and callback to a GtkWidget
Definition gtk-misc.c:2557
void set_renderer_markup(GtkTreeModel *mod, GtkTreeIter *iter, GtkCellRenderer *renderer, int col)
set Pango text markup for a GtkCellRenderer
Definition gtk-misc.c:1764
@ CONTAINER_WIN
Definition global.h:266
@ CONTAINER_SCR
Definition global.h:267
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:267
void hide_the_widgets(GtkWidget *widg)
hide GtkWidget
Definition gtk-misc.c:224
project * active_project
Definition project.c:47
#define NCALCS
#define MSD
Definition global.h:346
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:202
Messaging function declarations.
Function declarations for reading atomes project file Function declarations for saving atomes proje...
Definition global.h:118
void tool_set_visible(GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *mod, GtkTreeIter *iter, gpointer data)
Definition tools.c:188
void fill_tool_model()
fill the tool window tree model
Definition tools.c:91
GtkWidget * create_tool_tree()
create the toolbox tree view
Definition tools.c:298
void adjust_tool_model(int calc, int curve, gchar *string_path)
adjust the content of the tool box tree model
Definition tools.c:233
GtkTreeStore * tool_model
Definition tools.c:60
gchar * substitute_string(gchar *init, gchar *o_motif, gchar *n_motif)
substitute all patterns in string
Definition w_library.c:375
GtkWidget * tool_scroll
Definition tools.c:62
GtkWidget * create_curve_tool_box()
create the curve tool box window
Definition tools.c:339
GtkWidget * tool_tree
Definition tools.c:61
gchar * prepare_for_title(gchar *init)
prepare a string for a window title, getting rid of all markup
Definition tools.c:71
G_MODULE_EXPORT void toggle_show_hide_curve(GtkCellRendererToggle *cell_renderer, gchar *string_path, gpointer data)
To show/hide a curve by clicking in the tree view.
Definition tools.c:261
GtkWidget * create_curve(tint *data)
create the curve data plot window
Definition w_curve.c:581
int status
Definition w_advance.c:173
gboolean append(atom_search *asearch, project *this_proj, int i, int j)
test if the atom 'i' of species 'j' must be added to the tree store or not
Definition w_search.c:756
GdkPixbuf * pix
Definition workspace.c:69
GtkWidget * img
Definition workspace.c:70
Function declarations for workspace managment.