diff --git a/data/models/dimers random walk.xml b/data/models/dimers random walk.xml index 817dd1b..12ae465 100644 --- a/data/models/dimers random walk.xml +++ b/data/models/dimers random walk.xml @@ -55,12 +55,12 @@ - - - - - - + + + + + + diff --git a/include/base.h b/include/base.h index 1d4dcb6..00d7cea 100644 --- a/include/base.h +++ b/include/base.h @@ -58,6 +58,17 @@ enum N_MODE }; +/* + * Structure describing an arrow + */ +struct arrow_t { + uint load; + uint site; + uint x; + uint y; + uint z; +}; + /* * Read a file from filename into a provided buffer * diff --git a/include/graphics.h b/include/graphics.h index 9c64c60..f30f7b1 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -255,17 +255,6 @@ static inline void print_stack(int stack_id) void graphics_model_setup (const int stack_id); -/* - * Structure describing an arrow - */ -struct arrow_t { - GLuint load; - GLuint site; - GLuint x; - GLuint y; - GLuint z; -}; - int draw_one_arrow_vertex (const int stack_id, int space_X, int space_Y, diff --git a/include/parsing.h b/include/parsing.h index 1fa9179..8ac296e 100644 --- a/include/parsing.h +++ b/include/parsing.h @@ -33,4 +33,7 @@ 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/src/graphics/graphics.c b/src/graphics/graphics.c index 8bcc16c..49e3d5a 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -239,6 +239,7 @@ void graphics_model_setup (const int stack_id) long space_X; long space_Y; long space_Z; + long announced_arrows_nb; int density_max; char multiplicity; @@ -283,12 +284,12 @@ 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; @@ -300,15 +301,28 @@ void graphics_model_setup (const int stack_id) /*------------------------------------------------------------------------*/ + char state_id[30] = {0}; + struct arrow_t arrow = {0}; - for (int i = 0; i < density_max; i++) { + 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, - 1, // load - rand() % 6, // site - rand() % space_X, // x - rand() % space_Y, // y - rand() % space_Z); // 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/src/parsing/parsing.c b/src/parsing/parsing.c index 5a6f1d7..916fe85 100644 --- a/src/parsing/parsing.c +++ b/src/parsing/parsing.c @@ -35,6 +35,15 @@ #include "../../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; @@ -99,7 +108,7 @@ bool model_shutdown(void) 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); + // //printf(" <>--- line n°%lu <%s>\n", xmlGetLineNo(node), node->name); node = node->next; } return node; @@ -118,7 +127,7 @@ static inline xmlChar* getFirstTag(xmlChar *path) path = (xmlChar *)xmlStrchr(path, '/'); path = xmlStrsub (path, 1, xmlStrlen(path)); - printf("%s = %s + / + %s\n", preop,\ + //printf("%s = %s + / + %s\n", preop,\ xmlStrsub (preop, 0, xmlStrlen(preop) - xmlStrlen(path) - 1), path); return xmlStrsub (preop, 0, xmlStrlen(preop) - xmlStrlen(path) - 1); @@ -129,7 +138,7 @@ static inline xmlChar* getLastTag(xmlChar *path) while ((ulong)xmlStrchr (path, '/')) path = splitStrAtSlash((xmlChar *)path); - // printf("last tag in the path = <%s>\n", path); + // //printf("last tag in the path = <%s>\n", path); return path; // which is no more the given path but only its last tag ! } @@ -178,53 +187,52 @@ static xmlNodePtr model_get_node(xmlChar *path) return NULL; } -/******************************************************************************/ -/******************************************************************************/ /******************************************************************************/ -static long model_get_node_attrib(xmlNodePtr node) +static inline long model_get_node_long_attrib(xmlNodePtr node, char *id) { - long value = 0; + xmlAttr *attribute; + xmlChar* value; + long ret_value; if (node && node->properties) { - xmlAttr* attribute = node->properties; - xmlChar* value_txt = NULL; - char *ptr; - + attribute = node->properties; while(attribute && attribute->name && attribute->children) { - value_txt = xmlNodeListGetString(node->doc, attribute->children, 1); - value = strtol((char *)value_txt, &ptr, 10); - printf ("model_get_node_attrib <%s> = %s = %ld\n",\ - attribute->name, value_txt, value); + 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 value; + return 0; } -static long model_get_state_arrows_nb(xmlNodePtr node) +static inline bool model_get_node_str_attrib(xmlNodePtr node, + char *id, + char *dest) { - long arrows_nb= 0; - printf ("VRB0 model_get_state_arrows_nb <%s> start at line %ld\n", - node->name, xmlGetLineNo(node)); + xmlAttr *attribute; + xmlChar* value; - while (node && node->next) { - printf ("%s %ld >", (xmlChar *)node->name, arrows_nb); - if (!xmlStrcmp(node->name, (xmlChar *)"arrow")) ++arrows_nb; - printf (" %ld ", arrows_nb); - node = node->next; + 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; + } } - - printf ("\n"); - printf ("VRB0 model_get_state_arrows_nb = %ld end at line %ld\n", - arrows_nb, xmlGetLineNo(node)); - - return arrows_nb; + return false; } - + /******************************************************************************/ -/******************************************************************************/ -/******************************************************************************/ char model_get_dim(void) { @@ -247,20 +255,7 @@ long model_get_dim_value(const char *axis) xmlNodePtr node = model_get_node( (xmlChar *)"parameters/space-param/dimension"); - if (node && node->properties) { - attribute = node->properties; - - while(attribute && attribute->name && attribute->children) { - if (!xmlStrcmp(attribute->name, (const xmlChar *)axis)) { - value = xmlNodeListGetString(node->doc, attribute->children, 1); - ret_value = strtol((char *)value, NULL, 0); - xmlFree(value); - return ret_value; - } - attribute = attribute->next; - } - } - return 0; + return model_get_node_long_attrib(node, axis); } char model_get_multiplicity(void) @@ -277,132 +272,212 @@ char model_get_multiplicity(void) return 0; } -char model_get_condition(void) +bool model_get_next_state(char *new_state_id) { + static xmlNodePtr cur_node = NULL; xmlAttr *attribute; - xmlChar* value; - xmlNodePtr node = model_get_node( - (xmlChar *)"parameters/space-param/dimension"); + xmlChar *value; - if (xmlHasProp (node, (xmlChar *) "z")) return 3; - if (xmlHasProp (node, (xmlChar *) "y")) return 2; - if (xmlHasProp (node, (xmlChar *) "x")) return 1; - return 0; -} + if (cur_node == NULL) { + // Get first state + cur_node = model_get_node((xmlChar *)"savedstates/state"); -char model_get_cond_tree (xmlChar *path) -{ - xmlNodePtr node = model_get_node(path); - node = node->xmlChildrenNode; - node = getNextChild(node, (xmlChar *)"condition"); - node = xmlCopyNodeList (node->xmlChildrenNode); - printf("model_get_cond_tree(\"%s\") > line n°%ld\n", path, xmlGetLineNo(node)); - return 0; -} - -int model_get_cond (xmlChar *path, xmlChar *node_id) -{ - xmlNodePtr node = model_get_node(path); - printf("model_get_cond(...) {...node->name = %s...}\n", node->name); - node = getNextChild(node->next, (xmlChar *)"condition"); - node = getNextChild(node->next, (xmlChar *)"condition"); - - if (xmlHasProp (node, (xmlChar *) "site")) { - printf(" node %s has attribute site\n", node->name); + } else { + // Get next state + if (cur_node->next) + cur_node = cur_node->next; + else + return false; } - if (xmlHasProp (node, (xmlChar *) "node_id")) { - printf(" node %s has attribute %s with value %hhn %s %s\n", - node->name, - xmlHasProp (node, (xmlChar *) "node_id")->name, - xmlGetProp (node, (xmlChar *) "node_id"), - (xmlChar *)"?! xmlGetProp is deprecated !", - (xmlChar *)""); + // 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; } - node = getNextChild(node->next, (xmlChar *)"condition"); - return 0; + + // 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; } -int model_get_objects_list(xmlChar *path) +bool model_get_next_arrow(struct arrow_t *new_arrow, + const char *state_id, + char dimension) { - return xmlGetLineNo(model_get_node(path)); + 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; } - -xmlChar *model_get_states_list(xmlChar *path) -{ - xmlNodePtr node = model_get_node(path); - return (xmlChar *)xmlNodeGetContent(node); -} - -/* long model_get_state_arrows_count(xmlChar *path, long n) */ -/* { */ -/* // Ici, je sais que c'est le 'PREMIER' état qui est demandé car n == 0 */ -/* char compl[] = "/state/arrow"; */ -/* char *new_p = calloc(1, (sizeof(compl) + strlen((char *)path)) * sizeof(char)); */ -/* strcat(new_p, (char *)path); */ -/* strcat(new_p + strlen((char *)path), compl); // printf("%s\n", new_p); */ - -/* xmlNodePtr node = model_get_node((xmlChar *)new_p); */ -/* long size = model_get_state_arrows_nb(node); */ -/* int dim = model_get_dim((xmlChar *)"parameters/space-param/dimension"); */ -/* printf("VRB0 model_get_saved_state(size = %ld)->%p<-attrib dim = %d size = %ld\n",\ */ -/* size, (xmlNodePtr)model_get_node_attrib(node), dim, size * ( 2 + dim ) * sizeof(int)); */ - -/* int c = 0; */ -/* int *t = calloc(1, (size * ( 2 + dim ) * sizeof(int))); */ -/* // int rk = 0; */ -/* // int *s = calloc(1, ( 2 + dim ) * sizeof(int)); */ - -/* if(1) */ -/* { */ -/* long arrows_nb= 0; */ -/* printf ("VRB4 model_get_state_arrows_nb <%s> start at line %ld\n",\ */ -/* node->name, xmlGetLineNo(node)); */ -/* while (node && node->next){ */ -/* if (!xmlStrcmp(node->name, (xmlChar *)"arrow")) ++arrows_nb; */ -/* if (!xmlStrcmp(node->name, (xmlChar *)"arrow")) printf ("VRB4 %s-%ld ",\ */ -/* (xmlChar *)node->name, arrows_nb); */ -/* if (node && node->properties) { */ -/* xmlAttr* attribute = node->properties; */ -/* while(attribute) */ -/* { */ -/* xmlChar* value = xmlNodeListGetString(node->doc, attribute->children, 1); */ -/* printf("v=%s ", value); */ -/* *(t + c) = strtol((char*)value, NULL, 0); */ -/* ++c; */ -/* xmlFree(value); */ -/* attribute = attribute->next; */ -/* } */ -/* printf("\n"); */ -/* } */ -/* node = node->next; */ -/* } */ -/* printf ("VRB4 model_get_state_arrows_nb = %ld end at line %ld\n",\ */ -/* arrows_nb, xmlGetLineNo(node)); */ -/* for(int k = 0; k < c; k++) printf("%d ", *(t + k)); printf("\n"); */ -/* return arrows_nb; */ -/* } */ - -/* return (long) size * ( 2 + dim ) * sizeof(int); */ -/* } */ - -int model_get_state(xmlChar *path, xmlChar *state_id) -{ - printf("model_get_state (%s -> %s state)\n", path, state_id); - return 0; -} - -int model_get_conditions_list(xmlChar *path) -{ - printf("model_get_conditions_list(%s)\n", path); - return 0; -} - -int model_get_transitions_list(xmlChar *path) -{ - printf("model_get_transitions_list(%s)\n", path); - return 0; -} - - -