atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
cedit.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: 'cedit.c'
24*
25* Contains:
26*
27
28- The initialization of the curve layout edition dialog
29
30*
31* List of functions:
32
33 void prepbox (gpointer data);
34 void set_set (int a, int b, int c, gpointer data);
35 void set_visible_curve_data (GtkTreeViewColumn * col, GtkCellRenderer * renderer, GtkTreeModel * mod, GtkTreeIter * iter, gpointer data);
36 void edit_curve (gpointer data);
37
38 static void fill_proj_model (curve_edition * cedit, GtkTreeStore * store, gpointer data);
39
40 G_MODULE_EXPORT void run_curve_edit (GtkDialog * dial, gint response_id, gpointer data);
41
42 GtkWidget * create_projects_tree (gpointer data);
43
44*/
45
46#ifdef HAVE_CONFIG_H
47# include <config.h>
48#endif
49
50#include <gtk/gtk.h>
51#include <cairo.h>
52#include <cairo-pdf.h>
53#include <cairo-svg.h>
54#include <string.h>
55#include <stdlib.h>
56#include <math.h>
57
58#include "global.h"
59#include "interface.h"
60#include "callbacks.h"
61#include "project.h"
62#include "curve.h"
63
64extern G_MODULE_EXPORT void set_data_aspect (GtkComboBox * box, gpointer data);
65extern G_MODULE_EXPORT void update_axis (GtkComboBox * widg, gpointer data);
66extern void action_to_plot (gpointer data);
67extern gboolean was_not_added (ExtraSets * sets, int a, int b, int c);
68extern G_MODULE_EXPORT void choose_set (GtkComboBox * box, gpointer data);
69extern GtkWidget * create_org_list (gpointer data);
70extern GtkWidget * create_tab_1 (curve_edition * cedit, gpointer data);
71extern GtkWidget * create_tab_2 (curve_edition * cedit, gpointer data);
72extern GtkWidget * create_tab_3 (curve_edition * cedit, gpointer data);
73extern GtkWidget * create_tab_4 (curve_edition * cedit, gpointer data);
74
75int activeg = 0;
76int activec = 0;
77int activer = 0;
78char * lapos[2]={"x: ", "y: "};
79
87void prepbox (gpointer data)
88{
89 int i, n, o, p;
90 gchar * str;
91 project * extra_proj;
92 project * this_proj = get_project_by_id(((tint *)data) -> a);
93 Curve * this_curve = get_curve_from_pointer (data);
94 curve_edition * cedit = this_curve -> curve_edit;
95 str = g_strdup_printf ("%s - %s", prepare_for_title(this_proj -> name), this_curve -> name);
96 combo_text_append (cedit -> setcolorbox, str);
97 g_free (str);
98 CurveExtra * ctmp = this_curve -> extrac -> first;
99 for ( i=0 ; i < this_curve -> extrac -> extras ; i++ )
100 {
101 n = ctmp -> id.a;
102 o = ctmp -> id.b;
103 p = ctmp -> id.c;
104 extra_proj = get_project_by_id(n);
105 str = g_strdup_printf ("%s - %s", prepare_for_title(extra_proj -> name), extra_proj -> analysis[o] -> curves[p] -> name);
106 combo_text_append (cedit -> setcolorbox, str);
107 g_free (str);
108 if (ctmp -> next != NULL) ctmp = ctmp -> next;
109 }
110 if (this_curve -> extrac -> extras > 0)
111 {
112 widget_set_sensitive (cedit -> setcolorbox, 1);
113 }
114 else
115 {
116 widget_set_sensitive (cedit -> setcolorbox, 0);
117 }
118 gtk_widget_set_size_request (cedit -> setcolorbox, -1, 30);
119 combo_set_active (cedit -> setcolorbox, 0);
120 g_signal_connect (G_OBJECT(cedit -> setcolorbox), "changed", G_CALLBACK(choose_set), data);
121}
122
133void set_set (int a, int b, int c, gpointer data)
134{
135 Curve * this_curve = get_curve_from_pointer (data);
136 curve_edition * cedit = this_curve -> curve_edit;
137 cedit -> setcolorbox = destroy_this_widget (cedit -> setcolorbox);
138 cedit -> setcolorbox = create_combo ();
139 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cedit -> thesetbox, cedit -> setcolorbox, FALSE, FALSE, 0);
140 show_the_widgets (cedit -> setcolorbox);
141 activeg = ((tint *)data) -> a;
142 action_to_plot (& get_project_by_id(a) -> analysis[b] -> idcc[c]);
143 prepbox (data);
144 choose_set (GTK_COMBO_BOX(cedit -> setcolorbox), data);
145 cedit -> orgtree = destroy_this_widget (cedit -> orgtree);
146 add_container_child (CONTAINER_SCR, cedit -> datascroll, create_org_list(data));
147 show_the_widgets (cedit -> orgtree);
148 widget_set_sensitive (cedit -> orgtree, this_curve -> extrac -> extras);
149}
150
160static void fill_proj_model (curve_edition * cedit, GtkTreeStore * store, gpointer data)
161{
162 GtkTreeIter projlevel;
163 GtkTreeIter calclevel;
164 GtkTreeIter curvelevel;
165 project * this_proj;
166 int i, j, k, l;
167 gboolean append;
168 int pid = ((tint *)data) -> a;
169 int rid = ((tint *)data) -> b;
170 int cid = ((tint *)data) -> c;
171
172 /* Append a top level row and leave it empty */
173 if (cedit -> ppath != NULL) g_free (cedit -> ppath);
174 if (cedit -> cpath != NULL) g_free (cedit -> cpath);
175 cedit -> ppath = g_malloc0(nprojects*sizeof*cedit -> ppath);
176 cedit -> cpath = g_malloc0(nprojects*sizeof*cedit -> cpath);
177
178 project * the_proj = get_project_by_id (pid);
179 for (i=0; i<nprojects; i++)
180 {
181 this_proj = get_project_by_id (i);
182 gtk_tree_store_append (store, & projlevel, NULL);
183 gtk_tree_store_set (store, & projlevel, 0, 0, 1, prepare_for_title(this_proj -> name), 2, TRUE, 3, -1, -1);
184 cedit -> ppath[i] = gtk_tree_model_get_path ((GtkTreeModel *)store, & projlevel);
185 for (j=0; j<the_proj -> analysis[rid] -> c_sets; j++)
186 {
187 k = the_proj -> analysis[rid] -> compat_id[j];
188 if (this_proj -> analysis[k] -> calc_ok)
189 {
190 gtk_tree_store_append (store, & calclevel, & projlevel);
191 gtk_tree_store_set (store, & calclevel, 0, 0, 1, graph_name[k], 2, TRUE, 3, -1, -1);
192 if (j == 0)
193 {
194 cedit -> cpath[i] = gtk_tree_model_get_path ((GtkTreeModel *)store, & calclevel);
195 }
196 for (l = 0 ; l < this_proj -> analysis[k] -> numc ; l++)
197 {
198 append = FALSE;
199 if (i != pid && this_proj -> analysis[k] -> curves[l] -> ndata != 0)
200 {
201 append = TRUE;
202 }
203 else if (((i != pid) || (k != rid || l != cid)) && this_proj -> analysis[k] -> curves[l] -> ndata != 0)
204 {
205 append = TRUE;
206 }
207
208 if (append)
209 {
210 // Special condition for the F(k,t) and S(q,w)
211 if (rid == SKT)
212 {
213 if (cid < the_proj -> skt_sets && l > this_proj -> skt_sets-1)
214 {
215 append = FALSE;
216 }
217 else if (cid > the_proj -> skt_sets-1 && l < this_proj -> skt_sets)
218 {
219 append = FALSE;
220 }
221 }
222 }
223 if (append)
224 {
225 gtk_tree_store_append (store, & curvelevel, & calclevel);
226 gtk_tree_store_set (store, & curvelevel,
227 0, 1,
228 1, this_proj -> analysis[k] -> curves[l] -> name,
229 2, ! was_not_added (get_curve_from_pointer(data) -> extrac, i, k, l),
230 3, i,
231 4, k,
232 5, l, -1);
233 }
234 }
235 }
236 }
237 }
238}
239
240GtkTreeStore * projmodel;
241
251G_MODULE_EXPORT void toggle_curve (GtkCellRendererToggle * cell_renderer, gchar * string_path, gpointer data)
252{
253 int i, j, k;
254 gboolean status;
255 GtkTreeIter iter;
256 GtkTreePath * path = gtk_tree_path_new_from_string (string_path);
257 gtk_tree_model_get_iter (GTK_TREE_MODEL(projmodel), & iter, path);
258 gtk_tree_model_get (GTK_TREE_MODEL(projmodel), & iter, 2, & status, 3, & i, 4, & j, 5, & k, -1);
259 gtk_tree_store_set (projmodel, & iter, 2, ! status, -1);
260 set_set (i, j, k, data);
261}
262
274void set_visible_curve_data (GtkTreeViewColumn * col, GtkCellRenderer * renderer, GtkTreeModel * mod, GtkTreeIter * iter, gpointer data)
275{
276 int m;
277 gtk_tree_model_get (mod, iter, 0, & m, -1);
278 gtk_cell_renderer_set_visible (renderer, m);
279}
280
289GtkWidget * create_projects_tree (curve_edition * cedit, gpointer data)
290{
291 int i;
292 GtkTreeViewColumn * projcol[6];
293 GtkCellRenderer * projcell[6];
294 gchar * col_title[6] = {" ", i18n("Data sets"), i18n("Select"), " ", " ", " "};
295 gchar * ctype[6]={"text", "text", "active", "text", "text", "text"};
296 GType col_type[6] = {G_TYPE_INT, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT};
297 projmodel = gtk_tree_store_newv (6, col_type);
298 cedit -> projtree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(projmodel));
299 for (i=0; i<6; i++)
300 {
301 if (i == 2)
302 {
303 projcell[i] = gtk_cell_renderer_toggle_new ();
304 projcol[i] = gtk_tree_view_column_new_with_attributes(_(col_title[i]), projcell[i], ctype[i], i, NULL);
305 g_signal_connect (G_OBJECT(projcell[i]), "toggled", G_CALLBACK(toggle_curve), data);
306 gtk_tree_view_column_set_cell_data_func (projcol[i], projcell[i], set_visible_curve_data, NULL, NULL);
307 }
308 else
309 {
310 projcell[i] = gtk_cell_renderer_text_new();
311 projcol[i] = gtk_tree_view_column_new_with_attributes(_(col_title[i]), projcell[i], ctype[i], i, NULL);
312 }
313 gtk_tree_view_append_column(GTK_TREE_VIEW(cedit -> projtree), projcol[i]);
314 if (i == 0 || i > 2) gtk_tree_view_column_set_visible (projcol[i], FALSE);
315 }
316 fill_proj_model (cedit, projmodel, data);
317 g_object_unref (projmodel);
318 gtk_tree_view_expand_all (GTK_TREE_VIEW(cedit -> projtree));
319 return cedit -> projtree;
320}
321
331G_MODULE_EXPORT void run_curve_edit (GtkDialog * dial, gint response_id, gpointer data)
332{
333 destroy_this_dialog (dial);
334 if (get_curve_from_pointer(data) -> curve_edit)
335 {
336 g_free (get_curve_from_pointer(data) -> curve_edit);
337 get_curve_from_pointer(data) -> curve_edit = NULL;
338 }
339}
340
348void edit_curve (gpointer data)
349{
350 GtkWidget * ebox;
351 GtkWidget * enoote;
352 GtkWidget * dbox;
353 GtkWidget * scrollsets;
354
355 activer = ((tint *)data) -> b;
356 activec = ((tint *)data) -> c;
357// Axis data
358 Curve * this_curve = get_curve_from_pointer (data);
359 this_curve -> curve_edit = g_malloc0(sizeof*this_curve -> curve_edit);
360 curve_edition * this_cedit = this_curve -> curve_edit;
361
362 this_cedit -> win = dialogmodal (_("Edit curve"), GTK_WINDOW(this_curve -> window));
363 gtk_window_set_resizable (GTK_WINDOW (this_cedit -> win), FALSE);
364#ifndef GTK4
365 gtk_window_set_icon (GTK_WINDOW (this_cedit -> win), THETD);
366#endif
367 ebox = dialog_get_content_area (this_cedit -> win);
368 enoote = gtk_notebook_new ();
369 add_box_child_start (GTK_ORIENTATION_VERTICAL, ebox, enoote, FALSE, FALSE, 0);
370
371// The first tab of the notebook
372 gtk_notebook_append_page (GTK_NOTEBOOK(enoote), create_tab_1 (this_cedit, data), gtk_label_new (_("Graph")));
373// gtk_notebook_set_tab_label (GTK_NOTEBOOK (enoote), gtk_notebook_get_nth_page (GTK_NOTEBOOK (enoote), 0), gtk_label_new (_("Graph")));
374
375// The second tab of the notebook
376 gtk_notebook_append_page (GTK_NOTEBOOK(enoote), create_tab_2 (this_cedit, data), gtk_label_new (_("Data")));
377// gtk_notebook_set_tab_label (GTK_NOTEBOOK (enoote), gtk_notebook_get_nth_page (GTK_NOTEBOOK (enoote), 1), gtk_label_new (_("Data")));
378
379// The third tab of the notebook
380 gtk_notebook_append_page (GTK_NOTEBOOK(enoote), create_tab_3 (this_cedit, data), gtk_label_new (_("Legend")));
381// gtk_notebook_set_tab_label (GTK_NOTEBOOK (enoote), gtk_notebook_get_nth_page (GTK_NOTEBOOK (enoote), 2), gtk_label_new (_("Legend")));
382
383// The fourth tab of the notebook
384 gtk_notebook_append_page (GTK_NOTEBOOK(enoote), create_tab_4 (this_cedit, data), gtk_label_new (_("Axis")));
385// gtk_notebook_set_tab_label (GTK_NOTEBOOK (enoote), gtk_notebook_get_nth_page (GTK_NOTEBOOK (enoote), 3), gtk_label_new (_("Axis")));
386
387// The fifth tab of the notebook
388 dbox = create_vbox (BSEP);
389 add_box_child_start (GTK_ORIENTATION_VERTICAL, dbox, markup_label(_("<b>Add data set(s) to the active window</b>"), -1, 30, 0.5, 0.5), FALSE, FALSE, 0);
390 scrollsets = create_scroll (dbox, 250, 525, GTK_SHADOW_ETCHED_IN);
391 add_container_child (CONTAINER_SCR, scrollsets, create_projects_tree (this_cedit, data));
392 gtk_notebook_append_page (GTK_NOTEBOOK(enoote), dbox, gtk_label_new (_("Add data set")));
393// gtk_notebook_set_tab_label (GTK_NOTEBOOK (enoote), gtk_notebook_get_nth_page (GTK_NOTEBOOK (enoote), 4), gtk_label_new (_("Add data set")));
394
395 add_gtk_close_event (this_cedit -> win, G_CALLBACK(destroy_this_window), NULL);
396
397 g_signal_connect (G_OBJECT(this_cedit -> win), "response", G_CALLBACK(run_curve_edit), data);
398 show_the_widgets (this_cedit -> win);
399 set_data_aspect (GTK_COMBO_BOX(this_cedit -> data_aspect), data);
400 update_axis (GTK_COMBO_BOX(this_cedit -> axischoice), data);
401
402 dialog_id ++;
403 Event_loop[dialog_id] = g_main_loop_new (NULL, FALSE);
404 g_main_loop_run (Event_loop[dialog_id]);
405}
Callback declarations for main window.
G_MODULE_EXPORT void update_axis(GtkComboBox *widg, gpointer data)
change the axis
Definition tab-4.c:627
int activer
Definition cedit.c:77
G_MODULE_EXPORT void choose_set(GtkComboBox *box, gpointer data)
change the data set to customize
Definition tab-2.c:567
G_MODULE_EXPORT void set_data_aspect(GtkComboBox *box, gpointer data)
change data aspect (x/y or histogram bars)
Definition tab-2.c:603
void prepbox(gpointer data)
prepare the curve selection combo box
Definition cedit.c:87
G_MODULE_EXPORT void run_curve_edit(GtkDialog *dial, gint response_id, gpointer data)
curve edition dialog callback
Definition cedit.c:331
void set_visible_curve_data(GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *mod, GtkTreeIter *iter, gpointer data)
show / hide cell renderer
Definition cedit.c:274
int activec
Definition cedit.c:76
GtkWidget * create_tab_4(curve_edition *cedit, gpointer data)
handle the creation of the 4th tab of the curve edition dialog
Definition tab-4.c:691
void edit_curve(gpointer data)
create the curve edition dialog
Definition cedit.c:348
char * lapos[2]
Definition cedit.c:78
gboolean was_not_added(ExtraSets *sets, int a, int b, int c)
test if already in the menu or not
Definition m_curve.c:342
GtkWidget * create_org_list(gpointer data)
create the data set organisation widget
Definition tab-2.c:832
GtkWidget * create_projects_tree(curve_edition *cedit, gpointer data)
curve edition create the project(s) / curves tree model
Definition cedit.c:289
GtkTreeStore * projmodel
Definition cedit.c:240
G_MODULE_EXPORT void toggle_curve(GtkCellRendererToggle *cell_renderer, gchar *string_path, gpointer data)
show / hide curve cellrenderer toggle callback
Definition cedit.c:251
GtkWidget * create_tab_3(curve_edition *cedit, gpointer data)
handle the creation of the 3rd tab of the curve edition dialog
Definition tab-3.c:310
int activeg
Definition cedit.c:75
GtkWidget * create_tab_2(curve_edition *cedit, gpointer data)
handle the creation of the 2nd tab of the curve edition dialog
Definition tab-2.c:907
GtkWidget * create_tab_1(curve_edition *cedit, gpointer data)
handle the creation of the 1st tab of the curve edition dialog
Definition tab-1.c:527
void action_to_plot(gpointer data)
add to plot, or, remove curve from plot
Definition m_curve.c:227
void set_set(int a, int b, int c, gpointer data)
addjust widgets to handle the new curve
Definition cedit.c:133
Curve * get_curve_from_pointer(gpointer data)
get Curve pointer from pointer
Definition curve.c:313
Variable declarations for the curve widget Functions for interactions with the curve widget.
GtkWidget * axischoice
ColRGBA col
Definition d_measures.c:77
GtkTreePath * path
Definition datab.c:103
GType col_type[MAXDATA][12]
Definition dlp_field.c:946
int dialog_id
Definition global.c:170
GMainLoop * Event_loop[5]
Definition global.c:182
int nprojects
Definition global.c:161
GdkPixbuf * THETD
Definition global.c:222
#define i18n(String)
Definition global.c:80
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 * dialogmodal(gchar *str, GtkWindow *parent)
Create a new dialog modal window.
Definition gtk-misc.c:552
void combo_set_active(GtkWidget *combo, int pos)
set the active item's position
Definition gtk-misc.c:958
char * graph_name[]
Definition gui.c:123
#define BSEP
Definition global.h:261
G_MODULE_EXPORT gboolean destroy_this_window(GtkWidget *win, GdkEvent *event, gpointer data)
destroy a GtkWindow
Definition gtk-misc.c:2514
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
@ CONTAINER_SCR
Definition global.h:267
GtkWidget * create_combo()
create a GtkCombox widget, note deprecated in GTK4
Definition gtk-misc.c:1010
GtkWidget * dialog_get_content_area(GtkWidget *widg)
prepare GtkWidget to insert content in a GtkDialog window
Definition gtk-misc.c:861
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
create a GtkLabel with pango markup
Definition gtk-misc.c:1672
void add_box_child_start(int orientation, GtkWidget *widg, GtkWidget *child, gboolean expand, gboolean fill, int padding)
Add a GtkWidget in a GtkBox at the initial position.
Definition gtk-misc.c:340
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:247
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2235
void combo_text_append(GtkWidget *combo, gchar *text)
append text in GtkComboBox widget
Definition gtk-misc.c:987
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2213
gchar * prepare_for_title(gchar *init)
prepare a string for a window title, getting rid of all markup
Definition tools.c:71
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:267
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:837
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:202
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
Messaging function declarations.
double precision, dimension(98), parameter c
Function declarations for reading atomes project file Function declarations for saving atomes proje...
Definition glwin.h:350
Definition global.h:118
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