WIP: en route vers un automate : [ EXEC_EDIT X STATE_RULES_DATA ]

This commit is contained in:
Jean Sirmai 2024-06-28 08:16:45 +02:00
parent f5837225c2
commit 8012dd37fc
Signed by: jean
GPG Key ID: FB3115C340E057E3
5 changed files with 142 additions and 209 deletions

View File

@ -8,122 +8,52 @@
/* S T A T E S */
/******************************************************************************/
/* (exec / edit) < MODE
* X
* (state / rules / data) < STATUS
* X
* (measure / analyse / interpret)
* X
* (read / write)
*/
static int choice_EXEC_EDIT = EXEC;
static int choice_STATE_RULES_DATA = STATE;
static int mode = RUN;
void set_mode (int prescribed) {mode = prescribed;}
int get_mode () {return mode;}
void set_EXEC_EDIT (int prescribed) {
choice_EXEC_EDIT = prescribed;
SWITCH_TO (choice_EXEC_EDIT, choice_STATE_RULES_DATA);
}
int get_EXEC_EDIT () {return choice_EXEC_EDIT;}
static int status = INTER; // int get_status () {return status;}
void set_status (int prescribed) {status = prescribed;}
int get_status () {return status;}
void set_STATE_RULES_DATA (int prescribed) {
choice_STATE_RULES_DATA = prescribed;
SWITCH_TO (choice_EXEC_EDIT, choice_STATE_RULES_DATA);
}
int get_STATE_RULES_DATA () {return choice_STATE_RULES_DATA;}
/******************************************************************************/
/* T R A N S I T I O N S */
/******************************************************************************/
void SWITCH_TO (int asked) {
switch (asked) {
case (INTER) :
status = INTER; printf ("SWITCH_TO INTER\n");
void SWITCH_TO (int choice_EXEC_EDIT, int choice_STATE_RULES_DATA)
{
switch (choice_STATE_RULES_DATA) {
case (STATE) :
choice_STATE_RULES_DATA = STATE;
if (choice_EXEC_EDIT ) choice_EXEC_EDIT = EXEC;
else choice_EXEC_EDIT = EDIT;
break;
case (STATE) : // BEGIN_TO_EXEC_STOP
status = STATE; printf ("SWITCH_TO STATE\n");
case (RULES) :
choice_STATE_RULES_DATA = RULES;
if (choice_EXEC_EDIT ) choice_EXEC_EDIT = EXEC;
else choice_EXEC_EDIT = EDIT;
break;
case (RULES) : // EXEC_STOP_TO_RUN
status = RULES; printf ("SWITCH_TO RULES\n");
case (DATA) :
choice_STATE_RULES_DATA = DATA;
if (choice_EXEC_EDIT ) choice_EXEC_EDIT = EXEC;
else choice_EXEC_EDIT = EDIT;
break;
case (DATA) : // EXEC_RUN_TO_STOP
status = DATA; printf ("SWITCH_TO DATA\n");
break;
default : ;
default : printf("default in automaton.SWITCH_TO()\n");
}
//q gtk_window_present (GTK_WINDOW (main_window));
printf("SWITCH_TO %d X %d (EXEC_EDIT X STATE_RULES_DATA)\n",
choice_EXEC_EDIT,
choice_STATE_RULES_DATA);
}
/*
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 DATA_ANALYSIS
status = EXEC_RUN;
break;
case (1) : // EXEC_RUN
// 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;
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,13 +1,14 @@
#include <gtk-4.0/gtk/gtk.h>
#include <assert.h>
void set_status (int prescribed);
int get_status ();
void set_mode (int prescribed);
int get_mode ();
enum mode { RUN, EDIT };
enum choice { INTER, STATE, RULES, DATA };
enum choice_EXEC_EDIT { EXEC, EDIT };
enum choice_STATE_RULES_DATA { STATE, RULES, DATA };
// MEASURE, OBSERVE, INTERPRET, HELP, CONFIGURE };
void SWITCH_TO (int asked);
void set_EXEC_EDIT (int prescribed);
int get_EXEC_EDIT ();
void set_STATE_RULES_DATA (int prescribed);
int get_STATE_RULES_DATA ();
void SWITCH_TO (int choice_EXEC_EDIT, int choice_STATE_RULES_DATA);

View File

@ -2,6 +2,7 @@
#include <gtk-4.0/gtk/gtk.h>
#include "callback.h"
#include "contain.h"
#include "tree.h"
#include "contain.h"
#include "dialog.h"
@ -166,37 +167,36 @@ void on_axis_value_change(GtkAdjustment *adjustment, gpointer data)
/******************************************************************************/
/* B U T T O N S */
/******************************************************************************/
void on_toggle_MODEL_RUN_STOP (GtkWidget *btt_MODEL_RUN_STOP, gpointer data) {
/*void on_toggle_MODEL_RUN_STOP (GtkWidget *btt_MODEL_RUN_STOP, gpointer data) {
if (strcmp (gtk_button_get_label (GTK_BUTTON (btt_MODEL_RUN_STOP)), " run "))
gtk_button_set_label (GTK_BUTTON (btt_MODEL_RUN_STOP), " run ");
else gtk_button_set_label (GTK_BUTTON (btt_MODEL_RUN_STOP), " stop ");
}
else gtk_button_set_label (GTK_BUTTON (btt_MODEL_RUN_STOP), " stop ");}*/
void on_toggle_EXEC_EDIT (GtkWidget *btt_XOR_EXEC_EDIT, GtkWidget *btt_MODEL_RUN_STOP) {
if (get_mode()) {
void on_toggle_EXEC_EDIT (GtkWidget *btt_XOR_EXEC_EDIT, GtkWidget *window_child_STATE) { // *btt_MODEL_RUN_STOP) {
if (get_EXEC_EDIT()) {
gtk_button_set_icon_name (GTK_BUTTON (btt_XOR_EXEC_EDIT), "power-profile-balanced-rtl-symbolic");
gtk_button_set_label (GTK_BUTTON (btt_MODEL_RUN_STOP), " run ");
gtk_widget_set_sensitive (GTK_WIDGET (btt_MODEL_RUN_STOP), TRUE);
set_mode (0);
set_EXEC_EDIT (EXEC);
} else {
gtk_button_set_icon_name (GTK_BUTTON (btt_XOR_EXEC_EDIT), "preferences-system-symbolic");
gtk_button_set_icon_name (GTK_BUTTON (btt_XOR_EXEC_EDIT), "emblem-ok-symbolic"); // Transport Steam Engine !!
gtk_widget_set_sensitive (GTK_WIDGET (btt_MODEL_RUN_STOP), FALSE);
set_mode (1);
// gtk_button_set_icon_name (GTK_BUTTON (btt_XOR_EXEC_EDIT), "emblem-ok-symbolic"); // Transport Steam Engine !!
// gtk_widget_set_sensitive (GTK_WIDGET (btt_MODEL_RUN_STOP), FALSE);
// gtk_box_append (GTK_BOX (window_child_STATE), GTK_WIDGET (get_SPACE_EDIT_controls_box()));
set_EXEC_EDIT (EDIT);
}
// gtk_window_present (GTK_WINDOW (main_window));
}
void on_toggle_STATE_RULES_DATA (GtkWidget *btt, gpointer user_data) {
void on_toggle_STATE_RULES_DATA (GtkWidget *toggled_button, gpointer user_data) {
// https://docs.gtk.org/gtk4/class.ToggleButton.html < f..k ! bad code ++
const char *btt_name = gtk_check_button_get_label (GTK_CHECK_BUTTON (btt));
int is_active = gtk_check_button_get_active (GTK_CHECK_BUTTON (btt));
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));
int is_state_active = ! strcmp (btt_name, "state");
int is_rules_active = ! strcmp (btt_name, "rules");
int is_data_active = ! strcmp (btt_name, "data analysis");
int is_state_active = ! strcmp (toggled_button_name, "state");
int is_rules_active = ! strcmp (toggled_button_name, "rules");
int is_data_active = ! strcmp (toggled_button_name, "data analysis");
if (0 && is_active) printf ("> [%d] %d, %d, %d %14s\n",
is_active, is_state_active, is_rules_active, is_data_active, btt_name);
is_active, is_state_active, is_rules_active, is_data_active, toggled_button_name);
if (is_active) {
if (is_state_active) gtk_window_set_child (main_window, GTK_WIDGET (get_window_child_STATE()));
@ -208,13 +208,13 @@ void on_toggle_STATE_RULES_DATA (GtkWidget *btt, gpointer user_data) {
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);
SWITCH_TO (EXEC, STATE);
}
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);
SWITCH_TO (EXEC, RULES);
}
void on_WRITE_CURRENT_MODEL (GtkWidget *btt_WRITE_CURRENT_MODEL, gpointer data) {

152
contain.c
View File

@ -181,14 +181,14 @@ void window_header_bar (GtkWindow *window, char *title){
gpointer no_local_data = NULL;
GtkButton *btt_MODEL_RUN_STOP = GTK_BUTTON (gtk_button_new_with_label (" run "));
g_signal_connect (btt_MODEL_RUN_STOP, "clicked", G_CALLBACK (on_toggle_MODEL_RUN_STOP), no_local_data);
// GtkButton *btt_MODEL_RUN_STOP = GTK_BUTTON (gtk_button_new_with_label (" run "));
// g_signal_connect (btt_MODEL_RUN_STOP, "clicked", G_CALLBACK (on_toggle_MODEL_RUN_STOP), no_local_data);
GtkButton *btt_XOR_EXEC_EDIT = GTK_BUTTON (gtk_toggle_button_new ());
gtk_button_set_icon_name (btt_XOR_EXEC_EDIT, "system-run-symbolic"); // https://thenounproject.com/icon/train-134324/
gtk_button_set_icon_name (btt_XOR_EXEC_EDIT, "process-stop-symbolic");
gtk_button_set_icon_name (btt_XOR_EXEC_EDIT, "power-profile-balanced-rtl-symbolic");
g_signal_connect (btt_XOR_EXEC_EDIT, "clicked", G_CALLBACK (on_toggle_EXEC_EDIT), btt_MODEL_RUN_STOP);
g_signal_connect (btt_XOR_EXEC_EDIT, "clicked", G_CALLBACK (on_toggle_EXEC_EDIT), get_window_child_STATE()); // btt_MODEL_RUN_STOP);
GtkWidget *any_Label = GTK_WIDGET (gtk_label_new (" | "));
@ -207,7 +207,7 @@ void window_header_bar (GtkWindow *window, char *title){
gtk_check_button_set_group (GTK_CHECK_BUTTON (btt_open_DATA), group_STATE_RULES_DATA);
gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), GTK_WIDGET (btt_XOR_EXEC_EDIT));
gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), GTK_WIDGET (btt_MODEL_RUN_STOP)); // << pas ici ! TODO
// gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), GTK_WIDGET (btt_MODEL_RUN_STOP)); // << pas ici ! TODO
gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), GTK_WIDGET (any_Label));
gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), GTK_WIDGET (btt_open_STATE));
gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), GTK_WIDGET (btt_open_RULES));
@ -238,76 +238,6 @@ void main_window_design (GtkWindow *main_window){
static void icons_for_fun (GtkHeaderBar *header_bar)
{
GtkButton *go_home = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (go_home, "go-home-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (go_home));
GtkButton *user_trash = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (user_trash, "user-trash-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (user_trash));
GtkButton *help_biblio = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (help_biblio, "accessories-dictionary-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (help_biblio));
GtkButton *help_doc = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (help_doc, "emblem-documents-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (help_doc));
GtkButton *help_about = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (help_about, "help-about-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (help_about));
GtkButton *help_faq = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (help_faq, "help-faq-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (help_faq));
GtkButton *terminal = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (terminal, "utilities-terminal-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (terminal));
GtkButton *search = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (search, "folder-saved-search-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (search));
GtkButton *preferences_desktop_appearance = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (preferences_desktop_appearance, "preferences-desktop-appearance-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (preferences_desktop_appearance));
GtkButton *preferences_system = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (preferences_system, "preferences-system-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (preferences_system));
GtkButton *document_properties = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (document_properties, "document-properties-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (document_properties));
GtkButton *text_edit = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (text_edit, "text-editor-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (text_edit));
GtkButton *applications_utilities = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (applications_utilities, "applications-utilities-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (applications_utilities));
GtkButton *open_menu = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (open_menu, "open-menu-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (open_menu));
GtkButton *power_max = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (power_max, "power-profile-performance-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (power_max));
GtkButton *power_middle = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (power_middle, "power-profile-balanced-rtl-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (power_middle));
GtkButton *power_low = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (power_low, "power-profile-power-saver-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (power_low));
}
GtkWidget *get_window_child_STATE() {
GtkBox *page_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2));
@ -315,8 +245,7 @@ GtkWidget *get_window_child_STATE() {
gtk_box_append (page_box, GTK_WIDGET (gtk_separator_new (GTK_ORIENTATION_HORIZONTAL)));
gtk_box_append (page_box, GTK_WIDGET (get_SPACE_VIEW_box()));
gtk_box_append (page_box, GTK_WIDGET (gtk_separator_new (GTK_ORIENTATION_HORIZONTAL)));
if (!get_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()));
gtk_box_append (page_box, GTK_WIDGET (get_TIME_EXEC_controls_box()));
//SWITCH_TO (STATE);
return GTK_WIDGET (page_box);
}
@ -432,3 +361,74 @@ GtkWidget *get_window_child_DATA (){
return GTK_WIDGET (data_box);
}
static void icons_for_fun (GtkHeaderBar *header_bar)
{
GtkButton *go_home = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (go_home, "go-home-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (go_home));
GtkButton *user_trash = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (user_trash, "user-trash-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (user_trash));
GtkButton *help_biblio = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (help_biblio, "accessories-dictionary-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (help_biblio));
GtkButton *help_doc = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (help_doc, "emblem-documents-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (help_doc));
GtkButton *help_about = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (help_about, "help-about-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (help_about));
GtkButton *help_faq = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (help_faq, "help-faq-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (help_faq));
GtkButton *terminal = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (terminal, "utilities-terminal-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (terminal));
GtkButton *search = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (search, "folder-saved-search-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (search));
GtkButton *preferences_desktop_appearance = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (preferences_desktop_appearance, "preferences-desktop-appearance-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (preferences_desktop_appearance));
GtkButton *preferences_system = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (preferences_system, "preferences-system-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (preferences_system));
GtkButton *document_properties = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (document_properties, "document-properties-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (document_properties));
GtkButton *text_edit = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (text_edit, "text-editor-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (text_edit));
GtkButton *applications_utilities = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (applications_utilities, "applications-utilities-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (applications_utilities));
GtkButton *open_menu = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (open_menu, "open-menu-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (open_menu));
GtkButton *power_max = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (power_max, "power-profile-performance-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (power_max));
GtkButton *power_middle = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (power_middle, "power-profile-balanced-rtl-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (power_middle));
GtkButton *power_low = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (power_low, "power-profile-power-saver-symbolic");
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (power_low));
}

View File

@ -37,6 +37,8 @@ GtkFrame *get_frame_with_label();
void window_main_child_bottom (GtkBox *page_box);
//void window_main_child (GtkWindow *main_window, int selected_page);
void set_check_button_active (GtkButton *button, int active);
GtkWidget *get_TIME_EXEC_controls_box();
GtkWidget *get_SPACE_EDIT_controls_box();
GtkButton *get_GtkButton (char *btt_name);
GtkWidget *get_window_child_STATE();
GtkWidget *get_window_child_RULES();