Esempio n. 1
0
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;
	}
}
Esempio n. 2
0
static void
attach_phase_attrs (Agraph_t * g, int maxphase)
{
    Agsym_t* rk = agnodeattr(g,"rank","");
    Agsym_t* order = agnodeattr(g,"order","");
    Agnode_t* n;
    char buf[BUFSIZ];

    for (n = agfstnode(g); n; n = agnxtnode(g,n)) {
	if (maxphase >= 1) {
	    sprintf(buf, "%d", ND_rank(n));
	    ag_xset(n,rk,buf);
	}
	if (maxphase >= 2) {
	    sprintf(buf, "%d", ND_order(n));
	    ag_xset(n,order,buf);
	}
    }
}
Esempio n. 3
0
void dotneato_initialize(int argc, char** argv, char *str)
{
    char		*rest,c;
    int			i,nfiles;

    aginit();
    nfiles = 0;
    for (i = 1; i < argc; i++)
	if (argv[i][0] != '-') nfiles++;
    Files = N_NEW(nfiles + 1, char *);
    Files[nfiles++] = str;
    nfiles = 0;
    CmdName = argv[0];
    for (i = 1; i < argc; i++) {
	if (argv[i][0] == '-') {
	    rest = &(argv[i][2]);
	    switch (c = argv[i][1]) {
		case 'G': global_def(rest,agraphattr); break;
		case 'N': global_def(rest,agnodeattr); break;
		case 'E': global_def(rest,agedgeattr); break;
		case 'T': Output_lang = lang_select(rest); break;
		case 'V':
			  fprintf(stderr,"%s version %s (%s)\n",
				  Info[0], Info[1], Info[2]);
			  exit (0);
			  break;
		case 'l':
			  use_library(rest[0]?rest:(*argv[i+1]!='-'?argv[++i]:NULL));
			  break;
		case 'n': 
			  Nop = TRUE; 
			  if (isdigit(*rest)) Nop = atoi (rest);
			  break;
		case 'o':
			  Output_file = file_select(rest[0]?rest:argv[++i]);
			  break;
		case 's':
			  PSinputscale = (rest[0]?atof(rest):POINTS_PER_INCH);
			  break;
		case 'v': Verbose = TRUE; break;
		case 'x': Reduce = TRUE; break;
		default:
			  fprintf(stderr,"%s: option -%c unrecognized\n",CmdName,c);
	    }
	}
	else
	    Files[nfiles++] = argv[i];
    }
    if (Output_file == NULL) Output_file = stdout;
    /* set persistent attributes here */ 
    agnodeattr(NULL,"label",NODENAME_ESC);
}
Esempio n. 4
0
/* 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);
}
Esempio n. 5
0
File: demo.c Progetto: aosm/graphviz
int main(int argc, char** argv)
{
    Agraph_t *g;
    Agnode_t *n,*m;
    Agedge_t *e;
    Agsym_t  *a;
    GVC_t    *gvc;

    /* set up renderer context */
    gvc = gvContext();

    /* Accept -T and -o options like dot.
     * Input files are ignored in this demo. */
    dotneato_initialize(gvc, argc,argv);

    /* Create a simple digraph */
    g = agopen("g",AGDIGRAPH);
    n = agnode(g,"n");
    m = agnode(g,"m");
    e = agedge(g,n,m);

    /* Set an attribute - in this case one that affects the visible rendering */
    if (!(a = agfindattr(g->proto->n, "color")))
        a = agnodeattr(g, "color", "");
    agxset(n, a->index, "red");

    /* bind graph to GV context - currently must be done before layout */
    gvBindContext(gvc,g);

    /* Compute a layout */
    neato_layout(g);
    /* twopi_layout(g); */
    /* dot_layout(g); */

    /* Write the graph according to -T and -o options */
    dotneato_write(gvc);

    /* Clean out layout data */
    /* neato_cleanup(g); */
    /* twopi_cleanup(g); */
    /* dot_cleanup(g); */

    /* Free graph structures */
    agclose(g);

    /* Clean up output file and errors */
    dotneato_terminate(gvc);

    return 1;
}    
Esempio n. 6
0
char *setv(Agnode_t *n, char *attr, char *val)
{
    Agraph_t *g;
    Agsym_t *a;

    if (!n || !attr || !val)
	return NULL;
    g = n->graph->root;
    a = agfindattr(g->proto->n, attr);
    if (!a)
        a = agnodeattr(g, attr, empty_string);
    myagxset(n, a, val);
    return val;
}
Esempio n. 7
0
GVC_t *gvContextPlugins(const lt_symlist_t *builtins, int demand_loading)
{
    GVC_t *gvc;

#ifndef WITH_CGRAPH
    aginit();
    agnodeattr(NULL, "label", NODENAME_ESC);
#else
    agattr(NULL, AGNODE, "label", NODENAME_ESC);
#endif
    gvc = gvNEWcontext(builtins, demand_loading);
    gvconfig(gvc, FALSE); /* configure for available plugins */
    return gvc;
}
Esempio n. 8
0
GVC_t *gvContext(void)
{
    GVC_t *gvc;

#ifndef WITH_CGRAPH
    aginit();
    agnodeattr(NULL, "label", NODENAME_ESC);
#else
    agattr(NULL, AGNODE, "label", NODENAME_ESC);
#endif
    /* default to no builtins, demand loading enabled */
    gvc = gvNEWcontext(NULL, TRUE);
    gvconfig(gvc, FALSE); /* configure for available plugins */
    return gvc;
}
Esempio n. 9
0
gboolean
cls_node_collapse (ClsNode *cls_node)
{
	Agsym_t *sym;
	
	if (cls_node->expansion_status == CLS_NODE_COLLAPSED)
		return FALSE;

	if (!(sym = agfindattr(cls_node->graph->proto->n, "label")))
		sym = agnodeattr(cls_node->graph, "label", "");
	agxset(cls_node->agnode, sym->index, cls_node->sym_name);
	cls_node->expansion_status = CLS_NODE_COLLAPSED;

	return TRUE;
}
Esempio n. 10
0
/* 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;
}
Esempio n. 11
0
char *setv(Agnode_t *n, char *attr, char *val)
{
    Agraph_t *g;
    Agsym_t *a;

    if (!n || !attr || !val)
        return NULL;
    if (AGTYPE(n) == AGRAPH) { // protonode   
	g = (Agraph_t*)n;
    	a = agattr(g, AGNODE, attr, val); // create default attribute in psuodo protonode
	    // FIXME? - deal with html in "label" attributes
	return val;
    }
    g = agroot(agraphof(n));
    a = agattr(g, AGNODE, attr, NULL);
    if (!a)
        a = agnodeattr(g, attr, emptystring);
    myagxset(n, a, val);
    return val;
}
Esempio n. 12
0
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);
}
Esempio n. 13
0
void dotneato_initialize(GVC_t *gvc, int argc, char** argv)
{
	char	*rest,c, *val;
	int	i,v,nfiles;

	/* establish if we are running in a CGI environment */
	HTTPServerEnVar=getenv("SERVER_NAME");

	/* establish Gvfilepath, if any */
	Gvfilepath = getenv("GV_FILE_PATH");

	aginit();
	nfiles = 0;
	for (i = 1; i < argc; i++)
		if (argv[i][0] != '-') nfiles++;
	Files = N_NEW(nfiles + 1, char *);
	nfiles = 0;
	if (!CmdName) setCmdName (argv[0]);
	for (i = 1; i < argc; i++) {
		if (argv[i][0] == '-') {
			rest = &(argv[i][2]);
			switch (c = argv[i][1]) {
				case 'G': 
					if (*rest) global_def(rest,agraphattr); 
					else {
						fprintf(stderr,"Missing argument for -G flag\n");
						dotneato_usage (1);
					}
					break;
				case 'N': 
					if (*rest) global_def(rest,agnodeattr);
					else {
						fprintf(stderr,"Missing argument for -N flag\n");
						dotneato_usage (1);
					}
					break;
				case 'E':
					if (*rest) global_def(rest,agedgeattr);
					else {
						fprintf(stderr,"Missing argument for -E flag\n");
						dotneato_usage (1);
					}
					break;
				case 'T': 
					val = getFlagOpt (argc, argv, &i);
					if (!val) {
						fprintf(stderr,"Missing argument for -T flag\n");
						dotneato_usage (1);
					}
					gvrender_output_langname_job(gvc, val);
					break;
				case 'V':
					fprintf(stderr,"%s version %s (%s)\n",
						gvc->info[0], gvc->info[1], gvc->info[2]);
					exit (0);
					break;
				case 'l':
					val = getFlagOpt (argc, argv, &i);
					if (!val) {
						fprintf(stderr,"Missing argument for -l flag\n");
						dotneato_usage (1);
					}
					use_library(val);
					break;
				case 'o':
					val = getFlagOpt (argc, argv, &i);
					gvrender_output_filename_job(gvc, val);
					break;
				case 'q':
					if (*rest) {
						v = atoi(rest);
						if (v <= 0) {
							fprintf (stderr, "Invalid parameter \"%s\" for -q flag - ignored\n", rest);
						}
						else if (v == 1) agseterr (AGERR);
						else agseterr (AGMAX);
					}
					else agseterr (AGERR);
					break;
				case 's':
					if (*rest) {
						PSinputscale = atof(rest);
						if (PSinputscale <= 0) {
							fprintf (stderr, "Invalid parameter \"%s\" for -s flag\n", rest);
							dotneato_usage (1);
						}
					}
					else PSinputscale = POINTS_PER_INCH;
					break;
				case 'v': 
                    Verbose = TRUE; 
                    if (isdigit(*rest)) Verbose = atoi (rest);
                    break;
				case 'y': y_invert = TRUE; break;
				case '?': dotneato_usage (0); break;
				default:
					fprintf(stderr, "%s: option -%c unrecognized\n\n",
	                  CmdName,c);
                    dotneato_usage (1);
			}
		}
		else
		Files[nfiles++] = argv[i];
	}

	/* if no -Txxx, then set default format */
	if (!gvc->jobs || !gvc->jobs->output_langname) {
		gvrender_output_langname_job(gvc, "dot");
	}

	/* need to set Output_lang now based on the first -Txxx,
	 * so that CodeGen->textsize picks up an appropriate routine
	 * otherwise node sizing can be wrong for any or all of the products.
	 */
