WIP: use a stack to get images quickly. ^c^v and learn... something works...

This commit is contained in:
Jean Sirmai 2024-07-31 05:32:25 +02:00
parent c20715b3d4
commit d0c0525bd4
Signed by: jean
GPG Key ID: FB3115C340E057E3
7 changed files with 186 additions and 5 deletions

View File

@ -41,6 +41,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <time.h>
#include <glib-2.0/glib.h>
#include <gtk-4.0/gtk/gtk.h>

View File

@ -29,7 +29,6 @@
#pragma once
#include <stdio.h>
#include <stdbool.h>

View File

@ -86,6 +86,23 @@ int widget_get_object_transparency (int i); // top
/******************************************************************************/
// called in : src/widget/rules/distrib.c
// Define a structure for the stack
#define MAX_SIZE 22
typedef struct {
// Array to store stack elements
GtkWidget *arr[MAX_SIZE];
// Index of the top element in the stack
int top;
} Stack;
void initialize(Stack *stack);
bool isEmpty(Stack *stack);
bool isFull(Stack *stack);
void push(Stack *stack, GtkWidget *value);
GtkWidget *pop(Stack *stack);
GtkWidget *peek(Stack *stack);
void *push_images_onto_stack();
void *widget_get_selected_rule();
void *widget_get_rules_left_pane();
void *widget_get_rules_page();
@ -138,7 +155,8 @@ char *widget_get_text_address_any ();
// images in : data / image /
// used by : widget / rules.c
GtkBox *get_an_impression_of_what_a_rules_comparator_could_be();
void *get_an_impression_of_what_a_rules_comparator_could_be();
void *trying_to_fill_the_rules_comparator_from_stack();
/******************************************************************************/
/* L A B O */

View File

@ -120,11 +120,30 @@ void widget_let_us_create_a_complex_useless_and_expensive_tree (struct TreeNode_
#define W_IMAGE_ABSURD 1920 / 32 // 1920 x 960 ad hoc (pour mon écran)
#define H_IMAGE_ABSURD 960
GtkBox *get_an_impression_of_what_a_rules_comparator_could_be(){
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
("/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
("/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
@ -133,8 +152,10 @@ GtkBox *get_an_impression_of_what_a_rules_comparator_could_be(){
("/home/jean/Gem-Graph/gem-graph-client/data/image/glutamine.png")));
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/legumin.png")));
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/ATP.png")));
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/histidine.png")));
gtk_box_append (compare_left, GTK_WIDGET (gtk_picture_new_for_filename

View File

@ -34,3 +34,146 @@
// design a comparator (using 'before'/'after' stamps)
#define W_IMAGE_ABSURD 1920 / 32 // 1920 x 960 ad hoc (pour mon écran)
#define H_IMAGE_ABSURD 960
Stack stack;
// https://www.geeksforgeeks.org/implement-stack-in-c/
void *trying_to_fill_the_rules_comparator_from_stack(){
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);
// while (!isEmpty(&stack)) {
for (int i = 0; i < MAX_SIZE; i++)
gtk_box_append (compare_left, GTK_WIDGET (peek(&stack)));
// gtk_box_append (compare_right, GTK_WIDGET (pop(&stack)));
//}
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));
// gtk_box_append (inside, GTK_WIDGET (compare_right));
gtk_scrolled_window_set_child (comparator, GTK_WIDGET (inside));
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; }
bool isFull (Stack *stack) { return stack->top == MAX_SIZE - 1; }
void push (Stack *stack, GtkWidget *value)
{
// Check for stack overflow
if (isFull(stack)) {
printf("Stack Overflow\n");
return;
}
// Increment top and add the value to the top of the stack
stack->arr[++stack->top] = value;
//printf("Pushed %p onto the stack\n", value);
printf("%d ", stack->top);
}
GtkWidget *pop (Stack *stack) {
// Check for stack underflow
if (isEmpty(stack)) {
printf("Stack Underflow\n");
return NULL;
}
// Return the top element
GtkWidget *popped = stack->arr[stack->top];
// decrement top pointer
stack->top--;
printf("Popped %p from the stack ", popped);
// return the popped element
return popped;
}
GtkWidget *peek(Stack *stack) {
// Check if the stack is empty
if (isEmpty(stack)) {
printf("Stack is empty\n");
return NULL;
}
// Return the top element without removing it
return stack->arr[stack->top];
}
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);
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/AMP.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/glutamate.png")));
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/glutamine.png")));
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/legumin.png")));
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/histidine.png")));
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/phénylalanine.png")));
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/dopamine.png")));
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/ribonuclease.png")));
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/ascorbic acid.png")));
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/biotin.png")));
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/erythorbic acid.png")));
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/folic acid.png")));
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/glycerol.png")));
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/insuline.png")));
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/glutathione.png")));
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/lactic acid.png")));
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/pantothenic acid.png")));
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/pyridoxin.png")));
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/riboflavin.png")));
push(&stack, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/hb.png")));
end = clock();
long double t = (long double)(end - start) / CLOCKS_PER_SEC;
printf(" << stack filled in time : %Lg\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));
}*/
return 0;
}

View File

@ -52,8 +52,8 @@ 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 ();
gtk_box_append (rules_tree_box, GTK_WIDGET (get_an_impression_of_what_a_rules_comparator_could_be()));
return GTK_WIDGET (rules_tree_box);
}

View File

@ -38,4 +38,3 @@
// - ce qui appartient à "cet" arbre, et
// - ce qui serait commun à "tous" les arbres utilisés dans gem-graph