diff --git a/callback.d b/callback.d deleted file mode 100644 index 79a723e..0000000 --- a/callback.d +++ /dev/null @@ -1,3 +0,0 @@ -callback.o: callback.c tree.h \ - /gnu/store/fkmpkdav2zmz1k72989bdgpdrfac7rz1-glib-2.78.0/include/glib-2.0/glib.h \ - display.h contain.h texts.h in_depth.h diff --git a/callback.o b/callback.o deleted file mode 100644 index b0ee77b..0000000 Binary files a/callback.o and /dev/null differ diff --git a/contain.d b/contain.d deleted file mode 100644 index 80faf3a..0000000 --- a/contain.d +++ /dev/null @@ -1,3 +0,0 @@ -contain.o: contain.c tree.h \ - /gnu/store/fkmpkdav2zmz1k72989bdgpdrfac7rz1-glib-2.78.0/include/glib-2.0/glib.h \ - display.h contain.h texts.h callback.h diff --git a/contain.h b/contain.h index 4e7e9d7..75dbd48 100644 --- a/contain.h +++ b/contain.h @@ -7,6 +7,8 @@ /* */ /******************************************************************************/ +#include + #define W 1920 #define H 960 #define W_IMAGE W - 320 diff --git a/contain.o b/contain.o deleted file mode 100644 index b275591..0000000 Binary files a/contain.o and /dev/null differ diff --git a/dimers random walk.xml b/dimers random walk.xml new file mode 100644 index 0000000..12ae465 --- /dev/null +++ b/dimers random walk.xml @@ -0,0 +1,118 @@ + + + + + Modèle de test + + Léontine Patinette + + 2 + + 1630000000 + + 1.0 + + Ref + + + + + 0 + 9 + + + + + + + + + + + + + + + + 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/display.d b/display.d deleted file mode 100644 index 35b0d59..0000000 --- a/display.d +++ /dev/null @@ -1,3 +0,0 @@ -display.o: display.c tree.h \ - /gnu/store/fkmpkdav2zmz1k72989bdgpdrfac7rz1-glib-2.78.0/include/glib-2.0/glib.h \ - display.h contain.h texts.h diff --git a/display.o b/display.o deleted file mode 100644 index 5c92f89..0000000 Binary files a/display.o and /dev/null differ diff --git a/graph_area.c b/graph_area.c index cb18a3b..6672191 100644 --- a/graph_area.c +++ b/graph_area.c @@ -26,8 +26,8 @@ #include #include "base.h" -//#include "ui.h" -//#include "graphics.h" +#include "contain.h" +#include "graph_area.h" struct stack_index_t { long stack_id; diff --git a/graph_area.d b/graph_area.d deleted file mode 100644 index 682843f..0000000 --- a/graph_area.d +++ /dev/null @@ -1,3 +0,0 @@ -graph_area.o: graph_area.c \ - /gnu/store/fkmpkdav2zmz1k72989bdgpdrfac7rz1-glib-2.78.0/include/glib-2.0/glib.h \ - base.h diff --git a/graph_area.h b/graph_area.h index 8d622ee..9324857 100644 --- a/graph_area.h +++ b/graph_area.h @@ -172,25 +172,26 @@ void graphics_draw_plan (const int stack_id, GLuint a, GLuint b, GLuint c); * * @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); +////////////////////////// shader = glCreateShader(type); +////////////////////////// glShaderSource(shader, 1, &src, NULL); +////////////////////////// glCompileShader(shader); - glGetShaderiv(shader, GL_COMPILE_STATUS, &status); +////////////////////////// glGetShaderiv(shader, GL_COMPILE_STATUS, &status); if(status == GL_FALSE) { int log_len; char *buffer; - glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_len); +////////////////////////// glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_len); buffer = g_malloc(log_len + 1); assert (buffer); - glGetShaderInfoLog(shader, log_len, NULL, buffer); +////////////////////////// glGetShaderInfoLog(shader, log_len, NULL, buffer); g_warning("Compile failure in %s shader:\n%s", type == GL_VERTEX_SHADER ? "vertex" : "fragment", @@ -198,14 +199,14 @@ static inline GLuint create_shader(const int stack_id, int type, const char *src g_free(buffer); - glDeleteShader(shader); +////////////////////////// glDeleteShader(shader); return 0; } return shader; } - +*/ static inline void print_stack(int stack_id) { static int n = 0; diff --git a/graph_area.o b/graph_area.o deleted file mode 100644 index 714e38b..0000000 Binary files a/graph_area.o and /dev/null differ diff --git a/graph_stack.c.todo b/graph_stack.c.todo new file mode 100644 index 0000000..55f5db2 --- /dev/null +++ b/graph_stack.c.todo @@ -0,0 +1,333 @@ +/* + * Gem-graph OpenGL experiments + * + * Desc: GL functions + * + * Copyright (C) 2023 Arthur Menges + * Copyright (C) 2023 Adrien Bourmault + * Copyright (C) 2023 Jean Sirmai + * + * 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 . + */ + +#include +#include +#include "base.h" +#include "contain.h" +//#include "parsing.h" +#include "graph_area.h" + +#define TEST 0 + +struct graphic_stack_t *graphic_stack = NULL; +size_t graphic_stack_size = 0; +int *free_stack_slot = NULL; +size_t free_stack_slot_size = 0; + +/* + * Prints verbose human-readable debug messages + * + * @param source, XXX + * type, XXX + * id, XXX + * severity, XXX + * length, XXX + * msg, XXX + * data, XXX + * + * @return void + */ + +static void graphics_debug_callback(GLenum source, GLenum type, GLuint id, + GLenum severity, GLsizei length, + const GLchar *msg, const void *data) +{ + const char *errsource; + const char *errtype; + const char *errseverity; + const GLubyte *string; + GLenum code; + + switch (source) { + case GL_DEBUG_SOURCE_API: errsource = "API"; break; + case GL_DEBUG_SOURCE_WINDOW_SYSTEM: errsource = "WINDOW SYSTEM"; break; + case GL_DEBUG_SOURCE_SHADER_COMPILER: errsource = "SHADER COMPILER"; break; + case GL_DEBUG_SOURCE_THIRD_PARTY: errsource = "THIRD PARTY"; break; + case GL_DEBUG_SOURCE_APPLICATION: errsource = "APPLICATION"; break; + case GL_DEBUG_SOURCE_OTHER: errsource = "UNKNOWN"; break; + default: errsource = "UNKNOWN"; break; + } + + switch (type) { + case GL_DEBUG_TYPE_ERROR: errtype = "ERROR"; break; + case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: errtype = "DEPRECATED BEHAVIOR";break; + case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: errtype = "UNDEFINED BEHAVIOR"; break; + case GL_DEBUG_TYPE_PORTABILITY: errtype = "PORTABILITY"; break; + case GL_DEBUG_TYPE_PERFORMANCE: errtype = "PERFORMANCE"; break; + case GL_DEBUG_TYPE_OTHER: errtype = "OTHER"; break; + case GL_DEBUG_TYPE_MARKER: errtype = "MARKER"; break; + default: errtype = "UNKNOWN"; break; + } + + switch (severity) { + case GL_DEBUG_SEVERITY_HIGH: errseverity = "CRITICAL"; break; + case GL_DEBUG_SEVERITY_MEDIUM: errseverity = "ERROR"; break; + case GL_DEBUG_SEVERITY_LOW: errseverity = "WARNING"; break; + case GL_DEBUG_SEVERITY_NOTIFICATION: errseverity = "INFO"; break; + default: errseverity = "UNKNOWN"; break; + } + + code = glGetError(); + string = gluErrorString(code); + + g_printerr("[%s] %s (%s) from %s: %s\n", + errseverity, string, errtype, errsource, msg); +} + +/* -------------------------------------------------------------------------- */ + +/* + * Initializes graphical stack + * + * @param gl_area, ptr to the gl_area widget + * + * @return id if initialized + */ +int graphics_init(void *error_buffer) +{ + int cur_id = 0; + struct graphic_stack_t *stack; + + /* 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); */ + } else { + // Check if there are free slots + if (free_stack_slot_size) { + // We get the last free slot registered + cur_id = free_stack_slot[free_stack_slot_size-1]; + // Unregister it (ofc) + free_stack_slot = g_realloc(free_stack_slot, + free_stack_slot_size-- * + sizeof(int)); + } else { + cur_id = graphic_stack_size; + graphic_stack = g_realloc(graphic_stack, + ++graphic_stack_size * + sizeof(struct graphic_stack_t)); + } + } + + 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); */ + + stack = &graphic_stack[cur_id]; + stack->id = cur_id; + +////////////////////////// glEnable(GL_DEBUG_OUTPUT); +////////////////////////// glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); +////////////////////////// glEnable(GL_MULTISAMPLE); + + if (!graphics_init_shaders(cur_id)) + return -1; + + //print_stack(cur_id); + + graphics_init_buffers(cur_id); + +////////////////////////// glDebugMessageCallback(graphics_debug_callback, NULL); + + //print_stack(cur_id); + + return cur_id; +} + +/* + * Shutdowns a gl_area + * + * @param gl_area, ptr to the gl_area widget + * + * @return true if success + */ +bool graphics_shutdown(const int id, void *error_buffer) +{ + struct graphic_stack_t *stack; + + if (id >= graphic_stack_size || + graphic_stack_size == 0 || + graphic_stack == NULL) + return false; + + stack = &graphic_stack[id]; + + //XXX + free(stack->arrows_ptr); + stack->arrows_ptr = NULL; + stack->arrows_nb = 0; + + glDeleteBuffers(1, &stack->position_buffer); + glDeleteBuffers(1, &stack->color_buffer); + glDeleteProgram(stack->program); + + g_free(stack->buffer_vertex_origin); + g_free(stack->buffer_colors_origin); + g_free(stack->buffer_lines_origin); + g_free(stack->buffer_plans_origin); + + if (graphic_stack_size == 1) { + free(graphic_stack); + graphic_stack = NULL; + graphic_stack_size = 0; + } else { + memset(&graphic_stack[id], 0, sizeof(struct graphic_stack_t)); + free_stack_slot = g_realloc(free_stack_slot, + ++free_stack_slot_size * + sizeof(int)); + free_stack_slot[free_stack_slot_size-1] = id; + } + + return true; +} + +/* TODO + * #pragma omp parallel schedule(static, 12) + * void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) {} + * +// assert : space dimensions (x,y,z) > 0 +// assert : arrows localization within space and sites +// assert : no more than one arrow per address +// notify : weights are replaced, NOT added (could be !) + * + * Init space and arrows (= initial state) + * and allows ulterior creations, suppressions or modifications of the arrows[] array + * + * draws the space() + * triggers set_arrows() that modifies the list () and draws arrows + * + * Initialisation du générateur pseudo-aléatoire + * Attention, les vertex centraux de chaque unité d'espace (cube) + * peuvent être redondants (max 6) +*/ +void graphics_model_setup (const int stack_id) +{ + /*------------------------------------------------------------------------*/ + + /* I N I T I A L D A T A S P E C I F I C A T I O N */ + + /*------------------------------------------------------------------------*/ + + struct graphic_stack_t *stack = &graphic_stack[stack_id]; + char dimension; + long space_X; + long space_Y; + long space_Z; + long announced_arrows_nb; + int density_max; + char multiplicity; + +////////////////////////// dimension = model_get_dim(); +dimension = 1; // AD HOC (2024-06-04) + + g_print("[GRAPH DEBUG] dim = %d\n", dimension); + + space_X = 1; + space_Y = 1; + space_Z = 1; + + switch(dimension) { + case 3: +////////////////////////// space_Z = model_get_dim_value("z"); +; + case 2: +////////////////////////// space_Y = model_get_dim_value("y"); +; + // even in 1D, we must be able to see a grid (or not !) + if (!space_Y) + space_Y = 1; + case 1: +////////////////////////// space_X = model_get_dim_value("x"); +; + if (!space_X) + space_X = 1; + default: + break; + } + + g_print("[GRAPH DEBUG] x = %ld\n", space_X); + g_print("[GRAPH DEBUG] y = %ld\n", space_Y); + g_print("[GRAPH DEBUG] z = %ld\n", space_Z); + + density_max = space_X * space_Y * space_Z; + stack->arrows_nb = 0; + +////////////////////////// multiplicity = model_get_multiplicity(); +////////////////////////// g_print("[GRAPH DEBUG] site_multiplicity = %ld\n", multiplicity); + + /*------------------------------------------------------------------------*/ + + /* S P A C E D R A W I N G */ + + /*------------------------------------------------------------------------*/ + + 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; + stack->buffer_lines_0_arrow = stack->buffer_lines_size; + + /*------------------------------------------------------------------------*/ + + /* A R R O W S D R A W I N G */ + + /*------------------------------------------------------------------------*/ + + char state_id[30] = {0}; + struct arrow_t arrow = {0}; + +////////////////////////// assert(model_get_next_state(&state_id)); + + g_print("[GRAPH DEBUG] first state is = %s\n", state_id); + +////////////////////////// announced_arrows_nb = model_get_state_arrows_count(state_id); + +////////////////////////// g_print("[GRAPH DEBUG] announced_arrows_nb is = %ld\n", announced_arrows_nb); + +////////////////////////// while (model_get_next_arrow(&arrow, &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, // load +////////////////////////// arrow.site, // site +////////////////////////// arrow.x, // x +////////////////////////// arrow.y, // y +////////////////////////// arrow.z); // z +////////////////////////// } + +////////////////////////// if (stack->arrows_nb != announced_arrows_nb) +////////////////////////// g_printerr("ARGH : all the arrows have not been parsed !\n"); +} + diff --git a/in_depth.d b/in_depth.d deleted file mode 100644 index cced342..0000000 --- a/in_depth.d +++ /dev/null @@ -1 +0,0 @@ -in_depth.o: in_depth.c callback.h diff --git a/in_depth.o b/in_depth.o deleted file mode 100644 index f1014ed..0000000 Binary files a/in_depth.o and /dev/null differ diff --git a/main.d b/main.d deleted file mode 100644 index 6c89c45..0000000 --- a/main.d +++ /dev/null @@ -1 +0,0 @@ -main.o: main.c callback.h diff --git a/main.o b/main.o deleted file mode 100644 index 171dccf..0000000 Binary files a/main.o and /dev/null differ diff --git a/manifest.scm b/manifest.scm new file mode 100644 index 0000000..c1ac365 --- /dev/null +++ b/manifest.scm @@ -0,0 +1,30 @@ +;; +;; Dépendances sous GNU Guix +;; + + +(specifications->manifest + (list + "bash" + "coreutils" + "gcc-toolchain" + "pkg-config" + "valgrind" + "findutils" + "gdb" + "make" + "gtk" + "libxml2" + "glu" + "glew" + "glfw" + "cglm" + "libepoxy" + "pango@1.90.0" + "xorgproto" + "glib" + "mesa-headers" + "mesa" + "libadwaita" + ) +) diff --git a/myprogram b/myprogram deleted file mode 100755 index 32366c7..0000000 Binary files a/myprogram and /dev/null differ diff --git a/parsing.c.todo b/parsing.c.todo new file mode 100644 index 0000000..4879b66 --- /dev/null +++ b/parsing.c.todo @@ -0,0 +1,483 @@ +/* + * Gem-graph client + * + * Desc: Model parsing functions + * + * Copyright (C) 2023 Jean Sirmai + * Copyright (C) 2024 Adrien Bourmault + * + * 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 . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include // http://xmlsoft.org/examples/#parse1.c + // https://gnome.pages.gitlab.gnome.org/libxml2/devhelp/general.html + +#include "base.h" + +#define READ_SITE 1 << 0 +#define READ_WEIGHT 1 << 1 +#define READ_X 1 << 2 +#define READ_Y 1 << 3 +#define READ_Z 1 << 4 +#define SUCCESSFUL_READ_ARROW_X (READ_SITE | READ_WEIGHT | READ_X) +#define SUCCESSFUL_READ_ARROW_XY (READ_SITE | READ_WEIGHT | READ_X | READ_Y) +#define SUCCESSFUL_READ_ARROW_XYZ (READ_SITE | READ_WEIGHT | READ_X | READ_Y | READ_Z) + +static xmlDocPtr model; +static xmlHashTablePtr model_hashtable; + +bool model_init(const char *content, size_t length, const char *basename) +{ + xmlNode *node; + + /* + * this initialize the library and check potential ABI mismatches + * between the version it was compiled for and the actual shared + * library used. + */ + LIBXML_TEST_VERSION + + model = xmlReadMemory(content, length, basename, NULL, 0); + + if (model == NULL ) { + return false; + } + + node = xmlDocGetRootElement(model); + + if (node == NULL) { + g_printerr("Empty XML model !\n"); + xmlFreeDoc(model); + return false; + } + + if (xmlStrcmp(node->name, (xmlChar *) "gem-graph-model")) { + g_printerr("document of the wrong type, root node != gem-graph-model\n"); + xmlFreeDoc(model); + return false; + } + + model_hashtable = xmlHashCreate(0); + + if (model_hashtable == NULL) { + g_printerr("Can't create model hash table !\n"); + xmlFreeDoc(model); + return false; + } + + return true; +} + +bool model_shutdown(void) +{ + xmlFreeDoc(model); + xmlHashFree(model_hashtable, NULL); + + // Cleanup function for the XML library + xmlCleanupParser(); + + // This is to debug memory for regression tests + xmlMemoryDump(); + + return true; +} + +/******************************************************************************/ + +static inline xmlNodePtr getNextChild(xmlNodePtr node, xmlChar *last) +{ + while (node != NULL && xmlStrcmp(node->name, last)) { + // //printf(" <>--- line n°%lu <%s>\n", xmlGetLineNo(node), node->name); + node = node->next; + } + return node; +} + +static inline xmlChar* splitStrAtSlash(xmlChar *toSplit) +{ + toSplit = (xmlChar *)xmlStrchr(toSplit, '/'); + toSplit = xmlStrsub (toSplit, 1, xmlStrlen(toSplit)); + return toSplit; +} + +static inline xmlChar* getFirstTag(xmlChar *path) +{ + xmlChar *preop = path; + path = (xmlChar *)xmlStrchr(path, '/'); + path = xmlStrsub (path, 1, xmlStrlen(path)); + + //printf("%s = %s + / + %s\n", preop,\ + xmlStrsub (preop, 0, xmlStrlen(preop) - xmlStrlen(path) - 1), path); + + return xmlStrsub (preop, 0, xmlStrlen(preop) - xmlStrlen(path) - 1); +} + +static inline xmlChar* getLastTag(xmlChar *path) +{ + while ((ulong)xmlStrchr (path, '/')) + path = splitStrAtSlash((xmlChar *)path); + + // //printf("last tag in the path = <%s>\n", path); + return path; // which is no more the given path but only its last tag ! +} + +/******************************************************************************/ + +static xmlNodePtr model_get_node(xmlChar *path) +{ + xmlNodePtr node; + xmlChar *extrait; + xmlChar *reste, *last, *affich; + + // Lookup for node from path in hash table + node = xmlHashLookup(model_hashtable, path); + + // Found a node in hash table + if (node) { + return node; + + // no node found in hash table + } else { + reste = path; + affich = reste; + last = getLastTag(reste); + node = xmlDocGetRootElement(model); + + while (xmlStrchr (reste, '/')) { + extrait = getFirstTag(reste); + reste = splitStrAtSlash((xmlChar *)reste); + node = node->xmlChildrenNode; + node = getNextChild(node, extrait); + } + + if(node && xmlStrcmp(node->name, last)) { + node = node->xmlChildrenNode; + + while (node && xmlStrcmp(node->name, last)) { + node = node->next; + } + xmlHashAddEntry (model_hashtable, path, node); + } + + return node; + + } + + return NULL; +} + +/******************************************************************************/ + +static inline long model_get_node_long_attrib(xmlNodePtr node, char *id) +{ + xmlAttr *attribute; + xmlChar* value; + long ret_value; + + if (node && node->properties) { + attribute = node->properties; + while(attribute && attribute->name && attribute->children) { + if (!xmlStrcmp(attribute->name, (const xmlChar *)id)) { + value = xmlNodeListGetString(node->doc, attribute->children, 1); + ret_value = strtol((char *)value, NULL, 0); + xmlFree(value); + return ret_value; + } + attribute = attribute->next; + } + } + return 0; +} + +static inline bool model_get_node_str_attrib(xmlNodePtr node, + char *id, + char *dest) +{ + xmlAttr *attribute; + xmlChar* value; + + if (node && node->properties) { + attribute = node->properties; + while(attribute && attribute->name && attribute->children) { + if (!xmlStrcmp(attribute->name, (const xmlChar *)id)) { + value = xmlNodeListGetString(node->doc, attribute->children, 1); + strcpy(dest, value); + xmlFree(value); + return true; + } + attribute = attribute->next; + } + } + return false; +} + +/******************************************************************************/ + +char model_get_dim(void) +{ + xmlAttr *attribute; + xmlChar* value; + xmlNodePtr node = model_get_node( + (xmlChar *)"parameters/space-param/dimension"); + + if (xmlHasProp (node, (xmlChar *) "z")) return 3; + if (xmlHasProp (node, (xmlChar *) "y")) return 2; + if (xmlHasProp (node, (xmlChar *) "x")) return 1; + return 0; +} + +long model_get_dim_value(const char *axis) +{ + xmlAttr *attribute; + xmlChar *value; + long ret_value; + xmlNodePtr node = model_get_node( + (xmlChar *)"parameters/space-param/dimension"); + + return model_get_node_long_attrib(node, axis); +} + +char model_get_multiplicity(void) +{ + xmlAttr *attribute; + xmlChar* value; + xmlNodePtr node = model_get_node( + (xmlChar *)"parameters/space-param/site_multiplicity"); + + if (node->children) + if (node->children->content) + return (char)strtol((char *)node->children->content, NULL, 0); + + return 0; +} + +bool model_get_next_state(char *new_state_id) +{ + static xmlNodePtr cur_node = NULL; + xmlAttr *attribute; + xmlChar *value; + + if (cur_node == NULL) { + // Get first state + cur_node = model_get_node((xmlChar *)"savedstates/state"); + + } else { + // Get next state + if (cur_node->next) + cur_node = cur_node->next; + else + return false; + } + + // Lookup in properties + if (model_get_node_str_attrib(cur_node, "id", new_state_id)) + return true; + + cur_node = NULL; + return false; +} + +long model_get_state_arrows_count(const char *state_id) +{ + xmlNodePtr cur_node = NULL; + xmlAttr *attribute; + long value = 0; + bool found = false; + char temp_char[25]; + uint check = 0; // bit field checker + + //printf("NEW CALL : cur_node = %p\n", cur_node); + + assert(state_id); + + // Get first state node + cur_node = model_get_node((xmlChar *)"savedstates/state"); + + // Lookup in properties + while (cur_node && cur_node->properties) { + attribute = cur_node->properties; + + // Look for the id attribute + if (model_get_node_str_attrib(cur_node, "id", &temp_char)) { + if (!xmlStrcmp(temp_char, (const xmlChar *)state_id)) { + found = true; + break; + } + } + cur_node = cur_node->next; + } + + // Check if the state has been found + if (!found) { + cur_node = NULL; + return -1; + } + + + // Count arrows + if (cur_node->children) { + cur_node = cur_node->children; + while (cur_node) { + if (!xmlStrcmp(cur_node->name, (const xmlChar *)"arrow")) + value++; + cur_node = cur_node->next; + } + } else { + return -1; + } + return value; +} + +bool model_get_next_arrow(struct arrow_t *new_arrow, + const char *state_id, + char dimension) +{ + static xmlNodePtr cur_node = NULL; + xmlAttr *attribute; + xmlChar *value; + bool found = false; + char temp_char[25]; + uint check = 0; // bit field checker + + //printf("NEW CALL : cur_node = %p\n", cur_node); + + assert(new_arrow); + assert(state_id); + + if (cur_node == NULL) { + // Get first state node + cur_node = model_get_node((xmlChar *)"savedstates/state"); + + // Lookup in properties + while (cur_node && cur_node->properties) { + attribute = cur_node->properties; + + // Look for the id attribute + if (model_get_node_str_attrib(cur_node, "id", &temp_char)) { + if (!xmlStrcmp(temp_char, (const xmlChar *)state_id)) { + found = true; + break; + } + } + cur_node = cur_node->next; + } + + // Check if the state has been found + if (!found) { + cur_node = NULL; + return false; + } + + // Get first arrow + if (cur_node->children) { + cur_node = cur_node->children; + + found = false; + while (cur_node && cur_node->name) { + if (!xmlStrcmp(cur_node->name, (const xmlChar *)"arrow")) { + found = true; + break; + } + cur_node = cur_node->next; + } + } + + // Check if the state has been found + if (!found) { + cur_node = NULL; + return false; + } + + } else { + // Get next arrow + found = false; + while (cur_node->next) { + cur_node = cur_node->next; + if (!xmlStrcmp(cur_node->name, (const xmlChar *)"arrow")) { + found = true; + break; + } + } + + // Check if the state has been found + if (!found) { + cur_node = NULL; + return false; + } + } + + //printf("DURING CALL : cur_node = %p\n", cur_node); + //printf("DURING CALL : cur_node->name = %s\n", cur_node->name); + + // Lookup in properties + if (cur_node && cur_node->properties) { + attribute = cur_node->properties; + + while(attribute && attribute->name && attribute->children) { + //printf("attr name : %s\n", attribute->name); + if (!xmlStrcmp(attribute->name, (const xmlChar *)"site")) { + value = xmlNodeListGetString(cur_node->doc, attribute->children, 1); + new_arrow->site = strtol((char *)value, NULL, 0); + xmlFree(value); + check |= READ_SITE; + } + if (!xmlStrcmp(attribute->name, (const xmlChar *)"weight")) { + value = xmlNodeListGetString(cur_node->doc, attribute->children, 1); + new_arrow->load = strtol((char *)value, NULL, 0); + xmlFree(value); + check |= READ_WEIGHT; + } + if (!xmlStrcmp(attribute->name, (const xmlChar *)"x")) { + value = xmlNodeListGetString(cur_node->doc, attribute->children, 1); + new_arrow->x = strtol((char *)value, NULL, 0); + xmlFree(value); + check |= READ_X; + } + if (!xmlStrcmp(attribute->name, (const xmlChar *)"y")) { + value = xmlNodeListGetString(cur_node->doc, attribute->children, 1); + new_arrow->y = strtol((char *)value, NULL, 0); + xmlFree(value); + check |= READ_Y; + } + if (!xmlStrcmp(attribute->name, (const xmlChar *)"z")) { + value = xmlNodeListGetString(cur_node->doc, attribute->children, 1); + new_arrow->z = strtol((char *)value, NULL, 0); + xmlFree(value); + check |= READ_Z; + } + attribute = attribute->next; + } + + switch(dimension) { + case 3: + return (bool)(check & SUCCESSFUL_READ_ARROW_XYZ); + case 2: + return (bool)(check & SUCCESSFUL_READ_ARROW_XY); + case 1: + return (bool)(check & SUCCESSFUL_READ_ARROW_X); + } + } + cur_node = NULL; + return false; +} diff --git a/parsing.h.todo b/parsing.h.todo new file mode 100644 index 0000000..2c9c484 --- /dev/null +++ b/parsing.h.todo @@ -0,0 +1,39 @@ +/* + * Gem-graph OpenGL experiments + * + * Desc: Model parsing header + * + * Copyright (C) 2023 Arthur Menges + * Copyright (C) 2023 Adrien Bourmault + * + * 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 . + */ + +#pragma once +#include + +#include "base.h" + +bool model_init(const char *content, size_t length, const char *basename); +bool model_shutdown(void); + +char model_get_dim(void); +long model_get_dim_value(const char *axis); +char model_get_multiplicity(void); +bool model_get_next_state(char *new_state_id); +bool model_get_next_arrow(struct arrow_t *new_arrow, + const char *state_id, + char dimension); diff --git a/texts.d b/texts.d deleted file mode 100644 index 18de62c..0000000 --- a/texts.d +++ /dev/null @@ -1 +0,0 @@ -texts.o: texts.c diff --git a/texts.o b/texts.o deleted file mode 100644 index 8ea2834..0000000 Binary files a/texts.o and /dev/null differ diff --git a/tree.d b/tree.d deleted file mode 100644 index dccd5fb..0000000 --- a/tree.d +++ /dev/null @@ -1 +0,0 @@ -tree.o: tree.c contain.h texts.h callback.h diff --git a/tree.o b/tree.o deleted file mode 100644 index 91bb739..0000000 Binary files a/tree.o and /dev/null differ