/* FIXME */
	Output_lang = lang_select(gvc, gvc->jobs->output_langname, 0);

	/* set persistent attributes here (if not already set from command line options) */ 
	if (! (agfindattr(agprotograph()->proto->n, "label")))
		agnodeattr(NULL,"label",NODENAME_ESC);
}
Esempio n. 14
0
void dotneato_args_initialize(GVC_t * gvc, int argc, char **argv)
{
    char *rest, c, *val;
    int i, v, nfiles;

    /* establish if we are running in a CGI environment */
    HTTPServerEnVar = getenv("SERVER_NAME");

    /* establish Gvfilepath, if any */
    Gvfilepath = getenv("GV_FILE_PATH");

    /* configure for available plugins and codegens */
    gvconfig(gvc, gvc->common.config);
    if (gvc->common.config)
	exit (0);

    gvc->common.cmdname = dotneato_basename(argv[0]);
    i = gvlayout_select(gvc, gvc->common.cmdname);
    if (i == NO_SUPPORT)
	gvlayout_select(gvc, "dot");

    /* feed the globals */
    Verbose = gvc->common.verbose;
    CmdName = gvc->common.cmdname;

    aginit();
    nfiles = 0;
    for (i = 1; i < argc; i++)
	if (argv[i] && argv[i][0] != '-')
	    nfiles++;
    gvc->input_filenames = N_NEW(nfiles + 1, char *);
    nfiles = 0;
    for (i = 1; i < argc; i++) {
	if (argv[i] && argv[i][0] == '-') {
	    rest = &(argv[i][2]);
	    switch (c = argv[i][1]) {
	    case 'G':
		if (*rest)
		    global_def(rest, agraphattr);
		else {
		    fprintf(stderr, "Missing argument for -G flag\n");
		    dotneato_usage(1);
		}
		break;
	    case 'N':
		if (*rest)
		    global_def(rest, agnodeattr);
		else {
		    fprintf(stderr, "Missing argument for -N flag\n");
		    dotneato_usage(1);
		}
		break;
	    case 'E':
		if (*rest)
		    global_def(rest, agedgeattr);
		else {
		    fprintf(stderr, "Missing argument for -E flag\n");
		    dotneato_usage(1);
		}
		break;
	    case 'T':
		val = getFlagOpt(argc, argv, &i);
		if (!val) {
		    fprintf(stderr, "Missing argument for -T flag\n");
		    dotneato_usage(1);
		    exit(1);
		}
		v = gvjobs_output_langname(gvc, val);
		if (!v) {
		    fprintf(stderr, "Format: \"%s\" not recognized. Use one of:%s\n",
			val, gvplugin_list(gvc, API_device, val));
		    exit(1);
		}
		break;
	    case 'K':
		val = getFlagOpt(argc, argv, &i);
		if (!val) {
                    fprintf(stderr, "Missing argument for -K flag\n");
                    dotneato_usage(1);
                    exit(1);
                }
                v = gvlayout_select(gvc, val);
                if (v == NO_SUPPORT) {
                    fprintf(stderr, "Layout type: \"%s\" not recognized. Use one of:%s\n",
                        val, gvplugin_list(gvc, API_layout, val));
                    exit(1);
                }
		break;
	    case 'V':
		fprintf(stderr, "%s - %s version %s (%s)\n",
			gvc->common.cmdname, gvc->common.info[0], 
			gvc->common.info[1], gvc->common.info[2]);
		exit(0);
		break;
	    case 'l':
		val = getFlagOpt(argc, argv, &i);
		if (!val) {
		    fprintf(stderr, "Missing argument for -l flag\n");
		    dotneato_usage(1);
		}
		use_library(gvc, val);
		break;
	    case 'o':
		val = getFlagOpt(argc, argv, &i);
		if (! gvc->common.auto_outfile_names)
		    gvjobs_output_filename(gvc, val);
		break;
	    case 'q':
		if (*rest) {
		    v = atoi(rest);
		    if (v <= 0) {
			fprintf(stderr,
				"Invalid parameter \"%s\" for -q flag - ignored\n",
				rest);
		    } else if (v == 1)
			agseterr(AGERR);
		    else
			agseterr(AGMAX);
		} else
		    agseterr(AGERR);
		break;
	    case 's':
		if (*rest) {
		    PSinputscale = atof(rest);
		    if (PSinputscale <= 0) {
			fprintf(stderr,
				"Invalid parameter \"%s\" for -s flag\n",
				rest);
			dotneato_usage(1);
		    }
		} else
		    PSinputscale = POINTS_PER_INCH;
		break;
	    case 'x':
		Reduce = TRUE;
		break;
	    case 'y':
		Y_invert = TRUE;
		break;
	    case '?':
		dotneato_usage(0);
		break;
	    default:
		fprintf(stderr, "%s: option -%c unrecognized\n\n", gvc->common.cmdname,
			c);
		dotneato_usage(1);
	    }
	} else if (argv[i])
	    gvc->input_filenames[nfiles++] = argv[i];
    }

    /* if no -Txxx, then set default format */
    if (!gvc->jobs || !gvc->jobs->output_langname) {
	v = gvjobs_output_langname(gvc, "dot");
	assert(v);  /* "dot" should always be available as an output format */
    }

    /* set persistent attributes here (if not already set from command line options) */
    if (!(agfindattr(agprotograph()->proto->n, "label")))
	agnodeattr(NULL, "label", NODENAME_ESC);
}
Esempio n. 15
0
static inline Agsym_t* _agnodeattr(Agraph_t* object, QString attr, QString value){
    	setlocale(LC_NUMERIC,"en_US.UTF-8");

	return agnodeattr(object, const_cast<char *>(qPrintable(attr)),const_cast<char *>(qPrintable(value)));
}
Esempio n. 16
0
/* init:
 */
