atomes 1.3.2
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 i = (active_project -> steps > 1) ? 25 : 0;
103 gtk_window_set_resizable (GTK_WINDOW (curvetoolbox), TRUE);
104#ifdef GTK4
105 gtk_window_set_default_size (GTK_WINDOW (curvetoolbox), 300, 230+i);
106 gtk_widget_set_size_request (curvetoolbox, 300, 230+i);
107#else
108#ifdef G_OS_WIN32
109 gtk_widget_set_size_request (curvetoolbox, 300, 220+i);
110#else
111// gtk_widget_set_size_request (curvetoolbox, 300, 320+i);
112 gtk_widget_set_size_request (curvetoolbox, 300, 300+i);
113#endif
114#endif
115 gtk_window_set_resizable (GTK_WINDOW (curvetoolbox), FALSE);
116 }
117 gtk_tree_store_clear (tool_model);
118 for (i=0; i<NCALCS; i++)
119 {
120 if (i != MSD && i != SKT)
121 {
122 append = TRUE;
123 }
124 else
125 {
126 if (active_project)
127 {
128 append = (active_project -> steps > 1) ? TRUE : FALSE;
129 }
130 else
131 {
132 append = FALSE;
133 }
134 }
135 if (append)
136 {
137 gtk_tree_store_append (tool_model, & calc_level, NULL);
138 img = GTK_IMAGE(gtk_image_new_from_file(graph_img[i]));
139#ifdef GTK4
140 gtk_tree_store_set (tool_model, & calc_level, 0, -1, 1, -1, 2, img, 3, _(graph_name[i]), -1);
141#else
142 GdkPixbuf * pix = gtk_image_get_pixbuf(img);
143 gtk_tree_store_set (tool_model, & calc_level, 0, -1, 1, -1, 2, pix, 3, _(graph_name[i]), -1);
144#endif
145
146 gtk_image_clear (img);
147 if (active_project)
148 {
149 if (active_project -> analysis)
150 {
151 if (active_project -> analysis[i])
152 {
153 if (active_project -> analysis[i] -> numc > 0 && active_project -> analysis[i] -> calc_ok)
154 {
155 for (j=0; j<active_project -> analysis[i] -> numc; j++)
156 {
157 if (active_project -> analysis[i] -> curves[j] -> name && active_project -> analysis[i] -> curves[j] -> ndata)
158 {
159 gtk_tree_store_append (tool_model, & curve_level, & calc_level);
160 status = FALSE;
161 str = g_strdup_printf ("%s", active_project -> analysis[i] -> curves[j] -> name);
162 if (active_project -> analysis[i] -> curves[j] -> window != NULL)
163 {
164 if (GTK_IS_WIDGET(active_project -> analysis[i] -> curves[j] -> window))
165 {
166 if (gtk_widget_get_visible(active_project -> analysis[i] -> curves[j] -> window)) status = TRUE;
167 }
168 }
169 gtk_tree_store_set (tool_model, & curve_level, 0, i, 1, j, 3, str, 4, status, -1);
170 g_free (str);
171 }
172 }
173 }
174 }
175 }
176 }
177 }
178 }
179}
180
181/* void tool_set_visible (GtkTreeViewColumn * col,
182 GtkCellRenderer * renderer,
183 GtkTreeModel * mod,
184 GtkTreeIter * iter,
185 gpointer data)
186
187 \brief show/hide and sensitive/not a GtkCellRenderer
188
189 \param col the column
190 \param renderer the cell renderer
191 \param mod the model
192 \param iter the iter
193 \param data the associated data pointer
194*/
195void tool_set_visible (GtkTreeViewColumn * col,
196 GtkCellRenderer * renderer,
197 GtkTreeModel * mod,
198 GtkTreeIter * iter,
199 gpointer data)
200{
201 int i, j, k;
202 i = GPOINTER_TO_INT(data);
203 gtk_tree_model_get (mod, iter, 0, & j, -1);
204 gboolean vis = ((j < 0 && i == 2) || (j > -1 && i == 0)) ? FALSE : TRUE;
205 gtk_cell_renderer_set_visible (renderer, vis);
206 if (! active_project)
207 {
208 gtk_cell_renderer_set_sensitive (renderer, FALSE);
209 }
210 else if (j > -1 && active_project -> analysis)
211 {
212 if (active_project -> analysis[j])
213 {
214 if (active_project -> analysis[j] -> numc)
215 {
216 gtk_tree_model_get (mod, iter, 1, & k, -1);
217 if (active_project) gtk_cell_renderer_set_sensitive (renderer, active_project -> analysis[j] -> curves[k] -> ndata);
218 if (i == 1)
219 {
220 set_renderer_markup (mod, iter, renderer, 3);
221 }
222 }
223 }
224 }
225 else
226 {
227 gtk_cell_renderer_set_sensitive (renderer, TRUE);
228 }
229}
230
240void adjust_tool_model (int calc, int curve, gchar * string_path)
241{
242 GtkTreeIter iter;
243 GtkTreePath * path = gtk_tree_path_new_from_string (string_path);
244 gtk_tree_model_get_iter (GTK_TREE_MODEL(tool_model), & iter, path);
245 if (calc == SPH || calc == MSD)
246 {
247 int i, j;
248 gtk_tree_model_get (GTK_TREE_MODEL(tool_model), & iter, 0, & i, -1);
249 gtk_tree_model_get (GTK_TREE_MODEL(tool_model), & iter, 1, & j, -1);
250 if (i == calc && j == curve) gtk_tree_store_set (tool_model, & iter, 4, 0, -1);
251 }
252 else
253 {
254 gtk_tree_store_set (tool_model, & iter, 4, 0, -1);
255 }
256}
257
268G_MODULE_EXPORT void toggle_show_hide_curve (GtkCellRendererToggle * cell_renderer,
269 gchar * string_path, gpointer data)
270{
271 int i, j, k;
272 GtkTreeIter iter;
273 GtkTreePath * path = gtk_tree_path_new_from_string (string_path);
274 gtk_tree_model_get_iter (GTK_TREE_MODEL(tool_model), & iter, path);
275 gtk_tree_model_get (GTK_TREE_MODEL(tool_model), & iter, 0, & i, -1);
276 gtk_tree_model_get (GTK_TREE_MODEL(tool_model), & iter, 1, & j, -1);
277 gtk_tree_model_get (GTK_TREE_MODEL(tool_model), & iter, 4, & k, -1);
278#ifdef DEBUG
279 // g_debug ("Show curve:: i= %d, j= %d, k= %d", i, j, k);
280#endif // DEBUG
281 if (! k)
282 {
283 if (active_project -> analysis[i] -> curves[j] -> window == NULL)
284 {
285 active_project -> analysis[i] -> curves[j] -> window = create_curve (& active_project -> analysis[i] -> idcc[j]);
286 active_project -> analysis[i] -> curves[j] -> path = g_strdup_printf ("%s", string_path);
287 }
288 show_the_widgets (active_project -> analysis[i] -> curves[j] -> window);
289 }
290 else
291 {
292 if (active_project -> analysis[i] -> curves[j] -> window != NULL)
293 {
294 hide_the_widgets (active_project -> analysis[i] -> curves[j] -> window);
295 }
296 }
297 gtk_tree_store_set (tool_model, & iter, 4, ! k, -1);
298}
299
305GtkWidget * create_tool_tree ()
306{
307 GtkTreeViewColumn * tool_col[3];
308 GtkCellRenderer * tool_cell[3];
309 gchar * ctitle[3]={i18n("Logo"), i18n("Name"), i18n("Button")};
310 gchar * ctype[3]={"pixbuf", "text", "active"};
311 GType coltype[5]= {G_TYPE_INT, G_TYPE_INT, G_TYPE_OBJECT, G_TYPE_STRING, G_TYPE_BOOLEAN};
312 tool_model = gtk_tree_store_newv (5, coltype);
313 int i;
315 tool_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(tool_model));
316 for (i=0; i<3; i++)
317 {
318 switch (i)
319 {
320 case 0:
321 tool_cell[i] = gtk_cell_renderer_pixbuf_new ();
322 break;
323 case 1:
324 tool_cell[i] = gtk_cell_renderer_text_new ();
325 break;
326 case 2:
327 tool_cell[i] = gtk_cell_renderer_toggle_new ();
328 g_signal_connect (G_OBJECT(tool_cell[i]), "toggled", G_CALLBACK(toggle_show_hide_curve), NULL);
329 break;
330 }
331 tool_col[i] = gtk_tree_view_column_new_with_attributes (_(ctitle[i]), tool_cell[i], ctype[i], i+2, NULL);
332 gtk_tree_view_append_column (GTK_TREE_VIEW(tool_tree), tool_col[i]);
333 gtk_tree_view_column_set_alignment (tool_col[i], 0.5);
334 // if (i == 1) gtk_tree_view_column_set_attributes (tool_col[i], tool_cell[i], "markup", 3, NULL);
335 gtk_tree_view_column_set_cell_data_func (tool_col[i], tool_cell[i], tool_set_visible, GINT_TO_POINTER(i), NULL);
336 }
337 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(tool_tree), FALSE);
338 return tool_tree;
339}
340
347{
348 GtkWidget * ctbox;
349 ctbox = create_win (_("Toolboxes"), atomes_main_window, FALSE, FALSE);
350#ifdef GTK4
351 gtk_window_set_default_size (GTK_WINDOW (ctbox), 300, 230);
352 // gtk_widget_set_size_request (ctbox, 300, 230);
353#else
354#ifdef G_OS_WIN32
355 gtk_widget_set_size_request (ctbox, 300, 220);
356#else
357 gtk_widget_set_size_request (ctbox, 300, 300);
358#endif
359#endif
360 // New calculation icon to be added here
361
362 tool_scroll = create_scroll (NULL, -1, -1, GTK_SHADOW_NONE);
366 add_gtk_close_event (ctbox, G_CALLBACK(hide_this_window), NULL);
367 return (ctbox);
368}
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 * atomes_main_window
Definition global.c:208
#define i18n(String)
Definition global.c:80
GtkWidget * curvetoolbox
Definition global.c:212
Global variable declarations Global convenience function declarations Global data structure defin...
#define SKT
Definition global.h:349
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:347
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:267
@ CONTAINER_SCR
Definition global.h:268
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:348
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:119
void tool_set_visible(GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *mod, GtkTreeIter *iter, gpointer data)
Definition tools.c:195
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:305
void adjust_tool_model(int calc, int curve, gchar *string_path)
adjust the content of the tool box tree model
Definition tools.c:240
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:378
GtkWidget * tool_scroll
Definition tools.c:62
GtkWidget * create_curve_tool_box()
create the curve tool box window
Definition tools.c:346
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:268
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.