static void attr_set(char *name, char *value) { Agsym_t *ap = NULL; char *defval = ""; if (In_decl && (G->root == G)) defval = value; switch (Current_class) { case TAG_NODE: ap = agfindattr(G->proto->n,name); if (ap == NULL) ap = agnodeattr(AG.parsed_g,name,defval); else if (ap->fixed && In_decl) return; agxset(N,ap->index,value); break; case TAG_EDGE: ap = agfindattr(G->proto->e,name); if (ap == NULL) ap = agedgeattr(AG.parsed_g,name,defval); else if (ap->fixed && In_decl) return; agxset(E,ap->index,value); break; case 0: /* default */ case TAG_GRAPH: ap = agfindattr(G,name); if (ap == NULL) ap = agraphattr(AG.parsed_g,name,defval); else if (ap->fixed && In_decl) return; agxset(G,ap->index,value); break; } }
/* constrainY: * See constrainX. */ static void constrainY(graph_t* g, nitem* nlist, int nnodes, intersectfn ifn, int ortho) { Dt_t *list = dtopen(&constr, Dtobag); nitem *p = nlist; graph_t *cg; int i; for (i = 0; i < nnodes; i++) { p->val = p->pos.y; dtinsert(list, p); p++; } if (ortho) cg = mkConstraintG(g, list, ifn, distY); else cg = mkNConstraintG(g, list, ifn, distY); rank(cg, 2, INT_MAX); #ifdef DEBUG { Agsym_t *mlsym = agedgeattr(cg, "minlen", ""); Agsym_t *rksym = agnodeattr(cg, "rank", ""); char buf[100]; node_t *n; edge_t *e; for (n = agfstnode(cg); n; n = agnxtnode(cg, n)) { sprintf(buf, "%d", ND_rank(n)); agxset(n, rksym->index, buf); for (e = agfstedge(cg, n); e; e = agnxtedge(cg, e, n)) { sprintf(buf, "%d", ED_minlen(e)); agxset(e, mlsym->index, buf); } } } #endif p = nlist; for (i = 0; i < nnodes; i++) { int newpos, oldpos, delta; oldpos = p->pos.y; newpos = ND_rank(p->cnode); delta = newpos - oldpos; p->pos.y = newpos; p->bb.LL.y += delta; p->bb.UR.y += delta; p++; } closeGraph(cg); dtclose(list); }
char *setv(Agedge_t *e, char *attr, char *val) { Agraph_t *g; Agsym_t *a; if (!e || !attr || !val) return NULL; g = e->tail->graph->root; a = agfindattr(g->proto->e, attr); if (!a) a = agedgeattr(g, attr, empty_string); myagxset(e, a, val); return val; }
/* setAttr: * Sets object's name attribute to the given value. * Creates the attribute if not already set. */ static Agsym_t *setAttr(graph_t * g, void *obj, char *name, char *value, Agsym_t * ap) { if (ap == NULL) { switch (agobjkind(obj)) { case AGGRAPH: ap = agraphattr(g, name, ""); break; case AGNODE: ap = agnodeattr(g, name, ""); break; case AGEDGE: ap = agedgeattr(g, name, ""); break; } } agxset(obj, ap->index, value); return ap; }
int agsafeset(void* obj, char* name, char* value, char* def) { Agsym_t* a = agfindattr(obj, name); if (a == NULL) { if (!def) def = ""; switch (TAG_OF(obj)) { case TAG_GRAPH: a = agraphattr(((Agraph_t*)obj)->root, name, def); break; case TAG_NODE: a = agnodeattr(((Agnode_t*)obj)->graph, name, def); break; case TAG_EDGE: a = agedgeattr(((Agedge_t*)obj)->head->graph, name, def); break; } } return agxset(obj, a->index, value); }
static inline Agsym_t* _agedgeattr(Agraph_t* object, QString attr, QString value){ setlocale(LC_NUMERIC,"en_US.UTF-8"); return agedgeattr(object, const_cast<char *>(qPrintable(attr)),const_cast<char *>(qPrintable(value))); }
SBML_ODESOLVER_API int drawJacoby(cvodeData_t *data, char *file, char *format) { #if !USE_GRAPHVIZ SolverError_error( WARNING_ERROR_TYPE, SOLVER_ERROR_NO_GRAPHVIZ, "odeSolver has been compiled without GRAPHIZ functionality. ", "Graphs are printed to stdout in the graphviz' .dot format."); drawJacobyTxt(data, file); #else int i, j; GVC_t *gvc; Agraph_t *g; Agnode_t *r; Agnode_t *s; Agedge_t *e; Agsym_t *a; char name[WORDSIZE]; char label[WORDSIZE]; char *output[3]; char *command = "dot"; char *formatopt; char *outfile; /* setting name of outfile */ ASSIGN_NEW_MEMORY_BLOCK(outfile, strlen(file)+ strlen(format)+7, char, 0); sprintf(outfile, "-o%s_jm.%s", file, format); /* setting output format */ ASSIGN_NEW_MEMORY_BLOCK(formatopt, strlen(format)+3, char, 0); sprintf(formatopt, "-T%s", format); /* construct command-line */ output[0] = command; output[1] = formatopt; output[2] = outfile; output[3] = NULL; /* set up renderer context */ gvc = (GVC_t *) gvContext(); #if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION < 4 dotneato_initialize(gvc, 3, output); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION == 4 parse_args(gvc, 3, output); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION >= 6 || GRAPHVIZ_MAJOR_VERSION >= 3 gvParseArgs(gvc, 3, output); #endif g = agopen("G", AGDIGRAPH); /* avoid overlapping nodes, for graph embedding by neato */ a = agraphattr(g, "overlap", ""); agxset(g, a->index, "scale"); /* set graph label */ if ( Model_isSetName(data->model->m) ) sprintf(label, "%s at time %g", Model_getName(data->model->m), data->currenttime); else if ( Model_isSetId(data->model->m) ) sprintf(label, "%s at time %g", Model_getId(data->model->m), data->currenttime); else sprintf(label, "label=\"at time %g\";\n", data->currenttime); a = agraphattr(g, "label", ""); agxset(g, a->index, label); /* Set edges from species A to species B if the corresponding entry in the jacobian ((d[B]/dt)/d[A]) is not '0'. Set edge color 'red' and arrowhead 'tee' if negative. */ for ( i=0; i<data->model->neq; i++ ) { for ( j=0; j<data->model->neq; j++ ) { if ( evaluateAST(data->model->jacob[i][j], data) != 0 ) { sprintf(name, "%s", data->model->names[j]); r = agnode(g,name); agset(r, "label", data->model->names[j]); sprintf(label, "%s.htm", data->model->names[j]); a = agnodeattr(g, "URL", ""); agxset(r, a->index, label); sprintf(name,"%s", data->model->names[i]); s = agnode(g,name); agset(s, "label", data->model->names[i]); sprintf(label, "%s.htm", data->model->names[i]); a = agnodeattr(g, "URL", ""); agxset(s, a->index, label); e = agedge(g,r,s); a = agedgeattr(g, "label", ""); sprintf(name, "%g", evaluateAST(data->model->jacob[i][j], data)); agxset (e, a->index, name); if ( evaluateAST(data->model->jacob[i][j], data) < 0 ) { a = agedgeattr(g, "arrowhead", ""); agxset(e, a->index, "tee"); a = agedgeattr(g, "color", ""); agxset(e, a->index, "red"); } } } } /* Compute a layout */ #if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION <= 2 gvBindContext(gvc, g); dot_layout(g); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION == 4 gvlayout_layout(gvc, g); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION >= 6 || GRAPHVIZ_MAJOR_VERSION >= 3 gvLayoutJobs(gvc, g); #endif /* Write the graph according to -T and -o options */ #if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION <= 2 dotneato_write(gvc); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION == 4 emit_jobs(gvc, g); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION >= 6 || GRAPHVIZ_MAJOR_VERSION >= 3 gvRenderJobs(gvc, g); #endif /* Clean out layout data */ #if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION <= 2 dot_cleanup(g); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION == 4 gvlayout_cleanup(gvc, g); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION >= 6 || GRAPHVIZ_MAJOR_VERSION >= 3 gvFreeLayout(gvc, g); #endif /* Free graph structures */ #if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION <= 2 dot_cleanup(g); #endif agclose(g); /* Clean up output file and errors */ #if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION <= 2 gvFREEcontext(gvc); dotneato_eof(gvc); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION == 4 dotneato_terminate(gvc); #elif (GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION >= 6) || GRAPHVIZ_MAJOR_VERSION >= 3 gvFreeContext(gvc); #endif xfree(formatopt); xfree(outfile); #endif return 1; }
SBML_ODESOLVER_API int drawModel(Model_t *m, char* file, char *format) { #if !USE_GRAPHVIZ SolverError_error( WARNING_ERROR_TYPE, SOLVER_ERROR_NO_GRAPHVIZ, "odeSolver has been compiled without GRAPHIZ functionality. ", "Graphs are printed to stdout in the graphviz' .dot format."); drawModelTxt(m, file); #else GVC_t *gvc; Agraph_t *g; Agnode_t *r; Agnode_t *s; Agedge_t *e; Agsym_t *a; Species_t *sp; Reaction_t *re; const ASTNode_t *math; SpeciesReference_t *sref; ModifierSpeciesReference_t *mref; char *output[4]; char *command = "dot"; char *formatopt; char *outfile; int i,j; int reversible; char name[WORDSIZE]; char label[WORDSIZE]; /* setting name of outfile */ ASSIGN_NEW_MEMORY_BLOCK(outfile, strlen(file)+ strlen(format)+7, char, 0); sprintf(outfile, "-o%s_rn.%s", file, format); /* setting output format */ ASSIGN_NEW_MEMORY_BLOCK(formatopt, strlen(format)+3, char, 0); sprintf(formatopt, "-T%s", format); /* construct command-line */ output[0] = command; output[1] = formatopt; output[2] = outfile; output[3] = NULL; /* set up renderer context */ gvc = (GVC_t *) gvContext(); #if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION < 4 dotneato_initialize(gvc, 3, output); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION == 4 parse_args(gvc, 3, output); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION >= 6 || GRAPHVIZ_MAJOR_VERSION >= 3 gvParseArgs(gvc, 3, output); #endif g = agopen("G", AGDIGRAPH); /* avoid overlapping nodes, for graph embedding by neato */ a = agraphattr(g, "overlap", ""); agxset(g, a->index, "scale"); for ( i=0; i<Model_getNumReactions(m); i++ ) { re = Model_getReaction(m,i); reversible = Reaction_getReversible(re); sprintf(name, "%s", Reaction_getId(re)); r = agnode(g,name); a = agnodeattr(g, "shape", "ellipse"); agxset(r, a->index, "box"); sprintf(label, "%s", Reaction_isSetName(re) ? Reaction_getName(re) : Reaction_getId(re)); agset(r, "label", label); sprintf(label, "%s.htm", Reaction_getId(re)); a = agnodeattr(g, "URL", ""); agxset(r, a->index, label); for ( j=0; j<Reaction_getNumModifiers(re); j++ ) { mref = Reaction_getModifier(re,j); sp = Model_getSpeciesById(m, ModifierSpeciesReference_getSpecies(mref)); sprintf(name,"%s", Species_getId(sp)); s = agnode(g,name); sprintf(label, "%s", Species_isSetName(sp) ? Species_getName(sp) : Species_getId(sp)); agset(s, "label", label); if ( Species_getBoundaryCondition(sp) ) { a = agnodeattr(g, "color", ""); agxset(s, a->index, "blue"); } if ( Species_getConstant(sp) ) { a = agnodeattr(g, "color", ""); agxset(s, a->index, "green4"); } sprintf(label, "%s.htm", Species_getId(sp)); a = agnodeattr(g, "URL", ""); agxset(s, a->index, label); e = agedge(g,s,r); a = agedgeattr(g, "style", ""); agxset(e, a->index, "dashed"); a = agedgeattr(g, "arrowhead", ""); agxset(e, a->index, "odot"); } for ( j=0; j<Reaction_getNumReactants(re); j++ ) { sref = Reaction_getReactant(re,j); sp = Model_getSpeciesById(m, SpeciesReference_getSpecies(sref)); sprintf(name,"%s", Species_getId(sp)); s = agnode(g, name); sprintf(label, "%s", Species_isSetName(sp) ? Species_getName(sp) : Species_getId(sp)); agset(s, "label", label); if ( Species_getBoundaryCondition(sp) ) { a = agnodeattr(g, "color", ""); agxset(s, a->index, "blue"); } if ( Species_getConstant(sp) ) { a = agnodeattr(g, "color", ""); agxset(s, a->index, "green4"); } sprintf(label, "%s.htm", Species_getId(sp)); a = agnodeattr(g, "URL", ""); agxset(s, a->index, label); e = agedge(g,s,r); a = agedgeattr(g, "label", ""); if ( (SpeciesReference_isSetStoichiometryMath(sref)) ) { math = SpeciesReference_getStoichiometryMath(sref); if ( (strcmp(SBML_formulaToString(math),"1") != 0) ) { agxset (e, a->index, SBML_formulaToString(math)); } } else { if ( SpeciesReference_getStoichiometry(sref) != 1 ) { sprintf(name, "%g", SpeciesReference_getStoichiometry(sref)); agxset (e, a->index, name); } } if ( reversible == 1 ) { a = agedgeattr(g, "arrowtail", ""); agxset(e, a->index, "onormal"); } } for ( j=0; j<Reaction_getNumProducts(re); j++ ) { sref = Reaction_getProduct(re,j); sp = Model_getSpeciesById(m, SpeciesReference_getSpecies(sref)); sprintf(name,"%s", Species_getId(sp)); s = agnode(g,name); sprintf(label, "%s", Species_isSetName(sp) ? Species_getName(sp) : Species_getId(sp)); agset(s, "label", label); if ( Species_getBoundaryCondition(sp) ) { a = agnodeattr(g, "color", ""); agxset(s, a->index, "blue"); } if ( Species_getConstant(sp) ) { a = agnodeattr(g, "color", ""); agxset(s, a->index, "green4"); } sprintf(label, "%s.htm", Species_getId(sp)); a = agnodeattr(g, "URL", ""); agxset(s, a->index, label); e = agedge(g,r,s); a = agedgeattr(g, "label", ""); if ( SpeciesReference_isSetStoichiometryMath(sref) ) { math = SpeciesReference_getStoichiometryMath(sref); if ( (strcmp(SBML_formulaToString(math),"1") != 0) ) { agxset (e, a->index, SBML_formulaToString(math)); } } else { if ( SpeciesReference_getStoichiometry(sref) != 1 ) { sprintf(name, "%g",SpeciesReference_getStoichiometry(sref)); agxset (e, a->index,name); } } if ( reversible == 1 ) { a = agedgeattr(g, "arrowtail", ""); agxset(e, a->index, "onormal"); } } } /* Compute a layout */ #if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION <= 2 gvBindContext(gvc, g); dot_layout(g); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION == 4 gvlayout_layout(gvc, g); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION >= 6 || GRAPHVIZ_MAJOR_VERSION >= 3 gvLayoutJobs(gvc, g); #endif /* Write the graph according to -T and -o options */ #if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION <= 2 dotneato_write(gvc); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION == 4 emit_jobs(gvc, g); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION >= 6 || GRAPHVIZ_MAJOR_VERSION >= 3 gvRenderJobs(gvc, g); #endif /* Clean out layout data */ #if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION <= 2 dot_cleanup(g); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION == 4 gvlayout_cleanup(gvc, g); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION >= 6 || GRAPHVIZ_MAJOR_VERSION >= 3 gvFreeLayout(gvc, g); #endif /* Free graph structures */ #if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION <= 2 dot_cleanup(g); #else agclose(g); #endif /* Clean up output file and errors */ #if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION <= 2 gvFREEcontext(gvc); dotneato_eof(gvc); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION == 4 dotneato_terminate(gvc); #elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION >= 6 || GRAPHVIZ_MAJOR_VERSION >= 3 gvFreeContext(gvc); #endif xfree(formatopt); xfree(outfile); #endif return 1; }
main(int argc, char *argv[]) { Agraph_t **gs; Agraph_t **ccs; Agraph_t *g; Agraph_t *gp; char *fname; FILE *fp; int cnt; int i; init(argc, argv); if (!Files) { fprintf(stderr, "No input files given\n"); exit(1); } PSinputscale = POINTS_PER_INCH; if (doComps) { if (verbose) fprintf(stderr, "do Comps\n"); while (fname = *Files++) { fp = fopen(fname, "r"); if (!fp) { fprintf(stderr, "Could not open %s\n", fname); continue; } g = agread(fp); fclose(fp); if (!g) { fprintf(stderr, "Could not read graph\n"); continue; } printf("%s %d nodes %d edges %sconnected\n", g->name, agnnodes(g), agnedges(g), (isConnected(g) ? "" : "not ")); gs = ccomps(g, &cnt, "abc"); for (i = 0; i < cnt; i++) { gp = gs[i]; printf(" %s %d nodes %d edges\n", gp->name, agnnodes(gp), agnedges(gp)); } } } else { gs = N_GNEW(nFiles, Agraph_t *); cnt = 0; while (fname = Files[cnt]) { fp = fopen(fname, "r"); if (!fp) { fprintf(stderr, "Could not open %s\n", fname); exit(1); } g = agread(fp); fclose(fp); if (!g) { fprintf(stderr, "Could not read graph\n"); exit(1); } if (!single) { graph_init(g); ptest_initGraph(g); } initPos(g); /* if (Verbose) dumpG (g); */ gs[cnt++] = g; } if (single) { Agraph_t *root; Agnode_t *n; Agnode_t *np; Agnode_t *tp; Agnode_t *hp; Agedge_t *e; Agedge_t *ep; root = agopen("root", 0); agedgeattr(root, "pos", ""); for (i = 0; i < cnt; i++) { g = gs[i]; for (n = agfstnode(g); n; n = agnxtnode(g, n)) { if (agfindnode(root, n->name)) { fprintf(stderr, "Error: node %s in graph %d (%s) previously added\n", n->name, i, Files[i]); exit(1); } np = agnode(root, n->name); ND_pos(np)[0] = ND_pos(n)[0]; ND_pos(np)[1] = ND_pos(n)[1]; ND_coord_i(np).x = ND_coord_i(n).x; ND_coord_i(np).y = ND_coord_i(n).y; } for (n = agfstnode(g); n; n = agnxtnode(g, n)) { tp = agfindnode(root, n->name); for (e = agfstout(g, n); e; e = agnxtout(g, e)) { hp = agfindnode(root, e->head->name); ep = agedge(root, tp, hp); ED_spl(ep) = ED_spl(e); } } } graph_init(root); ptest_initGraph(root); ccs = ccomps(root, &cnt, 0); packGraphs(cnt, ccs, root, margin, doEdges); if (!doEdges) copyPos(root); else State = GVSPLINES; attach_attrs(root); for (i = 0; i < cnt; i++) { agdelete(root, ccs[i]); } agwrite(root, stdout); } else { packGraphs(cnt, gs, 0, margin, doEdges); if (doEdges) State = GVSPLINES; for (i = 0; i < cnt; i++) { if (!doEdges) copyPos(gs[i]); attach_attrs(gs[i]); agwrite(gs[i], stdout); } } } }
static inline Agsym_t* _agedgeattr(Agraph_t* object, QString attr, QString value){ setlocale(LC_NUMERIC,"en_US.UTF-8"); // Débug séparateur de décimales en version française return agedgeattr(object, const_cast<char *>(qPrintable(attr)),const_cast<char *>(qPrintable(value))); }