static void init(int argc, char *argv[], pack_info* pinfo)
{
    int c, len;
    char buf[BUFSIZ];
    char* bp;

    agnodeattr(NULL, "label", NODENAME_ESC);
    pinfo->mode = l_clust;
    pinfo->margin = CL_OFFSET;
    pinfo->doSplines = TRUE; /* Use edges in packing */
    pinfo->fixed = 0;
    pinfo->sz = 0;

    opterr = 0;
    while ((c = getopt(argc, argv, ":na:gvum:s:o:G:")) != -1) {
	switch (c) {
	case 'a':
	    len = strlen(optarg) + 2;
	    if (len > BUFSIZ)
		bp = N_GNEW(len, char);
	    else
		bp = buf;
	    sprintf (bp, "a%s\n", optarg);
	    parsePackModeInfo (bp, pinfo->mode, pinfo);
	    if (bp != buf)
		free (bp);
	    break;
	case 'n':
	    parsePackModeInfo ("node", pinfo->mode, pinfo);
	    break;
	case 's':
	    gname = optarg;
	    break;
	case 'g':
	    parsePackModeInfo ("graph", pinfo->mode, pinfo);
	    break;
	case 'm':
	    setUInt(&pinfo->margin, optarg);
	    break;
	case 'o':
	    outfp = openFile(optarg, "w");
	    break;
	case 'u':
	    pinfo->mode = l_undef;
	    break;
	case 'G':
	    if (*optarg)
		setNameValue(optarg);
	    else
		fprintf(stderr,
			"gvpack: option -G missing argument - ignored\n");
	    break;
	case 'v':
	    verbose = 1;
	    Verbose = 1;
	    break;
	case ':':
	    fprintf(stderr, "gvpack: option -%c missing argument - ignored\n", optopt);
	    break;
	case '?':
	    if (optopt == '?')
		usage(0);
	    else
		fprintf(stderr,
			"gvpack: option -%c unrecognized - ignored\n", optopt);
	    break;
	}
    }
Esempio n. 17
0
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;
}
Esempio n. 18
0
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;

}
Esempio n. 19
0
gboolean
cls_node_expand (ClsNode *cls_node, ClsNodeExpansionType expansion_type)
{
	Agsym_t *sym;
	GString *label;
	gint max_label_items = 0;
	gint real_items_length = 0;
	gint var_order = -1000;
	gint method_order = 0;
	IAnjutaSymbol *node_sym;
	IAnjutaIterable *iter;
	GError *err = NULL;
	
	if (cls_node->expansion_status == expansion_type ||
	    expansion_type == CLS_NODE_COLLAPSED)
		return FALSE;

	node_sym =
		IANJUTA_SYMBOL (ianjuta_symbol_query_search_id (cls_node->plugin->query_id,
		                                                cls_node->klass_id,
		                                                &err));
	if (err)
	{
		g_warning ("Symbol ID query failed: %s", err->message);
		g_error_free (err);
		err = NULL;
	}
	if (!node_sym)
		return FALSE;
	
	if (!(sym = agfindattr(cls_node->graph->proto->n, "shape")))
		sym = agnodeattr(cls_node->graph, "shape", "");
	agxset (cls_node->agnode, sym->index, "record");
	
	if (!(sym = agfindattr(cls_node->graph->proto->n, "label")))
		sym = agnodeattr(cls_node->graph, "label", "");
	
	label = g_string_new ("");
	g_string_printf (label, "{%s", cls_node->sym_name);
	
	/* get members from the passed symbol node */
	iter = ianjuta_symbol_query_search_members (cls_node->plugin->query_members,
	                                            node_sym, &err);
	if (err)
	{
		g_warning ("Class members query failed: %s", err->message);
		g_error_free (err);
		err = NULL;
	}

	real_items_length = ianjuta_iterable_get_length (iter, NULL);
	
	/* set the max number of items to draw */
	if (real_items_length <= NODE_HALF_DISPLAY_ELEM_NUM || 
	    expansion_type == CLS_NODE_FULL_EXPANDED) 
	{
		max_label_items = real_items_length;
		cls_node->expansion_status = CLS_NODE_FULL_EXPANDED;
	}
	else
	{
		max_label_items = NODE_HALF_DISPLAY_ELEM_NUM;
		cls_node->expansion_status = CLS_NODE_SEMI_EXPANDED;
	}

	g_hash_table_remove_all (cls_node->members);
	if (iter && real_items_length > 0)
	{
		gint i = 0;

		/* First member variables */
		do
		{
			const gchar *name, *args, *type_name;
			IAnjutaSymbol *symbol;
			GdkPixbuf *icon;
			
			symbol = IANJUTA_SYMBOL (iter);
			name = g_strdup (ianjuta_symbol_get_string (symbol,
			                                            IANJUTA_SYMBOL_FIELD_NAME,
			                                            NULL));
			args = ianjuta_symbol_get_string (symbol,
			                                  IANJUTA_SYMBOL_FIELD_SIGNATURE,
			                                  NULL);
			icon = (GdkPixbuf*) ianjuta_symbol_get_icon (symbol, NULL);
			
			if (!args) /* Member variables */
			{
				ClsNodeItem *cls_item = g_new0 (ClsNodeItem, 1);

				type_name = ianjuta_symbol_get_string (symbol, IANJUTA_SYMBOL_FIELD_TYPE_NAME, NULL);
				cls_item->cls_node = cls_node;
				cls_item->label = g_strconcat (name, " : ", type_name, NULL);
				cls_item->order = var_order++;
				if (icon)
					g_object_ref (icon);
				cls_item->icon = icon;
				
				g_hash_table_insert (cls_node->members,
				                     g_strdup (cls_item->label),
				                     cls_item);
				g_string_append_printf (label, "|%s", cls_item->label);

				/* Setup file and line */
				cls_item->type_name = g_strdup (type_name);
				cls_item->line = ianjuta_symbol_get_int (symbol,
				                                         IANJUTA_SYMBOL_FIELD_FILE_POS,
				                                         NULL);
				cls_item->file = ianjuta_symbol_get_file (symbol, NULL);
			}
			else /* Member methods */
			{
				ClsNodeItem *cls_item;
				gchar *method_key = g_strconcat (name, args, NULL);
				cls_item = g_hash_table_lookup (cls_node->members, method_key);

				if (cls_item) /* We found an entry for this method */
				{
					IAnjutaSymbolType sym_type
						= ianjuta_symbol_get_sym_type (symbol, NULL);
					if (!(sym_type & IANJUTA_SYMBOL_TYPE_PROTOTYPE))
					{
						/* This one is method, so take this one instead */
						g_free (cls_item->args);
						cls_item->args = g_strdup (args);

						if (cls_item->file) g_object_unref (cls_item->file);
						cls_item->file = NULL;

						/* Setup file and line */
						cls_item->line = ianjuta_symbol_get_int (symbol,
						                                         IANJUTA_SYMBOL_FIELD_FILE_POS,
						                                         NULL);
						cls_item->file = ianjuta_symbol_get_file (symbol, NULL);
					}
				}
				else /* We did not find a member entry, create a new one */
				{
					ClsNodeItem *cls_item = g_new0 (ClsNodeItem, 1);
					type_name = ianjuta_symbol_get_string (symbol,
					                                       IANJUTA_SYMBOL_FIELD_RETURNTYPE,
					                                       NULL);

					cls_item->cls_node = cls_node;
					if (type_name)
					{
						if (strlen (args) > 2)
							cls_item->label = g_strconcat (name, "(...)",
							                               " : ", type_name,
							                               NULL);
						else
							cls_item->label = g_strconcat (name, "()", " : ",
							                               type_name, NULL);
					}
					else
					{
						if (strlen (args) > 2)
							cls_item->label = g_strconcat (name, "(...)", NULL);
						else
							cls_item->label = g_strconcat (name, "()", NULL);
					}
					cls_item->args = g_strdup (args);
					cls_item->type_name = g_strdup (type_name);
					cls_item->order = method_order++;
					if (icon)
						g_object_ref (icon);
					cls_item->icon = icon;
					
					g_string_append_printf (label, "|%s", cls_item->label);
					g_hash_table_insert (cls_node->members, method_key,
					                     cls_item);
					
					/* Setup file and line */
					cls_item->line = ianjuta_symbol_get_int (symbol,
					                                         IANJUTA_SYMBOL_FIELD_FILE_POS,
					                                         NULL);
					cls_item->file = ianjuta_symbol_get_file (symbol, NULL);
				}
			}
			i++;
		}
		while (ianjuta_iterable_next (iter, NULL) && i < max_label_items);
	}
	if (iter)
		g_object_unref (iter);
	
	if (cls_node->expansion_status == CLS_NODE_SEMI_EXPANDED &&
	    real_items_length > NODE_HALF_DISPLAY_ELEM_NUM)
	{
		g_string_append_printf (label, "|%s", NODE_SHOW_ALL_MEMBERS_STR);
	}
	
	g_string_append_printf (label, "}");
	agxset(cls_node->agnode, sym->index, label->str);
	
	/* set the margin for icons */
	if (!(sym = agfindattr(cls_node->graph->proto->n, "margin")))
		sym = agnodeattr(cls_node->graph, "margin", "0.11,0.055");
	agxset(cls_node->agnode, sym->index, "0.3,0.03");

	g_string_free (label, TRUE);

	return TRUE;
}
Esempio n. 20
0
/*----------------------------------------------------------------------------
 * add a node to an Agraph. Check also if the node is yet in the hash_table so 
 * that we can build the label of the node with the class-data.
 */
