/*****************************************************************************\ * * * graph.h * * mini-afficheur de graphes * * * \*****************************************************************************/ /*****************************************************************************\ * graph file structure * \*****************************************************************************/ /* Syntaxe: * Une entite par ligne, chaque champ separe par un blanc. * Syntaxe volontairement rigide pour simplifier le parsing * Title: T string * Node: N id x y label * Edge: E id from_id to_id */ /*****************************************************************************\ * data types * \*****************************************************************************/ /* La structure d'un noeud */ typedef struct _Node { int id; /* unique identifier (number) */ int x; /* position */ int y; int width; /* to be calculated */ int height; /* to be calculated */ char *label; /* text to be displayed */ int baseline_x; int baseline_y; struct _Node *next; /* next node in graph */ } *Node; /* la structure d'un arc */ typedef struct _Edge { int id; /* unique identifier (number) */ int from_id; /* nodes connected by id */ int to_id; Node from; /* the nodes themselves */ Node to; struct _Edge *next; /* next edge in graph */ } *Edge; /* un graphe */ typedef struct _Graph { char *title; /* symbolic */ Node nodes; /* null-terminated list */ Edge edges; /* null-terminated list */ } *Graph; /*****************************************************************************\ * provided functions * \*****************************************************************************/ /* read a graph from file */ Graph ReadGraph(/* FILE *stream; */); /* writes textual representation */ void PrintGraph(/* Graph graph; FILE *stream; */); /* retourne la liste des edges liees au node donne */ Edge RelatedEdges(/* Graph graph; Node node; */); /* free une liste de edges */ FreeEdges(/* Edge edge; */); /* affiche une liste de nodes */ DisplayNodes(/* Node nodes; Display *dpy; Window window; GC draw_gc; GC fill_gc; */); /* affiche une liste de edges */ DisplayEdges(/* edges, dpy, window, gc) Edge edges; Display *dpy; Window window; GC gc; */); /*****************************************************************************\ * functions to be coded * \*****************************************************************************/ /* affiche un graph */ void DisplayGraph(/* Display *dpy; Window window; Graph graph; GC draw_gc; foreground: black GC fill_gc; background: white */); /* affiche un node */ DisplayNode(/* Node node; Display *dpy; Window window; GC draw_gc; GC fill_gc; */); /* affiche une edge */ DisplayEdge(/* Edge edge; Display *dpy; Window window; GC gc; */); /* retourne le premier node dont la bounding box contient le point (x,y) */ Node FindNode(/* Graph graph; int x; int y; */); /* a appeller apres avoir lu le graphe pour calculer les tailles des boites */ void FixGraphLabelDimensions(/* Graph graph; Font font; */);