atomes 1.1.15
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-2024 by CNRS and University of Strasbourg */
15
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 (int k, int l, int m);
34 void set_set (int a, int b, int c);
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 (GtkTreeStore * store);
39
40 G_MODULE_EXPORT void run_curve_edit (GtkDialog * dial, gint response_id, gpointer data);
41
42 GtkWidget * create_projects_tree ();
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 (gpointer data);
71extern GtkWidget * create_tab_2 (gpointer data);
72extern GtkWidget * create_tab_3 (gpointer data);
73extern GtkWidget * create_tab_4 (gpointer data);
74extern GtkWidget * data_aspect;
75extern GtkWidget * Glyph_box;
76extern GtkWidget * Hist_box;
77extern GtkWidget * orgtree;
78extern GtkWidget * datascroll;
79extern char * ctext[2];
80
81GtkWidget * setcolorbox = NULL;
82GtkWidget * thesetbox = NULL;
84GtkTreePath ** ppath = NULL;
85GtkTreePath ** cpath = NULL;
86GtkWidget * projtree = NULL;
87GtkWidget * xyp[2];
88
89char * lapos[2]={"x: ", "y: "};
90
100void prepbox (int k, int l, int m)
101{
102 int i, n, o, p;
103 gchar * str;
104
105 project * extra_proj;
106 project * this_proj = get_project_by_id(k);
107 str = g_strdup_printf ("%s - %s", prepare_for_title(this_proj -> name), this_proj -> curves[l][m] -> name);
109 g_free (str);
110 CurveExtra * ctmp = this_proj -> curves[l][m] -> extrac -> first;
111 for ( i=0 ; i < this_proj -> curves[l][m] -> extrac -> extras ; i++ )
112 {
113 n = ctmp -> id.a;
114 o = ctmp -> id.b;
115 p = ctmp -> id.c;
116 extra_proj = get_project_by_id(n);
117 str = g_strdup_printf ("%s - %s", prepare_for_title(extra_proj -> name), extra_proj -> curves[o][p] -> name);
119 g_free (str);
120 if (ctmp -> next != NULL) ctmp = ctmp -> next;
121 }
122 if (this_proj -> curves[l][m] -> extrac -> extras > 0)
123 {
125 }
126 else
127 {
129 }
130 gtk_widget_set_size_request (setcolorbox, -1, 40);
131 gtk_combo_box_set_active (GTK_COMBO_BOX (setcolorbox), 0);
132 g_signal_connect (G_OBJECT(setcolorbox), "changed", G_CALLBACK(choose_set), NULL);
133}
134
159
167static void fill_proj_model (GtkTreeStore * store)
168{
169 GtkTreeIter projlevel;
170 GtkTreeIter calclevel;
171 GtkTreeIter curvelevel;
172 project * this_proj;
173 int i, j, k;
174 int start, end, step;
175 gboolean append;
176
177 /* Append a top level row and leave it empty */
178 if (ppath != NULL) g_free (ppath);
179 if (cpath != NULL) g_free (cpath);
180 ppath = g_malloc0 (nprojects*sizeof*ppath);
181 cpath = g_malloc0 (nprojects*sizeof*cpath);
182 for (i=0; i<nprojects; i++)
183 {
184 this_proj = get_project_by_id(i);
185 gtk_tree_store_append (store, & projlevel, NULL);
186 gtk_tree_store_set (store, & projlevel, 0, 0, 1, prepare_for_title(this_proj -> name), 2, TRUE, 3, -1, -1);
187 ppath[i] = gtk_tree_model_get_path ((GtkTreeModel *)store, & projlevel);
188 if (activer == 0 || activer == 3)
189 {
190 start = 0;
191 end = 4;
192 step = 3;
193 }
194 else if (activer == 1 || activer == 2)
195 {
196 start = 1;
197 end = 3;
198 step = 1;
199 }
200 else
201 {
202 start = activer;
203 end = start + 1;
204 step = 1;
205 }
206 for (j=start; j<end; j=j+step)
207 {
208 if (this_proj -> initok[j])
209 {
210 gtk_tree_store_append (store, & calclevel, & projlevel);
211 gtk_tree_store_set (store, & calclevel, 0, 0, 1, graph_name[j], 2, TRUE, 3, -1, -1);
212 if (j == start)
213 {
214 cpath[i] = gtk_tree_model_get_path ((GtkTreeModel *)store, & calclevel);
215 }
216 for (k = 0 ; k < this_proj -> numc[j] ; k++)
217 {
218 append = FALSE;
219 if (i != activeg && this_proj -> curves[j][k] -> ndata != 0)
220 {
221 append = TRUE;
222 }
223 else if (((i != activeg) || (j != activer || k != activec)) && this_proj -> curves[j][k] -> ndata != 0)
224 {
225 append = TRUE;
226 }
227 if (append)
228 {
229 gtk_tree_store_append (store, & curvelevel, & calclevel);
230 gtk_tree_store_set (store, & curvelevel,
231 0, 1,
232 1, this_proj -> curves[j][k] -> name,
233 2, ! was_not_added (active_project -> curves[activer][activec] -> extrac, i, j, k),
234 3, i,
235 4, j,
236 5, k, -1);
237 }
238 }
239 }
240 }
241 }
242}
243
244GtkTreeStore * projmodel;
245
255G_MODULE_EXPORT void toggle_curve (GtkCellRendererToggle * cell_renderer, gchar * string_path, gpointer data)
256{
257 int i, j, k;
258 gboolean status;
259 GtkTreeIter iter;
260 GtkTreePath * path = gtk_tree_path_new_from_string (string_path);
261 gtk_tree_model_get_iter (GTK_TREE_MODEL(projmodel), & iter, path);
262 gtk_tree_model_get (GTK_TREE_MODEL(projmodel), & iter, 2, & status, 3, & i, 4, & j, 5, & k, -1);
263 gtk_tree_store_set (projmodel, & iter, 2, ! status, -1);
264 set_set (i, j, k);
265}
266
278void set_visible_curve_data (GtkTreeViewColumn * col, GtkCellRenderer * renderer, GtkTreeModel * mod, GtkTreeIter * iter, gpointer data)
279{
280 int m;
281 gtk_tree_model_get (mod, iter, 0, & m, -1);
282 gtk_cell_renderer_set_visible (renderer, m);
283}
284
291{
292 int i;
293 GtkTreeViewColumn * projcol[6];
294 GtkCellRenderer * projcell[6];
295 gchar * col_title[6] = {" ", "Data sets", "Select", " ", " ", " "};
296 gchar * ctype[6]={"text", "text", "active", "text", "text", "text"};
297 GType col_type[6] = {G_TYPE_INT, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT};
298 projmodel = gtk_tree_store_newv (6, col_type);
299 projtree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(projmodel));
300 for (i=0; i<6; i++)
301 {
302 if (i == 2)
303 {
304 projcell[i] = gtk_cell_renderer_toggle_new ();
305 projcol[i] = gtk_tree_view_column_new_with_attributes(col_title[i], projcell[i], ctype[i], i, NULL);
306 g_signal_connect (G_OBJECT(projcell[i]), "toggled", G_CALLBACK(toggle_curve), NULL);
307 gtk_tree_view_column_set_cell_data_func (projcol[i], projcell[i], set_visible_curve_data, NULL, NULL);
308 }
309 else
310 {
311 projcell[i] = gtk_cell_renderer_text_new();
312 projcol[i] = gtk_tree_view_column_new_with_attributes(col_title[i], projcell[i], ctype[i], i, NULL);
313 }
314 gtk_tree_view_append_column(GTK_TREE_VIEW(projtree), projcol[i]);
315 if (i == 0 || i > 2) gtk_tree_view_column_set_visible (projcol[i], FALSE);
316 }
317 fill_proj_model (projmodel);
318 g_object_unref (projmodel);
319 gtk_tree_view_expand_all (GTK_TREE_VIEW(projtree));
320 return projtree;
321}
322
332G_MODULE_EXPORT void run_curve_edit (GtkDialog * dial, gint response_id, gpointer data)
333{
334 destroy_this_dialog (dial);
335 int i;
336 for (i=0 ; i<2; i++) xyp[i] = NULL;
337 axischoice = NULL;
338}
339
347void edit_curve (gpointer data)
348{
349 GtkWidget * edit_box;
350 GtkWidget * ebox;
351 GtkWidget * enoote;
352 GtkWidget * dbox;
353 GtkWidget * scrollsets;
354
355// Axis data
356
357 tint * cd = (tint *) data;
358 int a = activeg = cd -> a;
359 int b = activer = cd -> b;
360 int c = activec = cd -> c;
361
362#ifdef DEBUG
363 g_debug ("CEDIT: a= %d, b= %d, c= %d", a, b, c);
364#endif
365
366 project * this_proj = get_project_by_id(a);
367
368 ctext[0] = "x ∈ [0.0, 1.0]";
369 ctext[1] = "y ∈ [0.0, 1.0]";
370 edit_box = dialogmodal ("Edit curve", GTK_WINDOW(this_proj -> curves[b][c] -> window));
371 gtk_window_set_resizable (GTK_WINDOW (edit_box), FALSE);
372#ifndef GTK4
373 gtk_window_set_icon (GTK_WINDOW (edit_box), THETD);
374#endif
376 enoote = gtk_notebook_new ();
377 add_box_child_start (GTK_ORIENTATION_VERTICAL, ebox, enoote, FALSE, FALSE, 0);
378
379// The first tab of the notebook
380 gtk_notebook_append_page (GTK_NOTEBOOK(enoote), create_tab_1 (data), gtk_label_new ("Graph"));
381// gtk_notebook_set_tab_label (GTK_NOTEBOOK (enoote), gtk_notebook_get_nth_page (GTK_NOTEBOOK (enoote), 0), gtk_label_new ("Graph"));
382
383// The second tab of the notebook
384 gtk_notebook_append_page (GTK_NOTEBOOK(enoote), create_tab_2 (data), gtk_label_new ("Data"));
385// gtk_notebook_set_tab_label (GTK_NOTEBOOK (enoote), gtk_notebook_get_nth_page (GTK_NOTEBOOK (enoote), 1), gtk_label_new ("Data"));
386
387// The third tab of the notebook
388 gtk_notebook_append_page (GTK_NOTEBOOK(enoote), create_tab_3 (data), gtk_label_new ("Legend"));
389// gtk_notebook_set_tab_label (GTK_NOTEBOOK (enoote), gtk_notebook_get_nth_page (GTK_NOTEBOOK (enoote), 2), gtk_label_new ("Legend"));
390
391// The fourth tab of the notebook
392 gtk_notebook_append_page (GTK_NOTEBOOK(enoote), create_tab_4 (data), gtk_label_new ("Axis"));
393// gtk_notebook_set_tab_label (GTK_NOTEBOOK (enoote), gtk_notebook_get_nth_page (GTK_NOTEBOOK (enoote), 3), gtk_label_new ("Axis"));
394
395// The fifth tab of the notebook
396 dbox = create_vbox (BSEP);
397 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);
398 scrollsets = create_scroll (dbox, 250, 525, GTK_SHADOW_ETCHED_IN);
400 gtk_notebook_append_page (GTK_NOTEBOOK(enoote), dbox, gtk_label_new ("Add data set"));
401// gtk_notebook_set_tab_label (GTK_NOTEBOOK (enoote), gtk_notebook_get_nth_page (GTK_NOTEBOOK (enoote), 4), gtk_label_new ("Add data set"));
402
404
405 if (gtk_combo_box_get_active (GTK_COMBO_BOX(data_aspect)))
406 {
408 }
409 else
410 {
412 }
413
414 g_signal_connect (G_OBJECT(edit_box), "response", G_CALLBACK(run_curve_edit), NULL);
416 set_data_aspect (GTK_COMBO_BOX(data_aspect), data);
417 update_axis (GTK_COMBO_BOX(axischoice), data);
418
419 dialog_id ++;
420 Event_loop[dialog_id] = g_main_loop_new (NULL, FALSE);
421 g_main_loop_run (Event_loop[dialog_id]);
422}
Callback declarations for main window.
G_MODULE_EXPORT void update_axis(GtkComboBox *widg, gpointer data)
change the axis
Definition tab-4.c:749
GtkWidget * xyp[2]
Definition cedit.c:87
GtkWidget * setcolorbox
Definition cedit.c:81
GtkWidget * datascroll
Definition tab-2.c:99
GtkWidget * create_tab_2(gpointer data)
handle the creation of the 2nd tab of the curve edition dialog
Definition tab-2.c:971
G_MODULE_EXPORT void choose_set(GtkComboBox *box, gpointer data)
change the data set to customize
Definition tab-2.c:629
G_MODULE_EXPORT void set_data_aspect(GtkComboBox *box, gpointer data)
change data aspect (x/y or histogram bars)
Definition tab-2.c:672
G_MODULE_EXPORT void toggle_curve(GtkCellRendererToggle *cell_renderer, gchar *string_path, gpointer data)
show / hide curve cellrenderer toggle callback
Definition cedit.c:255
G_MODULE_EXPORT void run_curve_edit(GtkDialog *dial, gint response_id, gpointer data)
curve edition dialog callback
Definition cedit.c:332
tint prc
Definition cedit.c:83
GtkWidget * create_projects_tree()
curve edition create the project(s) / curves tree model
Definition cedit.c:290
void set_visible_curve_data(GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *mod, GtkTreeIter *iter, gpointer data)
show / hide cell renderer
Definition cedit.c:278
GtkWidget * create_tab_1(gpointer data)
handle the creation of the 1st tab of the curve edition dialog
Definition tab-1.c:611
void edit_curve(gpointer data)
create the curve edition dialog
Definition cedit.c:347
void set_set(int a, int b, int c)
addjust widgets to handle the new curve
Definition cedit.c:144
GtkTreePath ** cpath
Definition cedit.c:85
char * lapos[2]
Definition cedit.c:89
gboolean was_not_added(ExtraSets *sets, int a, int b, int c)
test if already in the menu or not
Definition m_curve.c:339
GtkWidget * orgtree
Definition tab-2.c:97
GtkWidget * thesetbox
Definition cedit.c:82
GtkWidget * create_org_list(gpointer data)
create the data set organisation widget
Definition tab-2.c:895
GtkWidget * create_tab_4(gpointer data)
handle the creation of the 4th tab of the curve edition dialog
Definition tab-4.c:820
GtkTreeStore * projmodel
Definition cedit.c:244
GtkWidget * Glyph_box
Definition tab-2.c:92
char * ctext[2]
Definition tab-1.c:91
GtkWidget * projtree
Definition cedit.c:86
GtkTreePath ** ppath
Definition cedit.c:84
GtkWidget * data_aspect
Definition tab-2.c:80
GtkWidget * create_tab_3(gpointer data)
handle the creation of the 3rd tab of the curve edition dialog
Definition tab-3.c:365
void action_to_plot(gpointer data)
add to plot, or, remove curve from plot
Definition m_curve.c:225
void prepbox(int k, int l, int m)
prepare the curve selection combo box
Definition cedit.c:100
GtkWidget * Hist_box
Definition tab-2.c:93
Variable declarations for the curve widget Functions for interactions with the curve widget.
int activer
Definition w_curve.c:74
int activec
Definition w_curve.c:73
int activeg
Definition w_curve.c:72
GtkWidget * axischoice
Definition tab-4.c:90
ColRGBA col
Definition d_measures.c:77
GtkTreePath * path
Definition datab.c:103
GType col_type[MAXDATA][12]
Definition dlp_field.c:856
void edit_box(GtkWidget *vbox)
creation of the edit cell widgets
Definition edit_menu.c:282
int dialog_id
Definition global.c:167
GMainLoop * Event_loop[5]
Definition global.c:178
int nprojects
Definition global.c:158
GdkPixbuf * THETD
Definition global.c:216
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 * dialogmodal(gchar *str, GtkWindow *parent)
Create a new dialog modal window.
Definition gtk-misc.c:510
#define BSEP
Definition global.h:245
G_MODULE_EXPORT gboolean destroy_this_window(GtkWidget *win, GdkEvent *event, gpointer data)
destroy a GtkWindow
Definition gtk-misc.c:2344
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
@ CONTAINER_SCR
Definition global.h:251
GtkWidget * create_combo()
create a GtkCombox widget, note deprecated in GTK4
Definition gtk-misc.c:923
GtkWidget * dialog_get_content_area(GtkWidget *widg)
prepare GtkWidget to insert content in a GtkDialog window
Definition gtk-misc.c:825
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
Definition gtk-misc.c:1585
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:299
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:206
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2065
void combo_text_append(GtkWidget *combo, gchar *text)
append text in GtkComboBox widget
Definition gtk-misc.c:900
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2034
char * graph_name[NGRAPHS]
Definition gui.c:133
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:226
void hide_the_widgets(GtkWidget *widg)
hide GtkWidget
Definition gtk-misc.c:189
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:801
project * active_project
Definition project.c:47
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:173
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
int step
Definition ogl_draw.c:70
Messaging function declarations.
Function declarations for reading atomes project file Function declarations for saving atomes proje...
Definition global.h:104
int b
Definition tab-1.c:95
int c
Definition tab-1.c:95
int a
Definition tab-1.c:95
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