Debian Codegraph @

cmd/smyrna/topviewfuncs.c

raw
1 /*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11 #include "config.h"
12
13 #include <assert.h>
14 #include "topviewfuncs.h"
15 #include <cgraph/cgraph.h>
16 #include "smyrna_utils.h"
17 #include <common/colorprocs.h>
18 #include "draw.h"
19 #include "gui/frmobjectui.h"
20 #include <xdot/xdot.h>
21 #include <glcomp/glutils.h>
22 #include "selectionfuncs.h"
23 #include <common/types.h>
24 #include <common/utils.h>
25 #include <limits.h>
26 #include <float.h>
27 #include <math.h>
28 #include <stdbool.h>
29 #include <stdlib.h>
30 #include <util/alloc.h>
31 #include <util/gv_ctype.h>
32
33 static xdot *parseXdotwithattrs(void *e)
34 {
35 xdot* xDot=NULL;
36 xDot=parseXDotFOn (agget(e,"_draw_" ), OpFns,sizeof(sdot_op), xDot);
37 if (agobjkind(e) == AGRAPH)
38 xDot=parseXDotFOn (agget(e,"_background" ), OpFns,sizeof(sdot_op), xDot);
39 xDot=parseXDotFOn (agget(e,"_ldraw_" ), OpFns,sizeof(sdot_op), xDot);
40 xDot=parseXDotFOn (agget(e,"_hdraw_" ), OpFns,sizeof(sdot_op), xDot);
41 xDot=parseXDotFOn (agget(e,"_tdraw_" ), OpFns,sizeof(sdot_op), xDot);
42 xDot=parseXDotFOn (agget(e,"_hldraw_" ), OpFns,sizeof(sdot_op), xDot);
43 xDot=parseXDotFOn (agget(e,"_tldraw_" ), OpFns,sizeof(sdot_op), xDot);
44 if(xDot)
45 {
46 for (size_t cnt = 0; cnt < xDot->cnt; cnt++)
47 {
48 ((sdot_op*)(xDot->ops))[cnt].obj=e;
49 }
50 }
51 return xDot;
52
53 }
54
55 static void set_boundaries(Agraph_t * g)
56 {
57 Agnode_t *v;
58 Agsym_t* pos_attr = GN_pos(g);
59 glCompPoint pos;
60 float left = FLT_MAX, right = -FLT_MAX, top = -FLT_MAX, bottom = FLT_MAX;
61
62 for (v = agfstnode(g); v; v = agnxtnode(g, v))
63 {
64 pos=getPointFromStr(agxget(v, pos_attr));
65
66 left = fminf(left, pos.x);
67 right = fmaxf(right, pos.x);
68 top = fmaxf(top, pos.y);
69 bottom = fminf(bottom, pos.y);
70 }
71 view->bdxLeft = left;
72 view->bdyTop = top;
73 view->bdxRight = right;
74 view->bdyBottom = bottom;
75 }
76
77 static void draw_xdot(xdot* x, double base_z)
78 {
79 sdot_op *op;
80 if (!x)
81 return;
82
83 view->Topview->global_z=base_z;
84
85 op=(sdot_op*)x->ops;
86 for (size_t i = 0; i < x->cnt; i++, op++)
87 {
88 if(op->op.drawfunc)
89 op->op.drawfunc(&op->op,0);
90 }
91
92
93 }
94
95
96
97 static glCompPoint getEdgeHead(Agedge_t * edge)
98 {
99 return getPointFromStr(agget(aghead(edge),"pos"));
100 }
101 static glCompPoint getEdgeTail(Agedge_t * edge)
102 {
103 return getPointFromStr(agget(agtail(edge),"pos"));
104 }
105
106 static float getEdgeLength(Agedge_t *edge) {
107 glCompPoint A,B;
108 A=getEdgeTail(edge);
109 B=getEdgeHead(edge);
110 float rv = (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y) + (A.z - B.z) * (A.z - B.z);
111 rv=sqrtf(rv);
112 return rv;
113 }
114
115 static void glCompColorxlate(glCompColor *c, const char *str) {
116 gvcolor_t cl;
117 colorxlate(str, &cl, RGBA_DOUBLE);
118 c->R=cl.u.RGBA[0];
119 c->G=cl.u.RGBA[1];
120 c->B=cl.u.RGBA[2];
121 c->A=cl.u.RGBA[3];
122 }
123
124 /* If the "visible" attribute is not set or "", return true
125 * else evaluate as boolean
126 */
127 static int visible(Agsym_t* attr, void* obj)
128 {
129 if (attr) {
130 const char *const s = agxget(obj, attr);
131 if (*s) return mapbool(s);
132 }
133 return 1;
134 }
135
136 static int object_color(void* obj,glCompColor* c)
137 {
138 gvcolor_t cl;
139 Agraph_t* g=view->g[view->activeGraph];
140 Agraph_t* objg=agraphof(obj);
141 float Alpha = 1;
142 Agsym_t* vis;
143
144 const int objType = AGTYPE(obj);
145
146 if(objType==AGEDGE) {
147 Alpha=getAttrFloat(g,objg,"defaultedgealpha",1);
148 vis = GE_visible (objg);
149 }
150 else {
151 assert(objType == AGNODE);
152 Alpha=getAttrFloat(g,objg,"defaultnodealpha",1);
153 vis = GN_visible (objg);
154 }
155 if (!visible(vis,obj))
156 return 0;
157
158 char *previous_color_scheme = setColorScheme(agget (obj, "colorscheme"));
159 /*get objects's color attribute */
160 const char *const bf = getAttrStr(g,obj,"color",NULL);
161 if(bf && (*bf)) {
162 colorxlate(bf, &cl, RGBA_DOUBLE);
163 c->R = cl.u.RGBA[0];
164 c->G = cl.u.RGBA[1];
165 c->B = cl.u.RGBA[2];
166 c->A = cl.u.RGBA[3]*Alpha;
167 }
168 else
169 {
170 if(objType==AGEDGE)
171 getcolorfromschema(view->colschms, getEdgeLength(obj), view->Topview->maxedgelen,c);
172 else
173 {
174 colorxlate(agget(g, "defaultnodecolor"),&cl, RGBA_DOUBLE);
175 c->R = cl.u.RGBA[0];
176 c->G = cl.u.RGBA[1];
177 c->B = cl.u.RGBA[2];
178 c->A = cl.u.RGBA[3];
179 }
180 c->A *= Alpha;
181
182 }
183
184 char *color_scheme = setColorScheme(previous_color_scheme);
185 free(color_scheme);
186 free(previous_color_scheme);
187
188 return 1;
189 }
190
191
192 /*
193 draws multi edges , single edges
194 this function assumes glBegin(GL_LINES) has been called
195 */
196 static void draw_edge(glCompPoint posT, glCompPoint posH) {
197 glVertex3f(posT.x, posT.y, posT.z);
198 glVertex3f(posH.x, posH.y, posH.z);
199 }
200
201 static char* labelOf (Agraph_t* g, Agnode_t* v)
202 {
203 char* lbl;
204 char* s;
205
206 Agsym_t* data_attr = GN_labelattribute(g);
207 if (data_attr)
208 s = agxget (v, data_attr);
209 else
210 s = agxget (g, GG_labelattribute(g));
211 if ((*s == '\0') || !strcmp (s, "name"))
212 lbl = agnameof (v);
213 else {
214 lbl = agget (v, s);
215 if (!lbl) lbl = "";
216 }
217 return lbl;
218 }
219
220 static void renderSelectedNodes(Agraph_t * g)
221 {
222 Agnode_t *v;
223 xdot * x;
224 glCompPoint pos;
225 Agsym_t* l_color_attr = GG_nodelabelcolor(g);
226 glCompColor c;
227 int defaultNodeShape;
228
229 glCompColorxlate(&c,agxget(g,l_color_attr));
230
231 defaultNodeShape=getAttrBool(g,g,"defaultnodeshape",0);
232 if(defaultNodeShape==0)
233 glBegin(GL_POINTS);
234
235 for (v = agfstnode(g); v; v = agnxtnode(g, v))
236 {
237 if(!ND_selected(v))
238 continue;
239 x=parseXdotwithattrs(v);
240 draw_xdot(x,-1);
241 if(x)
242 freeXDot (x);
243 }
244
245 for (v = agfstnode(g); v; v = agnxtnode(g, v))
246 {
247 if(!ND_selected(v))
248 continue;
249 glColor4d(view->selectedNodeColor.R, view->selectedNodeColor.G,view->selectedNodeColor.B, view->selectedNodeColor.A);
250 pos = ND_A(v);
251 const double nodeSize = ND_size(v);
252
253 if (defaultNodeShape == 0)
254 glVertex3f(pos.x, pos.y, pos.z + 0.001f);
255 else if (defaultNodeShape == 1)
256 drawCircle(pos.x, pos.y, nodeSize, pos.z + 0.001);
257 }
258 if(defaultNodeShape==0)
259 glEnd();
260 for (v = agfstnode(g); v; v = agnxtnode(g, v))
261 {
262 if(!ND_selected(v))
263 continue;
264 if (ND_printLabel(v)==1)
265 {
266 pos = ND_A(v);
267 glColor4d(c.R, c.G,c.B, c.A);
268 glprintfglut(view->glutfont, pos.x, pos.y, pos.z + 0.002f, labelOf(g, v));
269 }
270 }
271 }
272
273
274
275 static void renderNodes(Agraph_t * g)
276 {
277 Agsym_t* pos_attr = GN_pos(g);
278 Agsym_t* size_attr = GN_size(g);
279 Agsym_t* selected_attr = GN_selected(g);
280 glCompColor c;
281
282 const int defaultNodeShape=getAttrInt(g, g, "defaultnodeshape", 0);
283
284 xdot *x = parseXdotwithattrs(g);
285 if (x) {
286 draw_xdot(x, -0.2);
287 freeXDot (x);
288 }
289 for (Agnode_t *v = agfstnode(g); v; v = agnxtnode(g, v)) {
290 if (!object_color(v, &(glCompColor){0}))
291 continue;
292 x=parseXdotwithattrs(v);
293 draw_xdot(x, -0.1);
294
295 if(x)
296 freeXDot (x);
297 }
298
299 if(defaultNodeShape==0)
300 glBegin(GL_POINTS);
301
302 int ind = 0;
303
304 for (Agnode_t *v = agfstnode(g); v; v = agnxtnode(g, v)) {
305 ND_TVref(v) = ind;
306 if(!object_color(v,&c))
307 {
308 ND_visible(v) = 0;
309 continue;
310 }
311 else
312 ND_visible(v) = 1;
313
314 if(l_int(v, selected_attr,0))
315 {
316 ND_selected(v) = 1;
317 }
318 glColor4d(c.R,c.G,c.B,c.A);
319 const glCompPoint pos = getPointFromStr(agxget(v, pos_attr));
320 double nodeSize = l_float(v, size_attr, 0);
321
322 ND_A(v) = pos;
323
324 if (nodeSize > 0)
325 nodeSize *= view->nodeScale;
326 else
327 nodeSize=view->nodeScale;
328 if(defaultNodeShape==0)
329 nodeSize=1;
330 ND_size(v) = nodeSize;
331 if (defaultNodeShape == 0)
332 glVertex3f(pos.x,pos.y,pos.z);
333 else if (defaultNodeShape == 1)
334 drawCircle(pos.x,pos.y,nodeSize,pos.z);
335 ind++;
336 }
337 if(defaultNodeShape==0)
338 glEnd();
339 }
340
341
342 static void renderSelectedEdges(Agraph_t * g)
343 {
344 /*xdots tend to be drawn as background shapes,that is why they are being rendered before edges*/
345
346 for (Agnode_t *v = agfstnode(g); v; v = agnxtnode(g, v)) {
347 for (Agedge_t *e = agfstout(g, v); e; e = agnxtout(g, e)) {
348 if(!ED_selected(e))
349 continue;
350 if (!object_color(e, &(glCompColor){0}))
351 continue;
352
353 xdot *const x = parseXdotwithattrs(e);
354 draw_xdot(x,0);
355 if(x)
356 freeXDot (x);
357 }
358 }
359
360 glBegin(GL_LINES);
361 for (Agnode_t *v = agfstnode(g); v; v = agnxtnode(g, v)) {
362 for (Agedge_t *e = agfstout(g, v); e; e = agnxtout(g, e)) {
363 if(!ED_selected(e))
364 continue;
365
366 if (!object_color(e, &(glCompColor){0}))
367 continue;
368 glColor4f(1,0,0,1);
369 glCompPoint posT = ED_posTail(e); // tail position
370 glCompPoint posH = ED_posHead(e); // head position
371 posT.z +=0.01f;
372 posH.z +=0.01f;
373 draw_edge(posT, posH);
374 }
375 }
376 glEnd();
377 }
378
379 /* skipWS:
380 * Skip whitespace
381 */
382 static char* skipWS (char* p)
383 {
384 while (gv_isspace(*p)) p++;
385 return p;
386 }
387
388 /* skipNWS:
389 * Skip non-whitespace
390 */
391 static char* skipNWS (char* p)
392 {
393 while (*p && !gv_isspace(*p)) p++;
394 return p;
395 }
396
397 /* readPoint:
398 * Parse x,y[,z] and store in pt.
399 * If z is not specified, set to 0.
400 * Return pointer to next character after reading the point.
401 * Return NULL on error.
402 */
403 static char* readPoint (char* p, xdot_point* pt)
404 {
405 char* endp;
406
407 pt->z = 0;
408 pt->x = strtod (p, &endp);
409 if (p == endp) {
410 return 0;
411 }
412 else
413 p = endp;
414 if (*p == ',') p++;
415 else return 0;
416
417 pt->y = strtod (p, &endp);
418 if (p == endp) {
419 return 0;
420 }
421 else
422 p = endp;
423 if ((*p == ' ') || (*p == '\0')) return p;
424 else if (*p == ',') p++;
425 else return 0;
426
427 pt->z = strtod (p, &endp);
428 if (p == endp) {
429 return 0;
430 }
431 else
432 return endp;
433 }
434
435 /* countPoints:
436 * count number of points in pos attribute; store in cntp;
437 * check for e and s points; store if found and increment number of
438 * points by 3 for each.
439 * return start of point list (skip over e and s points).
440 * return NULL on failure
441 */
442 static char *countPoints(char *pos, int *have_sp, xdot_point *sp, int *have_ep,
443 xdot_point *ep, size_t *cntp) {
444 size_t cnt = 0;
445 char* p;
446
447 pos = skipWS (pos);
448 if (*pos == 's') {
449 if ((pos = readPoint (pos+2, sp))) {
450 *have_sp = 1;
451 cnt += 3;
452 }
453 else
454 return 0;
455 }
456 else
457 *have_sp = 0;
458
459 pos = skipWS (pos);
460 if (*pos == 'e') {
461 if ((pos = readPoint (pos+2, ep))) {
462 *have_ep = 1;
463 cnt += 3;
464 }
465 else
466 return 0;
467 }
468 else
469 *have_ep = 0;
470
471 p = pos = skipWS (pos);
472
473 while (*p) {
474 cnt++;
475 p = skipNWS (p);
476 p = skipWS (p);
477 }
478 *cntp = cnt;
479
480 return pos;
481 }
482
483 /* storePoints:
484 * read comma-separated list of points
485 * and store them in ps
486 * Assumes enough storage is available.
487 * return -1 on error
488 */
489 static int storePoints (char* pos, xdot_point* ps)
490 {
491
492 while (*pos) {
493 if ((pos = readPoint (pos, ps))) {
494 ps++;
495 pos = skipWS(pos);
496 }
497 else
498 return -1;
499 }
500 return 0;
501 }
502
503 /* makeXDotSpline:
504 * Generate an xdot representation of an edge's pos attribute
505 */
506 static xdot* makeXDotSpline (char* pos)
507 {
508 xdot_point s, e;
509 int v, have_s, have_e;
510 size_t cnt;
511 static const size_t sz = sizeof(sdot_op);
512
513 if (*pos == '\0') return NULL;
514
515 pos = countPoints (pos, &have_s, &s, &have_e, &e, &cnt);
516 if (pos == 0) return NULL;
517
518 xdot_point* pts = gv_calloc(cnt, sizeof(xdot_point));
519 if (have_s) {
520 v = storePoints (pos, pts+3);
521 pts[0] = pts[1] = s;
522 pts[2] = pts[3];
523 }
524 else
525 v = storePoints (pos, pts);
526 if (v) {
527 free (pts);
528 return NULL;
529 }
530
531 if (have_e) {
532 pts[cnt-1] = pts[cnt-2] = e;
533 pts[cnt-3] = pts[cnt-4];
534 }
535
536 xdot_op* op = gv_calloc(sz, sizeof(char));
537 op->kind = xd_unfilled_bezier;
538 op->drawfunc = OpFns[xop_bezier];
539 op->u.bezier.cnt = cnt;
540 op->u.bezier.pts = pts;
541
542 xdot* xd = gv_alloc(sizeof(xdot));
543 xd->cnt = 1;
544 xd->sz = sz;
545 xd->ops = op;
546
547 return xd;
548 }
549
550 typedef void (*edgefn) (Agraph_t *, Agedge_t*, glCompColor);
551
552 static void renderEdgesFn(Agraph_t *g, edgefn ef, bool skipSelected) {
553 glCompColor c;
554
555 for (Agnode_t *v = agfstnode(g); v; v = agnxtnode(g, v)) {
556 for (Agedge_t *e = agfstout(g, v); e; e = agnxtout(g, e)) {
557 if (ND_visible(agtail(e)) == 0 || ND_visible(aghead(e)) == 0)
558 continue;
559
560 if(!object_color(e,&c)) {
561 continue;
562 }
563 if (ED_selected(e) && skipSelected)
564 continue;
565
566 ef (g, e, c);
567 }
568 }
569 }
570
571 static void edge_xdot (Agraph_t* g, Agedge_t* e, glCompColor c)
572 {
573 (void)g;
574 (void)c;
575
576 xdot *const x = parseXdotwithattrs(e);
577 draw_xdot(x,0);
578 if(x)
579 freeXDot (x);
580 }
581
582 static void edge_seg (Agraph_t* g, Agedge_t* e, glCompColor c)
583 {
584 Agsym_t* pos_attr = GN_pos(g);
585
586 glColor4d(c.R,c.G,c.B,c.A);
587 // tail position
588 const glCompPoint posT = getPointFromStr(agxget(agtail(e), pos_attr));
589 // head position
590 const glCompPoint posH = getPointFromStr(agxget(aghead(e), pos_attr));
591 draw_edge(posT, posH);
592 ED_posTail(e) = posT;
593 ED_posHead(e) = posH;
594 }
595
596 static void edge_spline (Agraph_t* g, Agedge_t* e, glCompColor c)
597 {
598 Agsym_t* pos_attr_e = GE_pos(g);
599
600 glColor4d(c.R,c.G,c.B,c.A);
601 xdot *const x = makeXDotSpline(agxget(e, pos_attr_e));
602 if (x) {
603 draw_xdot(x,0);
604 freeXDot (x);
605 }
606 }
607
608 static void renderEdges(Agraph_t * g)
609 {
610 Agsym_t* pos_attr_e = GE_pos(g);
611 int drawSegs = !(pos_attr_e && view->drawSplines);
612 /*xdots tend to be drawn as background shapes,that is why they are being rendered before edges*/
613
614 renderEdgesFn(g, edge_xdot, false);
615
616 if (drawSegs) {
617 glBegin(GL_LINES);
618 renderEdgesFn(g, edge_seg, true);
619 glEnd();
620 }
621 else
622 renderEdgesFn(g, edge_spline, true);
623 }
624
625 static void renderNodeLabels(Agraph_t * g)
626 {
627 Agnode_t *v;
628 glCompPoint pos;
629 Agsym_t* data_attr = GN_labelattribute(g);
630 Agsym_t* l_color_attr = GG_nodelabelcolor(g);
631 glCompColor c;
632
633 glCompColorxlate(&c,agxget(g,l_color_attr));
634
635 for (v = agfstnode(g); v; v = agnxtnode(g, v))
636 {
637 if(ND_visible(v)==0)
638 continue;
639 if(ND_selected(v)==1)
640 continue;
641
642 pos = ND_A(v);
643 glColor4d(c.R,c.G,c.B,c.A);
644 if(!data_attr)
645 glprintfglut(view->glutfont,pos.x,pos.y,pos.z,agnameof(v));
646 else
647 glprintfglut(view->glutfont,pos.x,pos.y,pos.z,agxget(v,data_attr));
648 }
649 }
650
651 static void renderEdgeLabels(Agraph_t * g)
652 {
653 Agedge_t *e;
654 Agnode_t *v;
655 glCompPoint posT;
656 glCompPoint posH;
657 Agsym_t* data_attr = GE_labelattribute(g);
658 Agsym_t* l_color_attr = GG_edgelabelcolor(g);
659 glCompColor c;
660
661 glCompColorxlate(&c,agxget(g,l_color_attr));
662
663 if(!data_attr || !l_color_attr)
664 return;
665
666 for (v = agfstnode(g); v; v = agnxtnode(g, v))
667 {
668 for (e = agfstout(g, v); e; e = agnxtout(g, e))
669 {
670
671 if (ND_visible(v)==0)
672 continue;
673
674 posT = ED_posTail(e);
675 posH = ED_posHead(e);
676 glColor4d(c.R,c.G,c.B,c.A);
677 float x = posH.x + (posT.x - posH.x) / 2;
678 float y = posH.y + (posT.y - posH.y) / 2;
679 float z = posH.z + (posT.z - posH.z) / 2;
680 glprintfglut(view->glutfont,x,y,z,agxget(e,data_attr));
681
682 }
683 }
684 }
685
686
687
688
689
690 static void cacheNodes(Agraph_t * g,topview* t)
691 {
692 if (t->cache.node_id != UINT_MAX) // clean existing cache
693 glDeleteLists(t->cache.node_id,1);
694 t->cache.node_id=glGenLists(1);
695 glNewList(t->cache.node_id,GL_COMPILE);
696 renderNodes(g);
697 glEndList();
698
699
700
701
702 }
703 static void cacheEdges(Agraph_t * g,topview* t)
704 {
705 if (t->cache.edge_id != UINT_MAX) // clean existing cache
706 glDeleteLists(t->cache.edge_id,1);
707 t->cache.edge_id=glGenLists(1);
708 glNewList(t->cache.edge_id,GL_COMPILE);
709 renderEdges(g);
710 glEndList();
711
712
713 }
714 void cacheSelectedEdges(Agraph_t * g,topview* t)
715 {
716 if (t->cache.seledge_id != UINT_MAX) // clean existing cache
717 glDeleteLists(t->cache.seledge_id,1);
718 t->cache.seledge_id=glGenLists(1);
719 glNewList(t->cache.seledge_id,GL_COMPILE);
720 renderSelectedEdges(g);
721 glEndList();
722
723
724 }
725 void cacheSelectedNodes(Agraph_t * g,topview* t)
726 {
727 if (t->cache.selnode_id != UINT_MAX) // clean existing cache
728 glDeleteLists(t->cache.selnode_id,1);
729 t->cache.selnode_id=glGenLists(1);
730 glNewList(t->cache.selnode_id,GL_COMPILE);
731 renderSelectedNodes(g);
732 glEndList();
733 }
734 static void cacheNodeLabels(Agraph_t * g,topview* t)
735 {
736 if (t->cache.nodelabel_id != UINT_MAX) // clean existing cache
737 glDeleteLists(t->cache.nodelabel_id,1);
738 t->cache.nodelabel_id=glGenLists(1);
739 glNewList(t->cache.nodelabel_id,GL_COMPILE);
740 renderNodeLabels(g);
741 glEndList();
742 }
743 static void cacheEdgeLabels(Agraph_t * g,topview* t)
744 {
745 if (t->cache.edgelabel_id != UINT_MAX) // clean existing cache
746 glDeleteLists(t->cache.edgelabel_id,1);
747 t->cache.edgelabel_id=glGenLists(1);
748 glNewList(t->cache.edgelabel_id,GL_COMPILE);
749 renderEdgeLabels(g);
750 glEndList();
751 }
752
753 void updateSmGraph(Agraph_t * g,topview* t)
754 {
755 Agnode_t *v;
756 Agedge_t *e;
757 float eLength=0;
758 float totalELength=0;
759
760 t->Nodecount=0;
761 t->maxedgelen=0;
762
763 t->global_z=0;
764 t->sel.selPoly = (glCompPoly_t){0};
765
766 if(!t)
767 return ;
768 /*Node Loop*/
769 for (v = agfstnode(g); v; v = agnxtnode(g, v)) {
770 for (e = agfstout(g, v); e; e = agnxtout(g, e))
771 {
772 eLength=getEdgeLength(e);
773 if(eLength > t->maxedgelen)
774 t->maxedgelen=eLength;
775 totalELength += eLength;
776 }
777 t->Nodecount++;
778
779 }
780 aginit(g, AGNODE, "nodeRec", sizeof(nodeRec), false);
781 aginit(g, AGEDGE, "edgeRec", sizeof(edgeRec), false);
782
783 set_boundaries(g);
784 view->Topview=t;
785
786
787 /*render nodes once to get set some attributes set,THIS IS A HACK, FIX IT*/
788 renderNodes(g);
789 cacheEdges(g,t);
790 cacheSelectedEdges(g,t);
791 cacheNodes(g,t);
792 cacheSelectedNodes(g,t);
793 cacheEdgeLabels(g,t);
794 cacheNodeLabels(g,t);
795 }
796 void initSmGraph(Agraph_t * g,topview* rv)
797 {
798 /*create attribute list*/
799 rv->attributes=load_attr_list(view->g[view->activeGraph]);
800
801 // set topological fisheye to NULL
802 rv->fisheyeParams.h = NULL;
803
804 rv->fisheyeParams.active = 0;
805 rv->cache.node_id = UINT_MAX;
806 rv->cache.selnode_id = UINT_MAX;
807 rv->cache.edge_id = UINT_MAX;
808 rv->cache.seledge_id = UINT_MAX;
809 rv->sel.selectEdges = false;
810 rv->sel.selectNodes = true;
811
812 updateSmGraph(g,rv);
813 }
814
815 void renderSmGraph(topview* t)
816 {
817 // We would like to have blending affect where node and edge overlap. To
818 // achieve this, depth test should be turned off.
819
820 glEnable(GL_POINT_SMOOTH);
821 glEnable(GL_DEPTH_TEST);
822 glEnable(GL_DEPTH);
823
824 if(view->drawedges)
825 {
826 glCallList(t->cache.edge_id);
827 glCallList(t->cache.seledge_id);
828 if(view->drawedgelabels)
829 {
830 if (view->zoom * -1 < t->fitin_zoom / view->labelnumberofnodes * -1)
831 glCallList(t->cache.edgelabel_id);
832
833 }
834 }
835 if(view->drawnodes)
836 {
837 glPointSize((float)(view->nodeScale * t->fitin_zoom / view->zoom));
838 glCallList(t->cache.node_id);
839 glCallList(t->cache.selnode_id);
840 if(view->drawnodelabels)
841 {
842 if (view->zoom * -1 < t->fitin_zoom / view->labelnumberofnodes * -1)
843 glCallList(t->cache.nodelabel_id);
844 }
845 }
846
847 }