Use parsed model to define dimension and space size of GLArea

This commit is contained in:
Adrien Bourmault 2024-01-11 22:27:52 +01:00
parent d50ce9afe1
commit 0da55ac88b
Signed by: neox
GPG Key ID: 2974E1D5F25DFCC8
10 changed files with 341 additions and 358 deletions

View File

@ -312,9 +312,8 @@ static inline void print_stack(int stack_id)
n++; n++;
} }
/*** TEST ***/
void main_test_graphics (const int stack_id); void graphics_model_setup (const int stack_id);
/* /*
* Structure describing an arrow * Structure describing an arrow

View File

@ -28,5 +28,8 @@
#include "../include/base.h" #include "../include/base.h"
bool model_init(const char *content, size_t length, const char *basename); 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);

View File

@ -129,7 +129,7 @@ void on_openfile_response(GtkNativeDialog *native,
int response, int response,
GemGraphClientWindow *self); GemGraphClientWindow *self);
void on_openfile_response_complete(GObject *source_object, void ui_model_loading(GObject *source_object,
GAsyncResult *result, GAsyncResult *result,
GemGraphClientWindow *self); GemGraphClientWindow *self);

View File

@ -18,6 +18,7 @@
"glu" "glu"
"glew" "glew"
"glfw" "glfw"
"cglm"
"libepoxy" "libepoxy"
"pango@1.90.0" "pango@1.90.0"
"xorgproto" "xorgproto"

View File

@ -27,6 +27,7 @@
#include <time.h> #include <time.h>
#include "../../include/base.h" #include "../../include/base.h"
#include "../../include/ui.h" #include "../../include/ui.h"
#include "../../include/parsing.h"
#include "../../include/graphics.h" #include "../../include/graphics.h"
#define TEST 0 #define TEST 0
@ -177,6 +178,11 @@ bool graphics_shutdown(const int id, void *error_buffer)
stack = &graphic_stack[id]; 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->position_buffer);
glDeleteBuffers(1, &stack->color_buffer); glDeleteBuffers(1, &stack->color_buffer);
glDeleteProgram(stack->program); glDeleteProgram(stack->program);
@ -220,7 +226,7 @@ bool graphics_shutdown(const int id, void *error_buffer)
* Attention, les vertex centraux de chaque unité d'espace (cube) * Attention, les vertex centraux de chaque unité d'espace (cube)
* peuvent être redondants (max 6) * peuvent être redondants (max 6)
*/ */
void main_test_graphics (const int stack_id) void graphics_model_setup (const int stack_id)
{ {
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
@ -229,19 +235,39 @@ void main_test_graphics (const int stack_id)
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
struct graphic_stack_t *stack = &graphic_stack[stack_id]; struct graphic_stack_t *stack = &graphic_stack[stack_id];
srand(time(NULL)); int rand(void); void srand(unsigned int seed);
int randomize = 10, console = 0, space_X = 1, space_Y = 1, space_Z = 1;
stack->arrows_nb = 0; char dimension = model_get_dim();
if (randomize) { g_print("[GRAPH DEBUG] dim = %d\n", dimension);
space_X = 1 + rand() % randomize;
space_Y = 1 + rand() % randomize; long space_X = 1;
space_Z = 1 + rand() % randomize; long space_Y = 1;
long 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
if (!space_Y)
space_Y = 1;
case 1:
space_X = model_get_dim_value("x");
if (!space_X)
space_X = 1;
default:
break;
} }
int density_max = space_X * space_Y * space_Z, specified_arrows_nb = density_max;
/* int max = fmax(space_X, space_Y); max = fmax(max, space_Z); */
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);
int density_max = space_X * space_Y * space_Z;
stack->arrows_nb = 0;
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
@ -271,8 +297,7 @@ void main_test_graphics (const int stack_id)
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
if (randomize) for (int i = 0; i < specified_arrows_nb; i++) for (int i = 0; i < density_max; i++) {
{
stack->arrows_nb = stack->arrows_nb =
set_arrow (stack_id, stack->arrows_nb, space_X, space_Y, space_Z, set_arrow (stack_id, stack->arrows_nb, space_X, space_Y, space_Z,
1, // load 1, // load
@ -280,26 +305,6 @@ void main_test_graphics (const int stack_id)
rand() % space_X, // x rand() % space_X, // x
rand() % space_Y, // y rand() % space_Y, // y
rand() % space_Z); // z rand() % space_Z); // z
if (i > 0 && i % 1000 == 0) printf("|");
if (i > 0 && i % 100000 == 0) printf("\n");
} }
else for (int i = 0; i < 6; i++)
stack->arrows_nb =
set_arrow (stack_id, stack->arrows_nb, 1, 1, 1, 1, i, 0, 0, 0);
int max_arrows_nb = stack->arrows_nb;
/*--------------------------------------------------------------------------------*/
/* F R E E */
/* ( F R E E 'S P A C E' : S E E G R A P H I C S H U T D O W N ) */
/*--------------------------------------------------------------------------------*/
free(stack->arrows_ptr);
stack->arrows_ptr = NULL;
stack->arrows_nb = 0;
} }

