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

« back to all changes in this revision

Viewing changes to dotty/dotty_layout.lefty

  • 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
#
 
2
# dotty_layout: layout functions and data structures
 
3
#
 
4
dotty.grablserver = function (lserver) {
 
5
    local fd;
 
6
 
 
7
    if (~dotty.lservers[lserver] | tablesize (dotty.lservers[lserver]) == 0) {
 
8
        if (~((fd = openio ('pipe', lserver, 'r+')) >= 0)) {
 
9
            dotty.message (0, concat ('cannot start ', lserver));
 
10
            return null;
 
11
        }
 
12
        dotty.lservers[lserver][fd] = [
 
13
            'fd' = fd;
 
14
            'count' = 0;
 
15
        ];
 
16
    }
 
17
    for (fd in dotty.lservers[lserver]) {
 
18
        dotty.lservers[lserver][fd].count =
 
19
                dotty.lservers[lserver][fd].count + 1;
 
20
        dotty.lservers.inuse[fd] = dotty.lservers[lserver][fd];
 
21
        remove (fd, dotty.lservers[lserver]);
 
22
        return fd;
 
23
    }
 
24
};
 
25
dotty.releaselserver = function (lserver, fd, state) {
 
26
    if (state == 'bad' | dotty.lservers.inuse[fd].count > 40) {
 
27
        closeio (fd, 'kill');
 
28
        remove (fd, dotty.lservers.inuse);
 
29
        return;
 
30
    }
 
31
    dotty.lservers[lserver][fd] = dotty.lservers.inuse[fd];
 
32
    remove (fd, dotty.lservers.inuse);
 
33
};
 
34
dotty.protogt.startlayout = function (gt) {
 
35
    local lpt, fd;
 
36
 
 
37
    if (gt.layoutpending >= 1) {
 
38
        lpt = dotty.layoutpending[gt.gtid];
 
39
        if (gt.layoutmode == 'async')
 
40
            monitor ('off', lpt.fd);
 
41
        dotty.releaselserver (gt.lserver, lpt.fd, 'bad');
 
42
        remove (gt.gtid, dotty.layoutpending);
 
43
        gt.layoutpending = 0;
 
44
        gt.haveinput = 0;
 
45
        dotty.popbusy (gt, gt.views);
 
46
    }
 
47
    if (~((fd = dotty.grablserver (gt.lserver)) >= 0))
 
48
        return null;
 
49
    dotty.pushbusy (gt, gt.views);
 
50
    writegraph (fd, gt.graph, 1);
 
51
    gt.layoutpending = 1;
 
52
    dotty.layoutpending[gt.gtid] = [
 
53
        'fd' = fd;
 
54
        'gtid' = gt.gtid;
 
55
    ];
 
56
    if (gt.layoutmode == 'async')
 
57
        monitor ('on', fd);
 
58
    return 1;
 
59
};
 
60
dotty.protogt.finishlayout = function (gt) {
 
61
    local graph, lpt, fd;
 
62
 
 
63
    if (~(gt.layoutpending >= 1)) {
 
64
        dotty.message (0, concat ('no layout pending for graph ', gt.gtid));
 
65
        return null;
 
66
    }
 
67
    lpt = dotty.layoutpending[gt.gtid];
 
68
    if (~(graph = readgraph (lpt.fd))) {
 
69
        if (gt.layoutmode == 'async')
 
70
            monitor ('off', lpt.fd);
 
71
        dotty.releaselserver (gt.lserver, lpt.fd, 'bad');
 
72
        if (gt.layoutpending == 2) {
 
73
            dotty.message (0, concat ('giving up on ', gt.lserver));
 
74
            if ((fd = openio ('file', 'dottybug.dot', 'w+')) >= 0) {
 
75
                writegraph (fd, gt.graph, 0);
 
76
                closeio (fd);
 
77
                dotty.message (0,
 
78
                        concat ('graph that causes ', gt.lserver));
 
79
                dotty.message (0,
 
80
                        'to fail has been saved in file dottybug.dot');
 
81
                dotty.message (0,
 
82
                        'please forward this file to ek@research.att.com');
 
83
            }
 
84
            dotty.popbusy (gt, gt.views);
 
85
            gt.layoutpending = 0;
 
86
            gt.haveinput = 0;
 
87
            return 1;
 
88
        }
 
89
        dotty.message (1,
 
90
                concat ('lost connection to ', gt.lserver, ', restarting...'));
 
91
        lpt.fd = dotty.grablserver (gt.lserver);
 
92
        writegraph (lpt.fd, gt.graph, 1);
 
93
        if (gt.layoutmode == 'async')
 
94
            monitor ('on', lpt.fd);
 
95
        gt.layoutpending = 2;
 
96
        gt.haveinput = 0;
 
97
        return null;
 
98
    }
 
99
    if (gt.layoutmode == 'async')
 
100
        monitor ('off', lpt.fd);
 
101
    dotty.releaselserver (gt.lserver, lpt.fd, null);
 
102
    remove (gt.gtid, dotty.layoutpending);
 
103
    gt.layoutpending = 0;
 
104
    gt.haveinput = 0;
 
105
    gt.unpacklayout (gt, graph);
 
106
    dotty.popbusy (gt, gt.views);
 
107
    return 1;
 
108
};
 
