Compare commits

..

1 Commits

15 changed files with 265 additions and 854 deletions

View File

@ -8,72 +8,115 @@
/* S T A T E S */
/******************************************************************************/
static int choice_EXEC_EDIT = EXEC;
static int choice_STATE_RULES_DATA = STATE;
/* (exec / edit)
* X
* (state / rules / data)
* X
* (measure / analyse / interpret)
* X
* (read / write)
*/
static int status = INTER; // int get_status () {return status;}
/******************************************************************************/
/* T R A N S I T I O N S */
/******************************************************************************/
static void debug_printing (int prescribed, int sub_automaton);
void set_EXEC_EDIT (int prescribed) {
if (choice_EXEC_EDIT != prescribed) {
debug_printing (prescribed, 0); // EXEC_EDIT is sub_automaton 0
choice_EXEC_EDIT = prescribed;
void SWITCH_TO (int asked) {
switch (asked) {
case (INTER) : // BEGIN_TO_EXEC_STOP
status = STATE; printf ("SWITCH_TO INTER\n");
break;
case (STATE) : // EXEC_STOP_TO_RUN
status = RULES; printf ("SWITCH_TO STATE\n");
break;
case (RULES) : // EXEC_RUN_TO_STOP
status = DATA; printf ("SWITCH_TO RULES\n");
break;
case (DATA) : // EXEC_TO_INTER
status = INTER; printf ("SWITCH_TO DATA\n");
break;
default : ;
}
//q gtk_window_present (GTK_WINDOW (main_window));
}
void set_STATE_RULES_DATA (int prescribed) {
if (choice_STATE_RULES_DATA != prescribed) {
debug_printing (prescribed, 1); // STATE_RULES_DATA is sub_automaton 1
choice_STATE_RULES_DATA = prescribed;
/*
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 : ;
}
}
/******************************************************************************/
/* G E T T E R S & D E B U G G E R S */
/******************************************************************************/
int get_EXEC_EDIT () {return choice_EXEC_EDIT;}
int get_STATE_RULES_DATA () {return choice_STATE_RULES_DATA;}
static char *get_str_EXEC_EDIT (int value) {
switch (value) {
case (EXEC) : return "EXEC";
case (EDIT) : return "EDIT";
default : printf("default in automaton.get_EXEC_EDIT ()\n"); return NULL;
}
}
static char *get_str_STATE_RULES_DATA (int value) {
switch (value) {
case (STATE) : return "STATE";
case (RULES) : return "RULES";
case (DATA) : return "DATA";
default : printf("default in automaton.get_STATE_RULES_DATA ()\n"); return NULL;
}
}
static void debug_printing (int prescribed, int sub_automaton) {
switch (sub_automaton) { // sub_automaton 0 is EXEC_EDIT and
// sub_automaton 1 is STATE_RULES_DATA
case (0) : printf("switch > %5s X %5s <> %5s X %5s\n",
get_str_EXEC_EDIT (choice_EXEC_EDIT),
get_str_STATE_RULES_DATA (choice_STATE_RULES_DATA),
get_str_EXEC_EDIT (prescribed),
get_str_STATE_RULES_DATA (choice_STATE_RULES_DATA));
break;
case (1) : printf("switch > %5s X %5s <> %5s X %5s\n",
get_str_EXEC_EDIT (choice_EXEC_EDIT),
get_str_STATE_RULES_DATA (choice_STATE_RULES_DATA),
get_str_EXEC_EDIT (choice_EXEC_EDIT),
get_str_STATE_RULES_DATA (prescribed));
break;
default : printf("default in automaton.debug_printing()\n");
}
}
} */

View File

@ -1,16 +1,9 @@
#include <gtk-4.0/gtk/gtk.h>
#include <assert.h>
enum choice_EXEC_EDIT { EXEC, EDIT };
enum choice_STATE_RULES_DATA { STATE, RULES, DATA };
// MEASURE, OBSERVE, INTERPRET, HELP, CONFIGURE }; ?
void set_status (int prescribed);
int get_status ();
void set_EXEC_EDIT (int prescribed);
void set_STATE_RULES_DATA (int prescribed);
int get_EXEC_EDIT ();
int get_STATE_RULES_DATA ();
// char *get_str_EXEC_EDIT (int value);
// char *get_str_STATE_RULES_DATA (int value);
enum choice { INTER, STATE, RULES, DATA };
void SWITCH_TO (int asked);

View File

@ -2,7 +2,6 @@
#include <gtk-4.0/gtk/gtk.h>
#include "callback.h"
#include "contain.h"
#include "tree.h"
#include "contain.h"
#include "dialog.h"
@ -80,14 +79,14 @@ gboolean on_glarea_render(GtkGLArea *area, GdkGLContext *context)
{
// Check if the widget is a glarea
if(gtk_gl_area_get_error(area) != NULL) {
on_auto_notification("An OpenGL error occured !");
////////////////////////// on_auto_notification("An OpenGL error occured !");
return false;
}
if (ui_render_stack(gtk_widget_get_parent(GTK_WIDGET(area))) == false) {
on_auto_notification("Failed to render corresponding graphic stack !");
return false;
}
////////////////////////// if (ui_render_stack(gtk_widget_get_parent(GTK_WIDGET(area))) == false) {
////////////////////////// on_auto_notification("Failed to render corresponding graphic stack !");
////////////////////////// return false;
////////////////////////// }
return true;
}
@ -163,53 +162,75 @@ void on_axis_value_change(GtkAdjustment *adjustment, gpointer data)
}
/******************************************************************************/
/* B U T T O N S */
/******************************************************************************/
void on_toggle_model_exec (GtkWidget *btt_run_stop_model_exec, gpointer data) {}
void on_toggle_observ_interpret (GtkWidget *btt_toggle_observ_interpret, gpointer data) {}
void on_toggle_exec_edit (GtkWidget *btt_exec_xor_edit, GtkWidget *btt_run_stop_model_exec) {
// 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);
}
void on_toggle_EXEC_EDIT (GtkWidget *toggled_button, gpointer user_data) {
if (get_EXEC_EDIT ()) {
gtk_button_set_icon_name (GTK_BUTTON (toggled_button), "power-profile-balanced-rtl-symbolic");
set_EXEC_EDIT (EXEC);
} else {
gtk_button_set_icon_name (GTK_BUTTON (toggled_button), "text-editor-symbolic");
set_EXEC_EDIT (EDIT);
void on_toggle_STATE_RULES_DATA (GtkButton *btt_toggle_STATE_RULES_DATA,
GtkButton *btt_toggle_STATE_DATA_RULES)
{
const char* current_label = gtk_button_get_label (GTK_BUTTON (btt_toggle_STATE_RULES_DATA));
if (0) printf ("callback.c (line 182) - current_label = %s\n", current_label);
if (! strcmp (current_label, "analyse")) {
gtk_button_set_label (btt_toggle_STATE_RULES_DATA, " state ");
gtk_button_set_label (GTK_BUTTON (btt_toggle_STATE_DATA_RULES), " state ");
window_main_child (main_window, 0);
}
switch (get_STATE_RULES_DATA()) {
case (STATE) : gtk_window_set_child (main_window, GTK_WIDGET (get_window_child_STATE())); break;
case (RULES) : gtk_window_set_child (main_window, GTK_WIDGET (get_window_child_RULES())); break;
case (DATA) : gtk_window_set_child (main_window, GTK_WIDGET (get_window_child_DATA())); break;
default : printf("default in callback.on_toggle_STATE_RULES_DATA()\n");
else if (! strcmp (current_label, " state ")) {
gtk_button_set_label (btt_toggle_STATE_RULES_DATA, " rules ");
gtk_button_set_label (GTK_BUTTON (btt_toggle_STATE_DATA_RULES), " rules ");
window_main_child (main_window, 1);
}
else {
gtk_button_set_label (btt_toggle_STATE_RULES_DATA, "analyse");
gtk_button_set_label (GTK_BUTTON (btt_toggle_STATE_DATA_RULES), "analyse");
window_main_child (main_window, 2);
}
}
void on_toggle_STATE_RULES_DATA (GtkWidget *toggled_button, gpointer user_data) {
void on_toggle_STATE_DATA_RULES (GtkButton *btt_toggle_STATE_RULES_DATA,
GtkButton *btt_toggle_STATE_DATA_RULES)
{
const char* current_label = gtk_button_get_label (GTK_BUTTON (btt_toggle_STATE_RULES_DATA));
if (0) printf ("callback.c (line 205) - current_label = %s\n", current_label);
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));
if (! strcmp (toggled_button_name, "state")) set_STATE_RULES_DATA (STATE);
if (! strcmp (toggled_button_name, "rules")) set_STATE_RULES_DATA (RULES);
if (! strcmp (toggled_button_name, "data analysis")) set_STATE_RULES_DATA (DATA);
if (is_active)
switch (get_STATE_RULES_DATA()) {
case (STATE) : gtk_window_set_child (main_window, GTK_WIDGET (get_window_child_STATE())); break;
case (RULES) : gtk_window_set_child (main_window, GTK_WIDGET (get_window_child_RULES())); break;
case (DATA) : gtk_window_set_child (main_window, GTK_WIDGET (get_window_child_DATA())); break;
default : printf("default in callback.on_toggle_STATE_RULES_DATA()\n");
}
if (! strcmp (current_label, "analyse")) {
gtk_button_set_label (btt_toggle_STATE_RULES_DATA, " state ");
gtk_button_set_label (btt_toggle_STATE_DATA_RULES, " state ");
window_main_child (main_window, 0);
}
else if (! strcmp (current_label, " rules ")) {
gtk_button_set_label (btt_toggle_STATE_RULES_DATA, "analyse");
gtk_button_set_label (btt_toggle_STATE_DATA_RULES, "analyse");
window_main_child (main_window, 1);
}
else {
gtk_button_set_label (btt_toggle_STATE_RULES_DATA, " rules ");
gtk_button_set_label (btt_toggle_STATE_DATA_RULES, " rules ");
window_main_child (main_window, 2);
}
}
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) {

View File

@ -14,14 +14,13 @@ void on_glarea_unrealize (GtkWidget *widget);
void on_axis_value_change (GtkAdjustment *adjustment, gpointer data);
void on_toggle_EXEC_EDIT (GtkWidget *btt_XOR_EXEC_EDIT, gpointer user_data);
void on_toggle_MODEL_RUN_STOP (GtkWidget *btt_MODEL_RUN_STOP, gpointer data);
void on_open_STATE (GtkWidget *btt_open_STATE, gpointer data);
void on_open_RULES (GtkWidget *btt_open_RULES, gpointer data);
void on_open_DATA (GtkWidget *btt_open_DATA, gpointer data);
void on_toggle_exec_edit (GtkWidget *btt_exec_xor_edit, GtkWidget *btt_run_stop_model_exec);
void on_toggle_model_exec (GtkWidget *btt_run_stop_model_exec, gpointer data);
void on_toggle_STATE_RULES_DATA (GtkButton *btt_toggle_STATE_RULES_DATA, GtkButton *btt_toggle_STATE_DATA_RULES);
void on_toggle_STATE_DATA_RULES (GtkButton *btt_toggle_STATE_DATA_RULES, GtkButton *btt_toggle_STATE_RULES_DATA);
void on_toggle_observ_interpret (GtkWidget *btt_toggle_observ_interpret, gpointer data);
void on_SAVE_CURRENT_MODEL_BEFORE_EDITING (GtkWidget *btt_SAVE_CURRENT_MODEL, gpointer data);
void on_DISCARD_CURRENT_MODEL_AND_START_EDITING (GtkWidget *btt_SAVE_CURRENT_MODEL, gpointer data);
void on_WRITE_CURRENT_MODEL (GtkWidget *btt_WRITE_CURRENT_MODEL, gpointer data);
void on_toggle_STATE_RULES_DATA (GtkWidget *btt, gpointer user_data);

224
contain.c
View File

@ -1,7 +1,6 @@
#include <stdio.h>
#include <gtk-4.0/gtk/gtk.h>
#include "graph_area.h"
#include "callback.h"
#include "automaton.h"
#include "display.h"
@ -135,8 +134,7 @@ GtkWidget *get_SPACE_VIEW_box(){
GtkBox *middle_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2));
gtk_box_append (middle_box, GTK_WIDGET (get_image_ALL_SPACE()));
// ui_setup_glarea (0, GTK_WIDGET (middle_box));
////////////////////////// gtk_box_append (middle_box, GTK_WIDGET (get_GLArea()));
gtk_box_append (middle_box, GTK_WIDGET (gtk_separator_new (GTK_ORIENTATION_VERTICAL)));
gtk_box_append (middle_box, GTK_WIDGET (right_box));
return GTK_WIDGET (middle_box);
@ -149,71 +147,81 @@ GtkWidget *get_SPACE_EDIT_controls_box() {
}
void window_main_child_bottom (GtkBox *page_box){
// gtk_box_append (page_box, GTK_WIDGET (get_TIME_EXEC_controls_box()));
// gtk_box_append (page_box, GTK_WIDGET (get_SPACE_EDIT_controls_box()));
}
static void icons_for_fun (GtkHeaderBar *header_bar);
static GtkButton *btt_open_STATE;
static GtkButton *btt_open_RULES;
static GtkButton *btt_open_DATA;
GtkButton *get_GtkButton (char *btt_name) {
if (strcmp (btt_name, "state")) return btt_open_STATE;
if (strcmp (btt_name, "rules")) return btt_open_RULES;
if (strcmp (btt_name, "data analysis")) return btt_open_DATA;
return NULL;
}
void set_check_button_active (GtkButton *button, int active){
const char *lab = gtk_button_get_label (button);
if (strcmp (lab, "state")) printf("set_check_button_active > %s\n", lab);
}
void window_header_bar (GtkWindow *window, char *title){
GtkWidget *header_bar = GTK_WIDGET (gtk_header_bar_new ());
gtk_header_bar_set_title_widget (GTK_HEADER_BAR (header_bar), gtk_label_new (title));
gtk_window_set_titlebar (window, header_bar);
// GtkWidget my_window_controls = *gtk_window_controls_new (GTK_PACK_END); // _START
// gtk_window_controls_set_decoration_layout (GTK_WINDOW_CONTROLS(my_window_controls), NULL); // const char* layout);
gpointer no_local_data = NULL;
GtkButton *btt_XOR_EXEC_EDIT = GTK_BUTTON (gtk_toggle_button_new ());
gtk_button_set_icon_name (btt_XOR_EXEC_EDIT, "system-run-symbolic");
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), no_local_data);
GtkButton *exec_xor_edit = GTK_BUTTON (gtk_toggle_button_new ());
gtk_button_set_icon_name (exec_xor_edit, "system-run-symbolic");
gtk_button_set_icon_name (exec_xor_edit, "power-profile-balanced-rtl-symbolic");
// g_signal_connect (exec_xor_edit, "clicked", G_CALLBACK (on_toggle_exec_edit), run_stop_model_exec);
GtkWidget *any_Label = GTK_WIDGET (gtk_label_new (" | "));
// GtkWidget* separe = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
// gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), GTK_WIDGET (separe));
GtkCheckButton *group_STATE_RULES_DATA = GTK_CHECK_BUTTON (gtk_check_button_new ());
GtkWidget *any_Label = GTK_WIDGET (gtk_label_new ("------------"));
btt_open_STATE = GTK_BUTTON (gtk_check_button_new_with_label ("state"));
g_signal_connect (btt_open_STATE, "toggled", G_CALLBACK (on_toggle_STATE_RULES_DATA), no_local_data);
gtk_check_button_set_group (GTK_CHECK_BUTTON (btt_open_STATE), group_STATE_RULES_DATA);
GtkButton *run_stop_model_exec = GTK_BUTTON (gtk_button_new_with_label (" run "));
g_signal_connect (run_stop_model_exec, "clicked", G_CALLBACK (on_toggle_model_exec), no_local_data);
btt_open_RULES = GTK_BUTTON (gtk_check_button_new_with_label ("rules"));
g_signal_connect (btt_open_RULES, "toggled", G_CALLBACK (on_toggle_STATE_RULES_DATA), no_local_data);
gtk_check_button_set_group (GTK_CHECK_BUTTON (btt_open_RULES), group_STATE_RULES_DATA);
GtkButton *btt_toggle_STATE_RULES_DATA = GTK_BUTTON (gtk_button_new_with_label (" state "));
GtkButton *btt_toggle_STATE_DATA_RULES = GTK_BUTTON (gtk_button_new_with_label (" state "));
g_signal_connect (btt_toggle_STATE_RULES_DATA, "clicked", G_CALLBACK (on_toggle_STATE_RULES_DATA), btt_toggle_STATE_DATA_RULES);
g_signal_connect (btt_toggle_STATE_RULES_DATA, "clicked", G_CALLBACK (on_toggle_STATE_DATA_RULES), btt_toggle_STATE_RULES_DATA);
btt_open_DATA = GTK_BUTTON (gtk_check_button_new_with_label ("data analysis"));
g_signal_connect (btt_open_DATA, "toggled", G_CALLBACK (on_toggle_STATE_RULES_DATA), no_local_data);
gtk_check_button_set_group (GTK_CHECK_BUTTON (btt_open_DATA), group_STATE_RULES_DATA);
// GtkButton *observ_interpret = GTK_BUTTON (gtk_button_new_with_label ("data analysis"));
// g_signal_connect (observ_interpret, "clicked", G_CALLBACK (on_toggle_observ_interpret), no_local_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 (exec_xor_edit));
gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), GTK_WIDGET (run_stop_model_exec));
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));
gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), GTK_WIDGET (btt_open_DATA));
gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), GTK_WIDGET (btt_toggle_STATE_RULES_DATA));
gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), GTK_WIDGET (btt_toggle_STATE_DATA_RULES));
// gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), GTK_WIDGET (observ_interpret));
icons_for_fun (GTK_HEADER_BAR (header_bar)); // https://iconduck.com/sets/adwaita-icon-theme
// https://iconduck.com/sets/carbon-icons < pas mal ...
// https://thenounproject.com/icon/train-134324/
// ma préférée : Transport Steam Engine Icon mais : [ process icon ] semble un bon choix...
}
void window_main_child (GtkWindow *main_window, int selected_page){
// in_depth.c : enum { STATE, RULES, MEASURE, OBSERVE, INTERPRET, HELP, CONFIGURE };
switch (selected_page) {
case (0) : // STATE
GtkBox *page_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2));
gtk_box_append (page_box, GTK_WIDGET (get_OBJECTS_and_SITUATIONS()));
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)));
window_main_child_bottom (page_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;
case (2) : gtk_window_set_child (main_window, GTK_WIDGET (get_measures_page_new())); break;
case (3) : gtk_window_set_child (main_window, GTK_WIDGET (get_results_page_new())); break;
case (4) : gtk_window_set_child (main_window, GTK_WIDGET (get_discuss_page_new())); break;
case (5) : gtk_window_set_child (main_window, GTK_WIDGET (get_help_page_new())); break;
default : gtk_window_set_child (main_window, GTK_WIDGET (get_SPACE_VIEW_box())); // + un "help message"
}
}
void main_window_design (GtkWindow *main_window){
window_main_child (main_window, 0); // 0 is the state page
window_header_bar (main_window,
"E coli (with permission from David S. Goodsell, 2009)");
gtk_check_button_set_active (GTK_CHECK_BUTTON (btt_open_STATE), TRUE);
gtk_window_present (GTK_WINDOW (main_window));
}
@ -228,131 +236,6 @@ void main_window_design (GtkWindow *main_window){
GtkWidget *get_window_child_STATE() {
if (0) printf("contain.get_window_child_STATE (line 235)\n");
GtkBox *page_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2));
gtk_box_append (page_box, GTK_WIDGET (get_OBJECTS_and_SITUATIONS()));
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_EXEC_EDIT ()) gtk_box_append (page_box, GTK_WIDGET (get_SPACE_EDIT_controls_box()));
else gtk_box_append (page_box, GTK_WIDGET (get_TIME_EXEC_controls_box()));
return GTK_WIDGET (page_box);
}
GtkWidget *get_window_child_RULES(){
if (0) printf("contain.get_window_child_RULES (line 246)\n");
GtkPaned *H_tree_vs_selected = GTK_PANED (gtk_paned_new (GTK_ORIENTATION_HORIZONTAL));
// GtkWidget *arbre_des_règles = gtk_frame_new ("Arbre des règles");
// GtkWidget *édition_de_la_règle_sélectionnée_n_1 = gtk_frame_new ("Inspection");
gtk_paned_set_start_child (H_tree_vs_selected, GTK_WIDGET (get_rules_tree_hpaned_new()));
gtk_paned_set_end_child (H_tree_vs_selected, GTK_WIDGET (get_selected_rules_vpaned_new()));
gtk_paned_set_position (H_tree_vs_selected, 400); // WARNING : c'est une position "absolue"
gtk_paned_set_wide_handle (H_tree_vs_selected, TRUE);
return GTK_WIDGET (H_tree_vs_selected);
}
GtkWidget *get_window_child_DATA (){
if (0) printf("contain.get_window_child_DATA (line 259)\n");
GtkBox *data_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 32));
GtkWidget* frame_rule_effect = gtk_frame_new ("rule effect\n-----------");
gtk_frame_set_label_align (GTK_FRAME (frame_rule_effect), 0.5);
GtkBox *rule_effect_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 8));
gtk_frame_set_child (GTK_FRAME (frame_rule_effect), GTK_WIDGET (rule_effect_box));
GtkWidget* frame_rule_topic = gtk_frame_new ("rule topic\n----------");
gtk_frame_set_label_align (GTK_FRAME (frame_rule_topic), 0.5);
GtkBox *rule_topic_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 8));
gtk_frame_set_child (GTK_FRAME (frame_rule_topic), GTK_WIDGET (rule_topic_box));
GtkWidget* frame_data_type = gtk_frame_new ("data type\n----------");
gtk_frame_set_label_align (GTK_FRAME (frame_data_type), 0.5);
GtkBox *data_type_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 8));
gtk_frame_set_child (GTK_FRAME (frame_data_type), GTK_WIDGET (data_type_box));
GtkWidget* frame_interpretations = gtk_frame_new ("interpretation\n---------------");
gtk_frame_set_label_align (GTK_FRAME (frame_interpretations), 0.5);
GtkBox *interpretations_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 8));
gtk_frame_set_child (GTK_FRAME (frame_interpretations), GTK_WIDGET (interpretations_box));
GtkWidget* frame_discussions = gtk_frame_new ("discussion\n------------");
gtk_frame_set_label_align (GTK_FRAME (frame_discussions), 0.5);
GtkBox *discussions_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 8));
gtk_frame_set_child (GTK_FRAME (frame_discussions), GTK_WIDGET (discussions_box));
GtkWidget* frame_separator = gtk_frame_new ("\n");
GtkWidget* frame_game = gtk_frame_new ("game\n------");
gtk_frame_set_label_align (GTK_FRAME (frame_game), 0.5);
GtkBox *game_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 8));
gtk_frame_set_child (GTK_FRAME (frame_game), GTK_WIDGET (game_box));
GtkWidget* frame_help = gtk_frame_new ("help\n-----");
gtk_frame_set_label_align (GTK_FRAME (frame_help), 0.5);
GtkBox *help_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 8));
gtk_frame_set_child (GTK_FRAME (frame_help), GTK_WIDGET (help_box));
gtk_box_append (data_box, GTK_WIDGET (frame_rule_effect));
gtk_box_append (data_box, GTK_WIDGET (frame_rule_topic));
gtk_box_append (data_box, GTK_WIDGET (frame_data_type));
gtk_box_append (data_box, GTK_WIDGET (frame_interpretations));
gtk_box_append (data_box, GTK_WIDGET (frame_discussions));
gtk_box_append (data_box, GTK_WIDGET (frame_separator));
gtk_box_append (data_box, GTK_WIDGET (frame_game));
gtk_box_append (data_box, GTK_WIDGET (frame_help));
gtk_box_append (rule_effect_box, gtk_button_new_with_label ("movement"));
gtk_box_append (rule_effect_box, gtk_button_new_with_label ("transport"));
gtk_box_append (rule_effect_box, gtk_button_new_with_label ("transformation"));
gtk_box_append (rule_topic_box, gtk_button_new_with_label ("objects"));
gtk_box_append (rule_topic_box, gtk_button_new_with_label ("situations"));
gtk_box_append (rule_topic_box, GTK_WIDGET (gtk_separator_new (GTK_ORIENTATION_HORIZONTAL)));
gtk_box_append (rule_topic_box, GTK_WIDGET (gtk_separator_new (GTK_ORIENTATION_HORIZONTAL)));
gtk_box_append (rule_topic_box, gtk_button_new_with_label ("accuracy"));
gtk_box_append (rule_topic_box, gtk_button_new_with_label ("pattern recognition"));
gtk_box_append (data_type_box, gtk_button_new_with_label ("repartitions"));
gtk_box_append (data_type_box, gtk_button_new_with_label ("evolutions"));
gtk_box_append (data_type_box, gtk_button_new_with_label ("correlations"));
gtk_box_append (interpretations_box, gtk_button_new_with_label ("stochastic"));
gtk_box_append (interpretations_box, gtk_button_new_with_label ("deterministic"));
gtk_box_append (interpretations_box, GTK_WIDGET (gtk_separator_new (GTK_ORIENTATION_HORIZONTAL)));
gtk_box_append (interpretations_box, GTK_WIDGET (gtk_separator_new (GTK_ORIENTATION_HORIZONTAL)));
gtk_box_append (interpretations_box, gtk_button_new_with_label ("physical"));
gtk_box_append (interpretations_box, gtk_button_new_with_label ("chemical"));
gtk_box_append (interpretations_box, gtk_button_new_with_label ("biological"));
gtk_box_append (interpretations_box, gtk_button_new_with_label ("social"));
gtk_box_append (interpretations_box, GTK_WIDGET (gtk_separator_new (GTK_ORIENTATION_HORIZONTAL)));
gtk_box_append (discussions_box, gtk_button_new_with_label ("context"));
gtk_box_append (discussions_box, gtk_button_new_with_label ("methodology"));
gtk_box_append (discussions_box, gtk_button_new_with_label ("comparisons"));
gtk_box_append (discussions_box, gtk_button_new_with_label ("to improve"));
gtk_box_append (discussions_box, gtk_button_new_with_label ("summary"));
gtk_box_append (game_box, gtk_button_new_with_label ("single player"));
gtk_box_append (game_box, gtk_button_new_with_label ("multiple players"));
gtk_box_append (game_box, gtk_button_new_with_label ("edition facilities"));
gtk_box_append (help_box, gtk_button_new_with_label ("modelization"));
gtk_box_append (help_box, gtk_button_new_with_label ("measurements"));
gtk_box_append (help_box, gtk_button_new_with_label ("results"));
gtk_box_append (help_box, gtk_button_new_with_label ("data analysis"));
gtk_box_append (help_box, GTK_WIDGET (gtk_separator_new (GTK_ORIENTATION_HORIZONTAL)));
gtk_box_append (help_box, GTK_WIDGET (gtk_separator_new (GTK_ORIENTATION_HORIZONTAL)));
gtk_box_append (help_box, gtk_button_new_with_label ("preferences"));
//SWITCH_TO (DATA);
return GTK_WIDGET (data_box);
}
static void icons_for_fun (GtkHeaderBar *header_bar)
{
GtkButton *go_home = GTK_BUTTON (gtk_button_new ());
@ -423,4 +306,3 @@ static void icons_for_fun (GtkHeaderBar *header_bar)
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

@ -31,14 +31,9 @@ G_END_DECLS
*/
void main_window_design (GtkWindow *main_window);
void set_check_button_active (GtkButton *button, int active);
void two_notebooks_in_two_panes (GtkWindow *window);
GtkFrame *get_frame_with_label();
GtkWidget *get_selected_rules_vpaned_new();
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();
GtkWidget *get_window_child_DATA();
GtkFrame *get_frame_with_label();
void window_main_child_bottom (GtkBox *page_box);
void window_main_child (GtkWindow *main_window, int selected_page);

View File

@ -21,7 +21,6 @@ GtkWidget *get_image_PHENYLALANINE();
GtkWidget *get_image_DOPAMINE();
GtkWidget *get_image_ATP();
GtkWidget *get_image_AMP();
GtkWidget *get_rules_tree_hpaned_new();
GtkProgressBar *get_ELAPSED_TIME_ProgressBar();
GtkBox *get_RUN_STOP_box();

View File

@ -151,9 +151,9 @@ void graphics_draw(const int stack_id)
{
struct graphic_stack_t *stack = &graphic_stack[stack_id];
g_printerr("[debug] graphics_draw() started\n");
//g_printerr("[debug] graphics_draw() started\n");
print_stack(stack_id);
//print_stack(stack_id);
GLint cur_viewport[4];
glGetIntegerv(GL_VIEWPORT, cur_viewport);
@ -166,9 +166,9 @@ void graphics_draw(const int stack_id)
mat4 v = GLM_MAT4_IDENTITY_INIT; // XXX define zoom and translations here ?
mat4 p = GLM_MAT4_IDENTITY_INIT;
glm_ortho(-1.0f, +1.0f, -1.0f, +1.0f, -1.0f, +1.0f, p);
//glm_ortho(-1.0f, +1.0f, -1.0f, +1.0f, -1.0f, +1.0f, p);
glm_ortho_default((float)cur_viewport[2] / (float)cur_viewport[3], p);
glm_perspective_default((float)cur_viewport[2] / (float)cur_viewport[3], p);
//glm_perspective_default((float)cur_viewport[2] / (float)cur_viewport[3], p);
/* Use our shaders */
glUseProgram(stack->program);
@ -191,7 +191,7 @@ void graphics_draw(const int stack_id)
glBindBuffer(GL_ARRAY_BUFFER, stack->color_buffer);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0,(void*)0);
glEnable(GL_DEPTH_TEST);
//glEnable(GL_DEPTH_TEST);
glDrawElements(GL_LINES, stack->buffer_lines_size, GL_UNSIGNED_INT, stack->buffer_lines_origin);
glDrawElements(GL_TRIANGLES, stack->buffer_plans_size, GL_UNSIGNED_INT, stack->buffer_plans_origin);
@ -203,5 +203,5 @@ void graphics_draw(const int stack_id)
glUseProgram(0);
glFlush();
g_printerr("[debug] graphics_draw() ended\n");
//g_printerr("[debug] graphics_draw() ended\n");
}

