diff --git a/include/widget.h b/include/widget.h index 9f1ba39..1e96beb 100644 --- a/include/widget.h +++ b/include/widget.h @@ -95,6 +95,11 @@ typedef struct { int top; } Stack; +int tuto_stack(); + +Stack get_stack(); +void set_stack (Stack *stack_new); + void initialize(Stack *stack); bool isEmpty(Stack *stack); bool isFull(Stack *stack); diff --git a/src/widget/labo.c b/src/widget/labo.c index 6448fae..7e40a45 100644 --- a/src/widget/labo.c +++ b/src/widget/labo.c @@ -117,37 +117,43 @@ void widget_let_us_create_a_complex_useless_and_expensive_tree (struct TreeNode_ struct TreeNode_t *cc = widget_create_user_tree_node("access"); widget_add_child_node(c, cc); } -#define W_IMAGE_ABSURD 1920 / 32 // 1920 x 960 ad hoc (pour mon écran) -#define H_IMAGE_ABSURD 960 -void *get_an_impression_of_what_a_rules_comparator_could_be(){ - GtkBox *compare_left = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2)); - gtk_widget_set_size_request (GTK_WIDGET (compare_left), W_IMAGE_ABSURD, H_IMAGE_ABSURD); - Stack stack; - // Initialize the stack - initialize(&stack); - // Push elements onto the stack and print the stack after each push - push(&stack, GTK_WIDGET (gtk_picture_new_for_filename + + + + + + + + + + + + + + + + +/* gtk_box_append (compare_left, peek(&stack)); +// gtk_box_append (compare_right, peek(&stack)); + + + + gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename ("/home/jean/Gem-Graph/gem-graph-client/data/image/AMP.png"))); - //printf("Top element: %p\n", peek(&stack)); - push(&stack, GTK_WIDGET (gtk_picture_new_for_filename - ("/home/jean/Gem-Graph/gem-graph-client/data/image/glutamate.png"))); - //printf("Top element: %p\n", peek(&stack)); - push(&stack, GTK_WIDGET (gtk_picture_new_for_filename + + gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename ("/home/jean/Gem-Graph/gem-graph-client/data/image/glutamine.png"))); - //printf("Top element: %p\n", peek(&stack)); - gtk_box_append (compare_left, peek(&stack)); - gtk_box_append (compare_left, peek(&stack)); - gtk_box_append (compare_left, peek(&stack)); - - gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename - ("/home/jean/Gem-Graph/gem-graph-client/data/image/AMP.png"))); - gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename + gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename ("/home/jean/Gem-Graph/gem-graph-client/data/image/glutamate.png"))); + + + + gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename ("/home/jean/Gem-Graph/gem-graph-client/data/image/glutamine.png"))); gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename @@ -189,9 +195,6 @@ void *get_an_impression_of_what_a_rules_comparator_could_be(){ gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename ("/home/jean/Gem-Graph/gem-graph-client/data/image/hb.png"))); - GtkBox *compare_right = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2)); - gtk_widget_set_size_request (GTK_WIDGET (compare_right), W_IMAGE_ABSURD, H_IMAGE_ABSURD); - gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename ("/home/jean/Gem-Graph/gem-graph-client/data/image/ADP.png"))); gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename @@ -235,11 +238,8 @@ void *get_an_impression_of_what_a_rules_comparator_could_be(){ gtk_box_append (compare_right, GTK_WIDGET (gtk_picture_new_for_filename ("/home/jean/Gem-Graph/gem-graph-client/data/image/hb.png"))); - GtkBox *comparator = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2)); - gtk_box_append (comparator, GTK_WIDGET (compare_left)); - gtk_box_append (comparator, GTK_WIDGET (compare_right)); -/* + GtkScrolledWindow *comparator = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new ()); GtkBox *inside = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2)); gtk_box_append (inside, GTK_WIDGET (compare_left)); @@ -247,9 +247,6 @@ void *get_an_impression_of_what_a_rules_comparator_could_be(){ gtk_scrolled_window_set_child (comparator, GTK_WIDGET (inside)); */ - return comparator; -} - /* "rule effect" diff --git a/src/widget/rules/tree_tools/compare.c b/src/widget/rules/tree_tools/compare.c index 902c5fd..2f88f5c 100644 --- a/src/widget/rules/tree_tools/compare.c +++ b/src/widget/rules/tree_tools/compare.c @@ -39,6 +39,9 @@ Stack stack; +Stack get_stack() {return stack;} +void set_stack (Stack *stack_new) {stack = *stack_new;} + // https://www.geeksforgeeks.org/implement-stack-in-c/ void *trying_to_fill_the_rules_comparator_from_stack(){ @@ -50,8 +53,8 @@ void *trying_to_fill_the_rules_comparator_from_stack(){ // gtk_widget_set_size_request (GTK_WIDGET (compare_right), W_IMAGE_ABSURD, H_IMAGE_ABSURD); // while (!isEmpty(&stack)) { - for (int i = 0; i < MAX_SIZE; i++) - gtk_box_append (compare_left, GTK_WIDGET (peek(&stack))); + for (int i = 0; i < MAX_SIZE; i++) ; + // gtk_box_append (compare_left, GTK_WIDGET (pop(&stack))); // gtk_box_append (compare_right, GTK_WIDGET (pop(&stack))); //} @@ -59,11 +62,54 @@ void *trying_to_fill_the_rules_comparator_from_stack(){ GtkBox *inside = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2)); gtk_box_append (inside, GTK_WIDGET (compare_left)); // gtk_box_append (inside, GTK_WIDGET (compare_right)); - gtk_scrolled_window_set_child (comparator, GTK_WIDGET (inside)); +// gtk_scrolled_window_set_child (comparator, GTK_WIDGET (inside)); return comparator; } + +#define W_IMAGE_ABSURD 1920 / 32 // 1920 x 960 ad hoc (pour mon écran) +#define H_IMAGE_ABSURD 960 + +void *get_an_impression_of_what_a_rules_comparator_could_be(){ + + GtkBox *compare_left = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2)); + gtk_widget_set_size_request (GTK_WIDGET (compare_left), W_IMAGE_ABSURD, H_IMAGE_ABSURD); + + GtkBox *compare_right = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2)); + gtk_widget_set_size_request (GTK_WIDGET (compare_right), W_IMAGE_ABSURD, H_IMAGE_ABSURD); + + Stack stack;// = get_stack(); + // Initialize the stack + initialize(&stack); + + push_images_onto_stack (stack); + // set_stack (stack); + + + // Push elements onto the stack and print the stack after each push + push(&stack, GTK_WIDGET (gtk_picture_new_for_filename + ("/home/jean/Gem-Graph/gem-graph-client/data/image/ATP.png"))); + push(&stack, GTK_WIDGET (gtk_picture_new_for_filename + ("/home/jean/Gem-Graph/gem-graph-client/data/image/ADP.png"))); + push(&stack, GTK_WIDGET (gtk_picture_new_for_filename + ("/home/jean/Gem-Graph/gem-graph-client/data/image/AMP.png"))); + //printf("Top element: %p\n", peek(&stack));q + + gtk_box_append (compare_left, pop(&stack)); + gtk_box_append (compare_left, pop(&stack)); + gtk_box_append (compare_left, pop(&stack)); +// gtk_box_append (compare_left, pop(&stack)); + + GtkBox *comparator = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2)); + gtk_box_append (comparator, GTK_WIDGET (compare_left)); + gtk_box_append (comparator, GTK_WIDGET (compare_right)); + + printf(" compare.c get_an_impression_of...()\n"); + return comparator; +} + + // structure for the stack is in widget.h (^c^v...) void initialize (Stack *stack) { stack->top = -1; } bool isEmpty (Stack *stack) { return stack->top == -1; } @@ -92,7 +138,7 @@ GtkWidget *pop (Stack *stack) { GtkWidget *popped = stack->arr[stack->top]; // decrement top pointer stack->top--; - printf("Popped %p from the stack ", popped); + printf("Popped %p from the stack %2d ", popped, stack->top); // return the popped element return popped; } @@ -108,13 +154,30 @@ GtkWidget *peek(Stack *stack) { } + +int tuto_stack() { +/* + Stack stack; + initialize(&stack); + push(&stack, GTK_WIDGET (gtk_label_new ("222"))); + printf("Top element: %d\n", gtk_label_get_label (GTK_LABEL (peek(&stack)))); + push(&stack, GTK_WIDGET (gtk_label_new ("111"))); printf("Top element: %d\n", peek(&stack)); + push(&stack, GTK_WIDGET (gtk_label_new ("000"))); printf("Top element: %d\n", peek(&stack)); + while (!isEmpty(&stack)) { + printf("Top element: %d ", peek(&stack)); + printf("Popped element: %d\n", gtk_label_get_label (GTK_LABEL (pop(&stack)))); + } +*/ + return 0; +} + void *push_images_onto_stack (Stack stack) { clock_t start, end; - start = clock(); printf("compare.c push_images_onto_stack() Init images stack\nStart filling stack >> "); - initialize(&stack); +// initialize(&stack); + start = clock(); push(&stack, GTK_WIDGET (gtk_picture_new_for_filename ("/home/jean/Gem-Graph/gem-graph-client/data/image/AMP.png"))); @@ -163,17 +226,19 @@ void *push_images_onto_stack (Stack stack) end = clock(); long double t = (long double)(end - start) / CLOCKS_PER_SEC; - printf(" << stack filled in time : %Lg\n", t); + printf(" << stack filled in %9Lg sec\n", t); // Pop elements from the stack and print the stack after each pop -/* while (!isEmpty(&stack)) { - printf("Top element: %p\n", peek(&stack)); - printf("Popped element: %p\n", pop(&stack)); - }*/ - + /* + while (!isEmpty(&stack)) printf("Popped element: %p\n", pop(&stack)); + * ... + Popped 0xf5e03b0 from the stack 0 Popped element: 0xf5e03b0 + Popped 0xf5bf500 from the stack -1 Popped element: 0xf5bf500 + make: *** [Makefile:70: run] Erreur de segmentation + */ return 0; } diff --git a/src/widget/rules/tree_tools/pilot_box.c b/src/widget/rules/tree_tools/pilot_box.c index 2080d61..c4dcd57 100644 --- a/src/widget/rules/tree_tools/pilot_box.c +++ b/src/widget/rules/tree_tools/pilot_box.c @@ -52,7 +52,9 @@ void *widget_get_rules_tree_tools () GtkBox *rules_tree_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0)); gtk_box_append (rules_tree_box, GTK_WIDGET (widget_get_user_rules_tree())); gtk_box_append (rules_tree_box, GTK_WIDGET (widget_get_rules_use ())); - push_images_onto_stack (); +// push_images_onto_stack (); +// trying_to_fill_the_rules_comparator_from_stack(); +// tuto_stack (); gtk_box_append (rules_tree_box, GTK_WIDGET (get_an_impression_of_what_a_rules_comparator_could_be())); return GTK_WIDGET (rules_tree_box); }