109
dotty.protogt.cancellayout = function (gt) {
 
110
    local lpt, vid;
 
111
 
 
112
    if (gt.layoutpending >= 1) {
 
113
        lpt = dotty.layoutpending[gt.gtid];
 
114
        if (gt.layoutmode == 'async')
 
115
            monitor ('off', lpt.fd);
 
116
        dotty.releaselserver (gt.lserver, lpt.fd, 'bad');
 
117
        remove (gt.gtid, dotty.layoutpending);
 
118
        gt.layoutpending = 0;
 
119
        gt.haveinput = 0;
 
120
        dotty.popbusy (gt, gt.views);
 
121
    }
 
122
};
 
123
dotty.protogt.unpacklayout = function (gt, graph2) {
 
124
    local graph, gid, sgraph1, sgraph2, nid, node1, node2;
 
125
    local t1, t2, t3, n2, i, j, k, l, m, eid, edge1, edge2, points;
 
126
    local pa1, pa2, pb1, pb2, la, lb;
 
127
 
 
128
    graph = gt.graph;
 
129
    for (gid in graph2.graphdict) {
 
130
        if (~(sgraph1 = graph.graphs[graph.graphdict[gid]]))
 
131
            continue;
 
132
        sgraph2 = graph2.graphs[graph2.graphdict[gid]];
 
133
        if (sgraph2.graphattr.bb & sgraph2.graphattr.bb ~= '') {
 
134
            t1 = split (sgraph2.graphattr.bb, ',');
 
135
            sgraph1.rect = [
 
136
                0 = ['x' = ston (t1[0]); 'y' = ston (t1[1]);];
 
137
                1 = ['x' = ston (t1[2]); 'y' = ston (t1[3]);];
 
138
            ];
 
139
        } else
 
140
            sgraph1.rect = [];
 
141
        if (sgraph2.graphattr.lp & sgraph2.graphattr.lp ~= '') {
 
142
            t1 = split (sgraph2.graphattr.lp, ',');
 
143
            sgraph1.lp = ['x' = ston (t1[0]); 'y' = ston (t1[1]);];
 
144
        } else
 
145
            sgraph1.lp = [];
 
146
    }
 
147
    for (nid in graph2.nodedict) {
 
148
        if (~(node1 = graph.nodes[graph.nodedict[nid]]))
 
149
            continue;
 
150
        node2 = graph2.nodes[graph2.nodedict[nid]];
 
151
        t1 = split (node2.attr.pos, ',');
 
152
        node1.pos = ['x' = ston (t1[0]); 'y' = ston (t1[1]);];
 
153
        node1.size.x = ston (node2.attr.width) * 72;
 
154
        node1.size.y = ston (node2.attr.height) * 72;
 
155
        if (node2.attr.rects)
 
156
            node1.fields = parsegraphlabel (node2.attr.label, node2.attr.rects);
 
157
    }
 
158
    for (eid in graph2.edges) {
 
159
        edge2 = graph2.edges[eid];
 
160
        if (edge2.attr.id) {
 
161
            if (~(edge1 = graph.edges[ston (edge2.attr.id)]))
 
162
                continue;
 
163
        } else if (graph == graph2)
 
164
            edge1 = edge2;
 
165
        if (edge2.attr.pos) {
 
166
            points = [];
 
167
            remove ('sp', edge1);
 
168
            remove ('ep', edge1);
 
169
            t2 = split (edge2.attr.pos, ';');
 
170
            for (k = 0; t2[k]; k = k + 1) {
 
171
                t3 = split (t2[k], ' ');
 
172
                n2 = tablesize (t3);
 
173
                j = 0;
 
174
            i = 0;
 
175
                t1 = split (t3[0], ',');
 
176
            while (t1[0] == 's' | t1[0] == 'e') {
 
177
                if (t1[0] == 's')
 
178
                    edge1.sp = ['x' = ston (t1[1]); 'y' = ston (t1[2]);];
 
179
                else # (t1[0] == 'e')
 
180
                    edge1.ep = ['x' = ston (t1[1]); 'y' = ston (t1[2]);];
 
181
                i = i + 1;
 
182
                    t1 = split (t3[i], ',');
 
183
            }
 
184
                points[k][j] = ['x' = ston (t1[0]); 'y' = ston (t1[1]);];
 
185
            i = i + 1;
 
186
                j = j + 1;
 
187
            while (i < n2) {
 
188
                    t1 = split (t3[i], ',');
 
189
                    points[k][j] = ['x' = ston (t1[0]); 'y' = ston (t1[1]);];
 
190
                j = j + 1;
 
191
                i = i + 1;
 
192
            }
 
193
        }
 
194
            if (k > 1) { # concentrators
 
195
                l = k;
 
196
                while (l > 1) {
 
197
                    la = tablesize (points[0]);
 
198
                    pa1 = points[0][0];
 
199
                    pa2 = points[0][la - 1];
 
200
                    for (k = 1; points[k]; k = k + 1) {
 
201
                        lb = tablesize (points[k]);
 
202
                        pb1 = points[k][0];
 
203
                        pb2 = points[k][lb - 1];
 
204
                        if (pa1.x == pb2.x & pa1.y == pb2.y) {
 
205
                            for (m = 1; m < la; m = m + 1) {
 
206
                                points[k][lb] = points[0][m];
 
207
                                lb = lb + 1;
 
208
                            }
 
209
                            points[0] = points[l - 1];
 
210
                            remove (l - 1, points);
 
211
                            break;
 
212
                        } else if (pa2.x == pb1.x & pa2.y == pb1.y) {
 
213
                            for (m = 1; m < lb; m = m + 1) {
 
214
                                points[0][la] = points[k][m];
 
215
                                la = la + 1;
 
216
                            }
 
217
                            points[k] = points[l - 1];
 
218
                            remove (l - 1, points);
 
219
                            break;
 
220
                        }
 
221
                    }
 
222
                    if (points[l - 1]) {
 
223
                        dotty.message (1, 'failed to match edge points');
 
224
                        break;
 
225
                    }
 
226
                    l = l - 1;
 
227
                }
 
228
            }
 
229
            edge1.points = points[0];
 
230
        }
 
231
        if (edge2.attr.lp) {
 
232
            t1 = split (edge2.attr.lp, ',');
 
233
            edge1.lp = ['x' = ston (t1[0]); 'y' = ston (t1[1]);];
 
234
        }
 
235
    }
 
236
    t1 = split (graph2.graphattr.bb, ',');
 
237
    graph.rect[0].x = ston (t1[0]);
 
238
    graph.rect[0].y = ston (t1[1]);
 
239
    graph.rect[1].x = ston (t1[2]);
 
240
    graph.rect[1].y = ston (t1[3]);
 
241
    if (graph2.graphattr.lp & graph2.graphattr.lp ~= '') {
 
242
        t1 = split (graph2.graphattr.lp, ',');
 
243
        graph.lp = ['x' = ston (t1[0]); 'y' = ston (t1[1]);];
 
244
    } else
 
245
        graph.lp = [];
 
246
    if (gt.graph ~= graph2)
 
247
        return;
 
248
    # strip position and size info from the attributes
 
249
    for (gid in graph2.graphdict) {
 
250
        sgraph2 = graph2.graphs[graph2.graphdict[gid]];
 
251
        if (sgraph2.graphattr.bb)
 
252
            remove ('bb', sgraph2.graphattr);
 
253
    }
 
254
    for (nid in graph2.nodedict) {
 
255
        node2 = graph2.nodes[graph2.nodedict[nid]];
 
256
        if (node2.attr.rects)
 
257
            remove ('rects', node2.attr);
 
258
        remove ('pos', node2.attr);
 
259
        remove ('width', node2.attr);
 
260
        remove ('height', node2.attr);
 
261
    }
 
262
    for (eid in graph2.edges) {
 
263
        edge2 = graph2.edges[eid];
 
264
        if (edge2.attr.pos)
 
265
            remove ('pos', edge2.attr);
 
266
        if (edge2.attr.lp)
 
267
            remove ('lp', edge2.attr);
 
268
    }
 
269
    remove ('bb', graph2.graphattr);
 
270
    if (graph2.graphattr.lp)
 
271
        remove ('lp', graph2.graphattr);
 
272
};