WIP: machine à états dans 'in_depth'

This commit is contained in:
Jean Sirmai 2024-06-09 13:27:15 +02:00
parent c7bbc8b1e6
commit e8b0427aac
Signed by: jean
GPG Key ID: FB3115C340E057E3
4 changed files with 67 additions and 44 deletions

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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 : ;
}
}

View File

@ -1,12 +1,6 @@
#include <gtk-4.0/gtk/gtk.h>
#include <assert.h>
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 ();