atomes 1.1.15
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
datab.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: 'datab.c'
24*
25* Contains:
26*
27
28 - The curve data edition window and associated callbacks
29
30*
31* List of functions:
32
33 G_MODULE_EXPORT gboolean on_data_button_event (GtkWidget * widget, GdkEvent * event, gpointer data);
34 G_MODULE_EXPORT gboolean cancel_win (GtkWindow * win, gpointer data);
35 G_MODULE_EXPORT gboolean cancel_win (GtkWidget * win, GdkEvent * event, gpointer data);
36
37 void get_tree_data (GtkWidget * tree);
38 void save_row (gpointer data, gpointer user_data);
39 void update_first_row (gpointer data, gpointer user_data);
40 void update_first_col ();
41 void add_to_last_row (gpointer data, gpointer user_data);
42 void add_to_last_col (double cte, gpointer data);
43 void multiply_last_row (gpointer data, gpointer user_data);
44 void multiply_last_col (double cte, gpointer data);
45 void select_row (gpointer data, gpointer user_data);
46 void copy_row (gpointer data, gpointer user_data);
47 void copy_content (gpointer data);
48 void add_row (gpointer data, gpointer user_data);
49 void delete_row (gpointer data, gpointer user_data);
50 void insert_cell (gpointer data);
51 void delete_cell (gpointer data);
52 void add_to_column (gpointer data);
53 void multiply_column (gpointer data);
54 void data_popup_menu (GtkWidget * top_level, double x, double y, gpointer data);
55 void data_popup_menu (GtkWidget * top_level, GdkEvent * event, gpointer data);
56 void data_button_event (GtkWidget * data_tree, double event_x, double event_y, guint event_button, guint event_type, gpointer data);
57 void data_button_event (GtkWidget * data_tree, GdkEvent * event, guint event_button, guint event_type, gpointer data);
58 void cancel_changes (GtkWidget * widg, gpointer data);
59 void edit_data (gpointer data);
60
61 static void fill_data_model (GtkListStore * store, project * this_proj, int b, int c);
62
63 G_MODULE_EXPORT void edit_cell (GtkCellRendererText * cell, gchar * path_string, gchar * new_text, gpointer user_data);
64 G_MODULE_EXPORT void adjust_value (GtkEntry * res, gpointer data);
65 G_MODULE_EXPORT void run_add_to_column (GtkDialog * wind, gint response_id, gpointer data);
66 G_MODULE_EXPORT void run_multiply_column (GtkDialog * wind, gint response_id, gpointer data);
67 G_MODULE_EXPORT void data_pop_action (GSimpleAction * action, GVariant * parameter, gpointer data);
68 G_MODULE_EXPORT void on_data_button_pressed (GtkGesture * gesture, int n_press, double x, double y, gpointer data);
69 G_MODULE_EXPORT void on_data_button_released (GtkGesture * gesture, int n_press, double x, double y, gpointer data);
70 G_MODULE_EXPORT void cancel_but (GtkButton * but, gpointer data);
71 G_MODULE_EXPORT void validate_changes (GtkButton * but, gpointer data);
72
73 GtkWidget * setview (project * this_proj, int b, int c);
74
75 GMenu * insert_place ();
76 GMenu * insert_data ();
77 GMenu * delete_data ();
78 GMenu* cell_actions ();
79 GMenu * cell_title ();
80 GMenu * column_actions ();
81 GMenu * column_title ();
82 GMenu * data_menu ();
83
84*/
85
86#include <gtk/gtk.h>
87#include <cairo.h>
88#include <string.h>
89#include <stdlib.h>
90#include <math.h>
91
92#include "global.h"
93#include "interface.h"
94#include "callbacks.h"
95#include "project.h"
96#include "curve.h"
97
99GtkTreeModel * curve_model;
100GList * lrows;
101GList * rows;
102GtkTreeSelection * sel;
103GtkTreePath * path;
104GtkTreeIter row;
105gchar * text;
106
114void get_tree_data (GtkWidget * tree)
115{
116 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW(tree));
117 curve_model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree));
118 lrows = gtk_tree_selection_get_selected_rows (sel, & curve_model);
119 nrows = gtk_tree_selection_count_selected_rows (sel);
120}
121
130void save_row (gpointer data, gpointer user_data)
131{
132 path = data;
133 tint * id = (tint *)user_data;
134 if (gtk_tree_model_get_iter (curve_model, & row, path))
135 {
136
137 gtk_tree_model_get (curve_model, & row, 1, & get_project_by_id(id -> a) -> curves[id -> b][id -> c] -> data[0][nrows],
138 2, & get_project_by_id(id -> a) -> curves[id -> b][id -> c] -> data[1][nrows], -1);
139 }
140 nrows = nrows + 1;
141}
142
151void update_first_row (gpointer data, gpointer user_data)
152{
153 path = data;
154 if (gtk_tree_model_get_iter (curve_model, & row, path))
155 {
156 nrows = nrows + 1;
157 gtk_list_store_set (GTK_LIST_STORE(curve_model), & row, 0, nrows, -1);
158 }
159}
160
168{
169 gtk_tree_selection_select_all (sel);
170 lrows = gtk_tree_selection_get_selected_rows (sel, & curve_model);
171 nrows = 0;
172 g_list_foreach (lrows, (GFunc)update_first_row, NULL);
173 gtk_tree_selection_unselect_all (sel);
174}
175
184void add_to_last_row (gpointer data, gpointer user_data)
185{
186 path = data;
187 double vold;
188 double * cte = (double *)user_data;
189 if (gtk_tree_model_get_iter (curve_model, & row, path))
190 {
191 gtk_tree_model_get (curve_model, & row, 2, & vold, -1);
192 gtk_list_store_set (GTK_LIST_STORE(curve_model), & row, 2, * cte + vold, -1);
193 }
194}
195
204void add_to_last_col (double cte, gpointer data)
205{
206 qint * dat = (qint *)data;
207 project * this_proj = get_project_by_id(dat -> a);
208 curve_model = gtk_tree_view_get_model (GTK_TREE_VIEW(this_proj -> curves[dat -> b][dat -> c] -> datatree));
209 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW(this_proj -> curves[dat -> b][dat -> c] -> datatree));
210 gtk_tree_selection_select_all (sel);
211 get_tree_data (this_proj -> curves[dat -> b][dat -> c] -> datatree);
212 g_list_foreach (lrows, (GFunc)add_to_last_row, & cte);
213 gtk_tree_selection_unselect_all (sel);
214}
215
224void multiply_last_row (gpointer data, gpointer user_data)
225{
226 path = data;
227 double vold;
228 double * cte = (double *) user_data;
229 if (gtk_tree_model_get_iter (curve_model, & row, path))
230 {
231 gtk_tree_model_get (curve_model, & row, 2, & vold, -1);
232 gtk_list_store_set (GTK_LIST_STORE(curve_model), & row, 2, * cte * vold, -1);
233 }
234}
235
244void multiply_last_col (double cte, gpointer data)
245{
246 qint * dat = (qint *)data;
247 project * this_proj = get_project_by_id(dat -> a);
248 curve_model = gtk_tree_view_get_model (GTK_TREE_VIEW(this_proj -> curves[dat -> b][dat -> c] -> datatree));
249 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW(this_proj -> curves[dat -> b][dat -> c] -> datatree));
250 gtk_tree_selection_select_all (sel);
251 get_tree_data (this_proj -> curves[dat -> b][dat -> c] -> datatree);
252 g_list_foreach (lrows, (GFunc)multiply_last_row, & cte);
253 gtk_tree_selection_unselect_all (sel);
254}
255
264void select_row (gpointer data, gpointer user_data)
265{
266 path = data;
267 if (gtk_tree_model_get_iter (curve_model, & row, path))
268 {
269 gtk_tree_selection_select_iter (sel, & row);
270 }
271}
272
281void copy_row (gpointer data, gpointer user_data)
282{
283 path = data;
284 int v1;
285 double v2, v3;
286 gchar * tmp;
287
288 if (gtk_tree_model_get_iter (curve_model, & row, path))
289 {
290 gtk_tree_model_get (curve_model, & row, 0, & v1, 1, & v2, 2, & v3, -1);
291 if (text == NULL)
292 {
293 text = g_strdup_printf ("%d\t%f\t%f\n", v1, v2, v3);
294 }
295 else
296 {
297 tmp = g_strdup_printf ("%s%d\t%f\t%f\n", text, v1, v2, v3);
298 g_free (text);
299 text = g_strdup_printf ("%s", tmp);
300 g_free (tmp);
301 }
302 }
303}
304
312void copy_content (gpointer data)
313{
314 text = NULL;
315 g_list_foreach (lrows, (GFunc)copy_row, NULL);
316#ifdef GTK3
317 gtk_clipboard_set_text (gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), text, -1);
318 gtk_clipboard_store (gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
319#endif
320 g_free (text);
321}
322
331void add_row (gpointer data, gpointer user_data)
332{
333 GtkTreeIter newrow;
334 if (gtk_tree_model_get_iter (curve_model, & row, path))
335 {
336 if (GPOINTER_TO_INT(user_data) == 0)
337 {
338 gtk_list_store_insert_before (GTK_LIST_STORE(curve_model), & newrow, & row);
339 }
340 else
341 {
342 gtk_list_store_insert_after (GTK_LIST_STORE(curve_model), & newrow, & row);
343 }
344 gtk_list_store_set (GTK_LIST_STORE(curve_model), & newrow, 0, 0, 1, 0.00000, 2, 0.00000, -1);
345 }
346}
347
356void delete_row (gpointer data, gpointer user_data)
357{
358 path = data;
359 if (gtk_tree_model_get_iter (curve_model, & row, path))
360 {
361 gtk_list_store_remove (GTK_LIST_STORE(curve_model), & row);
362 }
363}
364
372void insert_cell (gpointer data)
373{
374 if (GPOINTER_TO_INT(data) == 0)
375 {
376 path = (GtkTreePath *) g_list_nth_data (lrows, 0);
377 }
378 else
379 {
380 path = (GtkTreePath *) g_list_nth_data (lrows, nrows-1);
381 }
382 g_list_foreach (lrows, (GFunc)add_row, data);
384}
385
393void delete_cell (gpointer data)
394{
395 g_list_foreach (g_list_reverse (lrows), (GFunc)delete_row, NULL);
397}
398
409G_MODULE_EXPORT void edit_cell (GtkCellRendererText * cell, gchar * path_string, gchar * new_text, gpointer user_data)
410{
411 qint * id = (qint *)user_data;
412 project * this_proj = get_project_by_id (id -> a);
413 curve_model = gtk_tree_view_get_model(GTK_TREE_VIEW(this_proj -> curves[id -> b][id -> c] -> datatree));
414 gtk_tree_model_get_iter_from_string (curve_model, & row, path_string);
415 double val = string_to_double ((gpointer)new_text);
416 gtk_list_store_set (GTK_LIST_STORE(curve_model), & row, id -> d, val, -1);
417}
418
419GtkWidget * col_entry;
420
429G_MODULE_EXPORT void adjust_value (GtkEntry * res, gpointer data)
430{
431 const gchar * m = entry_get_text (res);
432 double v = string_to_double ((gpointer)m);
434}
435
445G_MODULE_EXPORT void run_add_to_column (GtkDialog * wind, gint response_id, gpointer data)
446{
447 if (response_id == GTK_RESPONSE_APPLY)
448 {
449 const gchar * p = entry_get_text (GTK_ENTRY(col_entry));
450 double c = string_to_double ((gpointer)p);
451 update_entry_double (GTK_ENTRY(col_entry), c);
452 add_to_last_col (c, data);
453 }
454 destroy_this_dialog (wind);
455}
456
464void add_to_column (gpointer data)
465{
466 GtkWidget * wind;
467 GtkWidget * box;
468 GtkWidget * hbox;
469 GtkWidget * lab;
470 gchar * str;
471 qint * dat = (qint *)data;
472 wind = dialogmodal ("Add constant to column", GTK_WINDOW(get_project_by_id(dat -> a) -> curves[dat -> b][dat -> c] -> window));
473 gtk_dialog_add_button (GTK_DIALOG (wind), "Apply", GTK_RESPONSE_APPLY);
474 box = dialog_get_content_area (wind);
475 hbox = create_hbox (0);
476 add_box_child_start (GTK_ORIENTATION_VERTICAL, box, hbox, TRUE, TRUE, 0);
477
478 str = g_strdup_printf ("Add Constant to Last Column");
479 lab = gtk_label_new (str);
480 gtk_widget_set_size_request (lab, 200, -1);
481 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, lab, TRUE, FALSE, 0);
482 col_entry = create_entry (G_CALLBACK(adjust_value), 100, 15, FALSE, NULL);
483 gtk_entry_set_alignment (GTK_ENTRY(col_entry), 1.0);
484 update_entry_double (GTK_ENTRY(col_entry), 1.0);
485 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, col_entry, FALSE, FALSE, 0);
486 run_this_gtk_dialog (wind, G_CALLBACK(run_add_to_column), data);
487}
488
498G_MODULE_EXPORT void run_multiply_column (GtkDialog * wind, gint response_id, gpointer data)
499{
500 if (response_id == GTK_RESPONSE_APPLY)
501 {
502 const gchar * p = entry_get_text (GTK_ENTRY(col_entry));
503 double c = string_to_double ((gpointer)p);
504 update_entry_double (GTK_ENTRY(col_entry), c);
505 multiply_last_col (c, data);
506 }
507 destroy_this_dialog (wind);
508}
509
517void multiply_column (gpointer data)
518{
519 GtkWidget * wind;
520 GtkWidget * box;
521 GtkWidget * hbox;
522 GtkWidget * lab;
523 gchar * str;
524 qint * dat = (qint *)data;
525 wind = dialogmodal ("Multiply Column by Constant", GTK_WINDOW(get_project_by_id(dat -> a) -> curves[dat -> b][dat -> c] -> window));
526 gtk_dialog_add_button (GTK_DIALOG (wind), "Apply", GTK_RESPONSE_APPLY);
527 box = dialog_get_content_area (wind);
528 hbox = create_hbox (0);
529 add_box_child_start (GTK_ORIENTATION_VERTICAL, box, hbox, TRUE, TRUE, 0);
530
531 str = g_strdup_printf ("Multiply Last Column by Constant");
532 lab = gtk_label_new (str);
533 gtk_widget_set_size_request (lab, 200, -1);
534 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, lab, TRUE, FALSE, 0);
535 col_entry = create_entry (G_CALLBACK(adjust_value), 100, 15, FALSE, NULL);
536 gtk_entry_set_alignment (GTK_ENTRY(col_entry), 1.0);
537 update_entry_double (GTK_ENTRY(col_entry), 1.0);
538 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, col_entry, FALSE, FALSE, 0);
539 run_this_gtk_dialog (wind, G_CALLBACK(run_multiply_column), data);
540}
541
547GMenu * insert_place ()
548{
549 GMenu * menu = g_menu_new ();
550 append_menu_item (menu, "Before", "data-pop.insert.before", NULL, NULL, IMG_STOCK, (gpointer)GO_UP, FALSE, FALSE, FALSE, NULL);
551 append_menu_item (menu, "After", "data-pop.insert.after", NULL, NULL, IMG_STOCK, (gpointer)GO_DOWN, FALSE, FALSE, FALSE, NULL);
552 return menu;
553}
554
560GMenu * insert_data ()
561{
562 GMenu * menu = g_menu_new ();
563 append_submenu (menu, "Insert Row(s)", insert_place());
564 return menu;
565}
566
572GMenu * delete_data ()
573{
574 GMenu * menu = g_menu_new ();
575 append_menu_item (menu, "Delete Row(s)", "data-pop.delete", NULL, NULL, IMG_STOCK, (gpointer)LIST_REM, FALSE, FALSE, FALSE, NULL);
576 return menu;
577}
578
585{
586 GMenu * menu = g_menu_new ();
587 append_menu_item (menu, "Copy Selected Row(s)", "data-pop.copy", NULL, NULL, IMG_STOCK, (gpointer)EDITC, FALSE, FALSE, FALSE, NULL);
588 g_menu_append_section (menu, NULL, (GMenuModel*)insert_data());
589 g_menu_append_section (menu, NULL, (GMenuModel*)delete_data());
590 return menu;
591}
592
598GMenu * cell_title ()
599{
600 GMenu * menu = g_menu_new ();
601 append_menu_item (menu, "Cell Based Operations", "None", NULL, NULL, IMG_NONE, NULL, FALSE, FALSE, FALSE, NULL);
602 return menu;
603}
604
611{
612 GMenu * menu = g_menu_new ();
613 append_menu_item (menu, "Add Constant to Last Column", "data-pop.add", NULL, NULL, IMG_STOCK, (gpointer)LIST_ADD, FALSE, FALSE, FALSE, NULL);
614 append_menu_item (menu, "Multiply Last Column by Constant", "data-pop.mul", NULL, NULL, IMG_STOCK, (gpointer)FCLOSE, FALSE, FALSE, FALSE, NULL);
615 return menu;
616}
617
623GMenu * column_title ()
624{
625 GMenu * menu = g_menu_new ();
626 append_menu_item (menu, "Column Based Operations", "None", NULL, NULL, IMG_NONE, NULL, FALSE, FALSE, FALSE, NULL);
627 return menu;
628}
629
635GMenu * data_menu ()
636{
637 GMenu * menu = g_menu_new ();
638 g_menu_append_section (menu, NULL, (GMenuModel*)cell_title());
639 g_menu_append_section (menu, NULL, (GMenuModel*)cell_actions());
640 g_menu_append_section (menu, NULL, (GMenuModel*)column_title());
641 g_menu_append_section (menu, NULL, (GMenuModel*)column_actions());
642 return menu;
643}
644
654G_MODULE_EXPORT void data_pop_action (GSimpleAction * action, GVariant * parameter, gpointer data)
655{
656 gchar * name = g_strdup_printf ("%s", g_action_get_name(G_ACTION(action)));
657 if (g_strcmp0 (name, "copy") == 0)
658 {
659 copy_content (data);
660 }
661 else if (g_strcmp0 (name, "insert.before") == 0)
662 {
663 insert_cell (data);
664 }
665 else if (g_strcmp0 (name, "insert.after") == 0)
666 {
667 insert_cell (data);
668 }
669 else if (g_strcmp0 (name, "delete") == 0)
670 {
671 delete_cell (data);
672 }
673 else if (g_strcmp0 (name, "add") == 0)
674 {
675 add_to_column (data);
676 }
677 else if (g_strcmp0 (name, "mul") == 0)
678 {
679 multiply_column (data);
680 }
681}
682
683#ifdef GTK4
694void data_popup_menu (GtkWidget * top_level, double x, double y, gpointer data)
695#else
705void data_popup_menu (GtkWidget * top_level, GdkEvent * event, gpointer data)
706#endif
707{
708 GSimpleActionGroup * data_popup = g_simple_action_group_new ();
709 GSimpleAction * pop_data[6];
710 pop_data[0] = g_simple_action_new ("copy", NULL);
711 pop_data[1] = g_simple_action_new ("insert.before", NULL);
712 pop_data[2] = g_simple_action_new ("insert.after", NULL);
713 pop_data[3] = g_simple_action_new ("delete", NULL);
714 pop_data[4] = g_simple_action_new ("add", NULL);
715 pop_data[5] = g_simple_action_new ("mul", NULL);
716
717 g_signal_connect (pop_data[0], "activate", G_CALLBACK(data_pop_action), NULL);
718 g_signal_connect (pop_data[1], "activate", G_CALLBACK(data_pop_action), GINT_TO_POINTER(0));
719 g_signal_connect (pop_data[2], "activate", G_CALLBACK(data_pop_action), GINT_TO_POINTER(1));
720 g_signal_connect (pop_data[3], "activate", G_CALLBACK(data_pop_action), NULL);
721 g_signal_connect (pop_data[4], "activate", G_CALLBACK(data_pop_action), data);
722 g_signal_connect (pop_data[5], "activate", G_CALLBACK(data_pop_action), data);
723
724 int i;
725 for (i=0; i<6; i++) g_action_map_add_action (G_ACTION_MAP(data_popup), G_ACTION(pop_data[i]));
726
727 GtkWidget * menu;
728#ifdef GTK4
729 menu = gtk_popover_menu_new_from_model_full ((GMenuModel *)data_menu(), GTK_POPOVER_MENU_NESTED);
730 gtk_widget_set_parent (menu, top_level);
731#else
732 menu = gtk_menu_new_from_model ((GMenuModel *)data_menu ());
733#endif
734 gtk_widget_insert_action_group (menu, "data-pop", G_ACTION_GROUP(data_popup));
735
736#ifdef GTK4
737 gtk_widget_set_size_request (menu, -1, 240);
738 pop_menu_at_pointer (menu, x, y);
739#else
740 pop_menu_at_pointer (menu, event);
741#endif
742}
743
744#ifdef GTK4
757void data_button_event (GtkWidget * data_tree, double event_x, double event_y, guint event_button, guint event_type, gpointer data)
758#else
770void data_button_event (GtkWidget * data_tree, GdkEvent * event, guint event_button, guint event_type, gpointer data)
771#endif
772{
773 if (event_type == GDK_BUTTON_PRESS)
774 {
775 get_tree_data (data_tree);
776 if (event_button == 3)
777 {
778#ifdef GTK4
779 data_popup_menu ((GtkWidget *)get_top_level(data_tree), event_x, event_y, data);
780#else
781 data_popup_menu (data_tree, event, data);
782#endif
783 }
784 }
785 else if (event_type == GDK_BUTTON_RELEASE)
786 {
787 g_list_foreach (lrows, (GFunc)gtk_tree_path_free, NULL);
788 g_list_free (lrows);
789 }
790}
791
792#ifdef GTK4
804G_MODULE_EXPORT void on_data_button_pressed (GtkGesture * gesture, int n_press, double x, double y, gpointer data)
805{
806 data_button_event (gtk_event_controller_get_widget ((GtkEventController*)gesture), x, y,
807 gtk_gesture_single_get_current_button ((GtkGestureSingle * )gesture), GDK_BUTTON_PRESS, data);
808}
809
821G_MODULE_EXPORT void on_data_button_released (GtkGesture * gesture, int n_press, double x, double y, gpointer data)
822{
823 data_button_event (gtk_event_controller_get_widget ((GtkEventController*)gesture), x, y,
824 gtk_gesture_single_get_current_button ((GtkGestureSingle * )gesture), GDK_BUTTON_RELEASE, data);
825}
826#else
836G_MODULE_EXPORT gboolean on_data_button_event (GtkWidget * widget, GdkEvent * event, gpointer data)
837{
838 GdkEventButton * bevent = (GdkEventButton*)event;
839 data_button_event (widget, event, bevent -> button, bevent -> type, data);
840 return FALSE;
841}
842#endif
843
854static void fill_data_model (GtkListStore * store, project * this_proj, int b, int c)
855{
856 GtkTreeIter datalevel;
857 int i;
858 for (i=0; i<this_proj -> curves[b][c] -> ndata; i++)
859 {
860 gtk_list_store_append (store, & datalevel);
861 gtk_list_store_set (store, & datalevel,
862 0, i+1,
863 1, this_proj -> curves[b][c] -> data[0][i],
864 2, this_proj -> curves[b][c] -> data[1][i], -1);
865 }
866}
867
877GtkWidget * setview (project * this_proj, int b, int c)
878{
879 GtkWidget * dataview;
880 GtkListStore * datamodel;
881 GType type[3]={G_TYPE_INT, G_TYPE_DOUBLE, G_TYPE_DOUBLE};
882 GtkTreeViewColumn * datacol[3];
883 GtkCellRenderer * datacel[3];
884 GtkTreeSelection * dataselect;
885// ColRGBA col[3];
886 gchar * name[3];
887 int i;
888 name[0]=g_strdup_printf (" ");
889 name[1]=g_strdup_printf ("%s", this_proj -> curves[b][c] -> axis_title[0]);
890 name[2]=g_strdup_printf ("%s\n%s", prepare_for_title(this_proj -> name), this_proj -> curves[b][c] -> name);
891 datamodel = gtk_list_store_newv (3, type);
892 fill_data_model (datamodel, this_proj, b, c);
893 dataview = gtk_tree_view_new_with_model (GTK_TREE_MODEL(datamodel));
894 //gtk_tree_view_set_rules_hint (GTK_TREE_VIEW(dataview), TRUE);
895 for (i=0; i<3; i++)
896 {
897 datacel[i] = gtk_cell_renderer_text_new();
898 /* if (i == 1)
899 \param 890: /afs /bin /boot /data /dev /etc /home /lib /lib64 /lost+found /media /mnt /opt /proc /root /run /sbin /share /srv /sys /tmp /usr /var if (i == 1) 890: /afs /bin /boot /data /dev /etc /home /lib /lib64 /lost+found /media /mnt /opt /proc /root /run /sbin /share /srv /sys /tmp /usr /var if (i == 1)
900 {
901 col[i].red = 62965;
902 col[i].green = 62965;
903 col[i].blue = 62965;
904 }
905 else
906 {
907 col[i].red = 51914;
908 col[i].green = 57825;
909 col[i].blue = 65535;
910 }
911 g_object_set (datacel[i], "cell-background-gdk", & col[i], "cell-background-set", TRUE, NULL); */
912 if (i > 0)
913 {
914 g_object_set (datacel[i], "editable", TRUE, NULL);
915 gtk_cell_renderer_set_alignment (datacel[i], 0.5, 0.5);
916 this_proj -> curves[b][c] -> idcol[i-1].a = this_proj -> id;
917 this_proj -> curves[b][c] -> idcol[i-1].b = b;
918 this_proj -> curves[b][c] -> idcol[i-1].c = c;
919 this_proj -> curves[b][c] -> idcol[i-1].d = i;
920 g_signal_connect (G_OBJECT(datacel[i]), "edited", G_CALLBACK(edit_cell), & this_proj -> curves[b][c] -> idcol[i-1]);
921 }
922 datacol[i] = gtk_tree_view_column_new_with_attributes(name[i], datacel[i], "text", i, NULL);
923 gtk_tree_view_column_set_alignment (datacol[i], 0.5);
924 gtk_tree_view_column_set_resizable (datacol[i], TRUE);
925 gtk_tree_view_append_column(GTK_TREE_VIEW(dataview), datacol[i]);
926 if (i > 0)
927 {
928 gtk_tree_view_column_set_min_width (datacol[i], 100);
929 }
930 }
931 g_object_unref (datamodel);
932 dataselect = gtk_tree_view_get_selection (GTK_TREE_VIEW(dataview));
933 gtk_tree_selection_set_mode (dataselect, GTK_SELECTION_MULTIPLE);
934#ifdef GTK3
935 g_signal_connect (G_OBJECT(dataview), "button_press_event", G_CALLBACK(on_data_button_event), & this_proj -> curves[b][c] -> idcol[1]);
936#else
937 add_widget_gesture_and_key_action (dataview, "datab-context-click", G_CALLBACK(on_data_button_pressed), & this_proj -> curves[b][c] -> idcol[1],
938 "datab-context-release", G_CALLBACK(on_data_button_released), & this_proj -> curves[b][c] -> idcol[1],
939 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
940#endif
941 gtk_tree_view_expand_all (GTK_TREE_VIEW(dataview));
942 return dataview;
943}
944
953void cancel_changes (GtkWidget * widg, gpointer data)
954{
955 tint * id = (tint *)data;
956 destroy_this_widget (widg);
957 get_project_by_id(id -> a) -> curves[id -> b][id -> c] -> datatree = NULL;
958}
959
968G_MODULE_EXPORT void cancel_but (GtkButton * but, gpointer data)
969{
970 cancel_changes (get_top_level(GTK_WIDGET(but)), data);
971}
972
973#ifdef GTK4
982G_MODULE_EXPORT gboolean cancel_win (GtkWindow * win, gpointer data)
983#else
993G_MODULE_EXPORT gboolean cancel_win (GtkWidget * win, GdkEvent * event, gpointer data)
994#endif
995{
996 cancel_changes ((GtkWidget *)win, data);
997 return TRUE;
998}
999
1008G_MODULE_EXPORT void validate_changes (GtkButton * but, gpointer data)
1009{
1010 tint * id = (tint *)data;
1011 project * this_proj = get_project_by_id(id -> a);
1012 curve_model = gtk_tree_view_get_model(GTK_TREE_VIEW(this_proj -> curves[id -> b][id -> c] -> datatree));
1013 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW(this_proj -> curves[id -> b][id -> c] -> datatree));
1014 gtk_tree_selection_select_all (sel);
1015 get_tree_data (this_proj -> curves[id -> b][id -> c] -> datatree);
1016 if (nrows != this_proj -> curves[id -> b][id -> c] -> ndata)
1017 {
1018 this_proj -> curves[id -> b][id -> c] -> ndata = nrows;
1019 g_free (this_proj -> curves[id -> b][id -> c] -> data[0]);
1020 this_proj -> curves[id -> b][id -> c] -> data[0] = g_malloc0 (nrows*sizeof*this_proj -> curves[id -> b][id -> c] -> data[0]);
1021 g_free (this_proj -> curves[id -> b][id -> c] -> data[1]);
1022 this_proj -> curves[id -> b][id -> c] -> data[1] = g_malloc0 (nrows*sizeof*this_proj -> curves[id -> b][id -> c] -> data[1]);
1023 }
1024 nrows = 0;
1025 g_list_foreach (lrows, (GFunc)save_row, data);
1026 cancel_changes (get_top_level(GTK_WIDGET(but)), data);
1027 update_curves ();
1028}
1029
1037void edit_data (gpointer data)
1038{
1039 GtkWidget * win;
1040 tint * id = (tint *)data;
1041 project * this_proj = get_project_by_id(id -> a);
1042 if (this_proj -> curves[id -> b][id -> c] -> datatree != NULL)
1043 {
1044 win = get_top_level(GTK_WIDGET(this_proj -> curves[id -> b][id -> c] -> datatree));
1045 }
1046 else
1047 {
1048 gchar * str = g_strdup_printf ("%s - %s", prepare_for_title (this_proj -> name), this_proj -> curves[id -> b][id -> c] -> name);
1049 win = create_win (str, MainWindow, FALSE, TRUE);
1050 g_free (str);
1051 gtk_window_set_default_size (GTK_WINDOW(win), 300, 600);
1052 GtkWidget * vbox = create_vbox (BSEP);
1053 this_proj -> curves[id -> b][id -> c] -> datatree = setview (this_proj, id -> b, id -> c);
1054 GtkWidget * scrol = create_scroll (vbox, -1, 570, GTK_SHADOW_ETCHED_IN);
1055 add_container_child (CONTAINER_SCR, scrol, this_proj -> curves[id -> b][id -> c] -> datatree);
1056 GtkWidget * hbox = create_hbox (0);
1057 GtkWidget * butc = create_button ("Cancel", IMG_STOCK, CANCEL, -1, -1, GTK_RELIEF_NORMAL, G_CALLBACK(cancel_but), data);
1058 GtkWidget * butv = create_button ("Apply", IMG_STOCK, EXECUTE, -1, -1, GTK_RELIEF_NORMAL, G_CALLBACK(validate_changes), data);
1059 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, butc, TRUE, TRUE, 0);
1060 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, butv, TRUE, TRUE, 0);
1061 gtk_widget_set_size_request (hbox, -1, 40);
1062 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, TRUE, TRUE, 0);
1064 add_gtk_close_event (win, G_CALLBACK(cancel_win), data);
1065 }
1066 show_the_widgets (win);
1067}
Callback declarations for main window.
void update_curves()
update all curve(s) rendering for all project(s) in the workspace
Definition curve.c:559
Variable declarations for the curve widget Functions for interactions with the curve widget.
GtkTreePath * path
Definition datab.c:103
G_MODULE_EXPORT void data_pop_action(GSimpleAction *action, GVariant *parameter, gpointer data)
curve data edition popup menu actions callbacks
Definition datab.c:654
void add_to_last_row(gpointer data, gpointer user_data)
add constant to last row
Definition datab.c:184
void delete_row(gpointer data, gpointer user_data)
delete row
Definition datab.c:356
void insert_cell(gpointer data)
insert row
Definition datab.c:372
void add_to_last_col(double cte, gpointer data)
add constant value to selected rows
Definition datab.c:204
void update_first_col()
update all rows in the first column
Definition datab.c:167
G_MODULE_EXPORT void run_multiply_column(GtkDialog *wind, gint response_id, gpointer data)
multiply column by constant - running the dialog
Definition datab.c:498
GMenu * cell_title()
create the cell based operations subemu
Definition datab.c:598
GtkTreeSelection * sel
Definition datab.c:102
void select_row(gpointer data, gpointer user_data)
select row
Definition datab.c:264
void copy_content(gpointer data)
copy selection
Definition datab.c:312
void data_popup_menu(GtkWidget *top_level, GdkEvent *event, gpointer data)
create curve data edition popup menu GTK3
Definition datab.c:705
int nrows
Definition datab.c:98
G_MODULE_EXPORT void edit_cell(GtkCellRendererText *cell, gchar *path_string, gchar *new_text, gpointer user_data)
edit cell in the curve data edition tree model
Definition datab.c:409
G_MODULE_EXPORT void cancel_but(GtkButton *but, gpointer data)
cancel curve data edition button callback
Definition datab.c:968
GMenu * delete_data()
create the delete data submenu
Definition datab.c:572
void add_row(gpointer data, gpointer user_data)
add row
Definition datab.c:331
G_MODULE_EXPORT gboolean on_data_button_event(GtkWidget *widget, GdkEvent *event, gpointer data)
on button event in the curve data edition window
Definition datab.c:836
GtkWidget * setview(project *this_proj, int b, int c)
create the curve data tree store
Definition datab.c:877
GMenu * cell_actions()
create the cell actions submenu
Definition datab.c:584
void save_row(gpointer data, gpointer user_data)
save row data and udpate calculation result accordingly
Definition datab.c:130
GtkTreeModel * curve_model
Definition datab.c:99
void get_tree_data(GtkWidget *tree)
get information on location in a GtkTreeView
Definition datab.c:114
G_MODULE_EXPORT void run_add_to_column(GtkDialog *wind, gint response_id, gpointer data)
add constant to column - running the dialog
Definition datab.c:445
void multiply_last_row(gpointer data, gpointer user_data)
multiply last row by constant
Definition datab.c:224
void multiply_last_col(double cte, gpointer data)
multiply last colum by constant value
Definition datab.c:244
gchar * text
Definition datab.c:105
GtkTreeIter row
Definition datab.c:104
void edit_data(gpointer data)
create edit curve data dialog
Definition datab.c:1037
GMenu * column_actions()
create the column actions submenu
Definition datab.c:610
void data_button_event(GtkWidget *data_tree, GdkEvent *event, guint event_button, guint event_type, gpointer data)
curve data edition mouse button event GTK3
Definition datab.c:770
void multiply_column(gpointer data)
multiply column by constant - creating dialog
Definition datab.c:517
void update_first_row(gpointer data, gpointer user_data)
update row in the first column
Definition datab.c:151
GMenu * column_title()
create the column based operations submenu
Definition datab.c:623
G_MODULE_EXPORT void validate_changes(GtkButton *but, gpointer data)
apply data edition changes
Definition datab.c:1008
GList * lrows
Definition datab.c:100
G_MODULE_EXPORT gboolean cancel_win(GtkWidget *win, GdkEvent *event, gpointer data)
cancel curve data edition callback GTK3
Definition datab.c:993
void cancel_changes(GtkWidget *widg, gpointer data)
cancel curve data edition
Definition datab.c:953
GList * rows
Definition datab.c:101
void add_to_column(gpointer data)
add constant to column - creating the dialog
Definition datab.c:464
G_MODULE_EXPORT void adjust_value(GtkEntry *res, gpointer data)
adjust constant value entry callback
Definition datab.c:429
GMenu * insert_data()
create the insert data submenu
Definition datab.c:560
void copy_row(gpointer data, gpointer user_data)
copy row
Definition datab.c:281
GtkWidget * col_entry
Definition datab.c:419
void delete_cell(gpointer data)
delete row
Definition datab.c:393
GMenu * data_menu()
create the curve data edition popup menu elements
Definition datab.c:635
GMenu * insert_place()
create the insertion submenu
Definition datab.c:547
float val
Definition dlp_init.c:117
GtkWidget * MainWindow
Definition global.c:201
double string_to_double(gpointer string)
convert string to double
Definition global.c:624
Global variable declarations Global convenience function declarations Global data structure defin...
void run_this_gtk_dialog(GtkWidget *dial, GCallback handler, gpointer data)
run a GTK (3 and 4) basic GtkDialog
Definition gtk-misc.c:492
#define EXECUTE
Definition global.h:216
@ IMG_NONE
Definition global.h:260
@ IMG_STOCK
Definition global.h:264
GtkWidget * create_entry(GCallback handler, int dim, int cdim, gboolean key_release, gpointer data)
Create a GtkEntry.
Definition gtk-misc.c:1314
void update_entry_double(GtkEntry *entry, double doubleval)
update the content of a GtkEntry as double
Definition gtk-misc.c:633
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
GtkWidget * create_win(gchar *str, GtkWidget *parent, gboolean modal, gboolean resiz)
create a new GtkWindow
Definition gtk-misc.c:445
const gchar * entry_get_text(GtkEntry *entry)
get the text in a GtkEntry
Definition gtk-misc.c:597
#define BSEP
Definition global.h:245
void pop_menu_at_pointer(GtkWidget *widg, GdkEvent *event)
popup a menu at pointer location
Definition gtk-misc.c:2301
void append_submenu(GMenu *menu, const gchar *label, GMenu *submenu)
append a GMenuItem with a subenu to a GMenu, and use markup for the GMenuItem
Definition gui.c:728
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 LIST_ADD
Definition global.h:213
@ CONTAINER_WIN
Definition global.h:250
@ CONTAINER_SCR
Definition global.h:251
GtkWidget * create_button(gchar *text, int image_format, gchar *image, int dimx, int dimy, int relief, GCallback handler, gpointer data)
create a simple button
Definition gtk-misc.c:1863
GtkWidget * get_top_level(GtkWidget *widg)
get the top level container, window, of a widget
Definition gtk-misc.c:2315
#define LIST_REM
Definition global.h:214
GtkWidget * dialog_get_content_area(GtkWidget *widg)
prepare GtkWidget to insert content in a GtkDialog window
Definition gtk-misc.c:825
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
#define CANCEL
Definition global.h:215
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2065
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:813
#define GO_DOWN
Definition global.h:196
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2034
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 append_menu_item(GMenu *menu, const gchar *label, const gchar *action, const gchar *accel, const gchar *custom, int format, const gchar *icon, gboolean check, gboolean status, gboolean radio, const gchar *rstatus)
create a menu item, then append it to a menu
Definition gui.c:758
#define GO_UP
Definition global.h:195
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:801
#define FCLOSE
Definition global.h:211
#define EDITC
Definition global.h:203
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
action
Definition glview.h:189
Messaging function declarations.
double y
Definition ogl_draw.c:57
double x
Definition ogl_draw.c:57
Function declarations for reading atomes project file Function declarations for saving atomes proje...
Definition global.h:112
Definition global.h:104
int b
Definition tab-1.c:95
int c
Definition tab-1.c:95
int d
Definition tab-1.c:95
int a
Definition tab-1.c:95
GtkWidget * axis_title
Definition tab-4.c:101
GtkWidget * res[2]
Definition w_encode.c:212
GtkWidget * hbox
Definition workspace.c:71
GtkWidget * vbox
Definition workspace.c:72
GtkWidget * lab
Definition workspace.c:73