~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to geo/geo.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <engine.h>
 
2
 
 
3
#ifdef DMALLOC
 
4
#include "dmalloc.h"
 
5
#endif
 
6
 
 
7
/* this illustrates how one might employ inheritance */
 
8
 
 
9
typedef struct geoview_s {
 
10
        engview_t       base;
 
11
        int                     ctr;    /* count number of layout updates */
 
12
} geoview_t;
 
13
 
 
14
static ilbool GeoOpen(ILview_t *client_view)
 
15
{
 
16
        engview_t       *rv;
 
17
        extern ILengine_t GeoGraph;     /* forward reference */
 
18
 
 
19
        unsigned int S[] = {
 
20
                sizeof(geoview_t),
 
21
                sizeof(engnode_t),
 
22
                sizeof(engedge_t)
 
23
        };
 
24
 
 
25
        rv = il_open_view(&GeoGraph, client_view, Agdirected, S);
 
26
        return TRUE;
 
27
}
 
28
 
 
29
static void GeoClose(ILview_t *client_view)
 
30
{
 
31
        il_close_view(client_view->pvt);
 
32
}
 
33
 
 
34
static ilcoord_t choose_random_pos(engview_t *view)
 
35
{
 
36
        ilcoord_t       rv;
 
37
        double          f;
 
38
 
 
39
        f = il_nodesep(view).x;
 
40
        rv.x = f * agnnodes(view->model.main) * drand48();
 
41
        rv.y = f * agnnodes(view->model.main) * drand48();
 
42
        return rv;
 
43
}
 
44
 
 
45
static void place_new_nodes(ILview_t *view)
 
46
{
 
47
        Agraph_t        *new_node_graph;
 
48
        Agnode_t        *n;
 
49
        ILnode_t        *spec;
 
50
        engview_t       *ev;
 
51
 
 
52
        new_node_graph = view->pvt->model.v[IL_INS];
 
53
        ev = view->pvt;
 
54
 
 
55
        for (n = agfstnode(new_node_graph); n; n = agnxtnode(n)) {
 
56
                spec = il_node(n);
 
57
                if (spec->pos_valid == FALSE)   /* need auto-placement */
 
58
                        il_set_pos(n,choose_random_pos(ev));
 
59
        }
 
60
}
 
61
 
 
62
static void move_old_nodes(ILview_t *view)
 
63
{
 
64
        Agraph_t        *moved_node_graph;
 
65
        Agnode_t        *n0, *n;
 
66
        Agedge_t        *e;
 
67
        ILnode_t        *spec;
 
68
 
 
69
        moved_node_graph = view->pvt->model.v[IL_MOD];
 
70
 
 
71
        for (n0 = agfstnode(moved_node_graph); n0; n0 = agnxtnode(n0)) {
 
72
                n = agsubnode(view->pvt->model.main,n0,FALSE);
 
73
                spec = il_node(n);
 
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));
 
77
 
 
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);
 
81
                }
 
82
        }
 
83
}
 
84
 
 
85
static void layout_edge(ILview_t *view, Agedge_t *model_e)
 
86
{
 
87
        Agnode_t        *u, *v;
 
88
        ILedge_t        *spec;
 
89
        engview_t       *ev;
 
90
        ilcurve_t       temp, *curve;
 
91
        ilcoord_t       A[2];
 
92
 
 
93
        ev = view->pvt;
 
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));
 
97
 
 
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.)
 
102
         */
 
103
        if (spec->pos) il_freeshape(vmregion(spec->pos),spec->pos);
 
104
 
 
105
        /* all this just to draw a line! */
 
106
        A[0] = il_pos(u);
 
107
        A[1] = il_pos(v);
 
108
        temp.p = A;
 
109
        temp.n = 2;
 
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*));
 
113
}
 
114
 
 
115
static void adjust_edges_of(ILview_t *view, Agraph_t *g)
 
116
{
 
117
        Agnode_t        *n;
 
118
        Agedge_t        *e;
 
119
 
 
120
        for (n = agfstnode(g); n; n = agnxtnode(n))
 
121
                for (e = agfstout(n); e; e = agnxtout(e))
 
122
                        layout_edge(view,e);
 
123
}
 
124
 
 
125
static void adjust_edges(ILview_t *view)
 
126
{
 
127
#ifndef EDGEROUTER
 
128
        adjust_edges_of(view,view->pvt->model.e[IL_INS]);
 
129
        adjust_edges_of(view,view->pvt->model.e[IL_MOD]);
 
130
#else
 
131
        ilroutem(view);
 
132
#endif
 
133
}
 
134
 
 
135
static ilbool GeoWork(ILview_t *view)
 
136
{
 
137
        geoview_t       *gv;
 
138
        engview_t       *ev;
 
139
        ilbool          rv;
 
140
 
 
141
        ev = view->pvt;
 
142
        gv = (geoview_t*)ev;
 
143
 
 
144
        place_new_nodes(view);
 
145
        move_old_nodes(view);
 
146
        adjust_edges(view);
 
147
        rv = il_issue_callbacks(ev);
 
148
        il_clear_callbacks(ev);
 
149
        gv->ctr++;
 
150
        return rv;
 
151
}
 
152
 
 
153
ILengine_t GeoGraph = {
 
154
        GeoOpen,
 
155
        GeoClose,
 
156
        il_batch_ins,
 
157
        il_batch_mod,
 
158
        il_batch_del,
 
159
        GeoWork,
 
160
        ilmdlobj_to_spec,
 
161
        ilspec_to_mdlobj
 
162
};