View File

@ -40,7 +40,7 @@ void graphics_init_buffers(const int stack_id)
struct graphic_stack_t *stack = &graphic_stack[stack_id]; struct graphic_stack_t *stack = &graphic_stack[stack_id];
//XXX //XXX
main_test_graphics (stack_id); graphics_model_setup(stack_id);
GLuint vao, vertex_buffer, color_buffer; GLuint vao, vertex_buffer, color_buffer;

View File

@ -11,7 +11,7 @@ out vec4 color;
void main(void) void main(void)
{ {
float zoom = 1.5f, chrominance = 1, luminance = 1; float zoom = 1.1f, chrominance = 1, luminance = 1;
gl_Position = gl_Position =
projection_matrix * view_matrix * model_matrix * vec4(in_position, zoom); projection_matrix * view_matrix * model_matrix * vec4(in_position, zoom);
color = vec4 (chrominance * in_color.rgb, luminance); color = vec4 (chrominance * in_color.rgb, luminance);

View File

@ -35,9 +35,13 @@
#include "../../include/base.h" #include "../../include/base.h"
static xmlDocPtr model;
static xmlHashTablePtr model_hashtable;
bool model_init(char *content, size_t length, char *basename) bool model_init(const char *content, size_t length, const char *basename)
{ {
xmlNode *node;
/* /*
* this initialize the library and check potential ABI mismatches * this initialize the library and check potential ABI mismatches
* between the version it was compiled for and the actual shared * between the version it was compiled for and the actual shared
@ -45,315 +49,276 @@ bool model_init(char *content, size_t length, char *basename)
*/ */
LIBXML_TEST_VERSION LIBXML_TEST_VERSION
xmlDocPtr doc; model = xmlReadMemory(content, length, basename, NULL, 0);
doc = xmlReadMemory(content, length, basename, NULL, 0); if (model == NULL ) {
return false;
if (doc == NULL ) { }
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 false;
} }
g_free(basename);
g_free(content);
return true; return true;
}
/* node = xmlDocGetRootElement(doc); */ bool model_shutdown(void)
{
xmlFreeDoc(model);
xmlHashFree(model_hashtable, NULL);
/* if (node == NULL) { */ // Cleanup function for the XML library
/* fprintf(stderr,"empty document\n"); */ xmlCleanupParser();
/* xmlFreeDoc(doc); */
/* return false; */
/* } */
/* if (xmlStrcmp(node->name, (xmlChar *) "gem-graph-model")) { */ // This is to debug memory for regression tests
/* fprintf(stderr,"document of the wrong type, root node != gem-graph-model\n"); */ xmlMemoryDump();
/* xmlFreeDoc(doc); */
/* return false; */
/* } */
/* my_table = xmlHashCreate(10); */ return true;
/* xmlDocPtr my_tree = xmlReadIO, */
/* xmlInputReadCallback ioread, */
/* xmlInputCloseCallback ioclose, */
/* void * ioctx, */
/* const char * URL, */
/* const char * encoding, */
/* int options); */
} }
/******************************************************************************/ /******************************************************************************/
/* bool model_shutdown(char *docname){ */ static 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;
}
/* * Cleanup function for the XML library. */ static xmlChar* splitStrAtSlash(xmlChar *toSplit)
/* */ {
/* xmlCleanupParser(); */ toSplit = (xmlChar *)xmlStrchr(toSplit, '/');
/* * this is to debug memory for regression tests */ toSplit = xmlStrsub (toSplit, 1, xmlStrlen(toSplit));
/* */ return toSplit;
/* xmlMemoryDump(); */ }
/* return true; */ static 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);
/* static xmlNodePtr getNextChild(xmlNodePtr node, xmlChar *last){ */ return xmlStrsub (preop, 0, xmlStrlen(preop) - xmlStrlen(path) - 1);
/* while (node != NULL && xmlStrcmp(node->name, last)) { */ }
/* // printf(" <>--- line n°%lu <%s>\n", xmlGetLineNo(node), node->name); */
/* node = node->next; */
/* } */
/* return node; */
/* } */
/* static xmlChar* splitStrAtSlash(xmlChar *toSplit){ */ static xmlChar* getLastTag(xmlChar *path)
/* toSplit = (xmlChar *)xmlStrchr(toSplit, '/'); */ {
/* toSplit = xmlStrsub (toSplit, 1, xmlStrlen(toSplit)); */ while ((ulong)xmlStrchr (path, '/')) path = splitStrAtSlash((xmlChar *)path);
/* return toSplit; */
/* } */
/* static xmlChar* getFirstTag(xmlChar *path){ */ // printf("last tag in the path = <%s>\n", path);
/* xmlChar *preop = path; */ return path; // which is no more the given path but only its last tag !
/* 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 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) */ 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 long model_get_node_attrib(xmlNodePtr node)
{
long value = 0;
if (node && node->properties) {
xmlAttr* attribute = node->properties;
xmlChar* value_txt = NULL;
char *ptr;
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);
attribute = attribute->next;
}
}
return value;
}
static long model_get_state_arrows_nb(xmlNodePtr node)
{
long arrows_nb= 0;
printf ("VRB0 model_get_state_arrows_nb <%s> start at line %ld\n",
node->name, xmlGetLineNo(node));
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;
}
printf ("\n");
printf ("VRB0 model_get_state_arrows_nb = %ld end at line %ld\n",
arrows_nb, xmlGetLineNo(node));
return arrows_nb;
}
/******************************************************************************/
/******************************************************************************/
/******************************************************************************/
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");
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;
}
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);
}
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 *)"");
}
node = getNextChild(node->next, (xmlChar *)"condition");
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));
}
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) */
/* { */ /* { */
/* xmlNodePtr node; */
/* // Lookup for node from path in hash table */
/* node = xmlHashLookup(my_table, path); */
/* // Found a node in hash table */
/* if(node){ */
/* if (VRB0) printf("xmlHashLookup (my_table, path: <%s>, tag: <%s> @>%p)\n", */
/* path, node->name, node); */
/* assert(node > (xmlNodePtr)2048); */
/* return node; */
/* // no node found in hash table */
/* } else { */
/* xmlChar *reste = path, *last = reste, *affich = reste; */
/* last = getLastTag(last); */
/* xmlNodePtr node = xmlDocGetRootElement(doc); */
/* if (VRB1) printf("line n° %lu : tag <%s> reste = %s\n",\ */
/* xmlGetLineNo(node), (xmlChar *)node->name, (xmlChar *)affich); */
/* xmlChar *extrait; */
/* while ((ulong)xmlStrchr (reste, '/')){ */
/* extrait = getFirstTag(reste); //printf("extrait = %s\n", extrait); */
/* reste = splitStrAtSlash((xmlChar *)reste);//printf("reste = %s\n", reste); */
/* node = node->xmlChildrenNode; */
/* node = getNextChild(node, extrait); */
/* if (VRB1) printf("line n°%lu : tag <%s> reste = %s\n",\ */
/* xmlGetLineNo(node), (xmlChar *)extrait, (xmlChar *)reste); */
/* } */
/* if(node != NULL && xmlStrcmp(node->name, last)) { */
/* node = node->xmlChildrenNode; */
/* while (node != NULL && xmlStrcmp(node->name, last)) { */
/* node = node->next; */
/* } */
/* if (VRB1) printf("line n°%lu : tag <%s>\n",\ */
/* xmlGetLineNo(node), (xmlChar *)node->name); */
/* xmlHashAddEntry (my_table, path, node); */
/* } */
/* if (VRB0) printf("VRB0 xmlHashAddEntry (my_table, path: <%s>, tag: <%s> @>%p)\n",\ */
/* path, node->name, node); */
/* return node; */
/* } */
/* return NULL; // ? */
/* } */
/******************************************************************************/
/******************************************************************************/
/******************************************************************************/
/* static long model_get_node_attrib(xmlNodePtr node) */
/* { */
/* long value = 0; */
/* if (node && node->properties) { */
/* xmlAttr* attribute = node->properties; */
/* xmlChar* value_txt = NULL; */
/* char *ptr; */
/* while(attribute && attribute->name && attribute->children) */
/* { */
/* value_txt = xmlNodeListGetString(node->doc, attribute->children, 1); */
/* value = strtol((char *)value_txt, &ptr, 10); */
/* if (VRB3) printf ("model_get_node_attrib <%s> = %s = %ld\n",\ */
/* attribute->name, value_txt, value); */
/* attribute = attribute->next; */
/* } */
/* } */
/* return value; */
/* } */
/* static long model_get_state_arrows_nb(xmlNodePtr node) */
/* { */
/* long arrows_nb= 0; */
/* if (VRB0) printf ("VRB0 model_get_state_arrows_nb <%s> start at line %ld\n",\ */
/* node->name, xmlGetLineNo(node)); */
/* while (node && node->next){ */
/* if (VRB2) printf ("%s %ld >", (xmlChar *)node->name, arrows_nb); */
/* if (!xmlStrcmp(node->name, (xmlChar *)"arrow")) ++arrows_nb; */
/* if (VRB2) printf (" %ld ", arrows_nb); */
/* node = node->next; */
/* } */
/* if (VRB2) printf ("\n"); */
/* if (VRB0) printf ("VRB0 model_get_state_arrows_nb = %ld end at line %ld\n",\ */
/* arrows_nb, xmlGetLineNo(node)); */
/* return arrows_nb; */
/* } */
/******************************************************************************/
/******************************************************************************/
/******************************************************************************/
/* char model_get_dim(xmlChar *path){ */
/* xmlNodePtr node = model_get_node(path); if (VRB2) printf("@node = %p ", node); */
/* if (node && node->properties) { */
/* xmlAttr* attribute = node->properties; */
/* while(attribute && attribute->name && attribute->children) */
/* { */
/* xmlChar* value = xmlNodeListGetString(node->doc, attribute->children, 1); */
/* // printf ("model_get_dim %s = %s\n", attribute->name, value); */
/* xmlFree(value); */
/* attribute = attribute->next; */
/* } */
/* } */
/* if (xmlHasProp (node, (xmlChar *) "z")) return 3; */
/* if (xmlHasProp (node, (xmlChar *) "y")) return 2; */
/* if (xmlHasProp (node, (xmlChar *) "x")) return 1; */
/* return 0; */
/* } */
/* int model_get_dim_value(xmlChar *path, xmlChar *axis){ */
/* xmlNodePtr node = model_get_node(path); */
/* //xmlNodePtr node= xmlTextReadernoderentNode(reader); */
/* if (node && node->properties) { */
/* xmlAttr* attribute = node->properties; */
/* while(attribute && attribute->name && attribute->children) */
/* { */
/* xmlChar* value = xmlNodeListGetString(node->doc, attribute->children, 1); */
/* if (!xmlStrcmp(attribute->name, axis)) */
/* return (int)strtol((char *)value, NULL, 0); */
/* } */
/* } */
/* return 0; */
/* } */
/* 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); */
/* } */
/* 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 *)""); */
/* } */
/* node = getNextChild(node->next, (xmlChar *)"condition"); */
/* return 0; */
/* } */
/* long model_get_dim_X (xmlChar *path){ */
/* xmlNodePtr node = xmlHashLookup(my_table, (xmlChar *)"get_X"); */
/* if(node){ */
/* //if (VRB1){ */
/* printf("get_X > tag <%s> found in hash table\n",\ */
/* node->name); // node->name = "x" */
/* //} */
/* return (long)xmlHashLookup(my_table, (xmlChar *)"get_X"); //TODO */
/* }else{ */
/* xmlNodePtr node = model_get_node(path); // node = dimension */
/* if (node && node->properties) { */
/* xmlAttr* attribute = node->properties; */
/* while(attribute && attribute->name && attribute->children) */
/* { */
/* xmlChar* value = xmlNodeListGetString(node->doc, attribute->children, 1); */
/* if (!xmlStrcmp(attribute->name, (xmlChar *)"x")) { */
/* xmlHashAddEntry (my_table, (xmlChar *)"get_X", attribute); */
/* return (int)strtol((char *)value, NULL, 0); */
/* } */
/* } */
/* } */
/* } */
/* return 0; */
/* } */
/* int model_get_dim_Y (xmlChar *path){ */
/* printf("model_get_dim_Y(%s)\n", path); */
/* return 0; */
/* } */
/* int model_get_dim_Z (xmlChar *path){ */
/* printf("model_get_dim_Z(%s)\n", path); */
/* 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)); */
/* } */
/* 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 */ /* // Ici, je sais que c'est le 'PREMIER' état qui est demandé car n == 0 */
/* char compl[] = "/state/arrow"; */ /* char compl[] = "/state/arrow"; */
/* char *new_p = calloc(1, (sizeof(compl) + strlen((char *)path)) * sizeof(char)); */ /* char *new_p = calloc(1, (sizeof(compl) + strlen((char *)path)) * sizeof(char)); */
@ -363,7 +328,7 @@ bool model_init(char *content, size_t length, char *basename)
/* xmlNodePtr node = model_get_node((xmlChar *)new_p); */ /* xmlNodePtr node = model_get_node((xmlChar *)new_p); */
/* long size = model_get_state_arrows_nb(node); */ /* long size = model_get_state_arrows_nb(node); */
/* int dim = model_get_dim((xmlChar *)"parameters/space-param/dimension"); */ /* int dim = model_get_dim((xmlChar *)"parameters/space-param/dimension"); */
/* if (VRB0) printf("VRB0 model_get_saved_state(size = %ld)->%p<-attrib dim = %d size = %ld\n",\ */ /* 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)); */ /* size, (xmlNodePtr)model_get_node_attrib(node), dim, size * ( 2 + dim ) * sizeof(int)); */
/* int c = 0; */ /* int c = 0; */
@ -374,51 +339,53 @@ bool model_init(char *content, size_t length, char *basename)
/* if(1) */ /* if(1) */
/* { */ /* { */
/* long arrows_nb= 0; */ /* long arrows_nb= 0; */
/* if (VRB4) printf ("VRB4 model_get_state_arrows_nb <%s> start at line %ld\n",\ */ /* printf ("VRB4 model_get_state_arrows_nb <%s> start at line %ld\n",\ */
/* node->name, xmlGetLineNo(node)); */ /* node->name, xmlGetLineNo(node)); */
/* while (node && node->next){ */ /* while (node && node->next){ */
/* if (!xmlStrcmp(node->name, (xmlChar *)"arrow")) ++arrows_nb; */ /* if (!xmlStrcmp(node->name, (xmlChar *)"arrow")) ++arrows_nb; */
/* if (VRB4 && !xmlStrcmp(node->name, (xmlChar *)"arrow")) printf ("VRB4 %s-%ld ",\ */ /* if (!xmlStrcmp(node->name, (xmlChar *)"arrow")) printf ("VRB4 %s-%ld ",\ */
/* (xmlChar *)node->name, arrows_nb); */ /* (xmlChar *)node->name, arrows_nb); */
/* if (node && node->properties) { */ /* if (node && node->properties) { */
/* xmlAttr* attribute = node->properties; */ /* xmlAttr* attribute = node->properties; */
/* while(attribute) */ /* while(attribute) */
/* { */ /* { */
/* xmlChar* value = xmlNodeListGetString(node->doc, attribute->children, 1); */ /* xmlChar* value = xmlNodeListGetString(node->doc, attribute->children, 1); */
/* if (VRB4) printf("v=%s ", value); */ /* printf("v=%s ", value); */
/* *(t + c) = strtol((char*)value, NULL, 0); */ /* *(t + c) = strtol((char*)value, NULL, 0); */
/* ++c; */ /* ++c; */
/* xmlFree(value); */ /* xmlFree(value); */
/* attribute = attribute->next; */ /* attribute = attribute->next; */
/* } */ /* } */
/* if (VRB4) printf("\n"); */ /* printf("\n"); */
/* } */ /* } */
/* node = node->next; */ /* node = node->next; */
/* } */ /* } */
/* if (VRB4) printf ("VRB4 model_get_state_arrows_nb = %ld end at line %ld\n",\ */ /* printf ("VRB4 model_get_state_arrows_nb = %ld end at line %ld\n",\ */
/* arrows_nb, xmlGetLineNo(node)); */ /* arrows_nb, xmlGetLineNo(node)); */
/* if (VRB4) for(int k = 0; k < c; k++) printf("%d ", *(t + k)); printf("\n"); */ /* for(int k = 0; k < c; k++) printf("%d ", *(t + k)); printf("\n"); */
/* return arrows_nb; */ /* return arrows_nb; */
/* } */ /* } */
/* return (long) size * ( 2 + dim ) * sizeof(int); */ /* return (long) size * ( 2 + dim ) * sizeof(int); */
/* } */ /* } */
/* int model_get_state(xmlChar *path, xmlChar *state_id){ */ int model_get_state(xmlChar *path, xmlChar *state_id)
/* printf("model_get_state (%s -> %s state)\n", path, state_id); */ {
/* return 0; */ printf("model_get_state (%s -> %s state)\n", path, state_id);
/* } */ return 0;
}
/* int model_get_conditions_list(xmlChar *path){ */ int model_get_conditions_list(xmlChar *path)
/* printf("model_get_conditions_list(%s)\n", path); */ {
/* return 0; */ printf("model_get_conditions_list(%s)\n", path);
/* } */ return 0;
}
/* int model_get_transitions_list(xmlChar *path){ */ int model_get_transitions_list(xmlChar *path)
/* printf("model_get_transitions_list(%s)\n", path); */ {
/* return 0; */ printf("model_get_transitions_list(%s)\n", path);
/* } */ return 0;
}

