7
/* this illustrates how one might employ inheritance */
9
typedef struct geoview_s {
11
int ctr; /* count number of layout updates */
14
static ilbool GeoOpen(ILview_t *client_view)
17
extern ILengine_t GeoGraph; /* forward reference */
25
rv = il_open_view(&GeoGraph, client_view, Agdirected, S);
29
static void GeoClose(ILview_t *client_view)
31
il_close_view(client_view->pvt);
34
static ilcoord_t choose_random_pos(engview_t *view)
39
f = il_nodesep(view).x;
40
rv.x = f * agnnodes(view->model.main) * drand48();
41
rv.y = f * agnnodes(view->model.main) * drand48();
45
static void place_new_nodes(ILview_t *view)
47
Agraph_t *new_node_graph;
52
new_node_graph = view->pvt->model.v[IL_INS];
55
for (n = agfstnode(new_node_graph); n; n = agnxtnode(n)) {
57
if (spec->pos_valid == FALSE) /* need auto-placement */
58
il_set_pos(n,choose_random_pos(ev));
62
static void move_old_nodes(ILview_t *view)
64
Agraph_t *moved_node_graph;
69
moved_node_graph = view->pvt->model.v[IL_MOD];
71
for (n0 = agfstnode(moved_node_graph); n0; n0 = agnxtnode(n0)) {
72
n = agsubnode(view->pvt->model.main,n0,FALSE);
74
if ((spec->update & IL_UPD_MOVE) == FALSE) continue;
75
if (spec->pos_valid == FALSE) /* need auto-placement */
76
il_set_pos(n,choose_random_pos(view->pvt));
78
/* mark its edges as needing auto-placement */
79
for (e = agfstedge(n); e; e = agnxtedge(e,n)) {
80
il_register_edge_callback(view->pvt,il_edge(e),IL_MOD);
85
static void layout_edge(ILview_t *view, Agedge_t *model_e)
90
ilcurve_t temp, *curve;
94
spec = il_edge(model_e);
95
u = il_find_node(ev,(ILnode_t*)(spec->tail.term));
96
v = il_find_node(ev,(ILnode_t*)(spec->head.term));
98
/* note: if the user provided an edge route, we're about to lose it.
99
* if we wanted to do this cleanly, we would need a test to determine
100
* if the user's edge spline or polyline was consistent with the
101
* endpoints and perhaps the rest of the layout. (this is just demo code.)
103
if (spec->pos) il_freeshape(vmregion(spec->pos),spec->pos);
105
/* all this just to draw a line! */
110
temp.type = IL_POLYLINE;
111
curve = il_clip_endpoints(ev, &temp, il_node(u), il_node(v));
112
spec->pos = il_newshape(agheap(ilmodel(view)), curve, NIL(ilshape_t*));
115
static void adjust_edges_of(ILview_t *view, Agraph_t *g)
120
for (n = agfstnode(g); n; n = agnxtnode(n))
121
for (e = agfstout(n); e; e = agnxtout(e))
125
static void adjust_edges(ILview_t *view)
128
adjust_edges_of(view,view->pvt->model.e[IL_INS]);
129
adjust_edges_of(view,view->pvt->model.e[IL_MOD]);
135
static ilbool GeoWork(ILview_t *view)
144
place_new_nodes(view);
145
move_old_nodes(view);
147
rv = il_issue_callbacks(ev);
148
il_clear_callbacks(ev);
153
ILengine_t GeoGraph = {