From: erg Date: Thu, 2 Sep 2010 22:01:00 +0000 (+0000) Subject: Make sure that if optional attributes are defined in a gvpr script, the cached X-Git-Tag: LAST_LIBGRAPH~32^2~1205 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f16f9de351fd2d8cb8b1238a00b448670319b9ec;p=graphviz Make sure that if optional attributes are defined in a gvpr script, the cached attribute pointers are updated; fix incorrect implementation of edge colors if schema is not smooth; fix problem choosing color for max length edges; since smooth is a property of a color schema and not each individual color, put the parameter into the schema struct; reset edge code to use alpha; change code to use alpha even if object explicitly provides its color. --- diff --git a/cmd/smyrna/gui/frmobjectui.c b/cmd/smyrna/gui/frmobjectui.c index 8975c70b5..91b52fb88 100644 --- a/cmd/smyrna/gui/frmobjectui.c +++ b/cmd/smyrna/gui/frmobjectui.c @@ -806,7 +806,7 @@ static void gvpr_select(char *attr, char *regex_str, int objType) if (objType == AGNODE) sfprintf(sf, "N[%s==\"%s\"]{selected = \"1\"}", attr, regex_str); - if (objType == AGEDGE) + else if (objType == AGEDGE) sfprintf(sf, "E[%s==\"%s\"]{selected = \"1\"}", attr, regex_str); diff --git a/cmd/smyrna/gvprpipe.c b/cmd/smyrna/gvprpipe.c index 5f98dd5bd..64f9b6c93 100644 --- a/cmd/smyrna/gvprpipe.c +++ b/cmd/smyrna/gvprpipe.c @@ -75,7 +75,6 @@ static ssize_t errfn(void *sp, const char *buf, size_t nbyte, void *dp) { return 0; } -#endif static void set_refresh(ViewInfo* v,char* script) { if(strstr(script,"pos")) @@ -89,6 +88,7 @@ static void set_refresh(ViewInfo* v,char* script) if(strstr(script,"selected")) v->refresh.selection=1; } +#endif int run_gvpr(Agraph_t * srcGraph, int argc, char *argv[]) { @@ -123,7 +123,8 @@ int run_gvpr(Agraph_t * srcGraph, int argc, char *argv[]) } } else { - set_refresh(view,argv[1]); + /* set_refresh(view,argv[1]); */ + updateRecord (srcGraph); update_graph_from_settings(srcGraph); // update_topview(srcGraph, view->Topview, 0); } diff --git a/cmd/smyrna/smyrnadefs.h b/cmd/smyrna/smyrnadefs.h index ae41cb989..f0596308d 100644 --- a/cmd/smyrna/smyrnadefs.h +++ b/cmd/smyrna/smyrnadefs.h @@ -171,7 +171,6 @@ typedef struct typedef struct { float perc; glCompColor c; - int smooth; } colorschema; @@ -189,12 +188,11 @@ typedef struct typedef struct { - int schemacount; + int schemacount; /* number of colors */ + int smooth; /* if true, interpolate */ colorschema *s; } colorschemaset; - - typedef enum { VT_NONE, VT_XDOT, diff --git a/cmd/smyrna/topviewfuncs.c b/cmd/smyrna/topviewfuncs.c index b22df20ae..1b4b77b4f 100644 --- a/cmd/smyrna/topviewfuncs.c +++ b/cmd/smyrna/topviewfuncs.c @@ -172,6 +172,7 @@ static int visible(Agsym_t* attr, void* obj) } else return 1; } + static int object_color(void* obj,glCompColor* c) { gvcolor_t cl; @@ -189,24 +190,22 @@ static int object_color(void* obj,glCompColor* c) Alpha=getAttrFloat(g,objg,"defaultedgealpha",1); vis = GE_visible (objg); } - if(objType==AGNODE) { + else if(objType==AGNODE) { Alpha=getAttrFloat(g,objg,"defaultnodealpha",1); vis = GN_visible (objg); } if (!visible(vis,obj)) return 0; - /*get edge's color attribute */ setColorScheme (agget (obj, "colorscheme")); - bf=getAttrStr(g,obj,"color",NULL); - if((bf)&&(strlen(bf)>0)) - { + /*get objects's color attribute */ + bf = getAttrStr(g,obj,"color",NULL); + if(bf && (*bf)) { colorxlate(bf, &cl, RGBA_DOUBLE); - c->R=cl.u.RGBA[0]; - c->G=cl.u.RGBA[1]; - c->B=cl.u.RGBA[2]; - c->A=cl.u.RGBA[3]; - + c->R = cl.u.RGBA[0]; + c->G = cl.u.RGBA[1]; + c->B = cl.u.RGBA[2]; + c->A = cl.u.RGBA[3]*Alpha; } else { @@ -215,20 +214,18 @@ static int object_color(void* obj,glCompColor* c) else { colorxlate(agget(g, "defaultnodecolor"),&cl, RGBA_DOUBLE); - c->R=cl.u.RGBA[0]; - c->G=cl.u.RGBA[1]; - c->B=cl.u.RGBA[2]; - c->A=cl.u.RGBA[3]; + c->R = cl.u.RGBA[0]; + c->G = cl.u.RGBA[1]; + c->B = cl.u.RGBA[2]; + c->A = cl.u.RGBA[3]; } - c->A=c->A*Alpha; + c->A = c->A*Alpha; } return return_value; } - - /* draws multi edges , single edges this function assumes glBegin(GL_LINES) has been called @@ -427,9 +424,6 @@ static void renderSelectedEdges(Agraph_t * g) } } - - - glBegin(GL_LINES); for (v = agfstnode(g); v; v = agnxtnode(g, v)) { @@ -639,8 +633,7 @@ static void renderEdgesFn (Agraph_t * g, edgefn ef, int skipSelected) if ((ND_visible(agtail(e))==0) || (ND_visible(aghead(e))==0)) continue; - if(!object_color(e,&c)) - { + if(!object_color(e,&c)) { ED_visible(e) = 0; continue; } @@ -669,7 +662,7 @@ static void edge_seg (Agraph_t* g, Agedge_t* e, glCompColor c) glCompPoint posT; /*Tail position*/ glCompPoint posH; /*Head position*/ - glColor4f(c.R,c.G,c.B,1); + glColor4f(c.R,c.G,c.B,c.A); posT=getPointFromStr(agxget(agtail(e), pos_attr)); posH=getPointFromStr(agxget(aghead(e), pos_attr)); draw_edge(&posT,&posH,getEdgeLength(e),0); @@ -682,7 +675,7 @@ static void edge_spline (Agraph_t* g, Agedge_t* e, glCompColor c) Agsym_t* pos_attr_e = GE_pos(g); xdot * x; - glColor4f(c.R,c.G,c.B,1); + glColor4f(c.R,c.G,c.B,c.A); x = makeXDotSpline (agxget(e,pos_attr_e)); if (x) { draw_xdot(x,0); diff --git a/cmd/smyrna/viewport.c b/cmd/smyrna/viewport.c index ff50ab931..3f13027ad 100755 --- a/cmd/smyrna/viewport.c +++ b/cmd/smyrna/viewport.c @@ -643,6 +643,19 @@ int add_graph_to_viewport_from_file(char *fileName) return add_graph_to_viewport(graph, fileName); } +/* updateRecord: + * Update fields which may be added dynamically. + */ +void updateRecord (Agraph_t* g) +{ + GN_size(g) = agattr (g, AGNODE, "size", 0); + GN_visible(g) = agattr (g, AGNODE, "visible", 0); + GN_selected(g) = agattr (g, AGNODE, "selected", 0); + + GE_pos(g)=agattr(g,AGEDGE,"pos",0); + GE_visible(g) = agattr (g, AGEDGE, "visible", 0); + GE_selected(g) = agattr (g, AGEDGE, "selected", 0); +} /* graphRecord: * add graphRec to graph if necessary. @@ -650,6 +663,7 @@ int add_graph_to_viewport_from_file(char *fileName) * We assume the graph has attributes nodelabelattribute, edgelabelattribute, * nodelabelcolor and edgelabelcolor from template.dot. * We assume nodes have pos attributes. + * Only size, visible, selected and edge pos may or may not be defined. */ static void graphRecord (Agraph_t* g) @@ -660,18 +674,12 @@ graphRecord (Agraph_t* g) GG_edgelabelcolor(g) = agattr (g, AGRAPH, "edgelabelcolor", 0); GN_pos(g) = agattr (g, AGNODE, "pos", 0); - GN_size(g) = agattr (g, AGNODE, "size", 0); - GN_visible(g) = agattr (g, AGNODE, "visible", 0); - GN_selected(g) = agattr (g, AGNODE, "selected", 0); GN_labelattribute(g) = agattr (g, AGNODE, agget(g,"nodelabelattribute"), 0); - GE_pos(g)=agattr(g,AGEDGE,"pos",0); - GE_visible(g) = agattr (g, AGEDGE, "visible", 0); - GE_selected(g) = agattr (g, AGEDGE, "selected", 0); GE_labelattribute(g) = agattr (g, AGEDGE, agget(g,"edgelabelattribute"), 0); -} - + updateRecord (g); +} void refreshViewport(int doClear) { @@ -1073,14 +1081,14 @@ void getcolorfromschema(colorschemaset * sc, float l, float maxl, glCompColor * c) { int ind; - /* float cuml=0.00; */ - float percl = l / maxl * 100.00; - for (ind = 0; ind < sc->schemacount; ind++) { - if (percl < sc->s[ind].perc) - break; - } + float percl = l / maxl; - if (sc->s[ind].smooth) { + if (sc->smooth) { + /* For smooth schemas, s[0].perc = 0, so we start with ind=1 */ + for (ind = 1; ind < sc->schemacount-1; ind++) { + if (percl < sc->s[ind].perc) + break; + } c->R = interpol(sc->s[ind - 1].perc, sc->s[ind].perc, sc->s[ind - 1].c.R, sc->s[ind].c.R, percl); @@ -1090,13 +1098,18 @@ void getcolorfromschema(colorschemaset * sc, float l, float maxl, c->B = interpol(sc->s[ind - 1].perc, sc->s[ind].perc, sc->s[ind - 1].c.B, sc->s[ind].c.B, percl); - c->A = 1; - } else { + } + else { + for (ind = 0; ind < sc->schemacount-1; ind++) { + if (percl < sc->s[ind].perc) + break; + } c->R = sc->s[ind].c.R; c->G = sc->s[ind].c.G; c->B = sc->s[ind].c.B; - c->A = 1; } + + c->A = 1; } /* set_color_theme_color: @@ -1108,15 +1121,29 @@ static void set_color_theme_color(colorschemaset * sc, char **colorstr, int smoo int colorcnt = sc->schemacount; gvcolor_t cl; float av_perc; - av_perc = 100.00 / (float) (colorcnt - 1); - for (ind = 0; ind < colorcnt; ind++) { - colorxlate(colorstr[ind], &cl, RGBA_DOUBLE); - sc->s[ind].c.R = cl.u.RGBA[0]; - sc->s[ind].c.G = cl.u.RGBA[1]; - sc->s[ind].c.B = cl.u.RGBA[2]; - sc->s[ind].c.A = cl.u.RGBA[3]; - sc->s[ind].perc = ind * av_perc; - sc->s[ind].smooth = smooth; + + sc->smooth = smooth; + if (smooth) { + av_perc = 1.0 / (float) (colorcnt-1); + for (ind = 0; ind < colorcnt; ind++) { + colorxlate(colorstr[ind], &cl, RGBA_DOUBLE); + sc->s[ind].c.R = cl.u.RGBA[0]; + sc->s[ind].c.G = cl.u.RGBA[1]; + sc->s[ind].c.B = cl.u.RGBA[2]; + sc->s[ind].c.A = cl.u.RGBA[3]; + sc->s[ind].perc = ind * av_perc; + } + } + else { + av_perc = 1.0 / (float) (colorcnt); + for (ind = 0; ind < colorcnt; ind++) { + colorxlate(colorstr[ind], &cl, RGBA_DOUBLE); + sc->s[ind].c.R = cl.u.RGBA[0]; + sc->s[ind].c.G = cl.u.RGBA[1]; + sc->s[ind].c.B = cl.u.RGBA[2]; + sc->s[ind].c.A = cl.u.RGBA[3]; + sc->s[ind].perc = (ind+1) * av_perc; + } } } diff --git a/cmd/smyrna/viewport.h b/cmd/smyrna/viewport.h index 262787546..9215bb300 100755 --- a/cmd/smyrna/viewport.h +++ b/cmd/smyrna/viewport.h @@ -53,6 +53,7 @@ extern "C" { void move_nodes(Agraph_t * g); extern void getcolorfromschema(colorschemaset * sc, float l, float maxl, glCompColor * c); + void updateRecord (Agraph_t* g); /* helper functions */