2024-05-31 22:34:15 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <gtk-4.0/gtk/gtk.h>
|
|
|
|
|
2024-06-11 19:20:44 +02:00
|
|
|
#include "callback.h"
|
2024-06-28 08:16:45 +02:00
|
|
|
#include "contain.h"
|
2024-06-02 22:49:16 +02:00
|
|
|
#include "tree.h"
|
2024-05-31 22:34:15 +02:00
|
|
|
#include "contain.h"
|
2024-06-11 00:11:50 +02:00
|
|
|
#include "dialog.h"
|
2024-05-31 22:34:15 +02:00
|
|
|
#include "texts.h"
|
2024-06-11 22:01:44 +02:00
|
|
|
#include "automaton.h"
|
2024-06-06 22:49:43 +02:00
|
|
|
#include "parsing.h"
|
|
|
|
#include "graph_area.h"
|
2024-05-31 22:34:15 +02:00
|
|
|
|
2024-06-02 22:14:24 +02:00
|
|
|
/******************************************************************************/
|
2024-06-11 16:39:40 +02:00
|
|
|
/* W I N D O W S A C T I V A T I O N */
|
2024-06-02 22:14:24 +02:00
|
|
|
/******************************************************************************/
|
2024-06-11 16:39:40 +02:00
|
|
|
|
|
|
|
static GtkWindow *main_window, *dialog_window;
|
|
|
|
|
|
|
|
void on_main_window_activation (GtkApplication *app, gpointer no_user_data)
|
2024-06-11 00:11:50 +02:00
|
|
|
{
|
2024-06-11 16:39:40 +02:00
|
|
|
main_window = GTK_WINDOW (gtk_application_window_new (app));
|
|
|
|
main_window_design (main_window);
|
|
|
|
g_signal_connect (app, "activate", G_CALLBACK (on_dialog_window_activation), main_window);
|
2024-06-11 00:11:50 +02:00
|
|
|
}
|
|
|
|
|
2024-06-11 19:20:44 +02:00
|
|
|
void on_dialog_window_activation (GtkApplication *app, gpointer no_user_data)
|
|
|
|
{
|
|
|
|
dialog_window = GTK_WINDOW (gtk_application_window_new (app));
|
|
|
|
dialog_window_design (main_window, dialog_window);
|
|
|
|
}
|
|
|
|
|
2024-06-11 16:39:40 +02:00
|
|
|
|
2024-06-07 23:34:08 +02:00
|
|
|
void on_auto_notification (const char *message)
|
2024-06-06 22:49:43 +02:00
|
|
|
{
|
|
|
|
/* Ignored (2024-06-06) because I don't know how to get "main_window" easily
|
|
|
|
|
|
|
|
if (window->toast_revealer == NULL) {
|
2024-06-11 16:39:40 +02:00
|
|
|
g_printerr("Can't find app->toast_overlay !\n");
|
2024-06-06 22:49:43 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->toast_text == NULL) {
|
2024-06-11 16:39:40 +02:00
|
|
|
g_printerr("Can't find app->toast_overlay !\n");
|
2024-06-06 22:49:43 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_label_set_label(window->toast_text, message);
|
|
|
|
gtk_revealer_set_reveal_child(window->toast_revealer, true);
|
|
|
|
*/
|
|
|
|
g_printerr("%s\n", message);
|
|
|
|
}
|
|
|
|
|
2024-06-02 22:14:24 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
/* T R E E */
|
|
|
|
/******************************************************************************/
|
2024-06-03 05:46:01 +02:00
|
|
|
void on_user_tree_expander_toggled (GtkExpander *expander, gpointer user_data)
|
2024-06-02 22:14:24 +02:00
|
|
|
{
|
|
|
|
GtkTreeListRow *row = GTK_TREE_LIST_ROW (user_data);
|
|
|
|
gboolean is_expanded = gtk_tree_list_row_get_expanded(row);
|
|
|
|
gtk_tree_list_row_set_expanded (row, !is_expanded);
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_bind_user_tree_factory (GtkSignalListItemFactory *factory, GObject* object, gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkListItem *list_item = GTK_LIST_ITEM (object); assert (list_item);
|
2024-06-03 05:46:01 +02:00
|
|
|
GtkTreeListRow *row = gtk_list_item_get_item (list_item); assert (row); // if (row != NULL) {...} ?
|
2024-06-02 22:14:24 +02:00
|
|
|
const gchar *text = gtk_string_object_get_string (GTK_STRING_OBJECT (gtk_tree_list_row_get_item (row)));
|
|
|
|
GtkWidget *expander = gtk_list_item_get_child (list_item);
|
|
|
|
gtk_expander_set_label (GTK_EXPANDER (expander), text);
|
|
|
|
g_signal_handlers_disconnect_by_func(expander, G_CALLBACK (on_user_tree_expander_toggled), row);
|
|
|
|
g_signal_connect(expander, "activate", G_CALLBACK (on_user_tree_expander_toggled), row);
|
2024-06-03 05:46:01 +02:00
|
|
|
gtk_widget_set_margin_start(expander, gtk_tree_list_row_get_depth(row) * 20);
|
2024-05-31 22:34:15 +02:00
|
|
|
}
|
|
|
|
|
2024-06-06 22:49:43 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
/* G L A R E A */
|
|
|
|
/******************************************************************************/
|
|
|
|
gboolean on_glarea_render(GtkGLArea *area, GdkGLContext *context)
|
|
|
|
{
|
|
|
|
// Check if the widget is a glarea
|
|
|
|
if(gtk_gl_area_get_error(area) != NULL) {
|
2024-06-27 20:00:15 +02:00
|
|
|
on_auto_notification("An OpenGL error occured !");
|
2024-06-06 22:49:43 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-06-27 20:00:15 +02:00
|
|
|
if (ui_render_stack(gtk_widget_get_parent(GTK_WIDGET(area))) == false) {
|
|
|
|
on_auto_notification("Failed to render corresponding graphic stack !");
|
|
|
|
return false;
|
|
|
|
}
|
2024-06-06 22:49:43 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* We need to set up our state when we realize the GtkGLArea widget */
|
|
|
|
void on_glarea_realize(GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GError *internal_error = NULL;
|
|
|
|
|
|
|
|
// Make the GL context current to be able to call the GL API
|
|
|
|
gtk_gl_area_make_current(GTK_GL_AREA(widget));
|
|
|
|
|
|
|
|
// Check if the widget is a glarea
|
|
|
|
if(gtk_gl_area_get_error(GTK_GL_AREA(widget)) != NULL) {
|
2024-06-07 23:34:08 +02:00
|
|
|
on_auto_notification("An OpenGL error occured !");
|
2024-06-06 22:49:43 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Link graphical stack to widget
|
|
|
|
if (ui_init_graphic_stack(gtk_widget_get_parent(widget),
|
|
|
|
internal_error) == false) {
|
2024-06-07 23:34:08 +02:00
|
|
|
on_auto_notification(
|
2024-06-06 22:49:43 +02:00
|
|
|
"Failed to link the graphic stack to widgets !");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_gl_area_set_auto_render(GTK_GL_AREA(widget), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We should tear down the state when unrealizing */
|
|
|
|
void on_glarea_unrealize(GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GError *internal_error = NULL;
|
|
|
|
|
|
|
|
// Make the GL context current to be able to call the GL API
|
|
|
|
gtk_gl_area_make_current(GTK_GL_AREA(widget));
|
|
|
|
|
|
|
|
// Check if the widget is a glarea
|
|
|
|
if(gtk_gl_area_get_error(GTK_GL_AREA(widget)) != NULL) {
|
2024-06-07 23:34:08 +02:00
|
|
|
on_auto_notification("An OpenGL error occured !");
|
2024-06-06 22:49:43 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy graphic stack
|
|
|
|
if (ui_shutdown_graphic_stack(gtk_widget_get_parent(widget),
|
|
|
|
internal_error) == false) {
|
2024-06-07 23:34:08 +02:00
|
|
|
on_auto_notification(
|
2024-06-06 22:49:43 +02:00
|
|
|
"Failed to shutdown the graphic stack !");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-06 23:23:25 +02:00
|
|
|
void on_axis_value_change(GtkAdjustment *adjustment, gpointer data)
|
|
|
|
{
|
|
|
|
|
|
|
|
GtkWidget *slider = gtk_widget_get_parent(GTK_WIDGET(data));
|
|
|
|
GtkWidget *container_widget = gtk_widget_get_parent(GTK_WIDGET(slider));
|
|
|
|
|
|
|
|
const gchar *label_text = gtk_label_get_label(GTK_LABEL(data));
|
|
|
|
|
|
|
|
// THANKS ASCIIIII/Unicode/Whateverrr !
|
|
|
|
int axis = label_text[0] - 'X';
|
|
|
|
|
|
|
|
g_assert(axis >= 0 && axis < N_AXIS);
|
|
|
|
|
|
|
|
/* Update the rotation angle */
|
|
|
|
ui_update_axis_stack(container_widget,
|
|
|
|
axis,
|
|
|
|
gtk_adjustment_get_value(adjustment));
|
|
|
|
|
|
|
|
/* Update the contents of the GL drawing area */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-06-02 22:49:16 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
/* B U T T O N S */
|
|
|
|
/******************************************************************************/
|
2024-06-28 10:13:22 +02:00
|
|
|
|
2024-06-28 12:46:31 +02:00
|
|
|
void on_toggle_EXEC_EDIT (GtkWidget *toggled_button, gpointer user_data) {
|
|
|
|
|
|
|
|
if (get_EXEC_EDIT ()) {
|
|
|
|
gtk_button_set_icon_name (GTK_BUTTON (toggled_button), "power-profile-balanced-rtl-symbolic");
|
2024-06-28 10:13:22 +02:00
|
|
|
set_EXEC_EDIT (EXEC);
|
2024-06-16 00:06:49 +02:00
|
|
|
} else {
|
2024-06-28 12:46:31 +02:00
|
|
|
gtk_button_set_icon_name (GTK_BUTTON (toggled_button), "text-editor-symbolic");
|
2024-06-28 10:13:22 +02:00
|
|
|
set_EXEC_EDIT (EDIT);
|
2024-06-16 00:06:49 +02:00
|
|
|
}
|
2024-06-28 12:46:31 +02:00
|
|
|
switch (get_STATE_RULES_DATA()) {
|
|
|
|
case (STATE) : gtk_window_set_child (main_window, GTK_WIDGET (get_window_child_STATE())); break;
|
|
|
|
case (RULES) : gtk_window_set_child (main_window, GTK_WIDGET (get_window_child_RULES())); break;
|
|
|
|
case (DATA) : gtk_window_set_child (main_window, GTK_WIDGET (get_window_child_DATA())); break;
|
|
|
|
default : printf("default in callback.on_toggle_STATE_RULES_DATA()\n");
|
|
|
|
}
|
2024-06-03 05:46:01 +02:00
|
|
|
}
|
|
|
|
|
2024-06-28 08:16:45 +02:00
|
|
|
void on_toggle_STATE_RULES_DATA (GtkWidget *toggled_button, gpointer user_data) {
|
2024-06-22 06:03:23 +02:00
|
|
|
|
2024-06-28 08:16:45 +02:00
|
|
|
const char *toggled_button_name = gtk_check_button_get_label (GTK_CHECK_BUTTON (toggled_button));
|
|
|
|
int is_active = gtk_check_button_get_active (GTK_CHECK_BUTTON (toggled_button));
|
2024-06-22 06:03:23 +02:00
|
|
|
|
2024-06-28 10:13:22 +02:00
|
|
|
if (! strcmp (toggled_button_name, "state")) set_STATE_RULES_DATA (STATE);
|
|
|
|
if (! strcmp (toggled_button_name, "rules")) set_STATE_RULES_DATA (RULES);
|
|
|
|
if (! strcmp (toggled_button_name, "data analysis")) set_STATE_RULES_DATA (DATA);
|
2024-06-22 06:03:23 +02:00
|
|
|
|
2024-06-28 10:13:22 +02:00
|
|
|
if (is_active)
|
|
|
|
switch (get_STATE_RULES_DATA()) {
|
|
|
|
case (STATE) : gtk_window_set_child (main_window, GTK_WIDGET (get_window_child_STATE())); break;
|
|
|
|
case (RULES) : gtk_window_set_child (main_window, GTK_WIDGET (get_window_child_RULES())); break;
|
|
|
|
case (DATA) : gtk_window_set_child (main_window, GTK_WIDGET (get_window_child_DATA())); break;
|
|
|
|
default : printf("default in callback.on_toggle_STATE_RULES_DATA()\n");
|
|
|
|
}
|
2024-06-22 05:37:08 +02:00
|
|
|
}
|
|
|
|
|
2024-06-11 19:20:44 +02:00
|
|
|
void on_SAVE_CURRENT_MODEL_BEFORE_EDITING (GtkWidget *btt_SAVE_CURRENT_MODEL, gpointer data) {
|
2024-06-11 22:49:42 +02:00
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (data), TRUE);
|
2024-06-12 00:16:45 +02:00
|
|
|
printf ("callback.c (line 201) - SAVE_CURRENT_MODEL_BEFORE_EDITING\n");
|
2024-06-11 19:20:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void on_DISCARD_CURRENT_MODEL_AND_START_EDITING (GtkWidget *btt_SAVE_CURRENT_MODEL, gpointer data) {
|
2024-06-12 00:16:45 +02:00
|
|
|
gtk_window_close (GTK_WINDOW (data));
|
|
|
|
printf ("callback.c (line 206) - DISCARD_CURRENT_MODEL_AND_START_EDITING\n");
|
2024-06-11 22:01:44 +02:00
|
|
|
}
|
|
|
|
|
2024-06-11 22:49:42 +02:00
|
|
|
void on_WRITE_CURRENT_MODEL (GtkWidget *btt_WRITE_CURRENT_MODEL, gpointer data) {
|
2024-06-12 00:16:45 +02:00
|
|
|
gtk_window_close (GTK_WINDOW (data));
|
|
|
|
printf ("callback.c (line 211) - WRITE_CURRENT_MODEL\n");
|
2024-06-11 19:20:44 +02:00
|
|
|
}
|
2024-06-11 22:49:42 +02:00
|
|
|
|