View File

@ -157,6 +157,8 @@ void on_closefile_action(GSimpleAction *action,
g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self)); g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self));
model_shutdown();
ui_disable_action("closefile"); ui_disable_action("closefile");
ui_disable_action("savefile"); ui_disable_action("savefile");
ui_disable_action("runmode"); ui_disable_action("runmode");
@ -306,14 +308,14 @@ void on_openfile_response(GtkNativeDialog *native,
// Load asynchroneously not to block control flow // Load asynchroneously not to block control flow
g_file_load_contents_async (file, g_file_load_contents_async (file,
NULL, NULL,
(GAsyncReadyCallback)on_openfile_response_complete, (GAsyncReadyCallback)ui_model_loading,
self); self);
} }
g_object_unref(native); g_object_unref(native);
} }
void on_openfile_response_complete(GObject *source_object, void ui_model_loading(GObject *source_object,
GAsyncResult *result, GAsyncResult *result,
GemGraphClientWindow *self) GemGraphClientWindow *self)
{ {
@ -335,18 +337,21 @@ void on_openfile_response_complete(GObject *source_object,
&error); &error);
// In case of error, print a warning to the standard error output // In case of error, print a warning to the standard error output
if (error != NULL) if (error != NULL) {
{
g_printerr("Unable to open “%s”: %s\n", g_printerr("Unable to open “%s”: %s\n",
g_file_peek_path(file), g_file_peek_path(file),
error->message); error->message);
ui_send_internal_notification("Unable to open file !");
g_free(error); g_free(error);
g_free(basename);
g_free(content);
return; return;
} }
if (model_init(content, length, basename) == false) { if (model_init(content, length, basename) == false) {
ui_send_internal_notification("Error while loading the model"); ui_send_internal_notification("Error while loading the model");
g_free(basename); g_free(basename);
g_free(content);
return; return;
} }
@ -357,5 +362,8 @@ void on_openfile_response_complete(GObject *source_object,
ui_enable_action("presentmode"); ui_enable_action("presentmode");
ui_enable_action("togglesidebar"); ui_enable_action("togglesidebar");
ui_set_stack(RUN_MODE); ui_set_stack(RUN_MODE);
g_free(basename);
g_free(content);
} }