View File

@ -39,23 +39,6 @@ static struct stack_index_t *stack_index = NULL;
size_t stack_index_size = 0;
int set_arrow (int stack_id, // 2024-06-27 DEBUG !
int arrows_nb,
int space_X,
int space_Y,
int space_Z,
int requested_weight,
int site,
int arrow_x,
int arrow_y,
int arrow_z) {
printf("graph_area.c > int set_arrow (...) 2024-06-27 DEBUG\n");
return 0;
} // 2024-06-27 DEBUG !
/*
* Look for stack entry and returns stack_id
*
@ -101,19 +84,19 @@ long ui_is_graphic_stack_ready(void *container_widget)
*/
bool ui_init_graphic_stack(void *container_widget, GError *error_buffer)
{
g_printerr("[debug] ui_init_graphic_stack()\n");
//g_printerr("[debug] ui_init_graphic_stack()\n");
g_printerr("[debug] ui_init_graphic_stack() : target is %p\n", container_widget);
//g_printerr("[debug] ui_init_graphic_stack() : target is %p\n", container_widget);
// look for stack_index entry
for (int i = 0; i < stack_index_size; i++) {
g_printerr("[debug] ui_init_graphic_stack() : i is %d\n", i);
g_printerr("[debug] ui_init_graphic_stack() : target would be %p\n",
stack_index[i].container_widget);
//g_printerr("[debug] ui_init_graphic_stack() : i is %d\n", i);
//g_printerr("[debug] ui_init_graphic_stack() : target would be %p\n",
//stack_index[i].container_widget);
if (stack_index[i].container_widget == (void *)container_widget) {
stack_index[i].stack_id = graphics_init(&error_buffer);
g_printerr("[debug] ui_init_graphic_stack() : stack_id is %ld\n",
stack_index[i].stack_id);
//g_printerr("[debug] ui_init_graphic_stack() : stack_id is %d\n",
//stack_index[i].stack_id);
if (stack_index[i].stack_id >= 0)
return true;
else
@ -168,15 +151,13 @@ bool ui_render_stack(GtkWidget *container_widget)
// look for stack_index entry
for (int i = 0; i < stack_index_size; i++) {
if (stack_index[i].container_widget == (void *)container_widget) {
graphics_draw (stack_index[i].stack_id);
////////////////////////// graphics_draw (stack_index[i].stack_id);
return true;
}
}
return false;
}
//void graphics_draw(const int stack_id) {printf("graph_area.c > void graphics_draw(const int stack_id) (161)\n");}
/*
* Look for stack entry and triggers OpenGL for drawing
*
@ -273,11 +254,11 @@ bool ui_setup_glarea(int target_mode, GtkWidget *target_widget)
{
GtkWidget *gl_area;
g_printerr("[debug] ui_setup_glarea()\n");
////g_printerr("[debug] ui_setup_glarea()\n");
assert(target_widget);
g_printerr("[debug] ui_setup_glarea() : target is %p\n", target_widget);
////g_printerr("[debug] ui_setup_glarea() : target is %p\n", target_widget);
if (stack_index == NULL) {
stack_index = g_malloc(sizeof(struct stack_index_t));
@ -298,12 +279,12 @@ bool ui_setup_glarea(int target_mode, GtkWidget *target_widget)
gl_area = GTK_WIDGET(gtk_gl_area_new());
assert(gl_area);
gtk_widget_set_size_request(gl_area, 1000, 1000);
//gtk_widget_set_size_request(gl_area, 1000, 1000);
gtk_gl_area_set_auto_render(GTK_GL_AREA(gl_area), true);
gtk_widget_set_hexpand(gl_area, TRUE);
gtk_widget_set_vexpand(gl_area, TRUE);
gtk_widget_set_halign(gl_area, GTK_ALIGN_CENTER);
gtk_widget_set_valign(gl_area, GTK_ALIGN_CENTER);
//gtk_widget_set_halign(gl_area, GTK_ALIGN_CENTER);
//gtk_widget_set_valign(gl_area, GTK_ALIGN_CENTER);
// The main "draw" call for GtkGLArea
g_signal_connect(GTK_GL_AREA(gl_area), "render", G_CALLBACK(on_glarea_render), NULL);
@ -315,13 +296,13 @@ bool ui_setup_glarea(int target_mode, GtkWidget *target_widget)
stack_index[stack_index_size-1].gl_area = (void*)gl_area;
g_printerr("[debug] ui_setup_glarea() : set target to %p\n", target_widget);
////g_printerr("[debug] ui_setup_glarea() : set target to %p\n", target_widget);
g_printerr("[debug] ui_setup_glarea() : stack_index (@0x%p) had %ld elements\n",
stack_index,
stack_index_size);
////g_printerr("[debug] ui_setup_glarea() : stack_index (@0x%p) had %ld elements\n",
//stack_index,
//stack_index_size);
gtk_box_append (GTK_BOX (target_widget), gl_area);
gtk_box_append(GTK_BOX(target_widget), gl_area);
gtk_widget_set_visible (GTK_WIDGET (gl_area), TRUE);
// Create sliders

View File

@ -25,8 +25,6 @@
#pragma once
#include <unistd.h>
#include <gtk-4.0/gtk/gtk.h>
#include <glib-2.0/glib.h>
#include <stdbool.h>
#include <epoxy/gl.h>
#include <GL/glu.h>
@ -36,10 +34,8 @@
#include "base.h"
//#include "draw.c"
// #define VERTEX_SHADER_FILE "src/graphics/shaders/shader.vert"
// #define FRAG_SHADER_FILE "src/graphics/shaders/shader.frag"
#define VERTEX_SHADER_FILE "shader.vert"
#define FRAG_SHADER_FILE "shader.frag"
#define VERTEX_SHADER_FILE "src/graphics/shaders/shader.vert"
#define FRAG_SHADER_FILE "src/graphics/shaders/shader.frag"
#define GL_TARGET_MAJOR_VERSION 0
#define GL_TARGET_MINOR_VERSION 4
@ -81,10 +77,6 @@ struct graphic_stack_t {
long buffer_plans_0_arrow;
};
bool ui_render_stack(GtkWidget *container_widget);
bool ui_setup_glarea(int target_mode, GtkWidget *target_widget);
/*
* Dynamic array of ptrs to dynamically allocated gl_area_entry
*/

View File

@ -111,12 +111,12 @@ int graphics_init(void *error_buffer)
int cur_id = 0;
struct graphic_stack_t *stack;
g_printerr("[debug] graphics_init()\n");
/* g_printerr("[debug] graphics_init()\n"); */
if (graphic_stack == NULL) {
graphic_stack = g_malloc0(sizeof(struct graphic_stack_t));
graphic_stack_size = 1;
g_printerr("[debug] graphics_init(): init graphic_stack @ %p\n", graphic_stack);
/* g_printerr("[debug] graphics_init(): init graphic_stack @ %p\n", graphic_stack); */
} else {
// Check if there are free slots
if (free_stack_slot_size) {
@ -136,9 +136,9 @@ int graphics_init(void *error_buffer)
memset(&graphic_stack[cur_id], 0, sizeof(struct graphic_stack_t));
g_printerr("[debug] graphics_init() : graphic_stack (@0x%p) has %ld elements\n",
graphic_stack,
graphic_stack_size);
/* g_printerr("[debug] graphics_init() : graphic_stack (@0x%p) has %ld elements\n", */
/* graphic_stack, */
/* graphic_stack_size); */
stack = &graphic_stack[cur_id];
stack->id = cur_id;
@ -147,11 +147,11 @@ int graphics_init(void *error_buffer)
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glEnable(GL_MULTISAMPLE);
if (!graphics_init_shaders(cur_id)) return -1;
////////////////////////// if (!graphics_init_shaders(cur_id)) return -1;
print_stack(cur_id);
//print_stack(cur_id);
graphics_init_buffers(cur_id);
////////////////////////// graphics_init_buffers(cur_id);
glDebugMessageCallback(graphics_debug_callback, NULL);
@ -286,10 +286,10 @@ void graphics_model_setup (const int stack_id)
/*------------------------------------------------------------------------*/
draw_space_ridges_vertex (stack_id, stack->buffer_vertex_size, space_X, space_Y, space_Z);
draw_space_ridges_lines (stack_id);
draw_grids_on_space_faces_vertex (stack_id, space_X, space_Y, space_Z);
draw_grids_on_space_faces_lines (stack_id, stack->buffer_lines_size, space_X, space_Y, space_Z);
////////////////////////// draw_space_ridges_vertex (stack_id, stack->buffer_vertex_size, space_X, space_Y, space_Z);
////////////////////////// draw_space_ridges_lines (stack_id);
////////////////////////// draw_grids_on_space_faces_vertex (stack_id, space_X, space_Y, space_Z);
////////////////////////// draw_grids_on_space_faces_lines (stack_id, stack->buffer_lines_size, space_X, space_Y, space_Z);
stack->buffer_vertex_0_arrow = stack->buffer_vertex_size;
stack->buffer_colors_0_arrow = stack->buffer_colors_size;
@ -314,10 +314,10 @@ void graphics_model_setup (const int stack_id)
while (model_get_next_arrow(&arrow, (char *)&state_id, dimension)) {
g_print("[GRAPH DEBUG] cur arrow has x = %d\n", arrow.x);
stack->arrows_nb = set_arrow (stack_id, stack->arrows_nb, space_X, space_Y, space_Z, arrow.load, arrow.site, arrow.x, arrow.y, arrow.z);
////////////////////////// stack->arrows_nb = set_arrow (stack_id, stack->arrows_nb, space_X, space_Y, space_Z, arrow.load, arrow.site, arrow.x, arrow.y, arrow.z);
}
if (stack->arrows_nb != announced_arrows_nb)
g_printerr("ARGH : not all arrows have been parsed !\n");
g_printerr("ARGH : all the arrows have not been parsed !\n");
}

View File

@ -1,314 +0,0 @@
/*
* Gem-graph OpenGL experiments
*
* Desc: OpenGL utils header
*
* Copyright (C) 2023 Arthur Menges <arthur.menges@a-lec.org>
* Copyright (C) 2023 Adrien Bourmault <neox@a-lec.org>
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
*
* This file is part of Gem-graph.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "base.h"
#include <unistd.h>
#include <stdbool.h>
#include <epoxy/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
#include <cglm/cglm.h>
#define VERTEX_SHADER_FILE "src/graphics/shaders/shader.vert"
#define FRAG_SHADER_FILE "src/graphics/shaders/shader.frag"
#define GL_TARGET_MAJOR_VERSION 0
#define GL_TARGET_MINOR_VERSION 4
/*
* Structure describing a gl_area and its parameters, used to create a table
* of Gem-graph client current gl_areas
*/
struct graphic_stack_t {
int id;
int mode;
float rotation_angles[N_AXIS]; // Rotation angles on each axis
GLuint vao; // init_buffers
GLuint position_buffer; // shutdown, draw
GLuint color_buffer; // shutdown, draw
GLuint program; // shutdown, init_shaders, draw
GLuint m; // init_shaders, draw
GLuint v; // init_shaders, draw
GLuint p; // init_shaders, draw
struct arrow_t *arrows_ptr;
long arrows_nb;
GLfloat *buffer_vertex_origin;
GLfloat *buffer_colors_origin;
GLuint *buffer_lines_origin;
GLuint *buffer_plans_origin;
long buffer_vertex_size;
long buffer_colors_size;
long buffer_lines_size;
long buffer_plans_size;
long buffer_vertex_0_arrow;
long buffer_colors_0_arrow;
long buffer_lines_0_arrow;
long buffer_plans_0_arrow;
};
/*
* Dynamic array of ptrs to dynamically allocated gl_area_entry
*/
extern struct graphic_stack_t *graphic_stack;
/*
* Initializes a gl_area
*
* @param gl_area, ptr to the gl_area widget
*
* @return true if initialized
*/
int graphics_init(void *error_buffer);
/*
* Draws the current buffer to a gl_area
*
* @param gl_area, ptr to the gl_area widget
*
* @return void
*/
//void graphics_draw(const int stack_id);
/*
* Shutdowns a gl_area
*
* @param gl_area, ptr to the gl_area widget
*
* @return true if success
*/
bool graphics_shutdown(const int stack_id, void *error_buffer);
/*
* Initializes the shaders of a gl_area and link them to a program
*
* @param gl_area, ptr to the gl_area widget
*
* @return true if initialized
*/
bool graphics_init_shaders(const int stack_id);
/* Initializes the buffer of a gl_area
* Calls according to the user preferences
* @param gl_area, ptr to the gl_area widget
* @return void
*/
void graphics_init_buffers(const int stack_id);
/*
* Draws a vertex (x, y, z)
* if (console) prints (x, y, z) values to console
*
* @param GLfloat x, GLfloat y, GLfloat z
*
* @return void
*/
void graphics_draw_vertex (const int stack_id,
GLfloat x,
GLfloat y,
GLfloat z);
/*
* Draws the color (r, g, b) associated to a vertex
* if (console) prints (r, g, b) values to console
*
* @param GLfloat r, GLfloat g, GLfloat b
*
* @return void
*/
void graphics_draw_color (const int stack_id, GLfloat r, GLfloat g, GLfloat b);
/*
* Writes values to describe a line from a to b into the line buffer
*
* @param coords GLuint (a,b)
*
* @return void
*/
void graphics_draw_line (const int stack_id, GLuint a, GLuint b);
/*
* Writes values to describe an (a,b,c) plan (triangle) into the plan buffer
*
* @param coords GLuint (a,b,c)
*
* @return void
*/
void graphics_draw_plan (const int stack_id, GLuint a, GLuint b, GLuint c);
/*
* Created and compile a shader
*
* @param type, shader type
* src, source code of shader
*
* @return shader id
*/
static inline GLuint create_shader(const int stack_id, int type, const char *src)
{
GLuint shader;
int status;
shader = glCreateShader(type);
glShaderSource(shader, 1, &src, NULL);
glCompileShader(shader);
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
if(status == GL_FALSE) {
int log_len;
char *buffer;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_len);
buffer = g_malloc(log_len + 1);
assert (buffer);
glGetShaderInfoLog(shader, log_len, NULL, buffer);
g_warning("Compile failure in %s shader:\n%s",
type == GL_VERTEX_SHADER ? "vertex" : "fragment",
buffer);
g_free(buffer);
glDeleteShader(shader);
return 0;
}
return shader;
}
static inline void print_stack(int stack_id)
{
static int n = 0;
printf("\n[n=%d]***************", n);
printf("id = %d\tmode = %d\n",
graphic_stack[stack_id].id,
graphic_stack[stack_id].mode);
printf("rotation_angles = ");
for (int i = 0; i < N_AXIS; i++) {
printf("%f\t", graphic_stack[stack_id].rotation_angles[i]); // Rotation angles on each axis
}
printf("\n");
printf("vao = %d\n", graphic_stack[stack_id].vao);
printf("position_buffer = %d\n", graphic_stack[stack_id].position_buffer);
printf("color_buffer = %d\n", graphic_stack[stack_id].color_buffer);
printf("program = %d\n", graphic_stack[stack_id].program);
printf("m = %d\n", graphic_stack[stack_id].m);
printf("v = %d\n", graphic_stack[stack_id].v);
printf("p = %d\n", graphic_stack[stack_id].p);
printf("arrows_ptr = %p\n", graphic_stack[stack_id].arrows_ptr);
printf("arrows_nb = %ld\n", graphic_stack[stack_id].arrows_nb);
printf("buffer_vertex_origin = %p\n", graphic_stack[stack_id].buffer_vertex_origin);
printf("buffer_colors_origin = %p\n", graphic_stack[stack_id].buffer_colors_origin);
printf("buffer_lines_origin = %p\n", graphic_stack[stack_id].buffer_lines_origin);
printf("buffer_plans_origin = %p\n", graphic_stack[stack_id].buffer_plans_origin);
printf("buffer_vertex_size = %ld\n", graphic_stack[stack_id].buffer_vertex_size);
printf("buffer_colors_size = %ld\n", graphic_stack[stack_id].buffer_colors_size);
printf("buffer_lines_size = %ld\n", graphic_stack[stack_id].buffer_lines_size);
printf("buffer_plans_size = %ld\n", graphic_stack[stack_id].buffer_plans_size);
printf("buffer_vertex_0_arrow = %ld\n", graphic_stack[stack_id].buffer_vertex_0_arrow);
printf("buffer_colors_0_arrow = %ld\n", graphic_stack[stack_id].buffer_colors_0_arrow);
printf("buffer_lines_0_arrow = %ld\n", graphic_stack[stack_id].buffer_lines_0_arrow);
printf("buffer_plans_0_arrow = %ld\n", graphic_stack[stack_id].buffer_plans_0_arrow);
printf("********************\n");
n++;
}
void graphics_model_setup (const int stack_id);
int draw_one_arrow_vertex (const int stack_id,
int space_X,
int space_Y,
int space_Z,
int weight,
int site,
int x,
int y,
int z);
int draw_one_arrow_line(const int stack_id,
int offset_vertex);
/*
* Writes grid ridges to vertex and color buffers
*
* @param coords long (x,y,z), step_x, step_y, step_z
*
* @return void
*/
int draw_space_ridges_vertex (const int stack_id,
long offset_vertex,
long x,
long y,
long z);
int draw_space_ridges_lines (const int stack_id);
/*
* Writes grid lines on space faces
*
* @param coords long (x,y,z)
*
* @return void
*/
long draw_grids_on_space_faces_vertex (const int stack_id,
long x,
long y,
long z);
long draw_grids_on_space_faces_lines (const int stack_id,
long offset_vertex,
long x,
long y,
long z);
int set_arrow (int stack_id,
int arrows_nb,
int space_X,
int space_Y,
int space_Z,
int requested_weight,
int site,
int arrow_x,
int arrow_y,
int arrow_z);

162
grid.c
View File

@ -1,162 +0,0 @@
/*
* Gem-graph
*
* Desc: OpenGL grid functions
*
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
* Copyright (C) 2023 Adrien Bourmault <neox@a-lec.org>
*
* This file is part of Gem-graph.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <time.h>
#include "base.h"
//#include "ui.h"
#include "graphics.h"
int draw_space_ridges_vertex (const int stack_id,
long offset_vertex,
long x,
long y,
long z)
{
GLfloat max = fmax(x, y); max = fmax(max, z);
graphics_draw_vertex (stack_id, offset_vertex - x / max, offset_vertex - y / max, - z / max);
graphics_draw_vertex (stack_id, offset_vertex + x / max, offset_vertex - y / max, - z / max);
graphics_draw_vertex (stack_id, offset_vertex - x / max, offset_vertex + y / max, - z / max);
graphics_draw_vertex (stack_id, offset_vertex - x / max, offset_vertex - y / max, + z / max);
graphics_draw_vertex (stack_id, offset_vertex + x / max, offset_vertex + y / max, - z / max);
graphics_draw_vertex (stack_id, offset_vertex + x / max, offset_vertex - y / max, + z / max);
graphics_draw_vertex (stack_id, offset_vertex - x / max, offset_vertex + y / max, + z / max);
graphics_draw_vertex (stack_id, offset_vertex + x / max, + y / max, + z / max);
graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f);
graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f);
graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f);
graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f);
graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f);
graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f);
graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f);
graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f);
return 8;
}
int draw_space_ridges_lines (const int stack_id)
{
graphics_draw_line (stack_id, 0, 1); graphics_draw_line (stack_id, 7, 4);
graphics_draw_line (stack_id, 0, 2); graphics_draw_line (stack_id, 7, 5);
graphics_draw_line (stack_id, 0, 3); graphics_draw_line (stack_id, 7, 6);
graphics_draw_line (stack_id, 1, 4); graphics_draw_line (stack_id, 2, 4);
graphics_draw_line (stack_id, 1, 5); graphics_draw_line (stack_id, 3, 5);
graphics_draw_line (stack_id, 2, 6); graphics_draw_line (stack_id, 3, 6);
return 12;
}
long draw_grids_on_space_faces_vertex (const int stack_id,
long x,
long y,
long z)
{
float i, max = fmax(x, y); max = fmax(max, z);
for (i = 1; i < x; i++) {
graphics_draw_vertex (stack_id, (2 * i / x - 1) * x / max, - y / max, - z / max);
graphics_draw_vertex (stack_id, (2 * i / x - 1) * x / max, - y / max, z / max);
graphics_draw_vertex (stack_id, (2 * i / x - 1) * x / max, y / max, z / max);
graphics_draw_vertex (stack_id, (2 * i / x - 1) * x / max, y / max, - z / max);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
}
/* offset_vertex += (x - 1) * 4; */ /* offset_colors += (x - 1) * 4; */
for (i = 1; i < y; i++) {
graphics_draw_vertex (stack_id, - x / max, (2 * i / y - 1) * y / max, - z / max);
graphics_draw_vertex (stack_id, - x / max, (2 * i / y - 1) * y / max, z / max);
graphics_draw_vertex (stack_id, x / max, (2 * i / y - 1) * y / max, z / max);
graphics_draw_vertex (stack_id, x / max, (2 * i / y - 1) * y / max, - z / max);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
}
/* offset_vertex += (y - 1) * 4; */ /* offset_colors += (y - 1) * 4; */
for (i = 1; i < z; i++) {
graphics_draw_vertex (stack_id, - x / max, - y / max, (2 * i / z - 1) * z / max);
graphics_draw_vertex (stack_id, - x / max, y / max, (2 * i / z - 1) * z / max);
graphics_draw_vertex (stack_id, x / max, y / max, (2 * i / z - 1) * z / max);
graphics_draw_vertex (stack_id, x / max, - y / max, (2 * i / z - 1) * z / max);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
}
return (x + y + z - 3) * 3;
}
long draw_grids_on_space_faces_lines (const int stack_id,
long offset_vertex,
long x,
long y,
long z)
{
offset_vertex = offset_vertex / 3;
for (int i = 0; i < x - 1; i ++) {
graphics_draw_line (stack_id, offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2);
graphics_draw_line (stack_id, offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3);
}
offset_vertex += (x - 1) * 4;
for (int i = 0; i < y - 1; i ++) {
graphics_draw_line (stack_id, offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3);
graphics_draw_line (stack_id, offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0);
}
offset_vertex += (y - 1) * 4;
for (int i = 0; i < z - 1; i ++) {
graphics_draw_line (stack_id, offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1);
graphics_draw_line (stack_id, offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0);
}
return (x + y + z - 3) * 4;
}

20
init.c
View File

@ -119,28 +119,12 @@ bool graphics_init_shaders(const int stack_id)
// Link shaders to program
program = glCreateProgram();
printf("\n------------------------------------------------------------------------------------------\n");
printf("[debug] graphics_init_shaders() : program = %d, vertex = %d, fragment = %d\n\
exec > ** (myprogram:-----): WARNING ** : --:--:--:---: Linking failure: (address)\n",
program, vertex, fragment);
/* (myprogram:11732): WARNING **: 10:37:34.233: v plusieurs 'run' successifs
* (myprogram:11883): WARNING **: 10:38:22.979: glLinkProgram(program); < commenté
* (myprogram:11953): WARNING **: 10:38:46.170:
* (myprogram:12034): WARNING **: 10:39:14.709:
* (myprogram:12182): WARNING **: 10:40:49.788:
* > probablement la même adresse dans la librairie 'mesa' d'OpenGL (?) */
glAttachShader(program, vertex);
glAttachShader(program, fragment);
printf("Failed to link the graphic stack to widgets ! <> see init.c graphics_init_shaders()\n");
printf("the error in not : vertex shader lacks `main' but : failed to link... (comment line 140)\n");
// https://registry.khronos.org/OpenGL-Refpages/gl4/html/glLinkProgram.xhtml
// glLinkProgram(program); // Linking failure: (address)
printf("------------------------------------------------------------------------------------------\n");
glLinkProgram(program);
glGetProgramiv(program, GL_LINK_STATUS, &status); // Linking failure: (address)
glGetProgramiv(program, GL_LINK_STATUS, &status);
if(status == GL_FALSE) {
int log_len;

2
main.c
View File

@ -20,7 +20,5 @@ int main (int argc, char **argv)
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
printf("in contain.get_SPACE_VIEW_box() (line 138) > ui_setup_glarea (0, GTK_WIDGET (middle_box)); < commented 2024/06/27 > TODO\n");
return status;
}