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; } }
char *setv(Agraph_t *g, char *attr, char *val) { Agsym_t *a; if (!g || !attr || !val) return NULL; a = agfindattr(g->root, attr); if (!a) a = agraphattr(g->root, attr, empty_string); myagxset(g, a, val); return val; }
/*---------------------------------------------------------------------------- * initialize the internal graphviz structure. */ static void cls_inherit_graph_init (AnjutaClassInheritance *plugin, gchar* graph_label) { Agsym_t *sym; gchar dpi_text[16]; snprintf (dpi_text, 16, "%d", INCH_TO_PIXELS_CONVERSION_FACTOR); aginit (); plugin->graph = agopen (graph_label, AGDIGRAPH); plugin->gvc = gvContext(); if (!(sym = agfindattr(plugin->graph->proto->n, "dpi"))) sym = agraphattr(plugin->graph, "dpi", dpi_text); agxset(plugin->graph, sym->index, dpi_text); }
/* 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); }
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; }
/* * Print in Graphviz format */ void FA_dump_dot_fn(struct FA *fa, const char *ofname, int inc_step) { struct FA_State *st_from = NULL; struct FA_State *st_to = NULL; struct FA_State *st = NULL; GVC_t *gvc = NULL; graph_t *g = NULL; Agedge_t *e = NULL; Agnode_t *e_from = NULL; Agnode_t *e_to = NULL; Agnode_t *state0 = NULL; Agnode_t **nodes = NULL; Agnode_t *node = NULL; char *argv[4] = { NULL }; char buf[4096]; int argc; int i; int ri, ci, ai; FA_ASSERT(fa); ASSERT(ofname != NULL); ASSERT(inc_step == FA_INSERT_EXT || inc_step == FA_INSERT_NOTHING); memset(buf, 0, sizeof(buf)); if (inc_step == FA_INSERT_EXT) (void)snprintf(buf, sizeof(buf) - 1, "-o%s.%d", ofname, fa->simstep); else (void)snprintf(buf, sizeof(buf) - 1, "-o%s", ofname); argv[0] = strdup("FLViz.exe"); argv[1] = strdup(buf); argv[2] = strdup("-Tsvg"); argv[3] = NULL; argc = (sizeof(argv) / sizeof(argv[0])) - 1; gvc = gvContext(); ASSERT(gvc != NULL); gvParseArgs(gvc, argc, argv); memset(buf, 0, sizeof(buf)); snprintf(buf, sizeof(buf) - 1, "flvizstep%d", fa->simstep); g = agopen(buf, AGDIGRAPHSTRICT); /* Ustawianie atrybutów dla grafu */ agraphattr(g, "size", "8,8"); agraphattr(g, "rankdir", "LR"); /* Stan 0 */ state0 = agnode(g, "state0"); agsafeset(state0, "label", "", ""); agsafeset(state0, "width", "0.1", ""); agsafeset(state0, "height", "0.1", ""); agsafeset(state0, "shape", "box", ""); agsafeset(state0, "style", "filled", ""); agsafeset(state0, "fillcolor", "white", ""); agsafeset(state0, "color", "white", ""); nodes = (Agnode_t **)calloc(sizeof(Agnode_t *), fa->nstates); ASSERT(nodes != NULL); for (i = 0; i < fa->nstates; i++) { st = &fa->states[i]; node = agnode(g, st->name); agsafeset(node, "label", st->name, ""); agsafeset(node, "width", "0.5", ""); agsafeset(node, "height", "0.5", ""); agsafeset(node, "shape", "circle", ""); if (st->flag & FA_STATE_LAST) agsafeset(node, "shape", "doublecircle", ""); agsafeset(node, "style", "filled", ""); agsafeset(node, "fillcolor", "gray", ""); if (st->flag & FA_STATE_CURR) agsafeset(node, "fillcolor", "green", ""); st->obj = node; nodes[i] = node; } e = agedge(g, state0, (Agnode_t *)fa->states[0].obj); agsafeset(e, "label", "START", ""); if (fa->trans_from == fa->state0 && fa->trans_to == &fa->states[0]) agsafeset(e, "color", "green", ""); for (ri = 0; ri < fa->nstates; ri++) { st_from = fa->transt[ri][0]; e_from = (Agnode_t *)st_from->obj; for (ai = 0; ai < fa->nalpha; ai++) { ci = ai + 1; st_to = fa->transt[ri][ci]; if (st_to == NULL) continue; e_to = (Agnode_t *)st_to->obj; e = agedge(g, e_from, e_to); agsafeset(e, "label", fa->alpha[ai].word, ""); if (fa->trans_from == st_from && fa->trans_to == st_to) agsafeset(e, "color", "green", ""); } } /* Compute a layout using layout engine from command line args */ gvLayoutJobs(gvc, g); /* Write the graph according to -T and -o options */ gvRenderJobs(gvc, g); gvFreeLayout(gvc, g); agclose(g); gvFreeContext(gvc); fa->simstep++; }