From e8b0427aac179dee3f808a95c4f216cef98fc9b9 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Sun, 9 Jun 2024 13:27:15 +0200 Subject: [PATCH] =?UTF-8?q?WIP:=20machine=20=C3=A0=20=C3=A9tats=20dans=20'?= =?UTF-8?q?in=5Fdepth'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- callback.c | 26 ++++++++++----------- contain.c | 8 +++---- in_depth.c | 67 ++++++++++++++++++++++++++++++++++++++---------------- in_depth.h | 10 ++------ 4 files changed, 67 insertions(+), 44 deletions(-) diff --git a/callback.c b/callback.c index a3120e9..e3a7199 100644 --- a/callback.c +++ b/callback.c @@ -160,31 +160,31 @@ void on_axis_value_change(GtkAdjustment *adjustment, gpointer data) /******************************************************************************/ void on_toggle_exec_edit (GtkWidget *btt_exec_xor_edit, GtkWidget *btt_run_stop_model_exec) { - if (get_exec_edit_mode()) { + if (get_status()) { gtk_button_set_icon_name (GTK_BUTTON (btt_exec_xor_edit), "power-profile-balanced-rtl-symbolic"); gtk_button_set_label (GTK_BUTTON (btt_run_stop_model_exec), " run "); gtk_widget_set_sensitive (GTK_WIDGET (btt_run_stop_model_exec), TRUE); - set_exec_edit_mode (0); + set_status (0); } else { gtk_button_set_icon_name (GTK_BUTTON (btt_exec_xor_edit), "document-edit-symbolic"); gtk_button_set_icon_name (GTK_BUTTON (btt_exec_xor_edit), "text-editor-symbolic"); // I hesitate - set_exec_edit_mode (1); + set_status (1); // Ici, il faudra prévenir l'utilisateur par une pop-up window : TODO (sauvegarde automatique sinon) // S'il ne prend pas la main, les données de la simulation en cours risquent d'être perdues gtk_button_set_label (GTK_BUTTON (btt_run_stop_model_exec), " off "); gtk_widget_set_sensitive (GTK_WIDGET (btt_run_stop_model_exec), FALSE); - set_run_xor_stop_exec (0); + set_status (0); } } void on_toggle_model_exec (GtkWidget *btt_run_stop_model_exec, gpointer data) { - if (get_run_xor_stop_exec() && ! get_exec_edit_mode()) { + if (get_status() && ! get_status()) { gtk_button_set_label (GTK_BUTTON (btt_run_stop_model_exec), " run "); - set_run_xor_stop_exec (0); + set_status (0); } else { gtk_button_set_label (GTK_BUTTON (btt_run_stop_model_exec), "stop"); - set_run_xor_stop_exec (1); + set_status (1); } } @@ -192,26 +192,26 @@ void on_toggle_model_exec (GtkWidget *btt_run_stop_model_exec, gpointer data) void on_toggle_state_rules (GtkWidget *btt_toggle_state_rules, gpointer data) { - if (get_run_xor_stop_exec()) { + if (get_status()) { gtk_button_set_label (GTK_BUTTON (btt_toggle_state_rules), "state"); window_main_child (main_window, 0); // 0 = state page (see contain.c) - set_run_xor_stop_exec (0); + set_status (0); } else { gtk_button_set_label (GTK_BUTTON (btt_toggle_state_rules), "rules"); window_main_child (main_window, 1); // 1 = rules page (see contain.c) - set_run_xor_stop_exec (1); + set_status (1); } } void on_toggle_observ_interpret (GtkWidget *btt_toggle_observ_interpret, gpointer data) { - if (get_observ_interpret()) { + if (get_status()) { gtk_button_set_label (GTK_BUTTON (btt_toggle_observ_interpret), "observe"); window_main_child (main_window, 2); // 2 = measures page (see contain.c) - set_observ_interpret (0); + set_status (0); } else { gtk_button_set_label (GTK_BUTTON (btt_toggle_observ_interpret), "interpret"); window_main_child (main_window, 3); // 3 = observe page (see contain.c) - set_observ_interpret (1); + set_status (1); } } diff --git a/contain.c b/contain.c index dffb487..bcb36f3 100644 --- a/contain.c +++ b/contain.c @@ -148,8 +148,8 @@ GtkWidget *get_SPACE_EDIT_controls_box() { void window_main_child_bottom (GtkBox *page_box){ - if (! get_exec_edit_mode ()) gtk_box_append (page_box, GTK_WIDGET (get_TIME_EXEC_controls_box())); - else gtk_box_append (page_box, GTK_WIDGET (get_SPACE_EDIT_controls_box())); + if (! get_status ()) gtk_box_append (page_box, GTK_WIDGET (get_TIME_EXEC_controls_box())); + else gtk_box_append (page_box, GTK_WIDGET (get_SPACE_EDIT_controls_box())); } static void icons_for_fun (GtkHeaderBar *header_bar); @@ -196,8 +196,8 @@ void window_main_child (GtkWindow *main_window, int selected_page){ gtk_box_append (page_box, GTK_WIDGET (get_SPACE_VIEW_box())); gtk_box_append (page_box, GTK_WIDGET (gtk_separator_new (GTK_ORIENTATION_HORIZONTAL))); window_main_child_bottom (page_box); -// if (get_exec_edit_mode ()) gtk_box_append (page_box, GTK_WIDGET (get_TIME_EXEC_controls_box())); -// else gtk_box_append (page_box, GTK_WIDGET (get_SPACE_EDIT_controls_box())); +// if (get_status ()) gtk_box_append (page_box, GTK_WIDGET (get_TIME_EXEC_controls_box())); +// else gtk_box_append (page_box, GTK_WIDGET (get_SPACE_EDIT_controls_box())); gtk_window_set_child (main_window, GTK_WIDGET (page_box)); break; case (1) : gtk_window_set_child (main_window, GTK_WIDGET (get_rules_page_new())); break; diff --git a/in_depth.c b/in_depth.c index 1d97059..bf952f8 100644 --- a/in_depth.c +++ b/in_depth.c @@ -7,17 +7,17 @@ /* S T A T E S */ /******************************************************************************/ -/* -(exec / edit) X (state / rules / measure) X (observ / interpret / read / write) -*/ - -// EXEC, EDIT, RUN, STOP, STATE, RULES, MEASURE, OBSERVE, INTERPRET, HELP, CONFIG +// (exec / edit) X (state / rules / measure) X (observ / interpret / read / write) enum { - EXEC_STOP, EXEC_RUN, - EXEC_STOP_EDIT_RULE, EXEC_RUN_EDIT_RULE, - EXEC_STOP_EDIT_MEASURE, EXEC_RUN_EDIT_MEASURE, - EDIT_STATE, EDIT_RULE, + EXEC_STOP, + EXEC_RUN, + EXEC_STOP_EDIT_RULE, + EXEC_RUN_EDIT_RULE, + EXEC_STOP_EDIT_MEASURE, + EXEC_RUN_EDIT_MEASURE, + EDIT_STATE, + EDIT_RULE, OBSERVE, INTERPRET, HELP, @@ -25,19 +25,48 @@ enum { }; static int status = EXEC_STOP; +int get_status () {return status;} /******************************************************************************/ /* T R A N S I T I O N S */ /******************************************************************************/ +void set_status (int prescribed) { + status = prescribed; if (0) printf ("status = %d\n", status); -int get_exec_edit_mode () {return status;} -void set_exec_edit_mode (int prescribed) {status = prescribed;} - -int get_run_xor_stop_exec () {return status;} -void set_run_xor_stop_exec (int prescribed) {status = prescribed;} - -int get_observ_interpret () {return status;} -void set_observ_interpret (int prescribed) {status = prescribed;} - -// if (0) printf ("status = %d\n", status); + switch (status) { + case (0) : /* EXEC_STOP */ + status = EXEC_RUN; + break; + case (1) : /* EXEC_RUN */ + status = EXEC_STOP; + break; + case (2) : /* EXEC_STOP_EDIT_STOP */ + status = EXEC_RUN_EDIT_RULE; + break; + case (3) : /* EXEC_RUN_EDIT_RULE */ + status = EXEC_STOP_EDIT_RULE; + break; + case (4) : /* EXEC_STOP_EDIT_MEASURE */ + status = EXEC_RUN_EDIT_MEASURE; + break; + case (5) : /* EXEC_RUN_EDIT_MEASURE */ + status = EXEC_STOP_EDIT_MEASURE; + break; + case (6) : /* EDIT_STATE */ + break; + case (7) : /* EDIT_RULE */ + break; + case (8) : /* OBSERVE */ + break; + case (9) : /* INTERPRET */ + break; + case (10) : /* HELP */ + break; + case (11) : /* CONFIGURE */ + break; + case (12) : /* OTHER */ + break; + default : ; + } +} diff --git a/in_depth.h b/in_depth.h index f87554e..b5e7e02 100644 --- a/in_depth.h +++ b/in_depth.h @@ -1,12 +1,6 @@ #include #include -void set_exec_edit_mode (int prescribed); -int get_exec_edit_mode (); - -void set_run_xor_stop_exec (int prescribed); -int get_run_xor_stop_exec (); - -void set_observ_interpret (int prescribed); -int get_observ_interpret (); +void set_status (int prescribed); +int get_status ();