summaryrefslogtreecommitdiff
path: root/src/graph
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2009-06-28 21:22:52 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2009-06-28 21:22:52 (GMT)
commit549dd203344a2f95f4bc596f963a854af004cba2 (patch)
tree3d840621a9edcb3decc3260ca688b4e75e52f04f /src/graph
parentf2696c85e502e36a529a1d8ee3d209498ac2c0e9 (diff)
Drawn graphic links between the different blocks of code.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@81 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/graph')
-rw-r--r--src/graph/dot.c90
-rw-r--r--src/graph/dot.h4
-rw-r--r--src/graph/layout.c29
-rw-r--r--src/graph/layout.h4
-rw-r--r--src/graph/node.c67
5 files changed, 182 insertions, 12 deletions
diff --git a/src/graph/dot.c b/src/graph/dot.c
index dc1c9a9..e4ee38c 100644
--- a/src/graph/dot.c
+++ b/src/graph/dot.c
@@ -71,16 +71,26 @@ graph_layout *create_graph_layout(char *cmds)
printf("ret = %d\n", ret);
-
+ /*
+ ret = gvLayoutJobs(result->context, result->graph);
+ printf("ret = %d\n", ret);
+ ret = gvRenderJobs(result->context, result->graph);
+ printf("ret = %d\n", ret);
+ */
ret = gvRender(result->context, result->graph, "dot", NULL);
+
+
+ ret = gvRender(result->context, result->graph, "plain", NULL);
+
printf("ret = %d\n", ret);
+
return result;
cdl_error:
@@ -136,13 +146,89 @@ void delete_graph_layout(graph_layout *layout)
void place_nodes_of_graph_layout(const graph_layout *layout, GtkFixed *fixed, GGraphNode **nodes, size_t count)
{
+ int height; /* Hauteur du graphique */
node_t *iter; /* Boucle de parcours */
GGraphNode *node; /* Intermédiaire concerné */
+ height = GD_bb(layout->graph).UR.y;
+
for (iter = agfstnode(layout->graph); iter != NULL; iter = agnxtnode(layout->graph, iter))
{
+
+ printf(" pos :: (%d ; %d)\n", iter->u.coord.x, height - iter->u.coord.y);
+
node = find_graph_node_by_name(nodes, count, iter->name);
- g_graph_node_place(node, fixed, (double)iter->u.coord.x, (double)iter->u.coord.y);
+ g_graph_node_place(node, fixed, iter->u.coord.x, height - iter->u.coord.y);
}
}
+
+
+/******************************************************************************
+* *
+* Paramètres : layout = graphique à supprimer de la mémoire. *
+* count = nombre d'éléments mis en place. *
+* *
+* Description : Charge la définition de tous les liens graphiques. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GtkLinkRenderer **create_links_from_graph_layout(const graph_layout *layout, size_t *count)
+{
+ GtkLinkRenderer **result; /* Liste à retourner */
+ int height; /* Hauteur du graphique */
+ node_t *niter; /* Boucle de parcours #1 */
+ edge_t *eiter; /* Boucle de parcours #2 */
+ splines *lines; /* Lignes déjà tracées */
+ int i; /* Boucle de parcours #3 */
+ int k; /* Boucle de parcours #4 */
+ GdkPoint *points; /* Points de ligne relus */
+ size_t points_count; /* Nombre de ces points */
+
+ result = NULL;
+ *count = 0;
+
+ height = GD_bb(layout->graph).UR.y;
+
+ for (niter = agfstnode(layout->graph); niter != NULL; niter = agnxtnode(layout->graph, niter))
+ for (eiter = agfstout(layout->graph, niter); eiter != NULL; eiter = agnxtout(layout->graph, eiter))
+ {
+ lines = ED_spl(eiter);
+
+ printf("edge == %p\n", eiter);
+
+ points = NULL;
+ points_count = 0;
+
+ for (i = 0; i < lines->size; i++)
+ {
+ points = (GdkPoint *)realloc(points, (points_count + lines->list[i].size) * sizeof(GdkPoint));
+
+ for (k = 0; k < lines->list[i].size; k++)
+ {
+ points[points_count + k].x = lines->list[i].list[k].x;
+ points[points_count + k].y = height - lines->list[i].list[k].y;
+
+ printf(" ... ( %d ; %d)\n",
+ lines->list[i].list[k].x, height - lines->list[i].list[k].y);
+
+ }
+
+ points_count += lines->list[i].size;
+
+ printf(" ...\n");
+
+ }
+
+ result = (GtkLinkRenderer **)realloc(result, ++(*count) * sizeof(GtkLinkRenderer *));
+ result[*count - 1] = gtk_link_renderer_new(points, points_count);
+
+ }
+
+ return result;
+
+}
diff --git a/src/graph/dot.h b/src/graph/dot.h
index 8538e52..630c1cb 100644
--- a/src/graph/dot.h
+++ b/src/graph/dot.h
@@ -26,6 +26,7 @@
#include "node.h"
+#include "../gtkext/gtklinkrenderer.h"
@@ -42,6 +43,9 @@ void delete_graph_layout(graph_layout *);
/* Place tous les éléments du graphique à l'écran. */
void place_nodes_of_graph_layout(const graph_layout *, GtkFixed *, GGraphNode **, size_t);
+/* Charge la définition de tous les liens graphiques. */
+GtkLinkRenderer **create_links_from_graph_layout(const graph_layout *, size_t *);
+
#endif /* _GRAPH_DOT_H */
diff --git a/src/graph/layout.c b/src/graph/layout.c
index c76df49..faf439b 100644
--- a/src/graph/layout.c
+++ b/src/graph/layout.c
@@ -26,6 +26,7 @@
#include <malloc.h>
#include <string.h>
+#include <gtk/gtkfixed.h>
#include "dot.h"
@@ -36,7 +37,7 @@
/******************************************************************************
* *
-* Paramètres : fixed = support à placer les différents éléments. *
+* Paramètres : view = support à placer les différents éléments. *
* views = morceaux de code à afficher de façon organisée. *
* count = quantité de ces morceaux de code. *
* *
@@ -48,12 +49,14 @@
* *
******************************************************************************/
-bool build_graph_view(GtkFixed *fixed, GtkBinView **views, size_t count)
+bool build_graph_view(GtkGraphView *view, GtkBinView **views, size_t count)
{
GGraphNode **nodes; /* Intermédiaires en place */
size_t i; /* Boucle de parcours */
char *cmds; /* Description à envoyer à dot */
graph_layout *layout; /* Graphique construit */
+ GtkLinkRenderer **links; /* Liens graphiques construits */
+ size_t links_count; /* Quantité de ces liens */
/* Création de la glue */
@@ -64,7 +67,8 @@ bool build_graph_view(GtkFixed *fixed, GtkBinView **views, size_t count)
/* Définition du graphique */
- cmds = strdup("digraph G {\n");
+ cmds = strdup("digraph G {\noverlap=false;\n splines=true;\n");
+ //cmds = strdup("digraph G {\n");
for (i = 0; i < count; i++)
cmds = g_graph_node_register_for_dot(nodes[i], cmds);
@@ -72,6 +76,20 @@ bool build_graph_view(GtkFixed *fixed, GtkBinView **views, size_t count)
+
+
+
+ for (i = 0; (i + 1) < count; i++)
+ {
+ char buffer[128];
+ snprintf(buffer, 128, "_%p -> _%p;\n", views[i], views[i + 1]);
+ cmds = stradd(cmds, buffer);
+ }
+
+
+
+
+
cmds = stradd(cmds, "}");
printf("first step :: '%s'\n", cmds);
@@ -80,9 +98,10 @@ bool build_graph_view(GtkFixed *fixed, GtkBinView **views, size_t count)
/* Affichage du graphique */
- place_nodes_of_graph_layout(layout, fixed, nodes, count);
-
+ place_nodes_of_graph_layout(layout, GTK_FIXED(view), nodes, count);
+ links = create_links_from_graph_layout(layout, &links_count);
+ gtk_graph_view_attach_links(view, links, links_count);
delete_graph_layout(layout);
diff --git a/src/graph/layout.h b/src/graph/layout.h
index cbb8e6c..5212168 100644
--- a/src/graph/layout.h
+++ b/src/graph/layout.h
@@ -26,15 +26,15 @@
#include <stdbool.h>
-#include <gtk/gtkfixed.h>
#include "../gtkext/gtkbinview.h"
+#include "../gtkext/gtkgraphview.h"
/* Dispose une série de morceaux d'affichage en graphique. */
-bool build_graph_view(GtkFixed *, GtkBinView **, size_t);
+bool build_graph_view(GtkGraphView *, GtkBinView **, size_t);
diff --git a/src/graph/node.c b/src/graph/node.c
index b220c4f..8432476 100644
--- a/src/graph/node.c
+++ b/src/graph/node.c
@@ -50,6 +50,9 @@ struct _GGraphNodeClass
{
GObjectClass parent; /* A laisser en premier */
+ double dpi_x; /* Résolution en abscisse */
+ double dpi_y; /* Résolution en ordonnée */
+
};
@@ -84,6 +87,44 @@ G_DEFINE_TYPE(GGraphNode, g_graph_node, G_TYPE_OBJECT);
static void g_graph_node_class_init(GGraphNodeClass *klass)
{
+ GdkScreen *screen; /* Ecran par défaut */
+ gint width; /* Largeur d'écran en pixels */
+ gint height; /* Hauteur d'écran en pixels */
+ gint width_mm; /* Largeur d'écran en mm. */
+ gint height_mm; /* Hauteur d'écran en mm. */
+
+ screen = gdk_screen_get_default();
+
+ width = gdk_screen_get_width(screen);
+ height = gdk_screen_get_height(screen);
+
+ width_mm = gdk_screen_get_width_mm(screen);
+ height_mm = gdk_screen_get_height_mm(screen);
+
+ /**
+ * Il y a 2.54 centimètres, soit 25.4 millimètres, dans un pouce.
+ * On a donc :
+ *
+ * dpi = N pixels / (M millimètres / (25.4 millimètres / 1 pouce))
+ * = N pixels / (M pouces / 25.4)
+ * = N * 25.4 pixels / M pouces
+ *
+ */
+
+ if (width_mm > 0 && height_mm > 0)
+ {
+ klass->dpi_x = (width * 25.4) / (double)width_mm;
+ klass->dpi_y = (height * 25.4) / (double)height_mm;
+ }
+ else
+ {
+ klass->dpi_x = 96;
+ klass->dpi_y = 96;
+ }
+
+
+ klass->dpi_x = 72;
+ klass->dpi_y = 72;
}
@@ -136,7 +177,7 @@ GGraphNode *g_graph_node_new(GtkBinView *view)
}
-
+#include <math.h>
/******************************************************************************
* *
* Paramètres : node = intermédiaire à consulter. *
@@ -153,14 +194,27 @@ GGraphNode *g_graph_node_new(GtkBinView *view)
char *g_graph_node_register_for_dot(const GGraphNode *node, char *cmds)
{
GtkRequisition requisition; /* Taille à l'écran requise */
+ char buffer[128];
+
+ gtk_widget_size_request(GTK_WIDGET(node->view), &requisition);
cmds = stradd(cmds, node->name);
+ cmds = stradd(cmds, " [shape=box, fixedsize ");
- gtk_widget_size_request(GTK_WIDGET(node->view), &requisition);
+ printf(" req=(%d ; %d) -->> (%g ; %g)\n",
+ requisition.width,
+ requisition.height,
+ requisition.width / G_GRAPH_NODE_GET_CLASS(node)->dpi_x,
+ requisition.height / G_GRAPH_NODE_GET_CLASS(node)->dpi_y);
+ snprintf(buffer, 128, ", width=\"%g\"", round(requisition.width / G_GRAPH_NODE_GET_CLASS(node)->dpi_x) + 1.0);
+ cmds = stradd(cmds, buffer);
- cmds = stradd(cmds, " [shape=box];\n");
+ snprintf(buffer, 128, ", height=\"%g\"", round(requisition.height / G_GRAPH_NODE_GET_CLASS(node)->dpi_y) + 1.0);
+ cmds = stradd(cmds, buffer);
+
+ cmds = stradd(cmds, "];\n");
return cmds;
@@ -184,6 +238,13 @@ char *g_graph_node_register_for_dot(const GGraphNode *node, char *cmds)
void g_graph_node_place(const GGraphNode *node, GtkFixed *fixed, gint x, gint y)
{
+ GtkRequisition requisition; /* Taille à l'écran actuelle */
+
+ gtk_widget_size_request(GTK_WIDGET(node->view), &requisition);
+
+ x -= requisition.width / 2;
+ y -= requisition.height / 2;
+
gtk_fixed_put(fixed, GTK_WIDGET(node->view), x, y);
}