static ClsNode*
cls_inherit_create_node (AnjutaClassInheritance *plugin,
                         const IAnjutaSymbol *node_sym)
{
	ClsNode *cls_node;
	Agsym_t *sym;
	gint font_size;
	const gchar *font_name;
	
#define FONT_SIZE_STR_LEN 16
	gchar font_size_str[FONT_SIZE_STR_LEN];

	cls_node = g_new0 (ClsNode, 1);
	cls_node->graph = plugin->graph;
	cls_node->canvas = plugin->canvas;
	cls_node->plugin = plugin;
	cls_node->sym_manager =
			anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell,
			                            IAnjutaSymbolManager, NULL);

	cls_node->sym_name =
		g_strdup (ianjuta_symbol_get_string (IANJUTA_SYMBOL (node_sym),
		                                     IANJUTA_SYMBOL_FIELD_NAME,
		                                     NULL));
	cls_node->klass_id =
		ianjuta_symbol_get_int (IANJUTA_SYMBOL (node_sym),
		                        IANJUTA_SYMBOL_FIELD_ID,
		                        NULL);
	cls_node->members =
		g_hash_table_new_full (g_str_hash, g_str_equal,
		                       (GDestroyNotify) g_free,
		                       (GDestroyNotify) cls_node_item_free);
	cls_node->expansion_status = CLS_NODE_COLLAPSED;
	cls_node->drawn_expansion_status = CLS_NODE_COLLAPSED;
	cls_node->edges_to =
		g_hash_table_new_full (g_direct_hash, g_direct_equal,
		                       NULL, (GDestroyNotify)cls_node_edge_free);
	cls_node->edges_from = g_hash_table_new (g_direct_hash, g_direct_equal);
	
	/* let's add the node to the graph */
	if ((cls_node->agnode = agnode (cls_node->graph,
	                                cls_node->sym_name)) == NULL)
	{
		cls_node_free (cls_node);
		return NULL;
	}
	
	/* set the font */
	if (!(sym = agfindattr(plugin->graph->proto->n, "fontname")))
		sym = agnodeattr(plugin->graph, "fontname", "");
	font_name =
		pango_font_description_get_family (plugin->canvas->style->font_desc);
	agxset(cls_node->agnode, sym->index, (char*)font_name);

	/* set the font-size */	
	if (!(sym = agfindattr(plugin->graph->proto->n, "fontsize")))
		sym = agnodeattr(plugin->graph, "fontsize", "");

	font_size =
		pango_font_description_get_size (plugin->canvas->style->font_desc)/
			PANGO_SCALE;

	/* The above font size in points is with real screen DPI, but graphviz
	 * rendering is done at fixed INCH_TO_PIXELS_CONVERSION_FACTOR dpi. So
	 * convert to the right font size points for graphviz.
	 */
	font_size =
		font_size * gdk_screen_get_resolution (gdk_screen_get_default ())
					/ INCH_TO_PIXELS_CONVERSION_FACTOR;
	
	snprintf (font_size_str, FONT_SIZE_STR_LEN, "%d", font_size);
	agxset(cls_node->agnode, sym->index, font_size_str);

	if (!(sym = agfindattr(plugin->graph->proto->n, "ratio")))
		sym = agnodeattr(plugin->graph, "ratio", "");
	agxset(cls_node->agnode, sym->index, "expand");	

	/* Set an attribute - in this case one that affects the visible rendering */
	if (!(sym = agfindattr(plugin->graph->proto->n, "shape")))
		sym = agnodeattr(plugin->graph, "shape", "");
	agxset(cls_node->agnode, sym->index, "box");
	
	if (!(sym = agfindattr(plugin->graph->proto->n, "label")))
		sym = agnodeattr(plugin->graph, "label", "");
	agxset(cls_node->agnode, sym->index, cls_node->sym_name);

	return cls_node;
}
Esempio n. 21
0
static void color(Agraph_t * g)
{
    int nn, i, j, cnt;
    Agnode_t *n, *v, **nlist;
    Agedge_t *e;
    char *p;
    double x, y, maxrank = 0.0;
    double sum[NC], d, lowsat, highsat;

    if (agfindattr(g->proto->n, "pos") == NULL) {
	fprintf(stderr,
		"graph must be run through 'dot' before 'gvcolor'\n");
	exit(1);
    }
    if (agfindattr(g->proto->n, "style") == NULL)
	agnodeattr(g, "style", "filled");
    if ((p = agget(g, "Defcolor")))
	setcolor(p, Defcolor);

    if ((p = agget(g, "rankdir")) && (p[0] == 'L'))
	LR = 1;
    if ((p = agget(g, "flow")) && (p[0] == 'b'))
	Forward = 0;
    if ((p = agget(g, "saturation"))) {
	if (sscanf(p, "%lf,%lf", &lowsat, &highsat) == 2) {
	    MinRankSaturation = lowsat;
	    MaxRankSaturation = highsat;
	    AdjustSaturation = 1;
	}
    }

    /* assemble the sorted list of nodes and store the initial colors */
    nn = agnnodes(g);
    nlist = (Agnode_t **) malloc(nn * sizeof(Agnode_t *));
    i = 0;
    for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
	nlist[i++] = n;
	if ((p = agget(n, "color")))
	    setcolor(p, ND_x(n));
	p = agget(n, "pos");
	sscanf(p, "%lf,%lf", &x, &y);
	ND_relrank(n) = (LR ? x : y);
	if (maxrank < ND_relrank(n))
	    maxrank = ND_relrank(n);
    }
    if (LR != Forward)
	for (i = 0; i < nn; i++) {
	    n = nlist[i];
	    ND_relrank(n) = maxrank - ND_relrank(n);
	}
    qsort((void *) nlist, (size_t) nn, sizeof(Agnode_t *),
	  (int (*)(const void *, const void *)) cmpf);

    /* this is the pass that pushes the colors through the edges */
    for (i = 0; i < nn; i++) {
	n = nlist[i];

	/* skip nodes that were manually colored */
	cnt = 0;
	for (j = 0; j < NC; j++)
	    if (ND_x(n)[j] != 0.0)
		cnt++;
	if (cnt > 0)
	    continue;

	for (j = 0; j < NC; j++)
	    sum[j] = 0.0;
	cnt = 0;
	for (e = agfstedge(g, n); e; e = agnxtedge(g, e, n)) {
	    v = e->head;
	    if (v == n)
		v = e->tail;
	    d = ND_relrank(v) - ND_relrank(n) - 0.01;
	    if (d < 0) {
		double t = 0.0;
		for (j = 0; j < NC; j++) {
		    t += ND_x(v)[j];
		    sum[j] += ND_x(v)[j];
		}
		if (t > 0.0)
		    cnt++;
	    }
	}
	if (cnt)
	    for (j = 0; j < NC; j++)
		ND_x(n)[j] = sum[j] / cnt;
    }

    /* apply saturation adjustment and convert color to string */
    for (i = 0; i < nn; i++) {
	double h, s, b, t;
	char buf[64];

	n = nlist[i];

	t = 0.0;
	for (j = 0; j < NC; j++)
	    t += ND_x(n)[j];
	if (t > 0.0) {
	    h = ND_x(n)[0];
	    if (AdjustSaturation) {
		s = ND_relrank(n) / maxrank;
		if (!Forward)
		    s = 1.0 - s;
		s = MinRankSaturation
		    + s * (MaxRankSaturation - MinRankSaturation);
	    } else
		s = 1.0;
	    s = s * ND_x(n)[1];
	    b = ND_x(n)[2];
	} else {
	    h = Defcolor[0];
	    s = Defcolor[1];
	    b = Defcolor[2];
	}
	sprintf(buf, "%f %f %f", h, s, b);
	agset(n, "color", buf);
    }
}
Esempio n. 22
0
static inline Agsym_t* _agnodeattr(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 agnodeattr(object, const_cast<char *>(qPrintable(attr)),const_cast<char *>(qPrintable(value)));
}