From 5ed02a396edd24d2fbccc15d6250e1235e070e98 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Tue, 3 Sep 2024 17:32:42 +0200 Subject: [PATCH] WIP: un [mode_console] pour tester la logique des commandes DO UNDO REDO ? --- (notes) | 9 +++- include/fsm.h | 2 + include/signal.h | 2 +- include/widget.h | 1 + src/fsm/engine/engine.c | 77 ++++++++++++++++---------------- src/fsm/{ => engine}/engine.java | 0 src/main.c | 2 +- src/signal.c | 17 ++++++- src/widget/topbar/dispatch.c | 1 + src/widget/topbar/left.c | 2 + 10 files changed, 70 insertions(+), 43 deletions(-) rename src/fsm/{ => engine}/engine.java (100%) diff --git a/(notes) b/(notes) index c450c2b..71a6bbb 100644 --- a/(notes) +++ b/(notes) @@ -1,4 +1,11 @@ -https://developer.gnome.org/hig/principles.html + + +https://www.man-linux-magique.net/man3/gets.html +https://zestedesavoir.com/tutoriels/755/le-langage-c-1/1043_aggregats-memoire-et-fichiers/4911_les-fichiers/ + +================================================= + +ttps://developer.gnome.org/hig/principles.html // https://docs.gtk.org/gio/class.MenuModel.html // https://www.geany.org/manual/gtk/gobject/index.html diff --git a/include/fsm.h b/include/fsm.h index c0a6afd..dcea719 100644 --- a/include/fsm.h +++ b/include/fsm.h @@ -126,4 +126,6 @@ void fsm_disp_add_chart (disp_list d, int *p_chart); int fsm_disp_get_chart (disp_list d, int from, int to); void fsm_disp_remove_chart (disp_list d, int *p_chart); +// --------------------------------------------------------------- WIP ------ void fsm_another_proto_engine (); +void *fsm_get_engine_page(); diff --git a/include/signal.h b/include/signal.h index dd8498b..ebe3983 100644 --- a/include/signal.h +++ b/include/signal.h @@ -160,4 +160,4 @@ void on_skip_this_step (GtkWidget *btt, gpointer data); void on_something_else (GtkWidget *btt, gpointer data); void on_closing_page (GtkWidget *btt, gpointer data); - +void on_start_new_engine (GtkWidget *btt, gpointer data); diff --git a/include/widget.h b/include/widget.h index 3d322a1..c9f6e44 100644 --- a/include/widget.h +++ b/include/widget.h @@ -108,6 +108,7 @@ void *widget_get_state_page(); // in : widget / state / dispatch.c void *widget_get_rules_page(); // in : widget / rules / dispatch.c void *widget_get_data_page(); // in : widget / data / dispatch.c void *widget_get_measure_page();// in : widget / measure / dispatch.c +void *widget_get_engine_page(); // in : fsm / engine / engine.c /******************************************************************************/ diff --git a/src/fsm/engine/engine.c b/src/fsm/engine/engine.c index 08a70e7..26ecb81 100644 --- a/src/fsm/engine/engine.c +++ b/src/fsm/engine/engine.c @@ -28,6 +28,8 @@ #include #include #include "../../../include/fsm.h" +#include "../../../include/widget.h" +#include "../../../include/signal.h" /******************************************************************************/ @@ -43,55 +45,29 @@ /* */ /******************************************************************************/ +static void listen (struct timespec rem, struct timespec req) +{ + + printf("\n\x1b[1F\x1b[2K"); // move to the beginning of previous line and clear it + nanosleep(&req , &rem); +} static void fsm_strange_engine() { int milliseconds = 100; struct timespec rem; struct timespec req= { - (int)(milliseconds / 1000), /* secs (Must be Non-Negative) */ - (milliseconds % 1000) * 1000000 /* nano (Must be in range of 0 to 999999999) */ + (int)(milliseconds / 1000), // secs (Must be Non-Negative) + (milliseconds % 1000) * 1000000 // nano (Must be in range of 0 to 999999999) }; + printf("fsm mode_console 😇️ (see@ 'src/engine/engine.c\n"); int stop = 0; while (! stop) { - printf(" | M . |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | W . |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | MO * |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | W=-O * |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | D=-- -O * |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | =- - - O * |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | -- O * |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | - O (*) |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | O (*) |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | O (*) |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | O (*) |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | O*) |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | (*O |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | (*) O |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | (*) O |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | (*) O |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | * O |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | * O |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | * O |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | * O |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | * O |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | O |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | O * |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | O . |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | O . |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | O . .|\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | O . .|\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | D . . |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | M- . . |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | W =- . . |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | M = --- . . |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | W =-- . . |\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | M=- . .|\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - printf(" | W- . .|\n\x1b[1F\x1b[2K"); nanosleep(&req , &rem); - stop = (getchar() == '\n'); + printf(" | °°°°°°°°°°°°°°°° |"); listen (rem, req); + printf(" | ************* *************|"); listen (rem, req); +// stop = (getchar() == '\n'); } - printf("\x1b[1Fsrc/fsm/engine.c | src/fsm/engine.c fsm_strange_engine stopped\n"); } @@ -99,8 +75,31 @@ void fsm_engine_init() { if (1) printf ("src/fsm/engine.c | src/fsm/engine.c fsm_engine_init()\n"); fsm_strange_engine(); - // \x1b[1F \x1b[2K == move to the beginning of previous line and clear it + printf("src/fsm/engine.c | src/fsm/engine.c fsm_strange_engine stopped\n"); //fsm_another_proto_engine(); } +static GtkBox *engine_page; +static GtkBox *edit_a_new_engine_box; +static GtkWidget *factory; +static GtkWidget *btt_edit_a_new_engine; + +void *fsm_get_engine_page() +{ + engine_page = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2)); + edit_a_new_engine_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2)); + factory = gtk_picture_new_for_filename + ("/home/jean/Gem-Graph/gem-graph-client/data/stamp/factory.png"); + btt_edit_a_new_engine = gtk_toggle_button_new_with_label ("edit a new engine"); + g_signal_connect (btt_edit_a_new_engine, "toggled", + G_CALLBACK (on_start_new_engine), NULL); + + gtk_box_append (edit_a_new_engine_box, GTK_WIDGET (factory)); + gtk_box_append (edit_a_new_engine_box, GTK_WIDGET (btt_edit_a_new_engine)); + gtk_box_append (engine_page, GTK_WIDGET (edit_a_new_engine_box)); + + gtk_widget_set_size_request (GTK_WIDGET (engine_page), 1000, 400); + + return engine_page; + } diff --git a/src/fsm/engine.java b/src/fsm/engine/engine.java similarity index 100% rename from src/fsm/engine.java rename to src/fsm/engine/engine.java diff --git a/src/main.c b/src/main.c index 820d020..2194d7a 100644 --- a/src/main.c +++ b/src/main.c @@ -139,13 +139,13 @@ int main (int argc, char **argv) GtkApplication *app = gtk_application_new ("org.gem-graph", G_APPLICATION_DEFAULT_FLAGS); - fsm_engine_init(); // def: fsm/engine/engine; fsm_init (); // fsm = finite state machine (see : src/fsm/dispatch.c) g_signal_connect (app, "activate", G_CALLBACK (on_windows_activation), NULL); // on_windows_activation <> see: src/widget/dispatch.c (NOT src/signal.c) status = g_application_run (G_APPLICATION (app), argc, argv); + g_object_unref (app); return status; diff --git a/src/signal.c b/src/signal.c index df9125b..98c3125 100644 --- a/src/signal.c +++ b/src/signal.c @@ -366,8 +366,17 @@ void on_situations_box_do_reset (GtkWidget *btt_reset, GtkScrollbar *reset_scrol void on_clicked_topbar_right_measure (GtkWidget *btt, gpointer data) { // fsm_measures_sorted_list_do something (); + +// 2024-09-03 - experimental area - +// j'essaie d'interagir avec l'affichage console +// widget_get_measure_page() < demeure intact (valide) +// pour revenir en arrière, +// il n'y a qu'à remplacer fsm_get_engine_page() +// par widget_get_measure_page() dans l'instruction suivante. + gtk_window_set_child (GTK_WINDOW (widget_get_main_window ()), - GTK_WIDGET (widget_get_measure_page())); + // GTK_WIDGET (widget_get_measure_page())); + GTK_WIDGET (fsm_get_engine_page())); } void on_start_new_measure (GtkWidget *btt, gpointer data) @@ -454,4 +463,10 @@ void on_measure_third_event_occurences_in_between (GtkWidget *btt, gpointer data GTK_WIDGET (widget_measure_third_event_occurences_in_between())); } +void on_start_new_engine (GtkWidget *btt, gpointer data) +{ + printf("src/signal.c | on_start_new_engine() > fsm_engine_init();\n"); + fsm_engine_init(); +} + diff --git a/src/widget/topbar/dispatch.c b/src/widget/topbar/dispatch.c index 5c18fd4..64255cb 100644 --- a/src/widget/topbar/dispatch.c +++ b/src/widget/topbar/dispatch.c @@ -31,6 +31,7 @@ #include "../../../include/base.h" #include "../../../include/signal.h" #include "../../../include/widget.h" +#include "../../../include/fsm.h" diff --git a/src/widget/topbar/left.c b/src/widget/topbar/left.c index bff4d08..8fb1762 100644 --- a/src/widget/topbar/left.c +++ b/src/widget/topbar/left.c @@ -85,6 +85,7 @@ void window_design_topbar_left (GtkWidget *header_bar) #define YOU_WANT_TO_START_ON_ANOTHER_PAGE 0 +#define YOU_DON_T_WANT_THE_MODE_CONSOLE 0 /******************************************************************************/ /* use the next lineS to select the page that will be presented first */ /* it triggers <=> signal.on_toggle_state_rule_data (a btt_NAME) */ @@ -92,6 +93,7 @@ void window_design_topbar_left (GtkWidget *header_bar) /* the last one is the winner (and the winner takes it all !...) */ /* THE LAST ONE IS THE WINNER (AND THE WINNER TAKES IT ALL !...) */ /******************************************************************************/ + if (YOU_DON_T_WANT_THE_MODE_CONSOLE) gtk_check_button_set_active (GTK_CHECK_BUTTON (widget_get_btt_synth()), TRUE); if (YOU_WANT_TO_START_ON_ANOTHER_PAGE) { // select one gtk_check_button_set_active (GTK_CHECK_BUTTON (widget_get_btt_rules()), TRUE);