Пример #1
0
        public static GTagBoxTree ExpandNode(GUTag tag, int level, ITagDB db, double x, double y, int direct, Size size, TreeLayoutEnv env, LayoutMode mode)
        {
            Logger.IN(tag.Title);
            Logger.D("Expand " + tag + " " + x + " " + y);
            //已经展开过,直接返回
            if (env.Get(tag) != null)
            {
                Logger.D("FOUND " + tag);
                Logger.OUT();
                return(env.Get(tag));
            }


            //创建子树的根对象
            GTagBoxTree root = new GTagBoxTree();

            root.GTagBox    = new GTagBox(level, tag, x, y, direct);
            root.totalRange = root.GTagBox.OutterBox;
            root.D("计算自身大小(不包括子节点)" + root.GTagBox.Tag);
            env.Add(tag, root);//这个特别需要注意,在递归展开之前,先要将该节点加入DB,否则可能会出现无限递归

            List <GUTag> children     = db.QueryTagChildren(tag);
            List <Size>  childrenSize = new List <Size>();

            GTagBoxTree pre      = null;
            GTagBoxTree cur      = null;
            double      childX   = x + direct * root.GTagBox.OutterBox.Width;
            double      childY   = y;
            int         MaxLevel = CalcMaxLevel(mode);

            //double h = 0;
            //double w = 0;
            if (level < MaxLevel)
            {
                //遍历展开所有子节点
                foreach (GUTag ctag in children)
                {
                    if (env.Get(ctag) != null)
                    {
                        continue;
                    }
                    cur = null;

                    //GTreeObj child = ExpandNode(ctag, level + 1, db, x + root.box.InnerBox.Width, y + h);
                    //h += child.OutBox.Height;
                    //w = Math.Max(w, child.OutBox.Width);
                    switch (mode)
                    {
                    case LayoutMode.TREE_COMPACT_MORE:
                    case LayoutMode.LRTREE_COMPACT_MORE:
                        cur = ExpandChildMoreCompact(level, MaxLevel, db, root, pre, ctag, direct, size, env, mode);
                        break;

                    case LayoutMode.TREE_COMPACT:
                    case LayoutMode.LRTREE_COMPACT:
                        cur = ExpandChildCompact(level, MaxLevel, db, root, pre, ctag, direct, size, env, mode);
                        break;

                    case LayoutMode.TREE_NO_COMPACT:
                    case LayoutMode.LRTREE_NO_COMPACT:
                        cur = ExpandChildNoCompact(level, MaxLevel, db, root, pre, ctag, direct, size, env, mode);
                        break;

                    default:
                        break;
                    }



                    //h += cur.OutBox.Height;
                    //w = Math.Max(w, cur.OutBox.Width);
                    root.totalRange.Union(cur.totalRange);
                    root.Children.Add(cur);


                    pre = cur;
                }
            }

            //根据所有子节点所占区域的大小,计算自己的位置
            //root.OutBox.Width = w + root.box.InnerBox.Width;
            //root.OutBox.Height = Math.Max(h, root.box.InnerBox.Height);
            //root.GTagBox.InnerBox.Y = (root.TotalRange.Top + root.TotalRange.Bottom) / 2;
            root.GTagBox.CenterRootY(root.totalRange);

            root.D(null);
            Logger.OUT();
            return(root);
        }