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