163
|
1 /* ----------------------------------------------------------------------------
|
|
2 * File : draw.c
|
|
3 * Purpose : drawing-specific routines for dynamic tree program
|
|
4 * ----------------------------------------------------------------------------
|
|
5 */
|
|
6
|
167
|
7 #include <stdlib.h>
|
163
|
8 #include <X11/Intrinsic.h>
|
|
9 #include <X11/StringDefs.h>
|
|
10
|
167
|
11 #include "dissolve.h"
|
163
|
12 #include "defs.h"
|
|
13 #include "tree.h"
|
|
14 #include "dbl.h"
|
|
15 #include "intf.h"
|
|
16
|
|
17 /* ------------------------------------------------------------------------- */
|
|
18 /* Global Variables */
|
|
19 /* ------------------------------------------------------------------------- */
|
|
20
|
|
21 Tree *TheTree;
|
|
22
|
|
23
|
|
24 /* ------------------------------------------------------------------------- */
|
|
25 /* Local Variables */
|
|
26 /* ------------------------------------------------------------------------- */
|
|
27
|
167
|
28 static char AnimationMode = FALSE;
|
163
|
29 static char strbuf[BUFSIZ];
|
|
30 static int AnimationStep = ANIMATION_STEP;
|
|
31
|
|
32
|
|
33 /* ------------------------------------------------------------------------- */
|
|
34 /* Functions */
|
|
35 /* ------------------------------------------------------------------------- */
|
|
36
|
|
37
|
|
38 /* ----------------------------------------------------------------------------
|
167
|
39 *
|
163
|
40 * BeginFrame() provides an abstraction for double buffering. It should
|
|
41 * be called prior to creating a new frame of animation.
|
167
|
42 *
|
163
|
43 * ----------------------------------------------------------------------------
|
|
44 */
|
|
45
|
|
46 void
|
167
|
47 BeginFrame(void)
|
163
|
48 {
|
|
49 DBLbegin_frame(TreeDrawingAreaDB);
|
|
50 }
|
|
51
|
|
52
|
|
53 /* ----------------------------------------------------------------------------
|
167
|
54 *
|
163
|
55 * EndFrame() provides an abstraction for double buffering. It should
|
|
56 * be called after creating a new frame of animation.
|
167
|
57 *
|
163
|
58 * ----------------------------------------------------------------------------
|
|
59 */
|
|
60
|
|
61 void
|
167
|
62 EndFrame(void)
|
163
|
63 {
|
|
64 DBLend_frame(TreeDrawingAreaDB, 0);
|
|
65 }
|
|
66
|
|
67
|
|
68 /* ----------------------------------------------------------------------------
|
167
|
69 *
|
163
|
70 * GetDrawingSize() gets the size of the drawing area, and returns the
|
|
71 * dimensions in the arguments.
|
167
|
72 *
|
163
|
73 * ----------------------------------------------------------------------------
|
|
74 */
|
|
75
|
167
|
76 static void
|
|
77 GetDrawingSize(int *width, int *height)
|
163
|
78 {
|
|
79 Dimension w, h;
|
167
|
80 Arg al [2];
|
|
81
|
|
82 XtSetArg (al [0], XtNwidth, &w);
|
|
83 XtSetArg (al [1], XtNheight, &h);
|
|
84 XtGetValues(TreeDrawingArea, al, 2);
|
163
|
85
|
|
86 *width = (int) w;
|
|
87 *height = (int) h;
|
|
88 }
|
|
89
|
|
90
|
|
91 /* ----------------------------------------------------------------------------
|
167
|
92 *
|
163
|
93 * SetDrawingSize() sets the size of the drawing area to the given
|
167
|
94 * dimensions.
|
|
95 *
|
|
96 * ----------------------------------------------------------------------------
|
|
97 */
|
|
98
|
|
99 static void
|
|
100 SetDrawingSize(int width, int height)
|
|
101 {
|
|
102 Arg al [2];
|
|
103 XtSetArg (al [0], XtNwidth, (Dimension) width);
|
|
104 XtSetArg (al [1], XtNheight, (Dimension) height);
|
|
105 XtSetValues (TreeDrawingArea, al, 2);
|
|
106 }
|
|
107
|
|
108
|
|
109 /* ----------------------------------------------------------------------------
|
|
110 *
|
|
111 * SetDrawingTree() is used to specify what tree is to be drawn in the
|
|
112 * drawing area.
|
|
113 *
|
163
|
114 * ----------------------------------------------------------------------------
|
|
115 */
|
|
116
|
|
117 void
|
167
|
118 SetDrawingTree(Tree *tree)
|
163
|
119 {
|
167
|
120 TheTree = tree;
|
163
|
121 }
|
|
122
|
|
123
|
|
124 /* ----------------------------------------------------------------------------
|
167
|
125 *
|
163
|
126 * SetNodeLabel() sets the label text of the specified node and computes
|
|
127 * the bounding rectangle so that the layout can be determined. This
|
|
128 * function is called when new nodes are created. If TreeAlignNodes is
|
|
129 * True, the string is truncated so that the node's width is no longer
|
|
130 * than TreeParentDistance.
|
167
|
131 *
|
163
|
132 * ----------------------------------------------------------------------------
|
|
133 */
|
|
134
|
|
135 void
|
167
|
136 SetNodeLabel(Tree *node, char *label)
|
163
|
137 {
|
|
138 int len;
|
|
139 int dummy;
|
|
140 XCharStruct rtrn;
|
167
|
141
|
163
|
142 len = strlen(label);
|
|
143 while (len > 1) {
|
|
144 XTextExtents(TreeLabelFont, label, len, &dummy, &dummy, &dummy, &rtrn);
|
|
145 node->width = rtrn.lbearing + rtrn.rbearing + (LABEL_MAT_WIDTH * 2) + 1;
|
|
146 node->height = rtrn.ascent + rtrn.descent + (LABEL_MAT_HEIGHT * 2) + 1;
|
|
147 if (TreeAlignNodes) {
|
|
148 if (node->width <= (2 * TreeParentDistance))
|
|
149 break;
|
|
150 else
|
|
151 len--;
|
|
152 }
|
|
153 else
|
|
154 break;
|
|
155 }
|
167
|
156
|
163
|
157 node->label.text = label;
|
|
158 node->label.len = len;
|
|
159 node->label.xoffset = LABEL_MAT_WIDTH + 1,
|
|
160 node->label.yoffset = rtrn.ascent + LABEL_MAT_HEIGHT + 1;
|
|
161 }
|
|
162
|
|
163
|
|
164 /* ----------------------------------------------------------------------------
|
167
|
165 *
|
|
166 * SetDrawColor() sets the drawing color of the TreeDrawingArea.
|
|
167 *
|
163
|
168 * ----------------------------------------------------------------------------
|
|
169 */
|
|
170
|
|
171 void
|
167
|
172 SetDrawColor(int color)
|
163
|
173 {
|
|
174 XSetForeground(TreeDrawingAreaDB->display, TreeDrawingAreaDB->gc,
|
|
175 TreeDrawingAreaDB->colors[color]);
|
|
176 }
|
|
177
|
|
178 /* ----------------------------------------------------------------------------
|
167
|
179 *
|
163
|
180 * SetLineWidth() sets the line width of lines drawn in the TreeDrawingArea.
|
167
|
181 *
|
163
|
182 * ----------------------------------------------------------------------------
|
|
183 */
|
|
184
|
167
|
185 static void
|
|
186 SetLineWidth(unsigned int width)
|
163
|
187 {
|
|
188 XSetLineAttributes(TreeDrawingAreaDB->display, TreeDrawingAreaDB->gc,
|
|
189 width, LineSolid, CapButt, JoinRound);
|
|
190 }
|
|
191
|
|
192
|
|
193 /* ----------------------------------------------------------------------------
|
167
|
194 *
|
|
195 * SetContours() sets the visibility of three possible contour modes:
|
163
|
196 * the outside contour, all subtree contours, or selected contours.
|
167
|
197 *
|
163
|
198 * ----------------------------------------------------------------------------
|
|
199 */
|
|
200
|
167
|
201 static void
|
|
202 SetContours(ContourOption option)
|
163
|
203 {
|
|
204 if (option == NoContours) {
|
|
205 switch (TreeShowContourOption) {
|
|
206 case OutsideContour:
|
|
207 DrawTreeContour(TheTree, New, BACKGROUND_COLOR, FALSE, FALSE, FALSE);
|
|
208 break;
|
|
209 case AllContours:
|
|
210 DrawTreeContour(TheTree, New, BACKGROUND_COLOR, FALSE, FALSE, TRUE);
|
|
211 break;
|
|
212 case SelectedContours:
|
|
213 DrawTreeContour(TheTree, New, BACKGROUND_COLOR, FALSE, TRUE, TRUE);
|
|
214 break;
|
|
215 default:
|
|
216 ;
|
|
217 }
|
|
218 DrawTreeContour(TheTree, New, BACKGROUND_COLOR, FALSE, FALSE, TRUE);
|
|
219 }
|
|
220 else if (option == OutsideContour) {
|
|
221 switch (TreeShowContourOption) {
|
|
222 case AllContours:
|
|
223 DrawTreeContour(TheTree, New, BACKGROUND_COLOR, FALSE, FALSE, TRUE);
|
|
224 break;
|
|
225 case SelectedContours:
|
|
226 DrawTreeContour(TheTree, New, BACKGROUND_COLOR, FALSE, TRUE, TRUE);
|
|
227 break;
|
|
228 default:
|
|
229 ;
|
|
230 }
|
|
231 DrawTreeContour(TheTree, New, CONTOUR_COLOR, FALSE, FALSE, FALSE);
|
|
232 } else if (option == AllContours) {
|
|
233 DrawTreeContour(TheTree, New, CONTOUR_COLOR, FALSE, FALSE, TRUE);
|
|
234 } else if (option == SelectedContours) {
|
|
235 switch (TreeShowContourOption) {
|
|
236 case AllContours:
|
|
237 DrawTreeContour(TheTree, New, BACKGROUND_COLOR, FALSE, FALSE, TRUE);
|
|
238 break;
|
|
239 case OutsideContour:
|
|
240 DrawTreeContour(TheTree, New, BACKGROUND_COLOR, FALSE, FALSE, FALSE);
|
|
241 break;
|
|
242 default:
|
|
243 DrawTreeContour(TheTree, New, BACKGROUND_COLOR, FALSE, FALSE, TRUE);
|
|
244 }
|
|
245 DrawTreeContour(TheTree, New, CONTOUR_COLOR, FALSE, TRUE, TRUE);
|
|
246 }
|
|
247 TreeShowContourOption = option;
|
|
248 }
|
|
249
|
|
250
|
|
251 /* ----------------------------------------------------------------------------
|
167
|
252 *
|
|
253 * HiliteNode() is called by Unzip() to change the color of a node.
|
|
254 *
|
163
|
255 * ----------------------------------------------------------------------------
|
|
256 */
|
|
257
|
|
258 void
|
167
|
259 HiliteNode(Tree *tree, PosMode pos_mode)
|
163
|
260 {
|
|
261 SetDrawColor(HIGHLIGHT_COLOR);
|
|
262 DrawNode(tree, pos_mode);
|
|
263 SetDrawColor(TREE_COLOR);
|
|
264 }
|
|
265
|
|
266
|
|
267 /* ----------------------------------------------------------------------------
|
167
|
268 *
|
163
|
269 * DrawNode() takes a node and draws the node in the specified widget
|
|
270 * at its (x,y) coordinate. (x, y) indicates the upper-left corner where
|
|
271 * the node is drawn. Also, a line is drawn from the center of the left
|
167
|
272 * edge to the center of the parent's right edge. 'draw_mode' specifies
|
163
|
273 * the drawing mode (whether or not the node is erased, rather than drawn).
|
|
274 * 'pos_mode' determines whether or not to use the old position of the node.
|
|
275 * This flag is used in animating the movement of a node from its old
|
|
276 * position to its new position.
|
167
|
277 *
|
163
|
278 * ----------------------------------------------------------------------------
|
|
279 */
|
|
280
|
|
281 void
|
167
|
282 DrawNode(Tree *node, PosMode pos_mode)
|
163
|
283 {
|
|
284 Widget w;
|
|
285 GC gc;
|
167
|
286
|
163
|
287 w = TreeDrawingArea;
|
|
288 gc = TreeDrawingAreaDB->gc;
|
167
|
289
|
163
|
290 if (pos_mode == Old) {
|
|
291 XDrawString(XtDisplay(w), XtWindow(w), gc,
|
|
292 node->old_pos.x + node->label.xoffset,
|
|
293 node->old_pos.y + node->label.yoffset,
|
|
294 node->label.text, node->label.len);
|
|
295 XDrawRectangle(XtDisplay(w), XtWindow(w), gc,
|
|
296 node->old_pos.x, node->old_pos.y,
|
|
297 node->width, node->height);
|
167
|
298 if (node->parent)
|
163
|
299 XDrawLine(XtDisplay(w), XtWindow(w), gc,
|
|
300 node->old_pos.x - 1,
|
|
301 node->old_pos.y + (node->height / 2),
|
|
302 node->parent->old_pos.x + node->parent->width + 1,
|
|
303 node->parent->old_pos.y + (node->parent->height / 2));
|
|
304 if (node->elision) {
|
|
305 XSetFillStyle(TreeDrawingAreaDB->display, TreeDrawingAreaDB->gc,
|
|
306 FillTiled);
|
|
307 XFillRectangle(XtDisplay(w), XtWindow(w), gc,
|
|
308 node->old_pos.x + node->width - ELISION_WIDTH,
|
|
309 node->old_pos.y + 1, ELISION_WIDTH, node->height - 1);
|
|
310 XSetFillStyle(TreeDrawingAreaDB->display, TreeDrawingAreaDB->gc,
|
|
311 FillSolid);
|
|
312 }
|
|
313 } else {
|
|
314 XDrawString(XtDisplay(w), XtWindow(w), gc,
|
|
315 node->pos.x + node->label.xoffset,
|
|
316 node->pos.y + node->label.yoffset,
|
|
317 node->label.text, node->label.len);
|
167
|
318
|
163
|
319 XDrawRectangle(XtDisplay(w), XtWindow(w), gc,
|
|
320 node->pos.x, node->pos.y,
|
|
321 node->width, node->height);
|
167
|
322 if (node->parent)
|
163
|
323 XDrawLine(XtDisplay(w), XtWindow(w), gc,
|
|
324 node->pos.x - 1,
|
|
325 node->pos.y + (node->height / 2),
|
|
326 node->parent->pos.x + node->parent->width + 1,
|
|
327 node->parent->pos.y + (node->parent->height / 2));
|
|
328 if (node->elision) {
|
|
329 XSetFillStyle(TreeDrawingAreaDB->display, TreeDrawingAreaDB->gc,
|
|
330 FillTiled);
|
|
331 XFillRectangle(XtDisplay(w), XtWindow(w), gc,
|
|
332 node->pos.x + node->width - ELISION_WIDTH,
|
|
333 node->pos.y + 1, ELISION_WIDTH, node->height - 1);
|
|
334 XSetFillStyle(TreeDrawingAreaDB->display, TreeDrawingAreaDB->gc,
|
|
335 FillSolid);
|
|
336 }
|
|
337 }
|
|
338 }
|
|
339
|
|
340
|
|
341 /* ----------------------------------------------------------------------------
|
167
|
342 *
|
163
|
343 * DrawTreeContour() draws the contour of the specified subtree. Bridges
|
|
344 * are not traversed, so the actual subtree contour is drawn, as opposed
|
|
345 * to the merged contour. 'color' specifies the drawing color. If 'detach'
|
|
346 * is True, the lines attaching the subtree contour to the node are not
|
|
347 * drawn. If 'select' is true, then only subtrees that are flagged as
|
|
348 * selected are shown. If 'recursive' is True, the entire tree is traversed.
|
167
|
349 *
|
163
|
350 * ----------------------------------------------------------------------------
|
|
351 */
|
|
352
|
|
353 void
|
167
|
354 DrawTreeContour(Tree *tree, PosMode pos_mode,
|
|
355 int color, int detach_p, int select_p, int recursive)
|
163
|
356 {
|
|
357 Widget w = TreeDrawingArea;
|
|
358 Polyline *contour, *tail;
|
|
359 Tree *child;
|
|
360 int x, y, i;
|
|
361
|
|
362 if (tree == NULL)
|
|
363 return;
|
|
364
|
167
|
365 if ((select_p && tree->show_contour) || !select_p) {
|
163
|
366
|
|
367 SetDrawColor(color);
|
|
368 SetLineWidth(TreeContourWidth);
|
167
|
369
|
163
|
370 /* draw upper contour */
|
|
371 contour = tree->contour.upper.head;
|
|
372 tail = tree->contour.upper.tail;
|
|
373 if (pos_mode == Old) {
|
|
374 x = tree->old_pos.x - tree->border;
|
|
375 y = tree->old_pos.y - tree->border;
|
|
376 }
|
|
377 else {
|
|
378 x = tree->pos.x - tree->border;
|
|
379 y = tree->pos.y - tree->border;
|
|
380 }
|
|
381
|
167
|
382 if (detach_p) { /* skip over attaching lines */
|
163
|
383 for (i = 0 ; i < 2 ; i++) {
|
|
384 x += contour->dx;
|
|
385 y += contour->dy;
|
|
386 contour = contour->link;
|
|
387 }
|
|
388 }
|
167
|
389
|
163
|
390 while (contour) {
|
|
391 XDrawLine(XtDisplay(w), XtWindow(w), TreeDrawingAreaDB->gc,
|
|
392 x, y, x + contour->dx, y + contour->dy);
|
|
393 x += contour->dx;
|
|
394 y += contour->dy;
|
|
395 if (contour == tail) /* make sure you don't follow bridges */
|
|
396 contour = NULL;
|
|
397 else
|
|
398 contour = contour->link;
|
|
399 }
|
|
400
|
|
401 /* draw lower contour */
|
|
402 contour = tree->contour.lower.head;
|
|
403 tail = tree->contour.lower.tail;
|
|
404 if (pos_mode == Old) {
|
|
405 x = tree->old_pos.x - tree->border;
|
|
406 y = tree->old_pos.y + tree->border + tree->height;
|
|
407 } else {
|
|
408 x = tree->pos.x - tree->border;
|
|
409 y = tree->pos.y + tree->border + tree->height;
|
|
410 }
|
|
411
|
167
|
412 if (detach_p) { /* skip over attaching lines */
|
163
|
413 for (i = 0 ; i < 2 ; i++) {
|
|
414 x += contour->dx;
|
|
415 y += contour->dy;
|
|
416 contour = contour->link;
|
|
417 }
|
|
418 }
|
|
419
|
|
420 while (contour) {
|
|
421 XDrawLine(XtDisplay(w), XtWindow(w), TreeDrawingAreaDB->gc,
|
|
422 x, y, x + contour->dx, y + contour->dy);
|
|
423 x += contour->dx;
|
|
424 y += contour->dy;
|
|
425 if (contour == tail) /* make sure you don't follow bridges */
|
|
426 contour = NULL;
|
|
427 else
|
|
428 contour = contour->link;
|
|
429 }
|
|
430 }
|
167
|
431
|
163
|
432 if (recursive) {
|
|
433 FOREACH_CHILD(child, tree)
|
|
434 if (!child->elision)
|
|
435 DrawTreeContour(child, pos_mode, color,
|
167
|
436 detach_p, select_p, recursive);
|
163
|
437 }
|
|
438
|
|
439 SetDrawColor(TREE_COLOR);
|
|
440 SetLineWidth(0);
|
|
441 }
|
|
442
|
|
443
|
|
444 /* ----------------------------------------------------------------------------
|
167
|
445 *
|
163
|
446 * DrawTree() traverses the given tree, drawing the node and connecting
|
|
447 * segments. The tree contours are also drawn at each step, if enabled.
|
|
448 * 'draw_mode' specifies the drawing mode in which the tree is drawn.
|
|
449 * 'pos_mode' determines whether or not to use the old position of the node.
|
|
450 * This flag is used in animating the movement of a node from its old
|
167
|
451 * position to its new position. DrawNode() is called to draw an individual
|
163
|
452 * node.
|
167
|
453 *
|
163
|
454 * ----------------------------------------------------------------------------
|
|
455 */
|
|
456
|
|
457 void
|
167
|
458 DrawTree(Tree *tree, PosMode pos_mode)
|
163
|
459 {
|
|
460 if (tree == NULL)
|
|
461 return;
|
|
462
|
|
463 DrawNode(tree, pos_mode);
|
|
464
|
|
465 /* do stuff that animates Unzip() */
|
|
466 if (tree->split) {
|
|
467 if (!AnimationMode ||
|
|
468 (tree->pos.x == tree->old_pos.x &&
|
|
469 tree->pos.y == tree->old_pos.y))
|
|
470 DrawTreeContour(tree, pos_mode, SPLIT_COLOR, FALSE, FALSE, FALSE);
|
|
471 else
|
|
472 DrawTreeContour(tree, pos_mode, ACTION_COLOR, FALSE, FALSE, FALSE);
|
|
473 }
|
|
474 if (tree->on_path)
|
|
475 HiliteNode(tree, pos_mode);
|
|
476
|
167
|
477 if (tree->child && !tree->elision)
|
163
|
478 DrawTree(tree->child, pos_mode);
|
|
479 if (tree->sibling)
|
|
480 DrawTree(tree->sibling, pos_mode);
|
|
481 }
|
|
482
|
|
483
|
|
484 /* ----------------------------------------------------------------------------
|
167
|
485 *
|
163
|
486 * ShiftTree() adjusts the positions of each node so that it moves from
|
|
487 * the "old" position towards the "new position". This is used by
|
|
488 * AnimateTree(). 'done' is set to FALSE if the tree is not in its
|
|
489 * final position; it is used to determine when to stop animating the tree.
|
167
|
490 *
|
163
|
491 * ----------------------------------------------------------------------------
|
|
492 */
|
|
493
|
167
|
494 static void
|
|
495 ShiftTree(Tree *tree, int *done)
|
163
|
496 {
|
|
497 Tree *child;
|
167
|
498
|
163
|
499 if (tree->old_pos.x != tree->pos.x ||
|
|
500 tree->old_pos.y != tree->pos.y)
|
|
501 {
|
|
502 tree->old_pos.x = tree->pos.x;
|
|
503 tree->old_pos.y = tree->pos.y;
|
|
504 }
|
167
|
505
|
163
|
506 FOREACH_CHILD(child, tree)
|
|
507 ShiftTree(child, done);
|
|
508 }
|
|
509
|
|
510
|
|
511 /* ----------------------------------------------------------------------------
|
167
|
512 *
|
163
|
513 * AnimateTree() draws the given tree in a series of steps to give the
|
|
514 * effect of animation from the "old" layout to the "new" layout of the
|
167
|
515 * tree.
|
|
516 *
|
163
|
517 * The algorithm used here is not efficient; the entire tree is drawn
|
|
518 * on each iteration of the animation sequence; it would be more efficient
|
|
519 * to only redraw what is necessary. However, the method used here takes
|
|
520 * advantage of existing code without modification.
|
167
|
521 *
|
163
|
522 * ----------------------------------------------------------------------------
|
|
523 */
|
|
524
|
167
|
525 static void
|
|
526 AnimateTree(Tree *tree)
|
163
|
527 {
|
|
528 int done = FALSE;
|
|
529
|
|
530 AnimationMode = FALSE;
|
|
531 /* highlight which nodes have to move */
|
|
532 BeginFrame();
|
|
533 DrawTree(tree, Old);
|
|
534 EndFrame();
|
167
|
535 Pause();
|
163
|
536 if (PauseAfterStep)
|
|
537 AnimationStep = ANIMATION_STEP_STEP;
|
|
538 while (!done) {
|
|
539 done = TRUE;
|
|
540 ShiftTree(tree, &done);
|
|
541 BeginFrame();
|
|
542 DrawTree(tree, Old);
|
|
543 EndFrame();
|
|
544 if (PauseAfterStep)
|
|
545 Pause();
|
|
546 }
|
|
547 if (PauseAfterStep)
|
|
548 AnimationStep = ANIMATION_STEP;
|
|
549 AnimationMode = FALSE;
|
|
550 }
|
|
551
|
|
552
|
|
553 /* ----------------------------------------------------------------------------
|
167
|
554 *
|
163
|
555 * AnimateZip() generates a sequence of frames that animates the Zip() step.
|
|
556 * It is similar in logical structure to Zip().
|
167
|
557 *
|
163
|
558 * ----------------------------------------------------------------------------
|
|
559 */
|
|
560
|
167
|
561 static void
|
|
562 AnimateZip(Tree *tree)
|
163
|
563 {
|
|
564 Tree *child;
|
167
|
565
|
163
|
566 /* show results of Join() step */
|
|
567 if (tree->child) {
|
|
568 BeginFrame();
|
|
569 FOREACH_CHILD(child, tree)
|
|
570 child->split = FALSE;
|
|
571 DrawTree(TheTree, New);
|
|
572 DrawTreeContour(tree, New, CONTOUR_COLOR, TRUE, FALSE, FALSE);
|
|
573 EndFrame();
|
|
574
|
|
575 StatusMsg("Zip: merge and join contours", FALSE);
|
167
|
576 Pause();
|
|
577
|
163
|
578 /* show results of AttachParent() step */
|
|
579 BeginFrame();
|
|
580 DrawTree(TheTree, New);
|
|
581 DrawTreeContour(tree, New, CONTOUR_COLOR, FALSE, FALSE, FALSE);
|
|
582 EndFrame();
|
|
583
|
|
584 StatusMsg("Zip: attach parents", FALSE);
|
167
|
585 Pause();
|
163
|
586 }
|
167
|
587
|
163
|
588 tree->on_path = FALSE;
|
167
|
589
|
163
|
590 if (tree->parent)
|
|
591 AnimateZip(tree->parent);
|
|
592 else {
|
|
593 tree->on_path = FALSE;
|
|
594 BeginFrame();
|
|
595 DrawTree(TheTree, New);
|
|
596 DrawTreeContour(TheTree, New, CONTOUR_COLOR, FALSE, FALSE, FALSE);
|
|
597 EndFrame();
|
|
598 StatusMsg("Zip: reassemble entire contour", FALSE);
|
167
|
599 Pause();
|
163
|
600 }
|
|
601 }
|
|
602
|
|
603
|
|
604 /* ----------------------------------------------------------------------------
|
167
|
605 *
|
|
606 * CountNodes() returns the number of nodes in the specified tree.
|
|
607 * Nodes below a node that has been collapsed are ignored.
|
|
608 *
|
163
|
609 * ----------------------------------------------------------------------------
|
|
610 */
|
|
611
|
167
|
612 static int
|
|
613 CountNodes(Tree *tree)
|
163
|
614 {
|
|
615 int num_nodes = 1; /* count root of subtree */
|
|
616 Tree *child;
|
167
|
617
|
163
|
618 if (!tree->elision) {
|
|
619 FOREACH_CHILD(child, tree)
|
|
620 num_nodes += CountNodes(child);
|
|
621 }
|
|
622 return (num_nodes);
|
|
623 }
|
|
624
|
|
625
|
|
626 /* ----------------------------------------------------------------------------
|
167
|
627 *
|
163
|
628 * CollectNodeRectangles() is a recursive function used by
|
|
629 * GetSubTreeRectangles() to collect the rectangles of descendant nodes
|
|
630 * into the pre-allocated storage passed to this function.
|
167
|
631 *
|
163
|
632 * ----------------------------------------------------------------------------
|
|
633 */
|
|
634
|
167
|
635 static void
|
|
636 CollectNodeRectangles(Tree *node, XRectangle **rectangles, int fill)
|
163
|
637 {
|
|
638 Tree *child;
|
167
|
639
|
163
|
640 (*rectangles)->x = node->pos.x;
|
|
641 (*rectangles)->y = node->pos.y;
|
|
642 if (fill) {
|
|
643 (*rectangles)->width = node->width + 1;
|
|
644 (*rectangles)->height = node->height + 1;
|
|
645 } else {
|
|
646 (*rectangles)->width = node->width;
|
|
647 (*rectangles)->height = node->height;
|
|
648 }
|
|
649 (*rectangles)++;
|
167
|
650
|
163
|
651 if (!node->elision)
|
167
|
652 FOREACH_CHILD(child, node)
|
163
|
653 CollectNodeRectangles(child, rectangles, fill);
|
|
654 }
|
|
655
|
|
656
|
|
657 /* ----------------------------------------------------------------------------
|
167
|
658 *
|
163
|
659 * GetSubTreeRectangles() builds an array of XRectangles that contain
|
167
|
660 * all the node rectangles in the tree, except the root node itself.
|
163
|
661 * The array is returned in 'rectangles' and the number of rectangles
|
|
662 * is returned in 'nrectangles.' Storage for the rectangles is allocated
|
|
663 * in this function. This function is used by PickAction to determine
|
|
664 * what rectangles need to be dissolved away. 'fill', if True, specifies
|
167
|
665 * that the rectangles should be 1 pixel larger in each dimension to
|
|
666 * compensate for FillRectangle behavior.
|
|
667 *
|
163
|
668 * ----------------------------------------------------------------------------
|
|
669 */
|
|
670
|
167
|
671 static void
|
|
672 GetSubTreeRectangles(Tree *tree, XRectangle **rectangles,
|
|
673 int *nrectangles, int fill)
|
163
|
674 {
|
|
675 Tree *child;
|
|
676 XRectangle *crect; /* current rectangle */
|
167
|
677
|
163
|
678 *nrectangles = CountNodes(tree) - 1; /* don't count root node */
|
|
679 *rectangles = (XRectangle *) malloc(sizeof(XRectangle) * *nrectangles);
|
|
680 ASSERT(*rectangles, "could not allocate memory for rectangles");
|
167
|
681
|
163
|
682 crect = *rectangles;
|
|
683 if (!tree->elision)
|
|
684 FOREACH_CHILD(child, tree)
|
|
685 CollectNodeRectangles(child, &crect, fill);
|
|
686 }
|
|
687
|
|
688
|
|
689 /* ----------------------------------------------------------------------------
|
167
|
690 *
|
163
|
691 * CollectNodeSegments() is a recursive function used by GetSubTreeSegments()
|
167
|
692 * to collect the line segments connecting nodes into the pre-allocated
|
163
|
693 * storage passed to this function.
|
167
|
694 *
|
163
|
695 * ----------------------------------------------------------------------------
|
|
696 */
|
|
697
|
167
|
698 static void
|
|
699 CollectNodeSegments(Tree *node, XSegment **segments)
|
163
|
700 {
|
|
701 Tree *child;
|
167
|
702
|
163
|
703 (*segments)->x1 = node->pos.x - 1;
|
|
704 (*segments)->y1 = node->pos.y + (node->height / 2),
|
|
705 (*segments)->x2 = node->parent->pos.x + node->parent->width + 1;
|
|
706 (*segments)->y2 = node->parent->pos.y + (node->parent->height / 2);
|
|
707 (*segments)++;
|
|
708
|
|
709 if (!node->elision)
|
167
|
710 FOREACH_CHILD(child, node)
|
163
|
711 CollectNodeSegments(child, segments);
|
|
712 }
|
|
713
|
|
714
|
|
715 /* ----------------------------------------------------------------------------
|
167
|
716 *
|
163
|
717 * GetSubTreeSegments() builds an array of XSegments that contain
|
|
718 * all the line segments connecting the nodes in the tree. The array is
|
|
719 * returned in 'segments' and the number of segments is returned in
|
|
720 * 'nsegments.' Storage for the segments is allocated in this function.
|
|
721 * This function is used by PickAction to determine what line segments
|
|
722 * rectangles need to be dissolved away.
|
167
|
723 *
|
163
|
724 * ----------------------------------------------------------------------------
|
|
725 */
|
|
726
|
167
|
727 static void
|
|
728 GetSubTreeSegments(Tree *tree, XSegment **segments, int *nsegments)
|
163
|
729 {
|
|
730 Tree *child;
|
|
731 XSegment *cseg; /* current segment */
|
|
732
|
|
733 *nsegments = CountNodes(tree) - 1;
|
|
734 *segments = (XSegment *) malloc(sizeof(XSegment) * *nsegments);
|
|
735 ASSERT(*segments, "could not allocate memory for segments");
|
167
|
736
|
163
|
737 cseg = *segments;
|
|
738 if (!tree->elision)
|
|
739 FOREACH_CHILD(child, tree)
|
|
740 CollectNodeSegments(child, &cseg);
|
|
741 }
|
|
742
|
|
743
|
|
744 /* ----------------------------------------------------------------------------
|
167
|
745 *
|
163
|
746 * ComputeSubTreeExtent() computes the extent of a subtree. This is
|
|
747 * easily computed based on the tree's contour, as in ComputeTreeSize().
|
167
|
748 * This extent is stored in the node, and used by SearchTree for
|
|
749 * pick-correlation.
|
|
750 *
|
163
|
751 * This function assumes that the given tree has at least one child; do not
|
167
|
752 * pass a leaf node to this function.
|
|
753 *
|
163
|
754 * ----------------------------------------------------------------------------
|
|
755 */
|
|
756
|
|
757 void
|
167
|
758 ComputeSubTreeExtent(Tree *tree)
|
163
|
759 {
|
|
760 int width, height;
|
|
761 int x_offset, y_offset;
|
|
762
|
|
763 ComputeTreeSize(tree, &width, &height, &x_offset, &y_offset);
|
|
764 tree->subextent.pos.x = tree->child->pos.x - tree->child->border;
|
|
765 tree->subextent.pos.y = tree->pos.y - y_offset;
|
|
766 tree->subextent.width = width - (tree->child->pos.x - tree->pos.x) - 1;
|
|
767 tree->subextent.height = height - 1;
|
|
768 }
|
|
769
|
|
770
|
|
771 /* ----------------------------------------------------------------------------
|
167
|
772 *
|
163
|
773 * SearchTree() determines if a node's rectangular region encloses the
|
167
|
774 * specified point in (x,y). Rather than using a brute-force search
|
163
|
775 * through all node rectangles of a given tree, the subtree extents
|
|
776 * are used in a recursive fashion to drive the search as long as the
|
|
777 * given point is enclosed in an extent. In the worst case, the search
|
|
778 * time would be on the order of a brute-force search, but with complex
|
167
|
779 * trees, this method reduces the number of visits.
|
|
780 *
|
163
|
781 * The extent of a subtree is computed by ComputeSubTreeExtent() and is
|
|
782 * stored in each node of the tree.
|
167
|
783 *
|
163
|
784 * ----------------------------------------------------------------------------
|
|
785 */
|
|
786
|
|
787 int
|
167
|
788 SearchTree(Tree *tree, int x, int y, Tree **node)
|
163
|
789 {
|
|
790 Tree *child;
|
167
|
791
|
163
|
792 if (tree == NULL)
|
|
793 return (FALSE);
|
|
794
|
|
795 if (PT_IN_RECT(x, y, tree->pos.x, tree->pos.y,
|
|
796 tree->pos.x + tree->width,
|
|
797 tree->pos.y + tree->height)) {
|
|
798 *node = tree;
|
|
799 return (TRUE);
|
|
800 }
|
167
|
801 if (tree->child && (PT_IN_EXTENT(x, y, tree->subextent)))
|
163
|
802 FOREACH_CHILD(child, tree) {
|
167
|
803 if (SearchTree(child, x, y, node))
|
163
|
804 return (TRUE);
|
|
805 }
|
|
806 return (FALSE);
|
|
807 }
|
|
808
|
|
809
|
|
810 /* ----------------------------------------------------------------------------
|
167
|
811 *
|
163
|
812 * ExposeHandler() handles expose events in the TreeDrawingArea. This
|
|
813 * function is not intelligent; it just redraws the entire contents.
|
167
|
814 *
|
163
|
815 * ----------------------------------------------------------------------------
|
|
816 */
|
|
817
|
|
818 void
|
167
|
819 ExposeHandler(Widget w, XtPointer closure,
|
|
820 XEvent *event, Boolean *continue_to_dispatch)
|
163
|
821 {
|
167
|
822 if (event->xexpose.count == 0) {
|
163
|
823 BeginFrame();
|
|
824 SetContours(TreeShowContourOption);
|
|
825 DrawTree(TheTree, New);
|
|
826 EndFrame();
|
|
827 }
|
|
828 }
|
|
829
|
|
830
|
|
831 /* ----------------------------------------------------------------------------
|
167
|
832 *
|
163
|
833 * ExpandCollapseNode is called to expand or collapse a node in the tree.
|
167
|
834 *
|
163
|
835 * ----------------------------------------------------------------------------
|
|
836 */
|
|
837
|
|
838 void
|
167
|
839 ExpandCollapseNode(Tree *node)
|
163
|
840 {
|
|
841 int width, height;
|
|
842 int old_width, old_height;
|
|
843 int x_offset, y_offset;
|
|
844 XRectangle *rectangles;
|
|
845 XSegment *segments;
|
|
846 int nrectangles, nsegments;
|
|
847 int expand = FALSE;
|
|
848 Widget w = TreeDrawingArea;
|
167
|
849
|
163
|
850 StatusMsg("", TRUE);
|
167
|
851
|
163
|
852 /* hilite node so that we know where we are */
|
|
853 /* DrawTree will hilite it as a side effect */
|
|
854 if (TreeShowSteps)
|
|
855 node->on_path = TRUE;
|
167
|
856
|
163
|
857 /* erase the contour before changing in the tree */
|
|
858 if ((TreeShowContourOption != NoContours) || TreeShowSteps) {
|
|
859 BeginFrame();
|
|
860 DrawTree(TheTree, New);
|
|
861 EndFrame();
|
|
862 }
|
167
|
863
|
163
|
864 sprintf(strbuf, "Node `%s' selected for %s", node->label.text,
|
|
865 node->elision ? "expansion" : "collapse");
|
|
866 StatusMsg(strbuf, FALSE);
|
167
|
867 Pause();
|
163
|
868
|
|
869 if (node->parent)
|
|
870 Unzip(node->parent);
|
|
871 else {
|
|
872 StatusMsg("Show entire contour", FALSE);
|
|
873 if (TreeShowSteps) {
|
|
874 BeginFrame();
|
|
875 DrawTreeContour(TheTree, New, CONTOUR_COLOR, FALSE, FALSE, FALSE);
|
|
876 DrawTree(TheTree, New);
|
|
877 EndFrame();
|
167
|
878 Pause();
|
163
|
879 }
|
|
880 }
|
|
881
|
|
882 /* are we collapsing a subtree? */
|
|
883 if (!node->elision) {
|
|
884 StatusMsg("Collapse subtree", FALSE);
|
|
885 GetSubTreeRectangles(node, &rectangles, &nrectangles, TRUE);
|
|
886 GetSubTreeSegments(node, &segments, &nsegments);
|
|
887 DissolveTree(XtDisplay(w), XtWindow(w),
|
|
888 rectangles, nrectangles,
|
|
889 segments, nsegments, TRUE);
|
|
890 free(rectangles);
|
|
891 free(segments);
|
167
|
892 Pause();
|
|
893
|
163
|
894 StatusMsg("Replace subtree contour with leaf contour", FALSE);
|
|
895 node->elision = TRUE;
|
|
896 if (TreeShowSteps)
|
|
897 node->split = TRUE; /* turned off in AnimateZip */
|
|
898 node->old_contour = node->contour;
|
|
899 node->width += ELISION_WIDTH;
|
|
900 LayoutLeaf(node);
|
|
901 BeginFrame();
|
|
902 SetContours(TreeShowContourOption);
|
|
903 DrawTree(TheTree, New);
|
|
904 EndFrame();
|
167
|
905 Pause();
|
163
|
906 } else {
|
|
907 StatusMsg("Replace leaf contour with old subtree contour", FALSE);
|
|
908 if (TreeShowSteps)
|
|
909 node->split = TRUE; /* turned off in AnimateZip */
|
|
910 RuboutLeaf(node);
|
|
911 node->contour = node->old_contour;
|
|
912 expand = TRUE;
|
|
913 }
|
167
|
914
|
163
|
915 if (node->parent)
|
|
916 Zip(node->parent);
|
167
|
917
|
163
|
918 ComputeTreeSize(TheTree, &width, &height, &x_offset, &y_offset);
|
|
919 PetrifyTree(TheTree, x_offset + MAT_SIZE, y_offset + MAT_SIZE);
|
|
920 GetDrawingSize(&old_width, &old_height);
|
|
921
|
|
922 if (expand) {
|
|
923 SetDrawingSize(width + (2 * MAT_SIZE), height + (2 * MAT_SIZE));
|
|
924 BeginFrame();
|
|
925 DrawTree(TheTree, Old);
|
|
926 EndFrame();
|
167
|
927 Pause();
|
163
|
928 StatusMsg("Move tree to new configuration", FALSE);
|
|
929 AnimateTree(TheTree);
|
|
930 } else {
|
|
931 /* we are shrinking or staying the same */
|
|
932 StatusMsg("Move tree to new configuration", FALSE);
|
|
933 AnimateTree(TheTree);
|
|
934 SetDrawingSize(width + (2 * MAT_SIZE), height + (2 * MAT_SIZE));
|
|
935 }
|
|
936
|
|
937 if (expand) {
|
|
938 StatusMsg("Expand subtree", FALSE);
|
|
939 node->elision = FALSE;
|
167
|
940
|
163
|
941 /* erase elision marker */
|
|
942 XSetFunction(TreeDrawingAreaDB->display, TreeDrawingAreaDB->gc,
|
|
943 GXclear);
|
|
944 XFillRectangle(XtDisplay(w), XtWindow(w), TreeDrawingAreaDB->gc,
|
|
945 node->pos.x + node->width - ELISION_WIDTH + 1,
|
|
946 node->pos.y, ELISION_WIDTH, node->height + 1);
|
|
947 XSetFunction(TreeDrawingAreaDB->display, TreeDrawingAreaDB->gc,
|
|
948 GXcopy);
|
|
949 node->width -= ELISION_WIDTH;
|
167
|
950
|
163
|
951 GetSubTreeRectangles(node, &rectangles, &nrectangles, FALSE);
|
|
952 GetSubTreeSegments(node, &segments, &nsegments);
|
|
953 /* dissolve the tree back in */
|
|
954 DissolveTree(XtDisplay(w), XtWindow(w),
|
|
955 rectangles, nrectangles,
|
|
956 segments, nsegments, FALSE);
|
|
957 free(rectangles);
|
|
958 free(segments);
|
167
|
959
|
163
|
960 /* draw text of nodes */
|
|
961 BeginFrame();
|
|
962 SetContours(TreeShowContourOption);
|
|
963 DrawTree(TheTree, New);
|
|
964 EndFrame();
|
167
|
965 Pause();
|
163
|
966 }
|
167
|
967
|
163
|
968 if (TreeShowSteps) {
|
|
969 node->on_path = FALSE;
|
|
970 if (node->parent)
|
|
971 AnimateZip(node->parent);
|
|
972 else
|
|
973 node->split = FALSE;
|
|
974 }
|
167
|
975
|
163
|
976 /* BUG: the display isn't properly updated here! */
|
|
977 /* There should probably be some code here that
|
167
|
978 clears the tree below the node currently being
|
|
979 collapsed or expanded. Hack added 20.03.95 (torgeir@ii.uib.no).
|
163
|
980 I'll try to fix this later. */
|
|
981
|
|
982 XClearArea(TreeDisplay, XtWindow(TreeDrawingArea), 0, 0, 0, 0, FALSE);
|
|
983
|
|
984 BeginFrame();
|
|
985 SetContours(TreeShowContourOption);
|
|
986 DrawTree(TheTree, New);
|
|
987 EndFrame();
|
167
|
988
|
163
|
989 StatusMsg("Ready", TRUE);
|
|
990 }
|
|
991
|
|
992 /* ----------------------------------------------------------------------------
|
167
|
993 *
|
163
|
994 * InsertNode() handles the task of inserting a new node in the tree,
|
|
995 * at the given position with respect to 'base_node'. When 'node_pos' is
|
|
996 * either Before or After, it is assumed that 'base_node' has a parent.
|
167
|
997 *
|
163
|
998 * ----------------------------------------------------------------------------
|
|
999 */
|
|
1000
|
|
1001 void
|
167
|
1002 InsertNode(Tree *base_node, NodePosition node_pos, char *new_node_text)
|
163
|
1003 {
|
|
1004 Tree *new_node;
|
|
1005 Tree *parent;
|
|
1006 Tree *sibling = NULL;
|
|
1007 Tree *child;
|
|
1008
|
|
1009 int width, height;
|
|
1010 int x_offset, y_offset;
|
|
1011
|
|
1012 StatusMsg("", TRUE);
|
|
1013
|
|
1014 new_node = MakeNode(); /* should check for memory failure */
|
|
1015 SetNodeLabel(new_node, new_node_text);
|
|
1016 LayoutLeaf(new_node);
|
|
1017
|
|
1018 /* figure out parent & sibling */
|
|
1019 if (node_pos == Child) {
|
|
1020 parent = base_node;
|
|
1021 /* find last child, if one exists */
|
|
1022 FOREACH_CHILD(child, parent)
|
|
1023 sibling = child;
|
|
1024 } else if (node_pos == After) {
|
|
1025 parent = base_node->parent;
|
|
1026 sibling = base_node;
|
|
1027 } else if (node_pos == Before) {
|
|
1028 parent = base_node->parent;
|
|
1029 FOREACH_CHILD(child, parent)
|
|
1030 if (child->sibling == base_node) {
|
|
1031 sibling = child;
|
|
1032 break;
|
|
1033 }
|
167
|
1034 } else {
|
|
1035 parent = NULL;
|
|
1036 abort();
|
163
|
1037 }
|
|
1038
|
|
1039 if (TreeShowSteps)
|
|
1040 parent->on_path = TRUE;
|
167
|
1041
|
163
|
1042 if ((TreeShowContourOption != NoContours) ||
|
|
1043 TreeShowSteps) {
|
|
1044 BeginFrame();
|
|
1045 DrawTree(TheTree, New);
|
|
1046 EndFrame();
|
|
1047 }
|
|
1048
|
|
1049 sprintf(strbuf, "Inserting `%s' as child of node `%s'",
|
|
1050 new_node_text, parent->label.text);
|
|
1051 StatusMsg(strbuf, FALSE);
|
167
|
1052 Pause();
|
|
1053
|
163
|
1054 /* erase the contour before changing in the tree */
|
167
|
1055
|
163
|
1056 Insert(parent, new_node, sibling);
|
167
|
1057
|
163
|
1058 ComputeTreeSize(TheTree, &width, &height, &x_offset, &y_offset);
|
|
1059 PetrifyTree(TheTree, x_offset + MAT_SIZE, y_offset + MAT_SIZE);
|
167
|
1060
|
163
|
1061 if (sibling)
|
|
1062 new_node->old_pos = sibling->old_pos;
|
|
1063 else if (new_node->sibling)
|
|
1064 new_node->old_pos = new_node->sibling->old_pos;
|
|
1065 else {
|
|
1066 new_node->old_pos.x = new_node->pos.x;
|
|
1067 new_node->old_pos.y = parent->old_pos.y;
|
|
1068 }
|
167
|
1069
|
163
|
1070 if (TreeShowSteps)
|
|
1071 new_node->split = TRUE;
|
|
1072
|
|
1073 SetDrawingSize(width + (2 * MAT_SIZE), height + (2 * MAT_SIZE));
|
|
1074 BeginFrame();
|
|
1075 DrawTree(TheTree, Old);
|
|
1076 EndFrame();
|
|
1077 StatusMsg("Insert: add new node and contour", FALSE);
|
167
|
1078 Pause();
|
|
1079
|
163
|
1080 StatusMsg("Move tree to new configuration", FALSE);
|
|
1081 AnimateTree(TheTree);
|
|
1082
|
|
1083 if (TreeShowSteps) {
|
|
1084 if (parent)
|
|
1085 AnimateZip(parent);
|
|
1086 }
|
|
1087
|
|
1088 BeginFrame();
|
|
1089 SetContours(TreeShowContourOption);
|
|
1090 DrawTree(TheTree, New);
|
|
1091 EndFrame();
|
|
1092
|
|
1093 StatusMsg("Ready", TRUE);
|
167
|
1094 }
|
163
|
1095
|
|
1096 /* ----------------------------------------------------------------------------
|
167
|
1097 *
|
163
|
1098 * DeleteNode() handles the task of deleting a given node in the tree.
|
167
|
1099 *
|
163
|
1100 * ----------------------------------------------------------------------------
|
|
1101 */
|
|
1102
|
|
1103 void
|
167
|
1104 DeleteNode(Tree *node)
|
163
|
1105 {
|
|
1106 Tree *parent;
|
|
1107
|
|
1108 XRectangle *rectangles;
|
|
1109 XSegment *segments;
|
|
1110 int nrectangles, nsegments;
|
|
1111 Widget w = TreeDrawingArea;
|
|
1112 int width, height;
|
|
1113 int x_offset, y_offset;
|
167
|
1114
|
163
|
1115 StatusMsg("", TRUE);
|
|
1116
|
|
1117 if (TreeShowSteps)
|
|
1118 node->on_path = TRUE;
|
167
|
1119
|
163
|
1120 /* erase the contour before changing in the tree */
|
|
1121 if ((TreeShowContourOption != NoContours) ||
|
|
1122 TreeShowSteps) {
|
|
1123 BeginFrame();
|
|
1124 DrawTree(TheTree, New);
|
|
1125 EndFrame();
|
|
1126 }
|
|
1127
|
|
1128 sprintf(strbuf, "Node `%s' selected for deletion", node->label.text);
|
|
1129 StatusMsg(strbuf, FALSE);
|
167
|
1130 Pause();
|
|
1131
|
163
|
1132 parent = node->parent;
|
167
|
1133
|
163
|
1134 if (parent)
|
|
1135 Unzip(parent);
|
|
1136 else
|
|
1137 TheTree = NULL; /* delete root of tree */
|
|
1138
|
|
1139 /* fade out deleted subtree */
|
|
1140 StatusMsg("Delete subtree", FALSE);
|
|
1141 GetSubTreeRectangles(node, &rectangles, &nrectangles, TRUE);
|
|
1142 GetSubTreeSegments(node, &segments, &nsegments);
|
|
1143 DissolveTree(XtDisplay(w), XtWindow(w),
|
|
1144 rectangles, nrectangles,
|
|
1145 segments, nsegments, TRUE);
|
|
1146 free(rectangles);
|
|
1147 free(segments);
|
|
1148
|
|
1149 Delete(node);
|
|
1150
|
|
1151 BeginFrame();
|
167
|
1152 if (TheTree)
|
163
|
1153 DrawTree(TheTree, New);
|
|
1154 EndFrame();
|
167
|
1155 Pause();
|
163
|
1156
|
|
1157 if (parent)
|
|
1158 Zip(parent);
|
167
|
1159
|
163
|
1160 if (TheTree) {
|
|
1161 ComputeTreeSize(TheTree, &width, &height, &x_offset, &y_offset);
|
|
1162 PetrifyTree(TheTree, x_offset + MAT_SIZE, y_offset + MAT_SIZE);
|
|
1163 StatusMsg("Move tree to new configuration", FALSE);
|
|
1164 AnimateTree(TheTree);
|
|
1165 SetDrawingSize(width + (2 * MAT_SIZE), height + (2 * MAT_SIZE));
|
167
|
1166 Pause();
|
163
|
1167
|
|
1168 if (TreeShowSteps) {
|
|
1169 if (parent)
|
|
1170 AnimateZip(parent);
|
|
1171 }
|
|
1172
|
|
1173 BeginFrame();
|
|
1174 SetContours(TreeShowContourOption);
|
|
1175 DrawTree(TheTree, New);
|
|
1176 EndFrame();
|
|
1177
|
|
1178 }
|
|
1179
|
|
1180 StatusMsg("Ready", TRUE);
|
|
1181 }
|
|
1182
|
|
1183
|
|
1184 /* ----------------------------------------------------------------------------
|
167
|
1185 *
|
|
1186 * ResetLabels() is called when the TreeAlignNodes mode is changed.
|
163
|
1187 * When TreeParentDistance changes, the node width changes, so this
|
167
|
1188 * function forces each node's width to be recomputed.
|
|
1189 *
|
163
|
1190 * ----------------------------------------------------------------------------
|
|
1191 */
|
|
1192
|
167
|
1193 void
|
|
1194 ResetLabels(Tree *tree)
|
163
|
1195 {
|
|
1196 Tree *child;
|
167
|
1197
|
163
|
1198 SetNodeLabel(tree, tree->label.text);
|
|
1199 FOREACH_CHILD(child, tree)
|
|
1200 ResetLabels(child);
|
|
1201 }
|
|
1202
|
|
1203
|
|
1204 /* ----------------------------------------------------------------------------
|
167
|
1205 *
|
|
1206 * SetupTree() handles the task of setting up the specified tree in
|
163
|
1207 * the drawing area.
|
167
|
1208 *
|
163
|
1209 * ----------------------------------------------------------------------------
|
|
1210 */
|
|
1211
|
|
1212 void
|
167
|
1213 SetupTree(Tree *tree)
|
163
|
1214 {
|
|
1215 int width, height;
|
|
1216 int x_offset, y_offset;
|
167
|
1217
|
163
|
1218 LayoutTree(tree);
|
|
1219 ComputeTreeSize(tree, &width, &height, &x_offset, &y_offset);
|
|
1220 PetrifyTree(tree, x_offset + MAT_SIZE, y_offset + MAT_SIZE);
|
|
1221 SetDrawingTree(tree);
|
|
1222 SetDrawingSize(width + (2 * MAT_SIZE), height + (2 * MAT_SIZE));
|
|
1223 BeginFrame();
|
|
1224 SetContours(TreeShowContourOption);
|
|
1225 DrawTree(tree, New);
|
|
1226 EndFrame();
|
|
1227 }
|