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

« back to all changes in this revision

Viewing changes to dag/geom.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
/*
 
2
 *      compute node and edge coordinates 
 
3
 */
 
4
 
 
5
#include <dag.h>
 
6
 
 
7
#ifdef DMALLOC
 
8
#include "dmalloc.h"
 
9
#endif
 
10
 
 
11
static void update_bb(ddview_t *view)
 
12
{
 
13
        Agnode_t        *left, *right;
 
14
        int                     r;
 
15
        double          lb,glb,rb,grb;  /* left and right bounds: local, global */
 
16
        ilcoord_t       sz;
 
17
        rank_t          *rd;
 
18
 
 
19
        glb = MAXDOUBLE; grb = -MAXDOUBLE;
 
20
        for (r = view->config->low; r <= view->config->high; r++) {
 
21
                if ((left = dd_leftmost(view,r))) {
 
22
                        sz = dd_nodesize(view,left);
 
23
                        lb = dd_pos(left).x - sz.x / 2.0;
 
24
                        if (glb > lb) glb = lb;
 
25
                        right = dd_rightmost(view,r);
 
26
                        sz = dd_nodesize(view,right);
 
27
                        rb = dd_pos(right).x + sz.x / 2.0;
 
28
                        if (grb < rb) grb = rb;
 
29
                }
 
30
        }
 
31
 
 
32
        view->base.client->actual_bb.ll.x = glb;
 
33
        rd = dd_rankd(view,view->config->low);
 
34
        if (rd)
 
35
                view->base.client->actual_bb.ll.y = rd->y_base - rd->delta_above;
 
36
 
 
37
        view->base.client->actual_bb.ur.x = grb;
 
38
        rd = dd_rankd(view,view->config->high);
 
39
        if (rd)
 
40
                view->base.client->actual_bb.ur.y = rd->y_base + rd->delta_below;
 
41
 
 
42
        /*BASE(view)->bb.size.ll.x = glb;
 
43
        BASE(view)->bb.size.ur.x = grb;*/
 
44
        BASE(view)->bb.size = view->base.client->actual_bb;
 
45
        BASE(view)->bb.valid = TRUE;
 
46
}
 
47
 
 
48
/* (re)spline edges */
 
49
 
 
50
static ilbool node_moved(Agnode_t *n)
 
51
{
 
52
        ddnode_t        *dspec;
 
53
 
 
54
        dspec = dd_node(n);
 
55
        if (dspec->prev.valid &&
 
56
                (dspec->cur.pos.x == dspec->prev.pos.x) &&
 
57
                (dspec->cur.pos.y == dspec->prev.pos.y)) return FALSE;
 
58
        return TRUE;
 
59
}
 
60
 
 
61
static ilbool edge_needs_redraw(ddview_t *view, ddpath_t *path)
 
62
{
 
63
        Agedge_t        *ve;
 
64
        Agnode_t        *n, *left, *right;
 
65
        double          x;
 
66
        double          sep;
 
67
        ddnode_t        *nd;
 
68
 
 
69
        if (path->unclipped_path == NILcurve) return TRUE; /* new edge */
 
70
        /* check for endpoint resize */
 
71
        if (il_node(agtail(path->model))->update & IL_UPD_SHAPE) return TRUE;
 
72
        if (il_node(aghead(path->model))->update & IL_UPD_SHAPE) return TRUE;
 
73
 
 
74
        ve = path->first;
 
75
        if (ve == NILedge) {    /* flat */
 
76
                if (node_moved(dd_rep(agtail(path->model)))) return TRUE;
 
77
                if (node_moved(dd_rep(aghead(path->model)))) return TRUE;
 
78
                return FALSE;
 
79
        }
 
80
        sep = view->base.client->separation.x;
 
81
        if (node_moved(agtail(ve))) return TRUE;
 
82
        while (dd_is_a_vnode((n = ve->node))) {
 
83
                if(NOT(dd_node(n)->actual_x_valid)) return TRUE;
 
84
                x = D(dd_node(n)->actual_x);
 
85
                if ((left = dd_left(view, n))) {
 
86
                        nd = dd_node(left);
 
87
                        if (dd_is_a_vnode(left)) {
 
88
                                if (nd->actual_x_valid && D(nd->actual_x) + sep > x) return TRUE;
 
89
                        }
 
90
                        else { if (nd->cur.pos.x + il_nodesize(BASE(view),nd->model).x / 2.0 + sep > x) return TRUE; }
 
91
                }
 
92
                if ((right = dd_right(view, n))) {
 
93
                        nd = dd_node(right);
 
94
                        if (dd_is_a_vnode(right)) {
 
95
                                if (nd->actual_x_valid && D(nd->actual_x) - sep < x) return TRUE;
 
96
                        }
 
97
                        else { if (nd->cur.pos.x - il_nodesize(BASE(view),nd->model).x / 2.0 - sep < x) return TRUE; }
 
98
                }
 
99
                ve = ve->node->out;
 
100
        }
 
101
        if (node_moved(aghead(ve))) return TRUE;
 
102
        return FALSE;
 
103
}
 
104
 
 
105
static void update_edges(ddview_t *view)
 
106
{
 
107
        Agnode_t        *mn;
 
108
        Agedge_t        *me;
 
109
        ddpath_t        *path;
 
110
        ILedge_t        *espec;
 
111
 
 
112
        for (mn = agfstnode(BASE(view)->model.main); mn; mn = agnxtnode(mn)) {
 
113
                for (me = agfstout(mn); me; me = agnxtout(me)) {
 
114
                        if (agsubedge(BASE(view)->model.e[IL_DEL],me,FALSE)) continue;
 
115
                        if ((path = dd_pathrep(me))) {
 
116
                                espec = ddm_espec(me);
 
117
                                if (edge_needs_redraw(view,path)) {
 
118
                                        if (path->unclipped_path)
 
119
                                                il_freecurve(vmregion(path->unclipped_path),
 
120
                                                        path->unclipped_path);
 
121
                                        path->unclipped_path = NILcurve;
 
122
                                        il_register_edge_callback(BASE(view), espec, IL_MOD);
 
123
                                }
 
124
                        }
 
125
                }
 
126
        }
 
127
        for (mn = agfstnode(BASE(view)->model.main); mn; mn = agnxtnode(mn)) {
 
128
                for (me = agfstout(mn); me; me = agnxtout(me)) {
 
129
                        if (agsubedge(BASE(view)->model.e[IL_DEL],me,FALSE)) continue;
 
130
                        if ((path = dd_pathrep(me)) && (path->unclipped_path == NILcurve))
 
131
                                dd_make_edge_spline(view,path);
 
132
                }
 
133
        }
 
134
}
 
135
 
 
136
/* recompute coordinates */
 
137
static int                      Giter;
 
138
 
 
139
void dd_update_geometry(ddview_t *view)
 
140
{
 
141
        Giter++;
 
142
 
 
143
        dd_update_X(view);
 
144
        dd_update_Y(view);
 
145
        update_bb(view);
 
146
dd_check_all(view);
 
147
        update_edges(view);
 
148
}