diff --git a/automaton.c b/automaton.c index 98499e0..8997ba6 100644 --- a/automaton.c +++ b/automaton.c @@ -1,56 +1,41 @@ #include #include #include "callback.h" +#include "automaton.h" /******************************************************************************/ /* S T A T E S */ /******************************************************************************/ -// (exec / edit) X (state / rules / measure) X (observ / interpret / read / write) +/* (exec / edit) + * X + * (state / rules / data) + * X + * (measure / analyse / interpret) + * X + * (read / write) + */ -enum { // S T A T E S - INTER, - EXEC_STOP, - EXEC_RUN, - EDIT_STATE, - EDIT_RULE, - MEASURE, - OBSERVE, - ANALYSE, - HELP, - CONFIGURE -}; +static int status = INTER; // int get_status () {return status;} -static int status = EXEC_STOP; // int get_status () {return status;} - -enum { // T R A N S I T I O N S - EXEC_TO_RUN, - RUN_TO_EXEC, - EXEC_TO_INTER, - INTER_TO_EDIT, - EDIT_TO_INTER, - INTER_TO_EXEC, -}; /******************************************************************************/ /* T R A N S I T I O N S */ /******************************************************************************/ void SWITCH_TO (int asked) { switch (asked) { - case (0) : // EXEC_TO_RUN - status = EXEC_RUN; + case (INTER) : // BEGIN_TO_EXEC_STOP + status = STATE; printf ("SWITCH_TO INTER\n"); break; - case (1) : // RUN_TO_EXEC - status = EXEC_STOP; + case (STATE) : // EXEC_STOP_TO_RUN + status = RULES; printf ("SWITCH_TO STATE\n"); break; - case (2) : // EXEC_TO_INTER - status = INTER; + case (RULES) : // EXEC_RUN_TO_STOP + status = DATA; printf ("SWITCH_TO RULES\n"); break; - case (3) : // EDIT_TO_INTER - // 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 - status = INTER; + case (DATA) : // EXEC_TO_INTER + status = INTER; printf ("SWITCH_TO DATA\n"); break; default : ; } @@ -67,15 +52,42 @@ void SWITCH_TO (int asked) { /* +enum { // S T A T E S + INTER, + EXEC_STOP, + EXEC_RUN, + EDIT_STATE, + EDIT_RULES_TREE, + EDIT_RULE, + EDIT_MEASURE, + OBSERVE, + ANALYSE, + HELP, + CONFIGURE +}; + +static int status = EXEC_STOP; // int get_status () {return status;} + +enum { // T R A N S I T I O N S + BEGIN_TO_EXEC_STOP + EXEC_STOP_TO_RUN, + EXEC_RUN_TO_STOP, + EXEC_TO_INTER, + INTER_TO_EDIT, + EDIT_TO_INTER, + INTER_TO_EXEC, +}; + + void set_status (int prescribed) { status = prescribed; if (0) printf ("status = %d\n", status); switch (status) { - case (0) : // EXEC_STOP + case (0) : // EXEC_STOP DATA_ANALYSIS status = EXEC_RUN; break; case (1) : // EXEC_RUN - // Ici, il faudra prévenir l'utilisateur par une pop-up window : TODO (sauvegarde automatique sinon) + // Ici, il faudra prévenir l'utilisateur par une pop-up window : (sauvegarde automatique sinon) // S'il ne prend pas la main, les données de la simulation en cours risquent d'être perdues status = EXEC_STOP; break; diff --git a/automaton.h b/automaton.h index b5e7e02..b6e96a9 100644 --- a/automaton.h +++ b/automaton.h @@ -4,3 +4,6 @@ void set_status (int prescribed); int get_status (); +enum choice { INTER, STATE, RULES, DATA }; + +void SWITCH_TO (int asked); diff --git a/callback.c b/callback.c index 92f2d6f..6840698 100644 --- a/callback.c +++ b/callback.c @@ -199,11 +199,13 @@ void on_toggle_observ_interpret (GtkWidget *btt_toggle_observ_interpret, gpointe void on_SAVE_CURRENT_MODEL_BEFORE_EDITING (GtkWidget *btt_SAVE_CURRENT_MODEL, gpointer data) { gtk_widget_set_sensitive (GTK_WIDGET (data), TRUE); printf ("callback.c (line 201) - SAVE_CURRENT_MODEL_BEFORE_EDITING\n"); + SWITCH_TO (INTER); } void on_DISCARD_CURRENT_MODEL_AND_START_EDITING (GtkWidget *btt_SAVE_CURRENT_MODEL, gpointer data) { gtk_window_close (GTK_WINDOW (data)); printf ("callback.c (line 206) - DISCARD_CURRENT_MODEL_AND_START_EDITING\n"); + SWITCH_TO (RULES); } void on_WRITE_CURRENT_MODEL (GtkWidget *btt_WRITE_CURRENT_MODEL, gpointer data) {