static void undoCompound(edge_t * e, graph_t * clg) { node_t *t = agtail(e); node_t *h = aghead(e); node_t *ntail; node_t *nhead; edge_t* ce; if (!(IS_CLUST_NODE(t) || IS_CLUST_NODE(h))) return; ntail = mapN(t, clg); nhead = mapN(h, clg); ce = cloneEdge(e, ntail, nhead); /* transfer drawing information */ ED_spl(ce) = ED_spl(e); ED_spl(e) = NULL; ED_label(ce) = ED_label(e); ED_label(e) = NULL; ED_xlabel(ce) = ED_xlabel(e); ED_xlabel(e) = NULL; ED_head_label(ce) = ED_head_label(e); ED_head_label(e) = NULL; ED_tail_label(ce) = ED_tail_label(e); ED_tail_label(e) = NULL; gv_cleanup_edge(e); }
static void undoCompound(edge_t * e, graph_t * clg) { node_t *t = e->tail; node_t *h = e->head; node_t *ntail; node_t *nhead; if (!(IS_CLUST_NODE(t) || IS_CLUST_NODE(h))) return; ntail = mapN(t, clg); nhead = mapN(h, clg); cloneEdge(e, ntail, nhead); }
/* mapN: * Convert cluster nodes back to ordinary nodes * If n is already ordinary, return it. * Otherwise, we know node's name is "__i:xxx" * where i is some number and xxx is the nodes's original name. * Create new node of name xxx if it doesn't exist and add n to clg * for later deletion. */ static node_t *mapN(node_t * n, graph_t * clg) { extern Agdict_t *agdictof(void *); node_t *nn; char *name; graph_t *g = n->graph; Agdict_t *d; Agsym_t **list; Agsym_t *sym; if (!(IS_CLUST_NODE(n))) return n; aginsert(clg, n); name = strchr(n->name, ':'); assert(name); name++; if ((nn = agfindnode(g, name))) return nn; nn = agnode(g, name); /* Set all attributes to default */ d = agdictof(n); list = d->list; while ((sym = *list++)) { /* Can use pointer comparison because of ref strings. */ if (agxget(nn, sym->index) != sym->value) agxset(nn, sym->index, sym->value); } return nn; }
/* mapN: * Convert cluster nodes back to ordinary nodes * If n is already ordinary, return it. * Otherwise, we know node's name is "__i:xxx" * where i is some number and xxx is the nodes's original name. * Create new node of name xxx if it doesn't exist and add n to clg * for later deletion. */ static node_t *mapN(node_t * n, graph_t * clg) { node_t *nn; char *name; graph_t *g = agraphof(n); Agsym_t *sym; if (!(IS_CLUST_NODE(n))) return n; agsubnode(clg, n, 1); name = strchr(agnameof(n), ':'); assert(name); name++; if ((nn = agfindnode(g, name))) return nn; nn = agnode(g, name, 1); agbindrec(nn, "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE); /* Set all attributes to default */ for (sym = agnxtattr(g, AGNODE, NULL); sym; (sym = agnxtattr(g, AGNODE, sym))) { if (agxget(nn, sym) != sym->defval) agxset(nn, sym, sym->defval); } return nn; }
/* processClusterEdges: * Look for cluster edges. Replace cluster edge endpoints * corresponding to a cluster with special cluster nodes. * Delete original nodes. * Return 0 if no cluster edges; 1 otherwise. */ int processClusterEdges(graph_t * g) { int rv; node_t *n; node_t *nxt; edge_t *e; graph_t *clg; agxbuf xb; Dt_t *map; Dt_t *cmap = mkClustMap (g); unsigned char buf[SMALLBUF]; map = dtopen(&mapDisc, Dtoset); clg = agsubg(g, "__clusternodes",1); agbindrec(clg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE); agxbinit(&xb, SMALLBUF, buf); for (n = agfstnode(g); n; n = agnxtnode(g, n)) { if (IS_CLUST_NODE(n)) continue; for (e = agfstout(g, n); e; e = agnxtout(g, e)) { checkCompound(e, clg, &xb, map, cmap); } } agxbfree(&xb); dtclose(map); rv = agnnodes(clg); for (n = agfstnode(clg); n; n = nxt) { nxt = agnxtnode(clg, n); agdelete(g, n); } agclose(clg); if (rv) SET_CLUST_EDGE(g); dtclose(cmap); return rv; }
static void writenodeandport(FILE * fp, node_t * node, char *port) { char *name; if (IS_CLUST_NODE(node)) name = strchr(node->name, ':') + 1; else name = node->name; fprintf(fp, "%s", agcanonical(name)); /* slimey i know */ if (port && *port) fprintf(fp, ":%s", agcanonical(port)); }
static void writenodeandport(FILE * f, node_t * node, char *port) { char *name; if (IS_CLUST_NODE(node)) name = canon (agraphof(node), strchr(agnameof(node), ':') + 1); else name = agcanonStr (agnameof(node)); printstring(f, " ", name); /* slimey i know */ if (port && *port) printstring(f, ":", agcanonStr(port)); }
/* _write_plain: */ void write_plain(GVJ_t * job, graph_t * g, FILE * f, boolean extend) { int i, j, splinePoints; char *tport, *hport; node_t *n; edge_t *e; bezier bz; pointf pt; char *lbl; char* fillcolor; #ifdef WITH_CGRAPH putstr = g->clos->disc.io->putstr; #endif // setup_graph(job, g); setYInvert(g); pt = GD_bb(g).UR; printdouble(f, "graph ", job->zoom); printdouble(f, " ", PS2INCH(pt.x)); printdouble(f, " ", PS2INCH(pt.y)); agputc('\n', f); for (n = agfstnode(g); n; n = agnxtnode(g, n)) { if (IS_CLUST_NODE(n)) continue; printstring(f, "node ", agcanonStr(agnameof(n))); printpoint(f, ND_coord(n)); if (ND_label(n)->html) /* if html, get original text */ #ifndef WITH_CGRAPH lbl = agcanonStr (agxget(n, N_label->index)); #else lbl = agcanonStr (agxget(n, N_label)); #endif else lbl = canon(agraphof(n),ND_label(n)->text); printdouble(f, " ", ND_width(n)); printdouble(f, " ", ND_height(n)); printstring(f, " ", lbl); printstring(f, " ", late_nnstring(n, N_style, "solid")); printstring(f, " ", ND_shape(n)->name); printstring(f, " ", late_nnstring(n, N_color, DEFAULT_COLOR)); fillcolor = late_nnstring(n, N_fillcolor, ""); if (fillcolor[0] == '\0') fillcolor = late_nnstring(n, N_color, DEFAULT_FILL); printstring(f, " ", fillcolor); agputc('\n', f); }
/* _write_plain: */ void write_plain(GVJ_t * job, graph_t * g, FILE * f, bool extend) { int i, j, splinePoints; char *tport, *hport; node_t *n; edge_t *e; bezier bz; point pt; char *lbl; // setup_graph(job, g); setYInvert(g); pt = GD_bb(g).UR; fprintf(f, "graph %.3f %.3f %.3f\n", job->zoom, PS2INCH(pt.x), PS2INCH(pt.y)); for (n = agfstnode(g); n; n = agnxtnode(g, n)) { if (IS_CLUST_NODE(n)) continue; fprintf(f, "node %s ", agcanonical(n->name)); printptf(f, ND_coord_i(n)); if (ND_label(n)->html) /* if html, get original text */ lbl = agxget(n, N_label->index); else lbl = ND_label(n)->text; if (lbl) lbl = agcanonical(lbl); else lbl = "\"\""; fprintf(f, " %.3f %.3f %s %s %s %s %s\n", ND_width(n), ND_height(n), lbl, late_nnstring(n, N_style, "solid"), ND_shape(n)->name, late_nnstring(n, N_color, DEFAULT_COLOR), late_nnstring(n, N_fillcolor, DEFAULT_FILL)); } for (n = agfstnode(g); n; n = agnxtnode(g, n)) { for (e = agfstout(g, n); e; e = agnxtout(g, e)) { if (extend && e->attr) { tport = e->attr[TAILX]; hport = e->attr[HEADX]; } else tport = hport = ""; if (ED_spl(e)) { splinePoints = 0; for (i = 0; i < ED_spl(e)->size; i++) { bz = ED_spl(e)->list[i]; splinePoints += bz.size; } fprintf(f, "edge "); writenodeandport(f, e->tail, tport); fprintf(f, " "); writenodeandport(f, e->head, hport); fprintf(f, " %d", splinePoints); for (i = 0; i < ED_spl(e)->size; i++) { bz = ED_spl(e)->list[i]; for (j = 0; j < bz.size; j++) printptf(f, bz.list[j]); } } if (ED_label(e)) { fprintf(f, " %s", agcanonical(ED_label(e)->text)); printptf(f, ED_label(e)->p); } fprintf(f, " %s %s\n", late_nnstring(e, E_style, "solid"), late_nnstring(e, E_color, DEFAULT_COLOR)); } } fprintf(f, "stop\n"); }
/* _write_plain: */ void write_plain(GVJ_t * job, graph_t * g, FILE * f, boolean extend) { int i, j, splinePoints; char *tport, *hport; node_t *n; edge_t *e; bezier bz; pointf pt; char *lbl; char* fillcolor; putstr = g->clos->disc.io->putstr; // setup_graph(job, g); setYInvert(g); pt = GD_bb(g).UR; printdouble(f, "graph ", job->zoom); printdouble(f, " ", PS2INCH(pt.x)); printdouble(f, " ", PS2INCH(pt.y)); agputc('\n', f); for (n = agfstnode(g); n; n = agnxtnode(g, n)) { if (IS_CLUST_NODE(n)) continue; printstring(f, "node ", agcanonStr(agnameof(n))); printpoint(f, ND_coord(n)); if (ND_label(n)->html) /* if html, get original text */ lbl = agcanonStr (agxget(n, N_label)); else lbl = canon(agraphof(n),ND_label(n)->text); printdouble(f, " ", ND_width(n)); printdouble(f, " ", ND_height(n)); printstring(f, " ", lbl); printstring(f, " ", late_nnstring(n, N_style, "solid")); printstring(f, " ", ND_shape(n)->name); printstring(f, " ", late_nnstring(n, N_color, DEFAULT_COLOR)); fillcolor = late_nnstring(n, N_fillcolor, ""); if (fillcolor[0] == '\0') fillcolor = late_nnstring(n, N_color, DEFAULT_FILL); printstring(f, " ", fillcolor); agputc('\n', f); } for (n = agfstnode(g); n; n = agnxtnode(g, n)) { for (e = agfstout(g, n); e; e = agnxtout(g, e)) { if (extend) { //assuming these two attrs have already been created by cgraph if (!(tport = agget(e,"tailport"))) tport = ""; if (!(hport = agget(e,"headport"))) hport = ""; } else tport = hport = ""; if (ED_spl(e)) { splinePoints = 0; for (i = 0; i < ED_spl(e)->size; i++) { bz = ED_spl(e)->list[i]; splinePoints += bz.size; } printstring(f, NULL, "edge"); writenodeandport(f, agtail(e), tport); writenodeandport(f, aghead(e), hport); printint(f, " ", splinePoints); for (i = 0; i < ED_spl(e)->size; i++) { bz = ED_spl(e)->list[i]; for (j = 0; j < bz.size; j++) printpoint(f, bz.list[j]); } } if (ED_label(e)) { printstring(f, " ", canon(agraphof(agtail(e)),ED_label(e)->text)); printpoint(f, ED_label(e)->pos); } printstring(f, " ", late_nnstring(e, E_style, "solid")); printstring(f, " ", late_nnstring(e, E_color, DEFAULT_COLOR)); agputc('\n', f); } } agputs("stop\n", f); }
static void checkCompound(edge_t * e, graph_t * clg, agxbuf * xb, Dt_t * map, Dt_t* cmap) { graph_t *tg; graph_t *hg; node_t *cn; node_t *cn1; node_t *t = agtail(e); node_t *h = aghead(e); edge_t *ce; item *ip; if (IS_CLUST_NODE(h)) return; tg = MAPC(t); hg = MAPC(h); if (!tg && !hg) return; if (tg == hg) { agerr(AGWARN, "cluster cycle %s -- %s not supported\n", agnameof(t), agnameof(t)); return; } ip = mapEdge(map, e); if (ip) { cloneEdge(e, ip->t, ip->h); return; } if (hg) { if (tg) { if (agcontains(hg, tg)) { agerr(AGWARN, "tail cluster %s inside head cluster %s\n", agnameof(tg), agnameof(hg)); return; } if (agcontains(tg, hg)) { agerr(AGWARN, "head cluster %s inside tail cluster %s\n", agnameof(hg),agnameof(tg)); return; } cn = clustNode(t, tg, xb, clg); cn1 = clustNode(h, hg, xb, clg); ce = cloneEdge(e, cn, cn1); insertEdge(map, t, h, ce); } else { if (agcontains(hg, t)) { agerr(AGWARN, "tail node %s inside head cluster %s\n", agnameof(t), agnameof(hg)); return; } cn = clustNode(h, hg, xb, clg); ce = cloneEdge(e, t, cn); insertEdge(map, t, h, ce); } } else { if (agcontains(tg, h)) { agerr(AGWARN, "head node %s inside tail cluster %s\n", agnameof(h), agnameof(tg)); return; } cn = clustNode(t, tg, xb, clg); ce = cloneEdge(e, cn, h); insertEdge(map, t, h, ce); } }