WIP: src/graphics, src/parsing: get multiplicity

This commit is contained in:
Adrien Bourmault 2024-01-12 11:17:40 +01:00
parent 3bb99b5a26
commit 5f2abbda15
3 changed files with 52 additions and 30 deletions

View File

@ -32,4 +32,5 @@ bool model_shutdown(void);
char model_get_dim(void);
long model_get_dim_value(const char *axis);
char model_get_multiplicity(void);

View File

@ -235,14 +235,20 @@ void graphics_model_setup (const int stack_id)
/*------------------------------------------------------------------------*/
struct graphic_stack_t *stack = &graphic_stack[stack_id];
char dimension;
long space_X;
long space_Y;
long space_Z;
int density_max;
char multiplicity;
char dimension = model_get_dim();
dimension = model_get_dim();
g_print("[GRAPH DEBUG] dim = %d\n", dimension);
long space_X = 1;
long space_Y = 1;
long space_Z = 1;
space_X = 1;
space_Y = 1;
space_Z = 1;
switch(dimension) {
case 3:
@ -265,10 +271,12 @@ void graphics_model_setup (const int stack_id)
g_print("[GRAPH DEBUG] y = %ld\n", space_Y);
g_print("[GRAPH DEBUG] z = %ld\n", space_Z);
int density_max = space_X * space_Y * 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 */
@ -282,13 +290,9 @@ void graphics_model_setup (const int stack_id)
/* 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;
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;
/*------------------------------------------------------------------------*/

View File

@ -3,8 +3,8 @@
*
* Desc: Model parsing functions
*
* 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>
* Copyright (C) 2024 Adrien Bourmault <neox@a-lec.org>
*
* This file is part of Gem-graph.
*
@ -96,7 +96,7 @@ bool model_shutdown(void)
/******************************************************************************/
static xmlNodePtr getNextChild(xmlNodePtr node, xmlChar *last)
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);
@ -105,14 +105,14 @@ static xmlNodePtr getNextChild(xmlNodePtr node, xmlChar *last)
return node;
}
static xmlChar* splitStrAtSlash(xmlChar *toSplit)
static inline xmlChar* splitStrAtSlash(xmlChar *toSplit)
{
toSplit = (xmlChar *)xmlStrchr(toSplit, '/');
toSplit = xmlStrsub (toSplit, 1, xmlStrlen(toSplit));
return toSplit;
}
static xmlChar* getFirstTag(xmlChar *path)
static inline xmlChar* getFirstTag(xmlChar *path)
{
xmlChar *preop = path;
path = (xmlChar *)xmlStrchr(path, '/');
@ -124,16 +124,15 @@ static xmlChar* getFirstTag(xmlChar *path)
return xmlStrsub (preop, 0, xmlStrlen(preop) - xmlStrlen(path) - 1);
}
static xmlChar* getLastTag(xmlChar *path)
static inline xmlChar* getLastTag(xmlChar *path)
{
while ((ulong)xmlStrchr (path, '/')) path = splitStrAtSlash((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)
@ -264,6 +263,32 @@ long model_get_dim_value(const char *axis)
return 0;
}
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;
}
char model_get_condition(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;
}
char model_get_cond_tree (xmlChar *path)
{
@ -298,14 +323,6 @@ int model_get_cond (xmlChar *path, xmlChar *node_id)
return 0;
}
int model_get_multiplicity (xmlChar *path)
{
xmlNodePtr node = model_get_node(path);
if (node)
return (int)strtol((char *)xmlNodeGetContent(node), NULL, 0);
return 0;
}
int model_get_objects_list(xmlChar *path)
{
return xmlGetLineNo(model_get_node(path));