View File

@ -281,12 +281,12 @@ bool ui_setup_glarea(int target_mode, GtkWidget *target_widget)
gl_area = GTK_WIDGET(gtk_gl_area_new()); gl_area = GTK_WIDGET(gtk_gl_area_new());
assert(gl_area); assert(gl_area);
//gtk_widget_set_size_request(gl_area, 1000, 1000);
gtk_gl_area_set_auto_render(GTK_GL_AREA(gl_area), true);
gtk_widget_set_hexpand(gl_area, TRUE); gtk_widget_set_hexpand(gl_area, TRUE);
gtk_widget_set_vexpand(gl_area, TRUE); gtk_widget_set_vexpand(gl_area, TRUE);
gtk_widget_set_halign(gl_area, GTK_ALIGN_CENTER); //gtk_widget_set_halign(gl_area, GTK_ALIGN_CENTER);
gtk_widget_set_valign(gl_area, GTK_ALIGN_CENTER); //gtk_widget_set_valign(gl_area, GTK_ALIGN_CENTER);
gtk_widget_set_size_request(gl_area, 500, 500);
gtk_gl_area_set_auto_render(GTK_GL_AREA(gl_area), true);
// The main "draw" call for GtkGLArea // The main "draw" call for GtkGLArea
g_signal_connect(GTK_GL_AREA(gl_area), g_signal_connect(GTK_GL_AREA(gl_area),