atomes 1.1.16
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-2024 by CNRS and University of Strasbourg */
15
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 * tooltree ();
47 GtkWidget * curvetbox ();
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 * toolscroll = NULL;
63
71gchar * prepare_for_title (gchar * init)
72{
73 gchar * str = g_strdup_printf ("%s", substitute_string (init, "<sub>", NULL));
74 str = g_strdup_printf ("%s", substitute_string (str, "</sub>", NULL));
75 str = g_strdup_printf ("%s", substitute_string (str, "<sup>", NULL));
76 str = g_strdup_printf ("%s", substitute_string (str, "</sup>", NULL));
77 str = g_strdup_printf ("%s", substitute_string (str, "<i>", NULL));
78 str = g_strdup_printf ("%s", substitute_string (str, "</i>", NULL));
79 return str;
80}
81
88{
89 GtkTreeIter calc_level, curve_level;
90 int i, j;
91 gboolean status, append;
92 gchar * str;
93 GtkImage * img;
94
96 {
97 i = (active_project -> steps > 1) ? 25 : 0;
98 gtk_window_set_resizable (GTK_WINDOW (curvetoolbox), TRUE);
99#ifdef GTK4
100 gtk_widget_set_size_request (curvetoolbox, 300, 210+i);
101#else
102 gtk_widget_set_size_request (curvetoolbox, 300, 240+i);
103#endif
104 gtk_window_set_resizable (GTK_WINDOW (curvetoolbox), FALSE);
105 }
106 gtk_tree_store_clear (tool_model);
107 for (i=0; i<NGRAPHS; i++)
108 {
109 if (i != MS)
110 {
111 append = TRUE;
112 }
113 else
114 {
115 if (active_project)
116 {
117 append = (active_project -> steps > 1) ? TRUE : FALSE;
118 }
119 else
120 {
121 append = FALSE;
122 }
123 }
124 if (append)
125 {
126 gtk_tree_store_append (tool_model, & calc_level, NULL);
127 img = GTK_IMAGE(gtk_image_new_from_file(graph_img[i]));
128#ifdef GTK4
129 gtk_tree_store_set (tool_model, & calc_level, 0, -1, 1, -1, 2, img, 3, graph_name[i], -1);
130#else
131 GdkPixbuf * pix = gtk_image_get_pixbuf(img);
132 gtk_tree_store_set (tool_model, & calc_level, 0, -1, 1, -1, 2, pix, 3, graph_name[i], -1);
133#endif
134
135 gtk_image_clear (img);
136 if (active_project)
137 {
138 if (active_project -> numc[i] > 0 && active_project -> visok[i])
139 {
140 for (j=0; j<active_project -> numc[i]; j++)
141 {
142 if (active_project -> curves[i][j] -> name && active_project -> curves[i][j] -> ndata)
143 {
144 gtk_tree_store_append (tool_model, & curve_level, & calc_level);
145 status = FALSE;
146 str = g_strdup_printf ("%s", active_project -> curves[i][j] -> name);
147 if (active_project -> curves[i][j] -> window != NULL)
148 {
149 if (GTK_IS_WIDGET(active_project -> curves[i][j] -> window))
150 {
151 if (gtk_widget_get_visible(active_project -> curves[i][j] -> window)) status = TRUE;
152 }
153 }
154 gtk_tree_store_set (tool_model, & curve_level, 0, i, 1, j, 3, str, 4, status, -1);
155 g_free (str);
156 }
157 }
158 }
159 }
160 }
161 }
162}
163
164/* void tool_set_visible (GtkTreeViewColumn * col,
165 GtkCellRenderer * renderer,
166 GtkTreeModel * mod,
167 GtkTreeIter * iter,
168 gpointer data)
169
170 \brief show/hide and sensitive/not a GtkCellRenderer
171
172 \param col the column
173 \param renderer the cell renderer
174 \param mod the model
175 \param iter the iter
176 \param data the associated data pointer
177*/
178void tool_set_visible (GtkTreeViewColumn * col,
179 GtkCellRenderer * renderer,
180 GtkTreeModel * mod,
181 GtkTreeIter * iter,
182 gpointer data)
183{
184 int i, j, k;
185 i = GPOINTER_TO_INT(data);
186 gtk_tree_model_get (mod, iter, 0, & j, -1);
187 gboolean vis = ((j < 0 && i == 2) || (j > -1 && i == 0)) ? FALSE : TRUE;
188 gtk_cell_renderer_set_visible (renderer, vis);
189 if (! active_project)
190 {
191 gtk_cell_renderer_set_sensitive (renderer, FALSE);
192 }
193 else if (j > -1 && active_project -> numwid > 0)
194 {
195 if (active_project -> numc[j])
196 {
197 gtk_tree_model_get (mod, iter, 1, & k, -1);
198 if (active_project) gtk_cell_renderer_set_sensitive (renderer, active_project -> curves[j][k] -> ndata);
199 }
200 }
201 else
202 {
203 gtk_cell_renderer_set_sensitive (renderer, TRUE);
204 }
205}
206
216void adjust_tool_model (int calc, int curve, gchar * string_path)
217{
218 GtkTreeIter iter;
219 GtkTreePath * path = gtk_tree_path_new_from_string (string_path);
220 gtk_tree_model_get_iter (GTK_TREE_MODEL(tool_model), & iter, path);
221 if (calc == SP || calc == MS)
222 {
223 int i, j;
224 gtk_tree_model_get (GTK_TREE_MODEL(tool_model), & iter, 0, & i, -1);
225 gtk_tree_model_get (GTK_TREE_MODEL(tool_model), & iter, 1, & j, -1);
226 if (i == calc && j == curve) gtk_tree_store_set (tool_model, & iter, 4, 0, -1);
227 }
228 else
229 {
230 gtk_tree_store_set (tool_model, & iter, 4, 0, -1);
231 }
232}
233
244G_MODULE_EXPORT void toggle_show_hide_curve (GtkCellRendererToggle * cell_renderer,
245 gchar * string_path, gpointer data)
246{
247 int i, j, k;
248 GtkTreeIter iter;
249 GtkTreePath * path = gtk_tree_path_new_from_string (string_path);
250 gtk_tree_model_get_iter (GTK_TREE_MODEL(tool_model), & iter, path);
251 gtk_tree_model_get (GTK_TREE_MODEL(tool_model), & iter, 0, & i, -1);
252 gtk_tree_model_get (GTK_TREE_MODEL(tool_model), & iter, 1, & j, -1);
253 gtk_tree_model_get (GTK_TREE_MODEL(tool_model), & iter, 4, & k, -1);
254#ifdef DEBUG
255 // g_debug ("Show curve:: i= %d, j= %d, k= %d", i, j, k);
256#endif // DEBUG
257 if (! k)
258 {
259 if (active_project -> curves[i][j] -> window == NULL)
260 {
261 active_project -> curves[i][j] -> window = create_curve (& active_project -> idcc[i][j]);
262 active_project -> curves[i][j] -> path = g_strdup_printf ("%s", string_path);
263 }
264 show_the_widgets (active_project -> curves[i][j] -> window);
265 }
266 else
267 {
268 if (active_project -> curves[i][j] -> window != NULL)
269 {
270 hide_the_widgets (active_project -> curves[i][j] -> window);
271 }
272 }
273 gtk_tree_store_set (tool_model, & iter, 4, ! k, -1);
274}
275
281GtkWidget * tooltree ()
282{
283 GtkTreeViewColumn * tool_col[3];
284 GtkCellRenderer * tool_cell[3];
285 gchar * ctitle[3]={"Logo", "Name", "Button"};
286 gchar * ctype[3]={"pixbuf", "text", "active"};
287 GType coltype[5]= {G_TYPE_INT, G_TYPE_INT, G_TYPE_OBJECT, G_TYPE_STRING, G_TYPE_BOOLEAN};
288 tool_model = gtk_tree_store_newv (5, coltype);
289 int i;
291 tool_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(tool_model));
292 for (i=0; i<3; i++)
293 {
294 switch (i)
295 {
296 case 0:
297 tool_cell[i] = gtk_cell_renderer_pixbuf_new ();
298 break;
299 case 1:
300 tool_cell[i] = gtk_cell_renderer_text_new ();
301 break;
302 case 2:
303 tool_cell[i] = gtk_cell_renderer_toggle_new ();
304 g_signal_connect (G_OBJECT(tool_cell[i]), "toggled", G_CALLBACK(toggle_show_hide_curve), NULL);
305 break;
306 }
307 tool_col[i] = gtk_tree_view_column_new_with_attributes (ctitle[i], tool_cell[i], ctype[i], i+2, NULL);
308 gtk_tree_view_append_column(GTK_TREE_VIEW(tool_tree), tool_col[i]);
309 gtk_tree_view_column_set_alignment (tool_col[i], 0.5);
310 gtk_tree_view_column_set_cell_data_func (tool_col[i], tool_cell[i], tool_set_visible, GINT_TO_POINTER(i), NULL);
311 }
312 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(tool_tree), FALSE);
313 return tool_tree;
314}
315
321GtkWidget * curvetbox ()
322{
323 GtkWidget * ctbox;
324 ctbox = create_win ("Toolboxes", MainWindow, FALSE, FALSE);
325#ifdef GTK4
326 gtk_widget_set_size_request (ctbox, 300, 210);
327#else
328 gtk_widget_set_size_request (ctbox, 300, 240);
329#endif
330 graph_img[0] = g_strdup_printf ("%s", PACKAGE_GR);
331 graph_img[1] = g_strdup_printf ("%s", PACKAGE_SQ);
332 graph_img[2] = g_strdup_printf ("%s", PACKAGE_SQ);
333 graph_img[3] = g_strdup_printf ("%s", PACKAGE_GR);
334 graph_img[4] = g_strdup_printf ("%s", PACKAGE_BD);
335 graph_img[5] = g_strdup_printf ("%s", PACKAGE_AN);
336 graph_img[6] = g_strdup_printf ("%s", PACKAGE_RI);
337 graph_img[7] = g_strdup_printf ("%s", PACKAGE_CH);
338 graph_img[8] = g_strdup_printf ("%s", PACKAGE_SP);
339 graph_img[9] = g_strdup_printf ("%s", PACKAGE_MS);
340
341 toolscroll = create_scroll (NULL, -1, -1, GTK_SHADOW_NONE);
345 add_gtk_close_event (ctbox, G_CALLBACK(hide_this_window), NULL);
346 return (ctbox);
347}
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:834
gchar * PACKAGE_AN
Definition global.c:93
gchar * PACKAGE_SP
Definition global.c:96
gchar * PACKAGE_BD
Definition global.c:92
gchar * PACKAGE_RI
Definition global.c:94
GtkWidget * MainWindow
Definition global.c:201
gchar * PACKAGE_GR
Definition global.c:90
gchar * PACKAGE_MS
Definition global.c:97
gchar * PACKAGE_CH
Definition global.c:95
GtkWidget * curvetoolbox
Definition global.c:205
gchar * PACKAGE_SQ
Definition global.c:91
Global variable declarations Global convenience function declarations Global data structure defin...
GtkWidget * create_scroll(GtkWidget *box, int dimx, int dimy, int shadow)
create a scroll window
Definition gtk-misc.c:1960
GtkWidget * create_win(gchar *str, GtkWidget *parent, gboolean modal, gboolean resiz)
create a new GtkWindow
Definition gtk-misc.c:445
G_MODULE_EXPORT gboolean hide_this_window(GtkWidget *win, GdkEvent *event, gpointer data)
hide a GtkWindow
Definition gtk-misc.c:2371
gchar * graph_img[NGRAPHS]
Definition gui.c:106
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:2387
#define NGRAPHS
@ CONTAINER_WIN
Definition global.h:250
@ CONTAINER_SCR
Definition global.h:251
#define MS
Definition global.h:331
char * graph_name[NGRAPHS]
Definition gui.c:133
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:226
void hide_the_widgets(GtkWidget *widg)
hide GtkWidget
Definition gtk-misc.c:189
#define SP
Definition global.h:330
project * active_project
Definition project.c:47
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:173
Messaging function declarations.
Function declarations for reading atomes project file Function declarations for saving atomes proje...
Definition global.h:104
void tool_set_visible(GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *mod, GtkTreeIter *iter, gpointer data)
Definition tools.c:178
GtkWidget * tooltree()
create the toolbox tree view
Definition tools.c:281
void fill_tool_model()
fill the tool window tree model
Definition tools.c:87
void adjust_tool_model(int calc, int curve, gchar *string_path)
adjust the content of the tool box tree model
Definition tools.c:216
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:372
GtkWidget * curvetbox()
create the curve tool box window
Definition tools.c:321
GtkWidget * toolscroll
Definition tools.c:62
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:244
GtkWidget * create_curve(tint *data)
create the curve data plot window
Definition w_curve.c:605
int status
Definition w_advance.c:160
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.