Change Eclipse configuration
[jabaws.git] / website / archive / binaries / mac / src / muscle / drawtree.cpp
1 #include "muscle.h"\r
2 #include "tree.h"\r
3 \r
4 /***\r
5 Simple tree drawing algorithm.\r
6 \r
7 y coordinate of node is index in depth-first traversal.\r
8 x coordinate is distance from root.\r
9 ***/\r
10 \r
11 static unsigned DistFromRoot(const Tree &tree, unsigned uNodeIndex)\r
12         {\r
13         const unsigned uRoot = tree.GetRootNodeIndex();\r
14         unsigned uDist = 0;\r
15         while (uNodeIndex != uRoot)\r
16                 {\r
17                 ++uDist;\r
18                 uNodeIndex = tree.GetParent(uNodeIndex);\r
19                 }\r
20         return uDist;\r
21         }\r
22 \r
23 static void DrawNode(const Tree &tree, unsigned uNodeIndex)\r
24         {\r
25         if (!tree.IsLeaf(uNodeIndex))\r
26                 DrawNode(tree, tree.GetLeft(uNodeIndex));\r
27 \r
28         unsigned uDist = DistFromRoot(tree, uNodeIndex);\r
29         for (unsigned i = 0; i < 5*uDist; ++i)\r
30                 Log(" ");\r
31         Log("%d\n", uNodeIndex);\r
32 \r
33         if (!tree.IsLeaf(uNodeIndex))\r
34                 DrawNode(tree, tree.GetRight(uNodeIndex));\r
35         }\r
36 \r
37 void DrawTree(const Tree &tree)\r
38         {\r
39         unsigned uRoot = tree.GetRootNodeIndex();\r
40         DrawNode(tree, uRoot);\r
41         }\r